From c13c1e33dddbd19c3694e4b4f32c01c4ca6bb051 Mon Sep 17 00:00:00 2001 From: div0 Date: Fri, 5 Jun 2009 07:26:20 +0000 Subject: [PATCH] html output git-svn-id: svn://svn.icculus.org/nexuiz/trunk@6866 f962a42d-fe04-0410-a3ab-8c8b0445ebaa --- misc/tools/WeaponEncounterProfile.pm | 50 +++++++++++++++++++ misc/tools/weapon-profiler-analyzer.pl | 69 +++++++++++++++++++++++--- misc/tools/weapon-profiler.pl | 32 ++---------- 3 files changed, 116 insertions(+), 35 deletions(-) diff --git a/misc/tools/WeaponEncounterProfile.pm b/misc/tools/WeaponEncounterProfile.pm index f1b0f8f78..2c338fdf9 100644 --- a/misc/tools/WeaponEncounterProfile.pm +++ b/misc/tools/WeaponEncounterProfile.pm @@ -25,6 +25,10 @@ sub load($) { 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 @@ sub allstats($$) } } +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; diff --git a/misc/tools/weapon-profiler-analyzer.pl b/misc/tools/weapon-profiler-analyzer.pl index c87970f5c..5681ee0e1 100755 --- a/misc/tools/weapon-profiler-analyzer.pl +++ b/misc/tools/weapon-profiler-analyzer.pl @@ -136,8 +136,6 @@ sub Evaluate($) ++$allweps{$k2}; } } - delete $allweps{"@!#%'n Tuba"}; -#delete $allweps{"Port-O-Launch"}; my @allweps = keys %allweps; my %values; @@ -200,7 +198,7 @@ sub out_text($@) 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') { @@ -230,15 +228,70 @@ sub out_text($@) print "\n"; } elsif($event eq 'end') + { + } +} + +sub out_html($@) +{ + my ($event, @data) = @_; + if($event eq 'start') + { + print "

Weapon Profiling

\n"; + } + elsif($event eq 'startmatrix') + { + my ($addr, $map, @columns) = @data; + $addr ||= 'any'; + $map ||= 'any'; + print "

For server @{[$addr || 'any']} map @{[$map || 'any']}:

\n"; + print "\n"; + printf '', $stats->weaponid_to_model($_), $stats->weaponid_to_name($_) for @columns; + print "\n"; + } + elsif($event eq 'startrow') + { + my ($row, $val) = @data; + printf '', $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 '', $win; + } + elsif($p > 0) + { + printf '', $v - $v * $p, 255, 0, $win; + } + elsif($p < 0) + { + #printf '', (255 - $v) - $v * $p, $v + $v * $p, 0, $win; + printf '', 255, $v + $v * $p, 0, $win; + } + else + { + printf '', $win; + } + } + elsif($event eq 'endrow') + { + print ""; + } + elsif($event eq 'endmatrix') { my ($min) = @data; $min ||= 0; - print " Relevance: $min\n"; - print "\n"; + print "
WeaponRating%s
%s%s%d%d%d%d%d
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 @@ $stats->allstats(sub 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 @@ $stats->allstats(sub } $out->(endrow => ()); } - $out->(endmatrix => ($addr, $min)); + $out->(endmatrix => ($min)); }); $out->(end => ()); diff --git a/misc/tools/weapon-profiler.pl b/misc/tools/weapon-profiler.pl index 5f62b0dae..2cc58d251 100755 --- a/misc/tools/weapon-profiler.pl +++ b/misc/tools/weapon-profiler.pl @@ -12,25 +12,6 @@ use Socket; 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 @@ while(my $addr = sockaddr_readable $sock->recv($_, 2048, 0)) $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 @@ while(my $addr = sockaddr_readable $sock->recv($_, 2048, 0)) $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); -- 2.39.2