]> git.xonotic.org Git - xonotic/xonotic.git/commitdiff
handle gametype and map name
authorRudolf Polzer <divVerent@xonotic.org>
Fri, 19 Aug 2011 19:50:05 +0000 (21:50 +0200)
committerRudolf Polzer <divVerent@xonotic.org>
Fri, 19 Aug 2011 19:50:05 +0000 (21:50 +0200)
misc/tools/WeaponEncounterProfile.pm
misc/tools/weapon-profiler-analyzer.pl

index 4218be62325c11a21c888b41504d95e0b1b33f39..55547bbf70be61f164b1fcec8f6413ce2138ef16 100644 (file)
@@ -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);
+                       }
                }
        }
 }
index 1c0415a49cdd987a74439906ff8fe335744824ec..1461d8e50c7b4c0c9f81d172363df5bb2197bc32 100755 (executable)
@@ -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 "<h2>For server @{[$addr || 'any']} map @{[$map || 'any']}:</h2>\n";
+               print "<h2>For server $addr type $type map $map</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";
@@ -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));