Mercurial > hg > batmud > misc
changeset 204:0dd8daa71369 misc
Change representation of "total" summary statistics; Internal code cleanups.
author | Matti Hamalainen <ccr@tnsp.org> |
---|---|
date | Wed, 13 Apr 2011 18:36:49 +0300 |
parents | 3918e138d976 |
children | 13bbc57c2afe |
files | magestats.pl |
diffstat | 1 files changed, 103 insertions(+), 98 deletions(-) [+] |
line wrap: on
line diff
--- a/magestats.pl Tue Mar 29 17:27:41 2011 +0300 +++ b/magestats.pl Wed Apr 13 18:36:49 2011 +0300 @@ -27,7 +27,7 @@ # Settings and defaults my $prog_name = "Magestats"; -my $prog_version = "0.7.0"; +my $prog_version = "0.7.5"; my $prog_file = $0; my $opt_cachefile; @@ -126,39 +126,39 @@ my $src = $spell_data{$type}; foreach my $spell (@{$src}) { - $spells->{$spell}{"type"} = $type; - $spells->{$spell}{"blasts"} = 0; - $spells->{"staff"}{$spell}{"blasts"} = 0; + $$spells{$spell}{"type"} = $type; + $$spells{$spell}{"blasts"} = 0; + $$spells{"staff"}{$spell}{"blasts"} = 0; } - $spells->{$type}{"essence"}{"increase"} = 0; - $spells->{$type}{"essence"}{"blasts"}{"single"} = []; - $spells->{$type}{"essence"}{"blasts"}{"area"} = []; - $spells->{$type}{"reinc"} = 0; + $$spells{$type}{"essence"}{"increase"} = 0; + $$spells{$type}{"essence"}{"blasts"}{"single"} = []; + $$spells{$type}{"essence"}{"blasts"}{"area"} = []; + $$spells{$type}{"reinc"} = 0; - $spells->{"staff"}{$type}{"blasts"} = 0; + $$spells{"staff"}{$type}{"blasts"} = 0; - $spells->{$type}{"blasts"} = 0; - $spells->{$type}{"reagents"} = 0; + $$spells{$type}{"blasts"} = 0; + $$spells{$type}{"reagents"} = 0; - $spells->{$type}{"single"} = $src->[0]; - $spells->{$type}{"area"} = $src->[1]; + $$spells{$type}{"single"} = $$src[0]; + $$spells{$type}{"area"} = $$src[1]; foreach my $crit (@crit_types) { - $spells->{$type}{"crits"}{$crit} = 0; + $$spells{$type}{"crits"}{$crit} = 0; } - push(@{$spells->{"single"}}, $src->[0]); - push(@{$spells->{"area"}}, $src->[1]); + push(@{$$spells{"single"}}, $$src[0]); + push(@{$$spells{"area"}}, $$src[1]); } -$spells->{"total"}{"blasts"} = 0; -$spells->{"total"}{"essence"} = 0; -$spells->{"total"}{"reagents"} = 0; +$$spells{"total"}{"blasts"} = 0; +$$spells{"total"}{"essence"} = 0; +$$spells{"total"}{"reagents"} = 0; -$spells->{"staff"}{"desc"} = ""; -$spells->{"staff"}{"data"}{"normal"} = []; -$spells->{"staff"}{"data"}{"ignore"} = []; -$spells->{"staff"}{"total"}{"blasts"} = 0; +$$spells{"staff"}{"desc"} = ""; +$$spells{"staff"}{"data"}{"normal"} = []; +$$spells{"staff"}{"data"}{"ignore"} = []; +$$spells{"staff"}{"total"}{"blasts"} = 0; ### Convert special characters to HTML/XML entities @@ -180,8 +180,8 @@ sub get_spell_type($) { my $spell = $_[0]; - die("get_spell_type($spell): No such spell.\n") unless exists($spells->{$spell}{"type"}); - return $spells->{$spell}{"type"}; + die("get_spell_type($spell): No such spell.\n") unless exists($$spells{$spell}{"type"}); + return $$spells{$spell}{"type"}; } @@ -231,38 +231,38 @@ { my ($desc, $line) = @_; - if ($spells->{"staff"}{"desc"} ne $desc) { - mlog(2, "Staff change '".$spells->{"staff"}{"desc"}."' -> '$desc'\n# $line\n"); + if ($$spells{"staff"}{"desc"} ne $desc) { + mlog(2, "Staff change '".$$spells{"staff"}{"desc"}."' -> '$desc'\n# $line\n"); my %blasts = (); my $area = 0; foreach my $type (keys %spell_data) { foreach my $class ("single", "area") { - my $name = $spells->{$type}{$class}; - $blasts{"ignore"}{$class} += $spells->{"staff"}{$name}{"blasts"}; - $blasts{"normal"}{$class} += $spells->{$name}{"blasts"}; + my $name = $$spells{$type}{$class}; + $blasts{"ignore"}{$class} += $$spells{"staff"}{$name}{"blasts"}; + $blasts{"normal"}{$class} += $$spells{$name}{"blasts"}; } } - push(@{$spells->{"staff"}{"data"}{"normal"}}, + push(@{$$spells{"staff"}{"data"}{"normal"}}, { "desc" => $desc, - "blasts" => $spells->{"total"}{"blasts"}, + "blasts" => $$spells{"total"}{"blasts"}, "major" => $blasts{"normal"}{"single"} + $blasts{"normal"}{"area"}, "single" => $blasts{"normal"}{"single"}, "area" => $blasts{"normal"}{"area"}, }); - push(@{$spells->{"staff"}{"data"}{"ignore"}}, + push(@{$$spells{"staff"}{"data"}{"ignore"}}, { "desc" => $desc, - "blasts" => $spells->{"staff"}{"total"}{"blasts"}, + "blasts" => $$spells{"staff"}{"total"}{"blasts"}, "major" => $blasts{"ignore"}{"single"} + $blasts{"ignore"}{"area"}, "single" => $blasts{"ignore"}{"single"}, "area" => $blasts{"ignore"}{"area"}, }); - $spells->{"staff"}{"desc"} = $desc; + $$spells{"staff"}{"desc"} = $desc; } } @@ -273,14 +273,14 @@ my $type = get_spell_type($last_spell); - $spells->{$last_spell}{"blasts"}++; - $spells->{"total"}{"blasts"}++; - $spells->{$type}{"blasts"}++; + $$spells{$last_spell}{"blasts"}++; + $$spells{"total"}{"blasts"}++; + $$spells{$type}{"blasts"}++; if ($staff_worn) { - $spells->{"staff"}{$last_spell}{"blasts"}++; - $spells->{"staff"}{"total"}{"blasts"}++; - $spells->{"staff"}{$type}{"blasts"}++; + $$spells{"staff"}{$last_spell}{"blasts"}++; + $$spells{"staff"}{"total"}{"blasts"}++; + $$spells{"staff"}{$type}{"blasts"}++; } # If essence was gained, get the type etc .. @@ -288,17 +288,17 @@ $essence_flag = 0; # Handle the post-reinc essence increase - if ($spells->{$type}{"reinc"}) { + if ($$spells{$type}{"reinc"}) { mlog(2, "Ignoring post-reinc essence gain for type $type.\n"); - $spells->{$type}{"reinc"} = 0; + $$spells{$type}{"reinc"} = 0; } else { - $spells->{"total"}{"essence"}++; - $spells->{$type}{"essence"}{"increase"}++; + $$spells{"total"}{"essence"}++; + $$spells{$type}{"essence"}{"increase"}++; # Save amount of major blasts for each "essence gain" step foreach my $class ("single", "area") { - my $name = $spells->{$type}{$class}; - push(@{$spells->{$type}{"essence"}{"blasts"}{$class}}, $spells->{$name}{"blasts"}); + my $name = $$spells{$type}{$class}; + push(@{$$spells{$type}{"essence"}{"blasts"}{$class}}, $$spells{$name}{"blasts"}); } } } @@ -307,7 +307,7 @@ if ($crit_flag) { $crit_flag = 0; # print STDERR "crit: $type : $last_spell : $crit_type\n"; - $spells->{$type}{"crits"}{$crit_type}++; + $$spells{$type}{"crits"}{$crit_type}++; } } @@ -369,7 +369,7 @@ } elsif ($s =~ /^Time to choose your reincarnation method./) { # Set reinc flags for each type that has essence foreach my $type (keys %spell_data) { - $spells->{$type}{"reinc"} = 1 if ($spells->{$type}{"essence"}{"increase"} > 0); + $$spells{$type}{"reinc"} = 1 if ($$spells{$type}{"essence"}{"increase"} > 0); } } elsif ($s =~ /^You watch with selfpride as your ($match) hits / || $s =~ /^You hit .+? with your ($match)\.$/) { spell_update($1) if ($gflag == 0); @@ -382,8 +382,8 @@ } elsif ($s =~ /^Your knowledge in elemental powers helps you to save the reagent for further use\./) { if ($last_spell ne "") { my $type = get_spell_type($last_spell); - $spells->{$type}{"reagents"}++; - $spells->{"total"}{"reagents"}++; + $$spells{$type}{"reagents"}++; + $$spells{"total"}{"reagents"}++; } } elsif ($s =~ /^You feel your skills in handling elemental forces improve\./) { $essence_flag = 1; @@ -486,6 +486,7 @@ } table.blasts { + width: 100%; background: #464; } @@ -518,10 +519,10 @@ my $tab = $opt_ignore ? "ignore" : "normal"; -foreach my $foo (@{$spells->{"staff"}{"data"}{$tab}}) { - print OUT "<tr><td>".$foo->{"blasts"}."</td><td>". - $foo->{"major"}."</td><td>".$foo->{"single"}."</td><td>". - $foo->{"area"}."</td><td>".htmlentities($foo->{"desc"})."</td></tr>\n"; +foreach my $foo (@{$$spells{"staff"}{"data"}{$tab}}) { + print OUT "<tr><td>".$$foo{"blasts"}."</td><td>". + $$foo{"major"}."</td><td>".$$foo{"single"}."</td><td>". + $$foo{"area"}."</td><td>".htmlentities($$foo{"desc"})."</td></tr>\n"; } print OUT " @@ -533,12 +534,9 @@ <li><b>Singles</b>: Major single blasts.</li> <li><b>Areas</b>: Major area blasts.</li> </ul> -"; - -print OUT qq| <h2>Blasts, essence, etc</h2> -<table class="info"> +<table class=\"info\"> <tr> <th>Type</th> <th>Blasts</th> @@ -546,20 +544,41 @@ <th>Essence gained</th> <th>Major blasts per essence gain</th> </tr> -|; +"; + +my %dographs = (); -my $major_blasts = 0; -foreach my $type (sort { $a cmp $b } keys %spell_data) { - if ($spells->{$type}{"blasts"} > 0) { +$dographs{"ALL"} = 1; +foreach my $type (keys %spell_data) { + next unless ($$spells{$type}{"blasts"} > 0); + + foreach my $crit (@crit_types) { + $$spells{"ALL"}{"crits"}{$crit} += $$spells{$type}{"crits"}{$crit}; + } + $$spells{"ALL"}{"reagents"} += $$spells{$type}{"reagents"}; + $$spells{"ALL"}{"blasts"} += $$spells{$type}{"blasts"}; + $$spells{"ALL"}{"essence"}{"increase"} += $$spells{$type}{"essence"}{"increase"}; - my $s_s = $spells->{$type}{"single"}; - my $s_a = $spells->{$type}{"area"}; + my $s_s = $$spells{$type}{"single"}; + my $s_a = $$spells{$type}{"area"}; + $$spells{"ALL"}{"single"} = "ALL_SINGLE"; + $$spells{"ALL"}{"area"} = "ALL_AREA"; + $$spells{"ALL_SINGLE"}{"blasts"} += $$spells{$s_s}{"blasts"}; + $$spells{"ALL_AREA"}{"blasts"} += $$spells{$s_a}{"blasts"}; + $dographs{$type} = 1; +} + - my $b_s = $spells->{$s_s}{"blasts"}; - my $b_a = $spells->{$s_a}{"blasts"}; - +foreach my $type (sort { $a cmp $b } keys %dographs) { + + my $s_s = $$spells{$type}{"single"}; + my $s_a = $$spells{$type}{"area"}; + + my $b_s = $$spells{$s_s}{"blasts"}; + my $b_a = $$spells{$s_a}{"blasts"}; my $total_blasts = $b_s + $b_a; - $major_blasts += $total_blasts; + + next unless ($total_blasts > 0); print OUT "<tr><td>$type</td><td> <table class=\"blasts\"><th></th><th>Single</th><th>Area</th></tr> @@ -568,43 +587,27 @@ <tr><th>Total</th><td colspan=\"2\">".$total_blasts."</td></tr>"; foreach my $crit (@crit_types) { - print OUT "<tr><th>$crit</th><td colspan=\"2\">".$spells->{$type}{"crits"}{$crit}."</td></tr>\n"; + print OUT "<tr><th>$crit</th><td colspan=\"2\">".$$spells{$type}{"crits"}{$crit}."</td></tr>\n"; } - printf OUT "</table></td><td><b>%d</b> (%1.2f %%)</td><td>%d</td><td>", - $spells->{$type}{"reagents"}, - ($total_blasts > 0) ? ($spells->{$type}{"reagents"} * 100.0) / $total_blasts : 0.0, - $spells->{$type}{"essence"}{"increase"}; + $$spells{$type}{"reagents"}, + ($total_blasts > 0) ? ($$spells{$type}{"reagents"} * 100.0) / $total_blasts : 0.0, + $$spells{$type}{"essence"}{"increase"}; - if (exists($spells->{$type}{"essence"}{"blasts"})) { + if ($type ne "ALL" && exists($$spells{$type}{"essence"}{"blasts"})) { my ($gfilename, $gpath, $gsuffix) = fileparse($opt_prefix); print OUT "<img src=\"".$gfilename.$gsuffix."_".$type.".".$opt_imgfmt."\" alt=\"?\" />"; + } else { + $dographs{$type} = 0; } print OUT " </td> </tr>\n"; - } } print OUT "</table> - -<p> -Total major blasts: <b>".$major_blasts."</b><br /> -Total blasts: <b>".$spells->{"total"}{"blasts"}."</b> (including minor)<br /> -Total reagents saved: <b>".$spells->{"total"}{"reagents"}."</b>"; - -if ($spells->{"total"}{"reagents"} > 0) { - printf OUT " (<b>%1.2f%%</b> of blasts)", ($spells->{"total"}{"reagents"} * 100.0) / $major_blasts; -} - -print OUT "<br /> -Total essence gained: <b>".$spells->{"total"}{"essence"}."</b><br /> -</p> -"; - -print OUT " </body> </html> "; @@ -615,9 +618,11 @@ ### mlog(1, "Outputting graphs '".$opt_prefix."_*.".$opt_imgfmt."'..."); -foreach my $type (sort { $a cmp $b } keys %spell_data) { - my $s = $spells->{$type}{"single"}; - my $a = $spells->{$type}{"area"}; +foreach my $type (keys %dographs) { + next unless $dographs{$type}; + + my $s = $$spells{$type}{"single"}; + my $a = $$spells{$type}{"area"}; my $graph = GD::Graph::linespoints->new($opt_width, $opt_height); $graph->set( @@ -629,13 +634,13 @@ ); my @titles = (); - for (my $i = 1; $i <= $spells->{$type}{"essence"}{"increase"}; $i++) { + for (my $i = 1; $i <= $$spells{$type}{"essence"}{"increase"}; $i++) { push(@titles, "+".$i); } my @total = (); - for (my $i = 0; $i < $spells->{$type}{"essence"}{"increase"}; $i++) { - push(@total, $spells->{$type}{"essence"}{"blasts"}{"single"}[$i] + $spells->{$type}{"essence"}{"blasts"}{"area"}[$i]); + for (my $i = 0; $i < $$spells{$type}{"essence"}{"increase"}; $i++) { + push(@total, $$spells{$type}{"essence"}{"blasts"}{"single"}[$i] + $$spells{$type}{"essence"}{"blasts"}{"area"}[$i]); } my @data = (