#!/usr/bin/perl

print "Args: @ARGV";

$i = 0;

print "Reading uniq.csv\n";

open (UNIQ_FILE,"<uniq.csv");

while (<UNIQ_FILE>)
{
	chomp;

	@uniq_line = split(/;/);

	for ($i = 1;$i <= $#uniq_line; $i++)
	{
		$uniq{$uniq_line[0]}{$uniq_line[$i]} = 1;
	}
}

close (UNIQ_FILE);

print "Done.\n";

($team_name) = split(/_/,$ARGV[0]);

print "Processing for team $team_name...\n";

open (PART_FILE,"$ARGV[0]");

while (<PART_FILE>)
{
	chomp;
	@line = split(/;/);

	if($uniq{$line[3]}{$team_name} != 1)	
	{
		print "Adding unique: $line[3]\n";
		$uniq{$line[3]}{$team_name} = 1;
	}
}

open (UNIQ_FILE,">uniq.csv");

foreach $bssid (keys %uniq)
{
	print "$bssid was found by";

	print UNIQ_FILE "$bssid";

	foreach $team_name (keys %{$uniq{$line[3]}})
	{
		print " $team_name";

		print UNIQ_FILE ";$team_name";
	}

	print "\n";

	print UNIQ_FILE "\n";
}

close (UNIQ_FILE);
