[nexuiz-commits] r6866 - trunk/misc/tools

DONOTREPLY at icculus.org DONOTREPLY at icculus.org
Fri Jun 5 03:26:23 EDT 2009


Author: div0
Date: 2009-06-05 03:26:20 -0400 (Fri, 05 Jun 2009)
New Revision: 6866

Modified:
   trunk/misc/tools/WeaponEncounterProfile.pm
   trunk/misc/tools/weapon-profiler-analyzer.pl
   trunk/misc/tools/weapon-profiler.pl
Log:
html output


Modified: trunk/misc/tools/WeaponEncounterProfile.pm
===================================================================
--- trunk/misc/tools/WeaponEncounterProfile.pm	2009-06-05 07:02:17 UTC (rev 6865)
+++ trunk/misc/tools/WeaponEncounterProfile.pm	2009-06-05 07:26:20 UTC (rev 6866)
@@ -25,6 +25,10 @@
 	{
 		chomp;
 		my ($addr, $map, $attackerweapon, $targweapon, $value) = split /\t/, $_;
+		$targweapon = int $self->weaponid_from_name($targweapon)
+			if $targweapon ne int $targweapon;
+		$attackerweapon = int $self->weaponid_from_name($attackerweapon)
+			if $attackerweapon ne int $attackerweapon;
 		$self->{stats}->{$addr}{$map}{$attackerweapon}{$targweapon} += $value;
 		$self->{mapstats}->{$map}{$attackerweapon}{$targweapon} += $value;
 		$self->{addrstats}->{$addr}{$attackerweapon}{$targweapon} += $value;
@@ -90,4 +94,50 @@
 	}
 }
 
+our %WeaponMap = (
+         1 => ["Laser", "laser"],
+         2 => ["Shotgun", "shotgun"],
+         3 => ["Uzi", "uzi"],
+         4 => ["Mortar", "gl"],
+         5 => ["Electro", "electro"],
+         6 => ["Crylink", "crylink"],
+         7 => ["Nex", "nex"],
+         8 => ["Hagar", "hagar"],
+         9 => ["Rocket Launcher", "rl"],
+        10 => ["Port-O-Launch", "porto"],
+        11 => ["MinstaNex", "minstanex"],
+        12 => ["Grappling Hook", "hookgun"],
+        13 => ["Heavy Laser Assault Cannon", "hlac"],
+        14 => ["T.A.G. Seeker", "seeker"],
+        15 => ["Camping Rifle", "campingrifle"],
+);
+
+sub weaponid_valid($$)
+{
+	my ($self, $id) = @_;
+	return exists $WeaponMap{$id};
+}
+
+sub weaponid_to_name($$)
+{
+	my ($self, $id) = @_;
+	return $WeaponMap{$id}[0];
+}
+
+sub weaponid_to_model($$)
+{
+	my ($self, $id) = @_;
+	return $WeaponMap{$id}[1];
+}
+
+sub weaponid_from_name($$)
+{
+	my ($self, $name) = @_;
+	for(keys %WeaponMap)
+	{
+		return $_
+			if $WeaponMap{$_}[0] eq $name;
+	}
+}
+
 1;

Modified: trunk/misc/tools/weapon-profiler-analyzer.pl
===================================================================
--- trunk/misc/tools/weapon-profiler-analyzer.pl	2009-06-05 07:02:17 UTC (rev 6865)
+++ trunk/misc/tools/weapon-profiler-analyzer.pl	2009-06-05 07:26:20 UTC (rev 6866)
@@ -136,8 +136,6 @@
 			++$allweps{$k2};
 		}
 	}
-	delete $allweps{"@!#%'n Tuba"};
-#delete $allweps{"Port-O-Launch"};
 	my @allweps = keys %allweps;
 	my %values;
 
@@ -200,7 +198,7 @@
 	elsif($event eq 'startrow')
 	{
 		my ($row, $val) = @data;
-		printf "  %-30s %8s |", $row, defined $val ? sprintf("%8.5f", $val) : "N/A";
+		printf "  %-30s %8s |", $stats->weaponid_to_name($row), defined $val ? sprintf("%8.5f", $val) : "N/A";
 	}
 	elsif($event eq 'cell')
 	{
@@ -231,14 +229,69 @@
 	}
 	elsif($event eq 'end')
 	{
+	}
+}
+
+sub out_html($@)
+{
+	my ($event, @data) = @_;
+	if($event eq 'start')
+	{
+		print "<html><body><h1>Weapon Profiling</h1>\n";
+	}
+	elsif($event eq 'startmatrix')
+	{
+		my ($addr, $map, @columns) = @data;
+		$addr ||= 'any';
+		$map ||= 'any';
+		print "<h2>For server @{[$addr || 'any']} map @{[$map || 'any']}:</h2>\n";
+		print "<table><tr><th>Weapon</th><th>Rating</th>\n";
+		printf '<th><img width=70 height=80 src="http://svn.icculus.org/*checkout*/nexuiz/trunk/Docs/htmlfiles/weaponimg/thirdperson-%s.png" alt="%s"></th>', $stats->weaponid_to_model($_), $stats->weaponid_to_name($_) for @columns;
+		print "</tr>\n";
+	}
+	elsif($event eq 'startrow')
+	{
+		my ($row, $val) = @data;
+		printf '<tr><th><img width=108 height=53 src="http://svn.icculus.org/*checkout*/nexuiz/trunk/Docs/htmlfiles/weaponimg/firstperson-%s.png" alt="%s"></th><th align=right>%s</th>', $stats->weaponid_to_model($row), $stats->weaponid_to_name($row), defined $val ? sprintf("%8.5f", $val) : "N/A";
+	}
+	elsif($event eq 'cell')
+	{
+		my ($win, $lose, $p) = @data;
+		my $v = 200;
+		if(!defined $p)
+		{
+			printf '<td align=center bgcolor="#808080">%d</td>', $win;
+		}
+		elsif($p > 0)
+		{
+			printf '<td align=center bgcolor="#%02x%02x%02x">%d</td>', $v - $v * $p, 255, 0, $win;
+		}
+		elsif($p < 0)
+		{
+			#printf '<td align=center bgcolor="#%02x%02x%02x">%d</td>', (255 - $v) - $v * $p, $v + $v * $p, 0, $win;
+			printf '<td align=center bgcolor="#%02x%02x%02x">%d</td>', 255, $v + $v * $p, 0, $win;
+		}
+		else
+		{
+			printf '<td align=center bgcolor="#ffff00">%d</td>', $win;
+		}
+	}
+	elsif($event eq 'endrow')
+	{
+		print "</tr>";
+	}
+	elsif($event eq 'endmatrix')
+	{
 		my ($min) = @data;
 		$min ||= 0;
-		print "  Relevance: $min\n";
-		print "\n";
+		print "</table>Relevance: $min\n";
 	}
+	elsif($event eq 'end')
+	{
+	}
 }
 
