1 |
#!/usr/bin/perl -W |
2 |
|
3 |
$ploticus_chron = 'ploticus png -prefab chron data=- x=1 y=2 xgrid=color=0.3 ygrid=color=0.3 datefmt=yyyymmdd mode=line gapmissing=yes yrange=0 -font Arial -diagfile /dev/null -backcolor black -color brightgreen'; |
4 |
$bar_width = 600; |
5 |
|
6 |
################################################################################ |
7 |
|
8 |
use Time::Local; |
9 |
|
10 |
%capacity_day = (); |
11 |
%players_day = (); |
12 |
%capacity_hour = (); |
13 |
%players_hour = (); |
14 |
%capacity_10m = (); |
15 |
%players_10m = (); |
16 |
|
17 |
%map = (); |
18 |
%game = (); |
19 |
%map7 = (); |
20 |
%game7 = (); |
21 |
|
22 |
$grand_total = 0; |
23 |
$grand_total7 = 0; |
24 |
$now = time; |
25 |
|
26 |
while ($line = <>) { |
27 |
chomp $line; |
28 |
($datetime, $game, $mission, $map, $maxplayers, $players) = split /\t/, $line; |
29 |
next if $map eq ''; |
30 |
$datetime =~ m|(....)(..)(..)/(..)(..)| or die 'match failed'; |
31 |
$year = $1; |
32 |
$month = $2; |
33 |
$day = $3; |
34 |
$date = "$year$month$day"; |
35 |
$hour = $4; |
36 |
$min = $5; |
37 |
$time = timegm(0, $min, $hour, $day, $month - 1, $year); |
38 |
# $gmm = "$game: $mission: $map"; |
39 |
$gmm = $map; |
40 |
$gm = "$game: $mission"; |
41 |
$players = 0 if ($players < 0); |
42 |
$maxplayers = 0 if ($maxplayers < 0); |
43 |
|
44 |
$grand_total += $players; |
45 |
|
46 |
# all time stats |
47 |
if (exists $players_day{$date}) { |
48 |
$players_day{$date} += $players; |
49 |
$capacity_day{$date} += $maxplayers; |
50 |
} else { |
51 |
$players_day{$date} = $players; |
52 |
$capacity_day{$date} = $maxplayers; |
53 |
} |
54 |
|
55 |
if ($players != 0) { |
56 |
if (exists $map{$gmm}) { |
57 |
$map{$gmm} += $players; |
58 |
} else { |
59 |
$map{$gmm} = $players; |
60 |
} |
61 |
if (exists $game{$gm}) { |
62 |
$game{$gm} += $players; |
63 |
} else { |
64 |
$game{$gm} = $players; |
65 |
} |
66 |
} |
67 |
|
68 |
# last 100 days |
69 |
next unless ($now - 100 * 24 * 60 * 60 < $time); |
70 |
|
71 |
$grand_total100 += $players; |
72 |
|
73 |
if ($players != 0) { |
74 |
if (exists $map100{$gmm}) { |
75 |
$map100{$gmm} += $players; |
76 |
} else { |
77 |
$map100{$gmm} = $players; |
78 |
} |
79 |
if (exists $game100{$gm}) { |
80 |
$game100{$gm} += $players; |
81 |
} else { |
82 |
$game100{$gm} = $players; |
83 |
} |
84 |
} |
85 |
|
86 |
# last 7 days |
87 |
next unless ($now - 7 * 24 * 60 * 60 < $time); |
88 |
|
89 |
$grand_total7 += $players; |
90 |
|
91 |
if (exists $players_hour{"$date.$hour"}) { |
92 |
$players_hour{"$date.$hour"} += $players; |
93 |
$capacity_hour{"$date.$hour"} += $maxplayers; |
94 |
} else { |
95 |
$players_hour{"$date.$hour"} = $players; |
96 |
$capacity_hour{"$date.$hour"} = $maxplayers; |
97 |
} |
98 |
|
99 |
if ($players != 0) { |
100 |
if (exists $map7{$gmm}) { |
101 |
$map7{$gmm} += $players; |
102 |
} else { |
103 |
$map7{$gmm} = $players; |
104 |
} |
105 |
if (exists $game7{$gm}) { |
106 |
$game7{$gm} += $players; |
107 |
} else { |
108 |
$game7{$gm} = $players; |
109 |
} |
110 |
} |
111 |
|
112 |
# last 24 hours |
113 |
next unless ($now - 24 * 60 * 60 < $time); |
114 |
|
115 |
if (exists $players_10m{"$date.$hour:$min"}) { |
116 |
$players_10m{"$date.$hour:$min"} += $players; |
117 |
$capacity_10m{"$date.$hour:$min"} += $maxplayers; |
118 |
} else { |
119 |
$players_10m{"$date.$hour:$min"} = $players; |
120 |
$capacity_10m{"$date.$hour:$min"} = $maxplayers; |
121 |
} |
122 |
|
123 |
} |
124 |
|
125 |
################################################################################ |
126 |
|
127 |
undef $/; |
128 |
open HEADER, '< header' or die "Failed to open header: $!"; |
129 |
$header = <HEADER>; |
130 |
|
131 |
$menu = <<END; |
132 |
<p class='menu'><a href='/t2stats/'>Home</a> | |
133 |
<a href='graphs'>Graphs</a> | |
134 |
<a href='games'>Game types</a> | |
135 |
<a href='maps'>Map popularity</a></p> |
136 |
END |
137 |
|
138 |
$now = gmtime; |
139 |
|
140 |
open INDEX, '>', 'index'; |
141 |
open GRAPHS, '>', 'graphs'; |
142 |
open GAMES, '>', 'games'; |
143 |
open MAPS, '>', 'maps'; |
144 |
|
145 |
print INDEX $header; |
146 |
print GRAPHS $header; |
147 |
print GAMES $header; |
148 |
print MAPS $header; |
149 |
|
150 |
print INDEX <<END; |
151 |
<h1>Tribes 2 Europe Statistics</h1> |
152 |
$menu |
153 |
<p>Updated every hour, last update $now UTC. All times in UTC. |
154 |
Data collected every 10 minutes by <a href='http://www.qstat.org/'>QStat</a>, |
155 |
processed by a <a href='http://cvs.strcprstskrzkrk.co.uk/t2stats/'>script</a>, |
156 |
and graphs plotted with <a href='http://ploticus.sourceforge.net/'>ploticus</a>. |
157 |
Created by <a href='http://www.strcprstskrzkrk.co.uk/'>James Bursa</a>.</p> |
158 |
|
159 |
END |
160 |
|
161 |
################################################################################ |
162 |
|
163 |
open PLOTA1, "|$ploticus_chron xinc='60 days' stubfmt='Mmmdd' -o images/players_full.png"; |
164 |
open PLOTA2, "|$ploticus_chron xinc='60 days' stubfmt='Mmmdd' -o images/capacity_full.png"; |
165 |
open PLOTA3, "|$ploticus_chron xinc='60 days' stubfmt='Mmmdd' -o images/usage_full.png"; |
166 |
|
167 |
foreach $date (sort keys %players_day) { |
168 |
$meanplayer = $players_day{$date} / (6.0 * 24.0); |
169 |
$meancapacity = $capacity_day{$date} / (6.0 * 24.0); |
170 |
$usage = $meanplayer / $meancapacity * 100.0; |
171 |
print PLOTA1 "$date\t$meanplayer\n"; |
172 |
print PLOTA2 "$date\t$meancapacity\n"; |
173 |
print PLOTA3 "$date\t$usage\n"; |
174 |
} |
175 |
|
176 |
close PLOTA1; close PLOTA2; close PLOTA3; |
177 |
|
178 |
open PLOTB1, "|$ploticus_chron unittype=datetime xinc='1 day' stubfmt='Www' -o images/players_week.png"; |
179 |
open PLOTB2, "|$ploticus_chron unittype=datetime xinc='1 day' stubfmt='Www' -o images/capacity_week.png"; |
180 |
open PLOTB3, "|$ploticus_chron unittype=datetime xinc='1 day' stubfmt='Www' -o images/usage_week.png"; |
181 |
|
182 |
foreach $date (sort keys %players_hour) { |
183 |
$meanplayer = $players_hour{$date} / 6.0; |
184 |
$meancapacity = $capacity_hour{$date} / 6.0; |
185 |
$usage = $meanplayer / $meancapacity * 100.0; |
186 |
print PLOTB1 "$date:00\t$meanplayer\n"; |
187 |
print PLOTB2 "$date:00\t$meancapacity\n"; |
188 |
print PLOTB3 "$date:00\t$usage\n"; |
189 |
} |
190 |
|
191 |
close PLOTB1; close PLOTB2; close PLOTB3; |
192 |
|
193 |
open PLOTC1, "|$ploticus_chron unittype=datetime xinc='2 hours' stubfmt='hh' -o images/players_day.png"; |
194 |
open PLOTC2, "|$ploticus_chron unittype=datetime xinc='2 hours' stubfmt='hh' -o images/capacity_day.png"; |
195 |
open PLOTC3, "|$ploticus_chron unittype=datetime xinc='2 hours' stubfmt='hh' -o images/usage_day.png"; |
196 |
|
197 |
foreach $date (sort keys %players_10m) { |
198 |
$meanplayer = $players_10m{$date}; |
199 |
$meancapacity = $capacity_10m{$date}; |
200 |
$usage = $meanplayer / $meancapacity * 100.0; |
201 |
print PLOTC1 "$date\t$meanplayer\n"; |
202 |
print PLOTC2 "$date\t$meancapacity\n"; |
203 |
print PLOTC3 "$date\t$usage\n"; |
204 |
} |
205 |
|
206 |
close PLOTC1; close PLOTC2; close PLOTC3; |
207 |
|
208 |
print INDEX <<END; |
209 |
<h2>Players online</h2> |
210 |
<p>All available data, averaged over each day. <a href='graphs'>More graphs</a>.<br> |
211 |
<img src='images/players_full.png' alt='Graph'></p> |
212 |
END |
213 |
|
214 |
print GRAPHS <<END; |
215 |
<h1>Tribes 2 Europe Statistics</h1> |
216 |
$menu |
217 |
<p>Graphs plotted with <a href='http://ploticus.sourceforge.net/'>ploticus</a>.</p> |
218 |
<h2>Average players online</h2> |
219 |
<p>All available data, averaged over each day:<br> |
220 |
<img src='images/players_full.png' alt='Graph'></p> |
221 |
<p>Last 7 days, averaged over each hour:<br> |
222 |
<img src='images/players_week.png' alt='Graph'></p> |
223 |
<p>Last 24 hours, sampled every 10 minutes:<br> |
224 |
<img src='images/players_day.png' alt='Graph'></p> |
225 |
|
226 |
<h2>Average server places available</h2> |
227 |
<p><img src='images/capacity_full.png' alt='Graph'></p> |
228 |
<p><img src='images/capacity_week.png' alt='Graph'></p> |
229 |
<p><img src='images/capacity_day.png' alt='Graph'></p> |
230 |
|
231 |
<h2>Percentage server places used</h2> |
232 |
<p><img src='images/usage_full.png' alt='Graph'></p> |
233 |
<p><img src='images/usage_week.png' alt='Graph'></p> |
234 |
<p><img src='images/usage_day.png' alt='Graph'></p> |
235 |
|
236 |
END |
237 |
|
238 |
################################################################################ |
239 |
|
240 |
$game_types = keys %game; |
241 |
|
242 |
$key = <<END; |
243 |
<p><img src='images/bar.png' width='10' height='10' alt='First value' /> last 7 days, |
244 |
<img src='images/bar7.png' width='10' height='10' alt='second value' /> last 100 days. |
245 |
$game_types game types. |
246 |
END |
247 |
|
248 |
print INDEX '<h2>Top 10 game types</h2>', $key, "<a href='games'>Full game type table</a>.</p>"; |
249 |
print GAMES '<h1>Game type popularity</h1>', $menu, $key, "</p>"; |
250 |
|
251 |
$i = 0; |
252 |
foreach $gm (sort { $game7{$b} <=> $game7{$a} } keys %game7) { |
253 |
$players100 = $game100{$gm}; |
254 |
$players7 = $game7{$gm}; |
255 |
$propn100 = $players100 / $grand_total100; |
256 |
$propn7 = $players7 / $grand_total7; |
257 |
$max = $propn7 if $i == 0; |
258 |
$width100 = int($propn100 / $max * $bar_width); |
259 |
$width7 = int($propn7 / $max * $bar_width); |
260 |
$pct100 = sprintf "%.3g", $propn100 * 100; |
261 |
$pct7 = sprintf "%.3g", $propn7 * 100; |
262 |
$class = $i % 2; |
263 |
$line = <<END; |
264 |
<p class='bar$class'>$gm<br><img src='images/bar.png' width='$width7' height='10' alt=''> $pct7%<br> |
265 |
<img src='images/bar7.png' width='$width100' height='10' alt=''> $pct100%</p> |
266 |
END |
267 |
print INDEX $line if $i < 10; |
268 |
print GAMES $line; |
269 |
$i++; |
270 |
} |
271 |
|
272 |
################################################################################ |
273 |
|
274 |
$maps = keys %map; |
275 |
|
276 |
$key = <<END; |
277 |
<p><img src='images/bar.png' width='10' height='10' alt='First value' /> last 7 days, |
278 |
<img src='images/bar7.png' width='10' height='10' alt='second value' /> last 100 days. |
279 |
$maps maps. |
280 |
Follow the link to search for a map on <a href='http://www.tribes2maps.com/'>Tribes2Maps</a>. |
281 |
END |
282 |
|
283 |
print INDEX '<h2>Top 10 maps</h2>', $key, "<a href='maps'>Full map popularity table</a>.</p>"; |
284 |
print MAPS '<h1>Map popularity</h1>', $menu, $key, "</p>"; |
285 |
|
286 |
$i = 0; |
287 |
foreach $gmm (sort { $map7{$b} <=> $map7{$a} } keys %map7) { |
288 |
$players100 = $map100{$gmm}; |
289 |
$players7 = $map7{$gmm}; |
290 |
$propn100 = $players100 / $grand_total100; |
291 |
$propn7 = $players7 / $grand_total7; |
292 |
$max = $propn7 if $i == 0; |
293 |
$width100 = int($propn100 / $max * $bar_width); |
294 |
$width7 = int($propn7 / $max * $bar_width); |
295 |
$pct100 = sprintf "%.3g", $propn100 * 100; |
296 |
$pct7 = sprintf "%.3g", $propn7 * 100; |
297 |
$class = $i % 2; |
298 |
$search = $gmm; |
299 |
$search =~ s/^Euro2_//; |
300 |
$search =~ s/^TL_//; |
301 |
$search =~ s/ \(x2\)$//; |
302 |
$search =~ s/^Cluster_//; |
303 |
$search =~ s/([^\w()'*~!.-])/sprintf '%%%02x', ord $1/eg; |
304 |
$line = <<END; |
305 |
<p class='bar$class'><a href="http://www.tribes2maps.com/cgi-bin/map_search.cgi?names_only=1;search=$search">$gmm</a><br> |
306 |
<img src='images/bar.png' width='$width7' height='10' alt=''> $pct7%<br> |
307 |
<img src='images/bar7.png' width='$width100' height='10' alt=''> $pct100%</p> |
308 |
END |
309 |
print INDEX $line if $i < 10; |
310 |
print MAPS $line; |
311 |
$i++; |
312 |
} |
313 |
|
314 |
################################################################################ |
315 |
|
316 |
$footer = <<END; |
317 |
<p class='footer'><a href='/'>Omroth</a> » Tribes 2 Europe Statistics</p> |
318 |
</body> |
319 |
</html> |
320 |
END |
321 |
|
322 |
print INDEX $footer; |
323 |
print GRAPHS $footer; |
324 |
print GAMES $footer; |
325 |
print MAPS $footer; |
326 |
|
327 |
close INDEX; |
328 |
close GRAPHS; |
329 |
close GAMES; |
330 |
close MAPS; |
331 |
|
332 |
system 'gzip --best -c index > index.gz'; |
333 |
system 'gzip --best -c graphs > graphs.gz'; |
334 |
system 'gzip --best -c games > games.gz'; |
335 |
system 'gzip --best -c maps > maps.gz'; |
336 |
|
337 |
################################################################################ |
338 |
|