annotate icesusplaque.pl @ 350:14b3b8dfc797 misc

Cleanups.
author Matti Hamalainen <ccr@tnsp.org>
date Fri, 20 Oct 2017 23:05:27 +0300
parents c79dd30a368f
children
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
350
14b3b8dfc797 Cleanups.
Matti Hamalainen <ccr@tnsp.org>
parents: 240
diff changeset
1 #!/usr/bin/perl -w
14b3b8dfc797 Cleanups.
Matti Hamalainen <ccr@tnsp.org>
parents: 240
diff changeset
2 #
14b3b8dfc797 Cleanups.
Matti Hamalainen <ccr@tnsp.org>
parents: 240
diff changeset
3 # Icesus top player plaque parser
134
b2685ec16e67 Update copyrights, add comments.
Matti Hamalainen <ccr@tnsp.org>
parents: 104
diff changeset
4 # Developed by Matti Hämäläinen (Ggr Pupunen) <ccr@tnsp.org>
b2685ec16e67 Update copyrights, add comments.
Matti Hamalainen <ccr@tnsp.org>
parents: 104
diff changeset
5 # (C) Copyright 2010 Tecnic Software productions (TNSP)
350
14b3b8dfc797 Cleanups.
Matti Hamalainen <ccr@tnsp.org>
parents: 240
diff changeset
6 #
14b3b8dfc797 Cleanups.
Matti Hamalainen <ccr@tnsp.org>
parents: 240
diff changeset
7 # Inputs a logfile with multiple Icesus top player plaque listings
14b3b8dfc797 Cleanups.
Matti Hamalainen <ccr@tnsp.org>
parents: 240
diff changeset
8 # and outputs a plaque with changed positions etc.
134
b2685ec16e67 Update copyrights, add comments.
Matti Hamalainen <ccr@tnsp.org>
parents: 104
diff changeset
9 #
350
14b3b8dfc797 Cleanups.
Matti Hamalainen <ccr@tnsp.org>
parents: 240
diff changeset
10 use strict;
14b3b8dfc797 Cleanups.
Matti Hamalainen <ccr@tnsp.org>
parents: 240
diff changeset
11 use warnings;
14b3b8dfc797 Cleanups.
Matti Hamalainen <ccr@tnsp.org>
parents: 240
diff changeset
12 use Date::Parse;
14b3b8dfc797 Cleanups.
Matti Hamalainen <ccr@tnsp.org>
parents: 240
diff changeset
13
104
fb5a3f75cfa3 Added script for generating 'weekly' exp plaques from icesus top player plaque logs, made for Nuane by request.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
14
350
14b3b8dfc797 Cleanups.
Matti Hamalainen <ccr@tnsp.org>
parents: 240
diff changeset
15 ### Settings
14b3b8dfc797 Cleanups.
Matti Hamalainen <ccr@tnsp.org>
parents: 240
diff changeset
16 my $opt_sep = 0;
14b3b8dfc797 Cleanups.
Matti Hamalainen <ccr@tnsp.org>
parents: 240
diff changeset
17 my $opt_topexp = 0;
14b3b8dfc797 Cleanups.
Matti Hamalainen <ccr@tnsp.org>
parents: 240
diff changeset
18 my $opt_plaque = 0;
14b3b8dfc797 Cleanups.
Matti Hamalainen <ccr@tnsp.org>
parents: 240
diff changeset
19 my $opt_filename = shift or die("Usage: [perl] $0 <logfilename> [-p] [-s] [-t]\n");
14b3b8dfc797 Cleanups.
Matti Hamalainen <ccr@tnsp.org>
parents: 240
diff changeset
20
14b3b8dfc797 Cleanups.
Matti Hamalainen <ccr@tnsp.org>
parents: 240
diff changeset
21
14b3b8dfc797 Cleanups.
Matti Hamalainen <ccr@tnsp.org>
parents: 240
diff changeset
22 ### Helper functions
104
fb5a3f75cfa3 Added script for generating 'weekly' exp plaques from icesus top player plaque logs, made for Nuane by request.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
23 sub get_period($)
fb5a3f75cfa3 Added script for generating 'weekly' exp plaques from icesus top player plaque logs, made for Nuane by request.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
24 {
350
14b3b8dfc797 Cleanups.
Matti Hamalainen <ccr@tnsp.org>
parents: 240
diff changeset
25 my @paskat = (30*24*60*60, 7*24*60*60, 24*60*60, 60*60, 60);
14b3b8dfc797 Cleanups.
Matti Hamalainen <ccr@tnsp.org>
parents: 240
diff changeset
26 my @opaskat = ("months", "weeks", "days", "hours", "minutes");
14b3b8dfc797 Cleanups.
Matti Hamalainen <ccr@tnsp.org>
parents: 240
diff changeset
27 my @upaskat = ("month", "week", "day", "hour", "minute");
104
fb5a3f75cfa3 Added script for generating 'weekly' exp plaques from icesus top player plaque logs, made for Nuane by request.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
28 my $cur = $_[0];
350
14b3b8dfc797 Cleanups.
Matti Hamalainen <ccr@tnsp.org>
parents: 240
diff changeset
29 if ($cur >= 0)
14b3b8dfc797 Cleanups.
Matti Hamalainen <ccr@tnsp.org>
parents: 240
diff changeset
30 {
104
fb5a3f75cfa3 Added script for generating 'weekly' exp plaques from icesus top player plaque logs, made for Nuane by request.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
31 my $str = "";
fb5a3f75cfa3 Added script for generating 'weekly' exp plaques from icesus top player plaque logs, made for Nuane by request.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
32 my ($r, $k, $p, $n);
fb5a3f75cfa3 Added script for generating 'weekly' exp plaques from icesus top player plaque logs, made for Nuane by request.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
33 $n = 0;
350
14b3b8dfc797 Cleanups.
Matti Hamalainen <ccr@tnsp.org>
parents: 240
diff changeset
34 foreach my $div (@paskat)
14b3b8dfc797 Cleanups.
Matti Hamalainen <ccr@tnsp.org>
parents: 240
diff changeset
35 {
104
fb5a3f75cfa3 Added script for generating 'weekly' exp plaques from icesus top player plaque logs, made for Nuane by request.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
36 $r = int($cur / $div);
fb5a3f75cfa3 Added script for generating 'weekly' exp plaques from icesus top player plaque logs, made for Nuane by request.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
37 $k = ($cur % $div);
350
14b3b8dfc797 Cleanups.
Matti Hamalainen <ccr@tnsp.org>
parents: 240
diff changeset
38 if ($r > 0)
14b3b8dfc797 Cleanups.
Matti Hamalainen <ccr@tnsp.org>
parents: 240
diff changeset
39 {
104
fb5a3f75cfa3 Added script for generating 'weekly' exp plaques from icesus top player plaque logs, made for Nuane by request.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
40 $p = ($r > 1) ? $opaskat[$n] : $upaskat[$n];
fb5a3f75cfa3 Added script for generating 'weekly' exp plaques from icesus top player plaque logs, made for Nuane by request.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
41 $str .= ", " if ($str ne "");
fb5a3f75cfa3 Added script for generating 'weekly' exp plaques from icesus top player plaque logs, made for Nuane by request.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
42 $str .= sprintf("%d %s", $r, $p);
fb5a3f75cfa3 Added script for generating 'weekly' exp plaques from icesus top player plaque logs, made for Nuane by request.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
43 }
fb5a3f75cfa3 Added script for generating 'weekly' exp plaques from icesus top player plaque logs, made for Nuane by request.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
44 $cur = $k;
fb5a3f75cfa3 Added script for generating 'weekly' exp plaques from icesus top player plaque logs, made for Nuane by request.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
45 $n++;
fb5a3f75cfa3 Added script for generating 'weekly' exp plaques from icesus top player plaque logs, made for Nuane by request.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
46 }
fb5a3f75cfa3 Added script for generating 'weekly' exp plaques from icesus top player plaque logs, made for Nuane by request.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
47 return $str;
350
14b3b8dfc797 Cleanups.
Matti Hamalainen <ccr@tnsp.org>
parents: 240
diff changeset
48 }
14b3b8dfc797 Cleanups.
Matti Hamalainen <ccr@tnsp.org>
parents: 240
diff changeset
49 else
14b3b8dfc797 Cleanups.
Matti Hamalainen <ccr@tnsp.org>
parents: 240
diff changeset
50 {
104
fb5a3f75cfa3 Added script for generating 'weekly' exp plaques from icesus top player plaque logs, made for Nuane by request.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
51 return "?";
fb5a3f75cfa3 Added script for generating 'weekly' exp plaques from icesus top player plaque logs, made for Nuane by request.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
52 }
fb5a3f75cfa3 Added script for generating 'weekly' exp plaques from icesus top player plaque logs, made for Nuane by request.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
53 }
350
14b3b8dfc797 Cleanups.
Matti Hamalainen <ccr@tnsp.org>
parents: 240
diff changeset
54
14b3b8dfc797 Cleanups.
Matti Hamalainen <ccr@tnsp.org>
parents: 240
diff changeset
55
14b3b8dfc797 Cleanups.
Matti Hamalainen <ccr@tnsp.org>
parents: 240
diff changeset
56 sub fmt_num($)
14b3b8dfc797 Cleanups.
Matti Hamalainen <ccr@tnsp.org>
parents: 240
diff changeset
57 {
14b3b8dfc797 Cleanups.
Matti Hamalainen <ccr@tnsp.org>
parents: 240
diff changeset
58 my $s = sprintf("%1.0f", $_[0]);
14b3b8dfc797 Cleanups.
Matti Hamalainen <ccr@tnsp.org>
parents: 240
diff changeset
59 $s =~ s/\d{1,3}(?=(\d{3})+(?!\d))/$&,/g if ($opt_sep);
14b3b8dfc797 Cleanups.
Matti Hamalainen <ccr@tnsp.org>
parents: 240
diff changeset
60 return $s;
14b3b8dfc797 Cleanups.
Matti Hamalainen <ccr@tnsp.org>
parents: 240
diff changeset
61 }
14b3b8dfc797 Cleanups.
Matti Hamalainen <ccr@tnsp.org>
parents: 240
diff changeset
62
14b3b8dfc797 Cleanups.
Matti Hamalainen <ccr@tnsp.org>
parents: 240
diff changeset
63
14b3b8dfc797 Cleanups.
Matti Hamalainen <ccr@tnsp.org>
parents: 240
diff changeset
64 sub fmt_value($$$)
14b3b8dfc797 Cleanups.
Matti Hamalainen <ccr@tnsp.org>
parents: 240
diff changeset
65 {
14b3b8dfc797 Cleanups.
Matti Hamalainen <ccr@tnsp.org>
parents: 240
diff changeset
66 if ($_[0] == $_[1]) {
14b3b8dfc797 Cleanups.
Matti Hamalainen <ccr@tnsp.org>
parents: 240
diff changeset
67 return sprintf("%".$_[2]."s", fmt_num($_[0]));
14b3b8dfc797 Cleanups.
Matti Hamalainen <ccr@tnsp.org>
parents: 240
diff changeset
68 } else {
14b3b8dfc797 Cleanups.
Matti Hamalainen <ccr@tnsp.org>
parents: 240
diff changeset
69 my $val = $_[0] - $_[1];
14b3b8dfc797 Cleanups.
Matti Hamalainen <ccr@tnsp.org>
parents: 240
diff changeset
70 return sprintf("%".$_[2]."s (%s%.0f)",
14b3b8dfc797 Cleanups.
Matti Hamalainen <ccr@tnsp.org>
parents: 240
diff changeset
71 fmt_num($_[0]), $val < 0 ? "" : "+", $val);
14b3b8dfc797 Cleanups.
Matti Hamalainen <ccr@tnsp.org>
parents: 240
diff changeset
72 }
14b3b8dfc797 Cleanups.
Matti Hamalainen <ccr@tnsp.org>
parents: 240
diff changeset
73 }
14b3b8dfc797 Cleanups.
Matti Hamalainen <ccr@tnsp.org>
parents: 240
diff changeset
74
14b3b8dfc797 Cleanups.
Matti Hamalainen <ccr@tnsp.org>
parents: 240
diff changeset
75
14b3b8dfc797 Cleanups.
Matti Hamalainen <ccr@tnsp.org>
parents: 240
diff changeset
76 ###
14b3b8dfc797 Cleanups.
Matti Hamalainen <ccr@tnsp.org>
parents: 240
diff changeset
77 ### Parse commandline arguments
14b3b8dfc797 Cleanups.
Matti Hamalainen <ccr@tnsp.org>
parents: 240
diff changeset
78 ###
14b3b8dfc797 Cleanups.
Matti Hamalainen <ccr@tnsp.org>
parents: 240
diff changeset
79 while (defined(my $opt = shift))
14b3b8dfc797 Cleanups.
Matti Hamalainen <ccr@tnsp.org>
parents: 240
diff changeset
80 {
14b3b8dfc797 Cleanups.
Matti Hamalainen <ccr@tnsp.org>
parents: 240
diff changeset
81 if ($opt eq "-s")
14b3b8dfc797 Cleanups.
Matti Hamalainen <ccr@tnsp.org>
parents: 240
diff changeset
82 {
14b3b8dfc797 Cleanups.
Matti Hamalainen <ccr@tnsp.org>
parents: 240
diff changeset
83 $opt_sep = 1;
14b3b8dfc797 Cleanups.
Matti Hamalainen <ccr@tnsp.org>
parents: 240
diff changeset
84 }
14b3b8dfc797 Cleanups.
Matti Hamalainen <ccr@tnsp.org>
parents: 240
diff changeset
85 elsif ($opt eq "-t")
14b3b8dfc797 Cleanups.
Matti Hamalainen <ccr@tnsp.org>
parents: 240
diff changeset
86 {
14b3b8dfc797 Cleanups.
Matti Hamalainen <ccr@tnsp.org>
parents: 240
diff changeset
87 $opt_topexp = 1;
14b3b8dfc797 Cleanups.
Matti Hamalainen <ccr@tnsp.org>
parents: 240
diff changeset
88 }
14b3b8dfc797 Cleanups.
Matti Hamalainen <ccr@tnsp.org>
parents: 240
diff changeset
89 elsif ($opt eq "-p")
14b3b8dfc797 Cleanups.
Matti Hamalainen <ccr@tnsp.org>
parents: 240
diff changeset
90 {
14b3b8dfc797 Cleanups.
Matti Hamalainen <ccr@tnsp.org>
parents: 240
diff changeset
91 $opt_plaque = 1;
14b3b8dfc797 Cleanups.
Matti Hamalainen <ccr@tnsp.org>
parents: 240
diff changeset
92 }
14b3b8dfc797 Cleanups.
Matti Hamalainen <ccr@tnsp.org>
parents: 240
diff changeset
93 }
14b3b8dfc797 Cleanups.
Matti Hamalainen <ccr@tnsp.org>
parents: 240
diff changeset
94
14b3b8dfc797 Cleanups.
Matti Hamalainen <ccr@tnsp.org>
parents: 240
diff changeset
95
14b3b8dfc797 Cleanups.
Matti Hamalainen <ccr@tnsp.org>
parents: 240
diff changeset
96 ### Initialize common global variables
14b3b8dfc797 Cleanups.
Matti Hamalainen <ccr@tnsp.org>
parents: 240
diff changeset
97 my $cplaque = {};
14b3b8dfc797 Cleanups.
Matti Hamalainen <ccr@tnsp.org>
parents: 240
diff changeset
98 my @plaques = ();
14b3b8dfc797 Cleanups.
Matti Hamalainen <ccr@tnsp.org>
parents: 240
diff changeset
99 my $state = 0;
14b3b8dfc797 Cleanups.
Matti Hamalainen <ccr@tnsp.org>
parents: 240
diff changeset
100 my $stamp = undef;
14b3b8dfc797 Cleanups.
Matti Hamalainen <ccr@tnsp.org>
parents: 240
diff changeset
101 my $stamps = 0;
14b3b8dfc797 Cleanups.
Matti Hamalainen <ccr@tnsp.org>
parents: 240
diff changeset
102
14b3b8dfc797 Cleanups.
Matti Hamalainen <ccr@tnsp.org>
parents: 240
diff changeset
103
14b3b8dfc797 Cleanups.
Matti Hamalainen <ccr@tnsp.org>
parents: 240
diff changeset
104 ### Parse input logfile for plaque data
14b3b8dfc797 Cleanups.
Matti Hamalainen <ccr@tnsp.org>
parents: 240
diff changeset
105 open(INFILE, "<", $opt_filename) or die("Could not open '".$opt_filename."'!\n");
14b3b8dfc797 Cleanups.
Matti Hamalainen <ccr@tnsp.org>
parents: 240
diff changeset
106
14b3b8dfc797 Cleanups.
Matti Hamalainen <ccr@tnsp.org>
parents: 240
diff changeset
107 while (defined(my $line = <INFILE>))
14b3b8dfc797 Cleanups.
Matti Hamalainen <ccr@tnsp.org>
parents: 240
diff changeset
108 {
14b3b8dfc797 Cleanups.
Matti Hamalainen <ccr@tnsp.org>
parents: 240
diff changeset
109 $line =~ s/[\r\n]+$//;
14b3b8dfc797 Cleanups.
Matti Hamalainen <ccr@tnsp.org>
parents: 240
diff changeset
110 if ($line =~ /^Server time: (.+)/)
14b3b8dfc797 Cleanups.
Matti Hamalainen <ccr@tnsp.org>
parents: 240
diff changeset
111 {
14b3b8dfc797 Cleanups.
Matti Hamalainen <ccr@tnsp.org>
parents: 240
diff changeset
112 $stamp = str2time($1);
14b3b8dfc797 Cleanups.
Matti Hamalainen <ccr@tnsp.org>
parents: 240
diff changeset
113 }
14b3b8dfc797 Cleanups.
Matti Hamalainen <ccr@tnsp.org>
parents: 240
diff changeset
114 elsif ($state == 0 && $line =~ /^\| +The top \d+ players of Icesus +lvl +Exp +\|/)
14b3b8dfc797 Cleanups.
Matti Hamalainen <ccr@tnsp.org>
parents: 240
diff changeset
115 {
14b3b8dfc797 Cleanups.
Matti Hamalainen <ccr@tnsp.org>
parents: 240
diff changeset
116 $state = 1;
14b3b8dfc797 Cleanups.
Matti Hamalainen <ccr@tnsp.org>
parents: 240
diff changeset
117 }
14b3b8dfc797 Cleanups.
Matti Hamalainen <ccr@tnsp.org>
parents: 240
diff changeset
118 elsif ($state == 1 && $line =~ /^\| +(\d+) +([A-Z][a-z]+) +(\d+) +([0-9][0-9,]+) +\|/)
14b3b8dfc797 Cleanups.
Matti Hamalainen <ccr@tnsp.org>
parents: 240
diff changeset
119 {
14b3b8dfc797 Cleanups.
Matti Hamalainen <ccr@tnsp.org>
parents: 240
diff changeset
120 my ($pos, $name, $level, $exp) = ($1, $2, $3, $4);
14b3b8dfc797 Cleanups.
Matti Hamalainen <ccr@tnsp.org>
parents: 240
diff changeset
121 $exp =~ s/,//g;
14b3b8dfc797 Cleanups.
Matti Hamalainen <ccr@tnsp.org>
parents: 240
diff changeset
122 $$cplaque{$name} = { "pos" => $pos, "level" => $level, "exp" => int($exp) };
14b3b8dfc797 Cleanups.
Matti Hamalainen <ccr@tnsp.org>
parents: 240
diff changeset
123 }
14b3b8dfc797 Cleanups.
Matti Hamalainen <ccr@tnsp.org>
parents: 240
diff changeset
124 elsif ($state == 1 && $line =~ /\`---------------------------------------------------------\'/)
14b3b8dfc797 Cleanups.
Matti Hamalainen <ccr@tnsp.org>
parents: 240
diff changeset
125 {
14b3b8dfc797 Cleanups.
Matti Hamalainen <ccr@tnsp.org>
parents: 240
diff changeset
126 # Save plaque data to array
14b3b8dfc797 Cleanups.
Matti Hamalainen <ccr@tnsp.org>
parents: 240
diff changeset
127 $state = 0;
14b3b8dfc797 Cleanups.
Matti Hamalainen <ccr@tnsp.org>
parents: 240
diff changeset
128 $$cplaque{0} = $stamp;
14b3b8dfc797 Cleanups.
Matti Hamalainen <ccr@tnsp.org>
parents: 240
diff changeset
129 $stamp = undef;
14b3b8dfc797 Cleanups.
Matti Hamalainen <ccr@tnsp.org>
parents: 240
diff changeset
130
14b3b8dfc797 Cleanups.
Matti Hamalainen <ccr@tnsp.org>
parents: 240
diff changeset
131 # We keep maximum of 100 plaques in memory
14b3b8dfc797 Cleanups.
Matti Hamalainen <ccr@tnsp.org>
parents: 240
diff changeset
132 shift(@plaques) if (scalar(@plaques) > 100);
14b3b8dfc797 Cleanups.
Matti Hamalainen <ccr@tnsp.org>
parents: 240
diff changeset
133 push(@plaques, $cplaque);
14b3b8dfc797 Cleanups.
Matti Hamalainen <ccr@tnsp.org>
parents: 240
diff changeset
134 undef($cplaque);
14b3b8dfc797 Cleanups.
Matti Hamalainen <ccr@tnsp.org>
parents: 240
diff changeset
135 $cplaque = {};
14b3b8dfc797 Cleanups.
Matti Hamalainen <ccr@tnsp.org>
parents: 240
diff changeset
136 }
14b3b8dfc797 Cleanups.
Matti Hamalainen <ccr@tnsp.org>
parents: 240
diff changeset
137 }
14b3b8dfc797 Cleanups.
Matti Hamalainen <ccr@tnsp.org>
parents: 240
diff changeset
138
14b3b8dfc797 Cleanups.
Matti Hamalainen <ccr@tnsp.org>
parents: 240
diff changeset
139 close(INFILE);
14b3b8dfc797 Cleanups.
Matti Hamalainen <ccr@tnsp.org>
parents: 240
diff changeset
140
14b3b8dfc797 Cleanups.
Matti Hamalainen <ccr@tnsp.org>
parents: 240
diff changeset
141 die("Not enough plaque data in input.\n") unless (scalar(@plaques) >= 2);
14b3b8dfc797 Cleanups.
Matti Hamalainen <ccr@tnsp.org>
parents: 240
diff changeset
142
14b3b8dfc797 Cleanups.
Matti Hamalainen <ccr@tnsp.org>
parents: 240
diff changeset
143
14b3b8dfc797 Cleanups.
Matti Hamalainen <ccr@tnsp.org>
parents: 240
diff changeset
144 ### Find plaques with time difference of a week
14b3b8dfc797 Cleanups.
Matti Hamalainen <ccr@tnsp.org>
parents: 240
diff changeset
145 my $p0 = undef;
14b3b8dfc797 Cleanups.
Matti Hamalainen <ccr@tnsp.org>
parents: 240
diff changeset
146 my $p1 = pop(@plaques);
14b3b8dfc797 Cleanups.
Matti Hamalainen <ccr@tnsp.org>
parents: 240
diff changeset
147 die("No timestamp found for primary comparision plaque.\n") unless defined($$p1{0});
14b3b8dfc797 Cleanups.
Matti Hamalainen <ccr@tnsp.org>
parents: 240
diff changeset
148
14b3b8dfc797 Cleanups.
Matti Hamalainen <ccr@tnsp.org>
parents: 240
diff changeset
149 foreach my $plaque (@plaques)
14b3b8dfc797 Cleanups.
Matti Hamalainen <ccr@tnsp.org>
parents: 240
diff changeset
150 {
14b3b8dfc797 Cleanups.
Matti Hamalainen <ccr@tnsp.org>
parents: 240
diff changeset
151 if (defined($$plaque{0}) && $$plaque{0} <= $$p1{0} - (7*24*60*60))
14b3b8dfc797 Cleanups.
Matti Hamalainen <ccr@tnsp.org>
parents: 240
diff changeset
152 {
14b3b8dfc797 Cleanups.
Matti Hamalainen <ccr@tnsp.org>
parents: 240
diff changeset
153 $p0 = $plaque;
14b3b8dfc797 Cleanups.
Matti Hamalainen <ccr@tnsp.org>
parents: 240
diff changeset
154 }
14b3b8dfc797 Cleanups.
Matti Hamalainen <ccr@tnsp.org>
parents: 240
diff changeset
155 }
14b3b8dfc797 Cleanups.
Matti Hamalainen <ccr@tnsp.org>
parents: 240
diff changeset
156
14b3b8dfc797 Cleanups.
Matti Hamalainen <ccr@tnsp.org>
parents: 240
diff changeset
157 die("Could not find old enough plaque to make a weekly comparision.\n") unless defined($p0);
14b3b8dfc797 Cleanups.
Matti Hamalainen <ccr@tnsp.org>
parents: 240
diff changeset
158
14b3b8dfc797 Cleanups.
Matti Hamalainen <ccr@tnsp.org>
parents: 240
diff changeset
159
14b3b8dfc797 Cleanups.
Matti Hamalainen <ccr@tnsp.org>
parents: 240
diff changeset
160 ### Compute results
14b3b8dfc797 Cleanups.
Matti Hamalainen <ccr@tnsp.org>
parents: 240
diff changeset
161 my %final = ();
14b3b8dfc797 Cleanups.
Matti Hamalainen <ccr@tnsp.org>
parents: 240
diff changeset
162 my %expers = ();
14b3b8dfc797 Cleanups.
Matti Hamalainen <ccr@tnsp.org>
parents: 240
diff changeset
163
14b3b8dfc797 Cleanups.
Matti Hamalainen <ccr@tnsp.org>
parents: 240
diff changeset
164 foreach my $name (keys %{$p1}) {
14b3b8dfc797 Cleanups.
Matti Hamalainen <ccr@tnsp.org>
parents: 240
diff changeset
165 my $entry1 = $$p1{$name};
14b3b8dfc797 Cleanups.
Matti Hamalainen <ccr@tnsp.org>
parents: 240
diff changeset
166 next if ($name eq 0);
14b3b8dfc797 Cleanups.
Matti Hamalainen <ccr@tnsp.org>
parents: 240
diff changeset
167 # Check if player is on the previous plaque
14b3b8dfc797 Cleanups.
Matti Hamalainen <ccr@tnsp.org>
parents: 240
diff changeset
168 if (defined($$p0{$name})) {
14b3b8dfc797 Cleanups.
Matti Hamalainen <ccr@tnsp.org>
parents: 240
diff changeset
169 my $entry0 = $$p0{$name};
14b3b8dfc797 Cleanups.
Matti Hamalainen <ccr@tnsp.org>
parents: 240
diff changeset
170 # Yes, print a "diff" line
14b3b8dfc797 Cleanups.
Matti Hamalainen <ccr@tnsp.org>
parents: 240
diff changeset
171 $final{$$entry1{"pos"}} = sprintf(
14b3b8dfc797 Cleanups.
Matti Hamalainen <ccr@tnsp.org>
parents: 240
diff changeset
172 "| %-10s | %-12s | %-10s | %-30s |\n",
14b3b8dfc797 Cleanups.
Matti Hamalainen <ccr@tnsp.org>
parents: 240
diff changeset
173 fmt_value($$entry1{"pos"}, $$entry0{"pos"}, 3),
14b3b8dfc797 Cleanups.
Matti Hamalainen <ccr@tnsp.org>
parents: 240
diff changeset
174 $name,
14b3b8dfc797 Cleanups.
Matti Hamalainen <ccr@tnsp.org>
parents: 240
diff changeset
175 fmt_value($$entry1{"level"}, $$entry0{"level"}, 3),
14b3b8dfc797 Cleanups.
Matti Hamalainen <ccr@tnsp.org>
parents: 240
diff changeset
176 fmt_value($$entry1{"exp"}, $$entry0{"exp"}, 15)
14b3b8dfc797 Cleanups.
Matti Hamalainen <ccr@tnsp.org>
parents: 240
diff changeset
177 );
14b3b8dfc797 Cleanups.
Matti Hamalainen <ccr@tnsp.org>
parents: 240
diff changeset
178 my $exp = $$entry1{"exp"} - $$entry0{"exp"};
14b3b8dfc797 Cleanups.
Matti Hamalainen <ccr@tnsp.org>
parents: 240
diff changeset
179 if ($exp > 0) {
14b3b8dfc797 Cleanups.
Matti Hamalainen <ccr@tnsp.org>
parents: 240
diff changeset
180 $expers{$exp}{"name"} = $name;
14b3b8dfc797 Cleanups.
Matti Hamalainen <ccr@tnsp.org>
parents: 240
diff changeset
181 $expers{$exp}{"total"} = $$entry1{"exp"};
14b3b8dfc797 Cleanups.
Matti Hamalainen <ccr@tnsp.org>
parents: 240
diff changeset
182 }
14b3b8dfc797 Cleanups.
Matti Hamalainen <ccr@tnsp.org>
parents: 240
diff changeset
183 } else {
14b3b8dfc797 Cleanups.
Matti Hamalainen <ccr@tnsp.org>
parents: 240
diff changeset
184 # No, print a normal line
14b3b8dfc797 Cleanups.
Matti Hamalainen <ccr@tnsp.org>
parents: 240
diff changeset
185 $final{$$entry1{"pos"}} = sprintf(
14b3b8dfc797 Cleanups.
Matti Hamalainen <ccr@tnsp.org>
parents: 240
diff changeset
186 "| %-10s | %-12s | %-10s | %-30s |\n",
14b3b8dfc797 Cleanups.
Matti Hamalainen <ccr@tnsp.org>
parents: 240
diff changeset
187 $$entry1{"pos"}, $name, $$entry1{"level"}, $$entry1{"exp"}
14b3b8dfc797 Cleanups.
Matti Hamalainen <ccr@tnsp.org>
parents: 240
diff changeset
188 );
14b3b8dfc797 Cleanups.
Matti Hamalainen <ccr@tnsp.org>
parents: 240
diff changeset
189 }
14b3b8dfc797 Cleanups.
Matti Hamalainen <ccr@tnsp.org>
parents: 240
diff changeset
190 }
14b3b8dfc797 Cleanups.
Matti Hamalainen <ccr@tnsp.org>
parents: 240
diff changeset
191
14b3b8dfc797 Cleanups.
Matti Hamalainen <ccr@tnsp.org>
parents: 240
diff changeset
192
14b3b8dfc797 Cleanups.
Matti Hamalainen <ccr@tnsp.org>
parents: 240
diff changeset
193 ### Print output
14b3b8dfc797 Cleanups.
Matti Hamalainen <ccr@tnsp.org>
parents: 240
diff changeset
194 my ($shead, $sbar);
14b3b8dfc797 Cleanups.
Matti Hamalainen <ccr@tnsp.org>
parents: 240
diff changeset
195
14b3b8dfc797 Cleanups.
Matti Hamalainen <ccr@tnsp.org>
parents: 240
diff changeset
196 if ($opt_plaque)
14b3b8dfc797 Cleanups.
Matti Hamalainen <ccr@tnsp.org>
parents: 240
diff changeset
197 {
14b3b8dfc797 Cleanups.
Matti Hamalainen <ccr@tnsp.org>
parents: 240
diff changeset
198 $sbar = $shead = sprintf(
14b3b8dfc797 Cleanups.
Matti Hamalainen <ccr@tnsp.org>
parents: 240
diff changeset
199 "| %-10s | %-12s | %-10s | %-30s |",
14b3b8dfc797 Cleanups.
Matti Hamalainen <ccr@tnsp.org>
parents: 240
diff changeset
200 "Pos", "Name", "Lvl", "Exp");
14b3b8dfc797 Cleanups.
Matti Hamalainen <ccr@tnsp.org>
parents: 240
diff changeset
201
14b3b8dfc797 Cleanups.
Matti Hamalainen <ccr@tnsp.org>
parents: 240
diff changeset
202 $sbar =~ tr/\|/+/;
14b3b8dfc797 Cleanups.
Matti Hamalainen <ccr@tnsp.org>
parents: 240
diff changeset
203 $sbar =~ s/[^\+]/-/g;
14b3b8dfc797 Cleanups.
Matti Hamalainen <ccr@tnsp.org>
parents: 240
diff changeset
204
14b3b8dfc797 Cleanups.
Matti Hamalainen <ccr@tnsp.org>
parents: 240
diff changeset
205 print
14b3b8dfc797 Cleanups.
Matti Hamalainen <ccr@tnsp.org>
parents: 240
diff changeset
206 "" . scalar localtime($$p0{0})." to ".scalar localtime($$p1{0})." (".get_period($$p1{0} - $$p0{0}).")\n".
14b3b8dfc797 Cleanups.
Matti Hamalainen <ccr@tnsp.org>
parents: 240
diff changeset
207 "$sbar\n$shead\n$sbar\n";
14b3b8dfc797 Cleanups.
Matti Hamalainen <ccr@tnsp.org>
parents: 240
diff changeset
208
14b3b8dfc797 Cleanups.
Matti Hamalainen <ccr@tnsp.org>
parents: 240
diff changeset
209 foreach my $place (sort { $a <=> $b } keys %final)
14b3b8dfc797 Cleanups.
Matti Hamalainen <ccr@tnsp.org>
parents: 240
diff changeset
210 {
14b3b8dfc797 Cleanups.
Matti Hamalainen <ccr@tnsp.org>
parents: 240
diff changeset
211 print $final{$place};
14b3b8dfc797 Cleanups.
Matti Hamalainen <ccr@tnsp.org>
parents: 240
diff changeset
212 }
14b3b8dfc797 Cleanups.
Matti Hamalainen <ccr@tnsp.org>
parents: 240
diff changeset
213
14b3b8dfc797 Cleanups.
Matti Hamalainen <ccr@tnsp.org>
parents: 240
diff changeset
214 print "$sbar\n";
14b3b8dfc797 Cleanups.
Matti Hamalainen <ccr@tnsp.org>
parents: 240
diff changeset
215 }
14b3b8dfc797 Cleanups.
Matti Hamalainen <ccr@tnsp.org>
parents: 240
diff changeset
216
14b3b8dfc797 Cleanups.
Matti Hamalainen <ccr@tnsp.org>
parents: 240
diff changeset
217
14b3b8dfc797 Cleanups.
Matti Hamalainen <ccr@tnsp.org>
parents: 240
diff changeset
218 ### Bestestest expmakers
14b3b8dfc797 Cleanups.
Matti Hamalainen <ccr@tnsp.org>
parents: 240
diff changeset
219 if ($opt_topexp)
14b3b8dfc797 Cleanups.
Matti Hamalainen <ccr@tnsp.org>
parents: 240
diff changeset
220 {
14b3b8dfc797 Cleanups.
Matti Hamalainen <ccr@tnsp.org>
parents: 240
diff changeset
221 $sbar = $shead = sprintf(
14b3b8dfc797 Cleanups.
Matti Hamalainen <ccr@tnsp.org>
parents: 240
diff changeset
222 "| %-15s | %7s | %-15s | %-15s |",
14b3b8dfc797 Cleanups.
Matti Hamalainen <ccr@tnsp.org>
parents: 240
diff changeset
223 "Exp gain", "% (*)", "Total exp", "Name");
14b3b8dfc797 Cleanups.
Matti Hamalainen <ccr@tnsp.org>
parents: 240
diff changeset
224
14b3b8dfc797 Cleanups.
Matti Hamalainen <ccr@tnsp.org>
parents: 240
diff changeset
225 $sbar =~ tr/\|/+/;
14b3b8dfc797 Cleanups.
Matti Hamalainen <ccr@tnsp.org>
parents: 240
diff changeset
226 $sbar =~ s/[^\+]/-/g;
14b3b8dfc797 Cleanups.
Matti Hamalainen <ccr@tnsp.org>
parents: 240
diff changeset
227
14b3b8dfc797 Cleanups.
Matti Hamalainen <ccr@tnsp.org>
parents: 240
diff changeset
228 print
14b3b8dfc797 Cleanups.
Matti Hamalainen <ccr@tnsp.org>
parents: 240
diff changeset
229 "" . scalar localtime($$p0{0})." to ".scalar localtime($$p1{0}).
14b3b8dfc797 Cleanups.
Matti Hamalainen <ccr@tnsp.org>
parents: 240
diff changeset
230 " (".get_period($$p1{0} - $$p0{0}).")\n" unless ($opt_plaque);
14b3b8dfc797 Cleanups.
Matti Hamalainen <ccr@tnsp.org>
parents: 240
diff changeset
231
14b3b8dfc797 Cleanups.
Matti Hamalainen <ccr@tnsp.org>
parents: 240
diff changeset
232 print "\nTop exp gainers:\n$sbar\n$shead\n$sbar\n";
14b3b8dfc797 Cleanups.
Matti Hamalainen <ccr@tnsp.org>
parents: 240
diff changeset
233 foreach my $exp (sort { $b <=> $a } keys %expers)
14b3b8dfc797 Cleanups.
Matti Hamalainen <ccr@tnsp.org>
parents: 240
diff changeset
234 {
14b3b8dfc797 Cleanups.
Matti Hamalainen <ccr@tnsp.org>
parents: 240
diff changeset
235 my $s = sprintf("%4.2f%%", ($exp * 100.0) / $expers{$exp}{"total"});
14b3b8dfc797 Cleanups.
Matti Hamalainen <ccr@tnsp.org>
parents: 240
diff changeset
236 printf("| %15s | %7s | %15s | %-15s |\n",
14b3b8dfc797 Cleanups.
Matti Hamalainen <ccr@tnsp.org>
parents: 240
diff changeset
237 fmt_num($exp), $s, fmt_num($expers{$exp}{"total"}), $expers{$exp}{"name"});
14b3b8dfc797 Cleanups.
Matti Hamalainen <ccr@tnsp.org>
parents: 240
diff changeset
238 }
14b3b8dfc797 Cleanups.
Matti Hamalainen <ccr@tnsp.org>
parents: 240
diff changeset
239
14b3b8dfc797 Cleanups.
Matti Hamalainen <ccr@tnsp.org>
parents: 240
diff changeset
240 print "$sbar\n(*) = Gain % of total experience.\n";
14b3b8dfc797 Cleanups.
Matti Hamalainen <ccr@tnsp.org>
parents: 240
diff changeset
241 }