-my $out = \&out_text;
+my $out = $ENV{html} ? \&out_html : \&out_text;
 
 LoadData();
 $out->(start => ());
@@ -247,7 +300,7 @@
 	my ($addr, $map, $data) = @_;
 	my $values = Evaluate $data;
 	my $valid = defined [values %$values]->[0];
-	my @weapons_sorted = sort { $valid ? $values->{$b} <=> $values->{$a} : $a cmp $b } keys %$values;
+	my @weapons_sorted = sort { $valid ? $values->{$b} <=> $values->{$a} : $a <=> $b } keys %$values;
 	my $min = undef;
 	$out->(startmatrix => ($addr, $map, @weapons_sorted));
 	for my $row(@weapons_sorted)
@@ -263,6 +316,6 @@
 		}
 		$out->(endrow => ());
 	}
-	$out->(endmatrix => ($addr, $min));
+	$out->(endmatrix => ($min));
 });
 $out->(end => ());

Modified: trunk/misc/tools/weapon-profiler.pl
===================================================================
--- trunk/misc/tools/weapon-profiler.pl	2009-06-05 07:02:17 UTC (rev 6865)
+++ trunk/misc/tools/weapon-profiler.pl	2009-06-05 07:26:20 UTC (rev 6866)
@@ -12,25 +12,6 @@
 use sigtrap qw(die normal-signals);
 use WeaponEncounterProfile;
 
-my %weaponmap = (
-         1 => "Laser",
-         2 => "Shotgun",
-         3 => "Uzi",
-         4 => "Mortar",
-         5 => "Electro",
-         6 => "Crylink",
-         7 => "Nex",
-         8 => "Hagar",
-         9 => "Rocket Launcher",
-        10 => "Port-O-Launch",
-        11 => "MinstaNex",
-        12 => "Grappling Hook",
-        13 => "Heavy Laser Assault Cannon",
-        14 => "T.A.G. Seeker",
-        15 => "Camping Rifle",
-	0 => "@!#%'n Tuba"
-);
-
 my ($statsfile) = @ARGV;
 my $password = $ENV{rcon_password};
 my $server = $ENV{rcon_address};
@@ -173,13 +154,11 @@
 			$type &= 0xFF
 				if $type < 10000;
 			$killweapon = $type
-				if defined $weaponmap{$type}; # if $type is not a weapon deathtype, count the weapon of the killer
+				if $stats->weaponid_valid($type); # if $type is not a weapon deathtype, count the weapon of the killer
 			$killweapon = 0
-				if not defined $weaponmap{$killweapon}; # invalid weapon? that's 0 then
+				if not $stats->weaponid_valid($killweapon); # invalid weapon? that's 0 then
 			$victimweapon = 0
-				if not defined $weaponmap{$victimweapon}; # dito
-			$killweapon = $weaponmap{$killweapon};
-			$victimweapon = $weaponmap{$victimweapon};
+				if not $stats->weaponid_valid($victimweapon); # dito
 			next
 				if $killflags =~ /S|I/ or $victimflags =~ /T/; # no strength, shield or typekills (these skew the statistics)
 			AddKill($addr, $currentmap{$addr}, $killweapon, $victimweapon, +1);
@@ -190,10 +169,9 @@
 			$type &= 0xFF
 				if $type < 10000;
 			$killweapon = $type
-				if defined $weaponmap{$type};
+				if $stats->weaponid_valid($type);
 			$killweapon = 0
-				if not defined $weaponmap{$killweapon};
-			$killweapon = $weaponmap{$killweapon};
+				if not $stats->weaponid_valid($killweapon);
 			next
 				if $killflags =~ /S/; # no strength suicides (happen too easily accidentally)
 			AddKill($addr, $currentmap{$addr}, $killweapon, $killweapon, +1);



More information about the nexuiz-commits mailing list