From 864c4b3126439d3d84992e1fe78678ab52dac05b Mon Sep 17 00:00:00 2001 From: Rudolf Polzer Date: Fri, 19 Aug 2011 21:50:05 +0200 Subject: [PATCH] handle gametype and map name --- misc/tools/WeaponEncounterProfile.pm | 47 ++++++++++++++++++++------ misc/tools/weapon-profiler-analyzer.pl | 14 ++++---- 2 files changed, 45 insertions(+), 16 deletions(-) diff --git a/misc/tools/WeaponEncounterProfile.pm b/misc/tools/WeaponEncounterProfile.pm index 4218be62..55547bbf 100644 --- a/misc/tools/WeaponEncounterProfile.pm +++ b/misc/tools/WeaponEncounterProfile.pm @@ -17,6 +17,7 @@ sub load($) my ($self) = @_; $self->{stats} = {}; $self->{mapstats} = {}; + $self->{typestats} = {}; $self->{addrstats} = {}; $self->{allstats} = {}; open my $fh, "<", $self->{fn} @@ -53,7 +54,12 @@ sub load($) if $targweapon ne int $targweapon; $attackerweapon = int $self->weaponid_from_name($attackerweapon) if $attackerweapon ne int $attackerweapon; - $self->{stats}->{$addr}{$map}{$attackerweapon}{$targweapon} += $value; + $map =~ /(.*?)_(.*)/ + or do { warn "invalid map name: $map"; next; }; + (my $type, $map) = ($1, $2); + $self->{stats}->{$addr}{$type}{$map}{$attackerweapon}{$targweapon} += $value; + $self->{typestats}->{$type}{$attackerweapon}{$targweapon} += $value; + $self->{typemapstats}->{$type}{$map}{$attackerweapon}{$targweapon} += $value; $self->{mapstats}->{$map}{$attackerweapon}{$targweapon} += $value; $self->{addrstats}->{$addr}{$attackerweapon}{$targweapon} += $value; $self->{allstats}->{$attackerweapon}{$targweapon} += $value; @@ -82,14 +88,19 @@ sub save($) sub event($$$$$$) { - my ($self, $addr, $map, $attackerweapon, $targweapon, $type) = @_; + my ($self, $addr, $map, $attackerweapon, $targweapon, $value) = @_; return if $map eq ''; - if($type > 0) + if($value > 0) { - $self->{stats}->{$addr}{$map}{$attackerweapon}{$targweapon} += $type; - $self->{mapstats}->{$map}{$attackerweapon}{$targweapon} += $type; - $self->{addrstats}->{$addr}{$attackerweapon}{$targweapon} += $type; - $self->{allstats}->{$attackerweapon}{$targweapon} += $type; + $map =~ /(.*?)_(.*)/ + or do { warn "invalid map name: $map"; return; }; + (my $type, $map) = ($1, $2); + $self->{stats}->{$addr}{$type}{$map}{$attackerweapon}{$targweapon} += $value; + $self->{typemapstats}->{$type}{$map}{$attackerweapon}{$targweapon} += $value; + $self->{typestats}->{$type}{$attackerweapon}{$targweapon} += $value; + $self->{mapstats}->{$map}{$attackerweapon}{$targweapon} += $value; + $self->{addrstats}->{$addr}{$attackerweapon}{$targweapon} += $value; + $self->{allstats}->{$attackerweapon}{$targweapon} += $value; } } @@ -101,19 +112,35 @@ sub allstats($$) # send per-host stats while(my ($k, $v) = each %{$self->{addrstats}}) { - $callback->($k, undef, $v); + $callback->($k, undef, undef, $v); + } + # send per-type stats + while(my ($k, $v) = each %{$self->{typestats}}) + { + $callback->(undef, $k, undef, $v); + } + # send per-type-map stats + while(my ($k1, $v1) = each %{$self->{typemapstats}}) + { + while(my ($k2, $v2) = each %$v1) + { + $callback->(undef, $k1, $k2, $v2); + } } # send per-map stats while(my ($k, $v) = each %{$self->{mapstats}}) { - $callback->(undef, $k, $v); + $callback->(undef, undef, $k, $v); } # send single stats while(my ($k1, $v1) = each %{$self->{stats}}) { while(my ($k2, $v2) = each %$v1) { - $callback->($k1, $k2, $v2); + while(my ($k3, $v3) = each %$v2) + { + $callback->($k1, $k2, $k3, $v3); + } } } } diff --git a/misc/tools/weapon-profiler-analyzer.pl b/misc/tools/weapon-profiler-analyzer.pl index 1c0415a4..1461d8e5 100755 --- a/misc/tools/weapon-profiler-analyzer.pl +++ b/misc/tools/weapon-profiler-analyzer.pl @@ -191,10 +191,11 @@ sub out_text($@) } elsif($event eq 'startmatrix') { - my ($addr, $map, @columns) = @data; + my ($addr, $type, $map, @columns) = @data; $addr ||= 'any'; $map ||= 'any'; - print "For server @{[$addr || 'any']} map @{[$map || 'any']}:\n"; + $type ||= 'any'; + print "For server $addr type $type map $map:\n"; } elsif($event eq 'startrow') { @@ -242,10 +243,11 @@ sub out_html($@) } elsif($event eq 'startmatrix') { - my ($addr, $map, @columns) = @data; + my ($addr, $type, $map, @columns) = @data; $addr ||= 'any'; + $type ||= 'any'; $map ||= 'any'; - print "

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

\n"; + print "

For server $addr type $type map $map

\n"; print "\n"; printf '', $stats->weaponid_to_model($_), $stats->weaponid_to_name($_) for @columns; print "\n"; @@ -298,12 +300,12 @@ LoadData(); $out->(start => ()); $stats->allstats(sub { - my ($addr, $map, $data) = @_; + my ($addr, $type, $map, $data) = @_; my $values = Evaluate $data; my $valid = defined [values %$values]->[0]; my @weapons_sorted = sort { $valid ? $values->{$b} <=> $values->{$a} : $a <=> $b } keys %$values; my $min = undef; - $out->(startmatrix => ($addr, $map, @weapons_sorted)); + $out->(startmatrix => ($addr, $type, $map, @weapons_sorted)); for my $row(@weapons_sorted) { $out->(startrow => $row, ($valid ? $values->{$row} : undef)); -- 2.39.2
WeaponRating%s