1 |
#!/usr/bin/perl -W |
2 |
|
3 |
$ploticus_chron = 'ploticus png -prefab chron data=- x=1 y=2 xgrid=color=0.8 ygrid=color=0.8 datefmt=yyyymmdd mode=line gapmissing=yes yrange=0 -font Arial -diagfile /dev/null'; |
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 |
$grand_total += $players; |
44 |
|
45 |
# all time stats |
46 |
if (exists $players_day{$date}) { |
47 |
$players_day{$date} += $players; |
48 |
$capacity_day{$date} += $maxplayers; |
49 |
} else { |
50 |
$players_day{$date} = $players; |
51 |
$capacity_day{$date} = $maxplayers; |
52 |
} |
53 |
|
54 |
if ($players != 0) { |
55 |
if (exists $map{$gmm}) { |
56 |
$map{$gmm} += $players; |
57 |
} else { |
58 |
$map{$gmm} = $players; |
59 |
} |
60 |
if (exists $game{$gm}) { |
61 |
$game{$gm} += $players; |
62 |
} else { |
63 |
$game{$gm} = $players; |
64 |
} |
65 |
} |
66 |
|
67 |
# last 7 days |
68 |
next unless ($now - 7 * 24 * 60 * 60 < $time); |
69 |
|
70 |
$grand_total7 += $players; |
71 |
|
72 |
if (exists $players_hour{"$date.$hour"}) { |
73 |
$players_hour{"$date.$hour"} += $players; |
74 |
$capacity_hour{"$date.$hour"} += $maxplayers; |
75 |
} else { |
76 |
$players_hour{"$date.$hour"} = $players; |
77 |
$capacity_hour{"$date.$hour"} = $maxplayers; |
78 |
} |
79 |
|
80 |
if ($players != 0) { |
81 |
if (exists $map7{$gmm}) { |
82 |
$map7{$gmm} += $players; |
83 |
} else { |
84 |
$map7{$gmm} = $players; |
85 |
} |
86 |
if (exists $game7{$gm}) { |
87 |
$game7{$gm} += $players; |
88 |
} else { |
89 |
$game7{$gm} = $players; |
90 |
} |
91 |
} |
92 |
|
93 |
# last 24 hours |
94 |
next unless ($now - 24 * 60 * 60 < $time); |
95 |
|
96 |
if (exists $players_10m{"$date.$hour:$min"}) { |
97 |
$players_10m{"$date.$hour:$min"} += $players; |
98 |
$capacity_10m{"$date.$hour:$min"} += $maxplayers; |
99 |
} else { |
100 |
$players_10m{"$date.$hour:$min"} = $players; |
101 |
$capacity_10m{"$date.$hour:$min"} = $maxplayers; |
102 |
} |
103 |
|
104 |
} |
105 |
|
106 |
################################################################################ |
107 |
|
108 |
$now = gmtime; |
109 |
|
110 |
open INDEX, '>', '../index.html'; |
111 |
|
112 |
print INDEX <<END; |
113 |
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" |
114 |
"http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd"> |
115 |
<html xmlns="http://www.w3.org/1999/xhtml"> |
116 |
<head> |
117 |
<title>Tribes 2 Europe Statistics</title> |
118 |
<style type='text/css'> |
119 |
body { background-color: white; margin: 3em; font-family: sans-serif; } |
120 |
p { text-align: center; } |
121 |
address { text-align: right; } |
122 |
h1, h2 { background-color: #ccffcc; padding: 0.5em; } |
123 |
p.bar0, p.bar1 { text-align: left; margin-top: 0; margin-bottom: 0; font-size: 75%; } |
124 |
p.bar1 { background-color: #eee; } |
125 |
</style> |
126 |
</head> |
127 |
|
128 |
<body> |
129 |
<h1>Tribes 2 Europe Statistics</h1> |
130 |
<p>This page updated every hour, last update $now UTC. All times in UTC. |
131 |
Data collected every 10 minutes by <a href='http://www.qstat.org/'>QStat</a>, |
132 |
processed by a <a href='scripts/'>script</a>, and graphs plotted |
133 |
with <a href='http://ploticus.sourceforge.net/'>ploticus</a>.</p> |
134 |
<address>- <a href='mailto:t2stats\@strcprstskrzkrk.co.uk'>James Bursa</a></address> |
135 |
|
136 |
END |
137 |
|
138 |
################################################################################ |
139 |
|
140 |
open PLOTA1, "|$ploticus_chron xinc='14 days' stubfmt='Mmmdd' -o ../images/players_full.png"; |
141 |
open PLOTA2, "|$ploticus_chron xinc='14 days' stubfmt='Mmmdd' -o ../images/capacity_full.png"; |
142 |
open PLOTA3, "|$ploticus_chron xinc='14 days' stubfmt='Mmmdd' -o ../images/usage_full.png"; |
143 |
|
144 |
foreach $date (sort keys %players_day) { |
145 |
$meanplayer = $players_day{$date} / (6.0 * 24.0); |
146 |
$meancapacity = $capacity_day{$date} / (6.0 * 24.0); |
147 |
$usage = $meanplayer / $meancapacity * 100.0; |
148 |
print PLOTA1 "$date\t$meanplayer\n"; |
149 |
print PLOTA2 "$date\t$meancapacity\n"; |
150 |
print PLOTA3 "$date\t$usage\n"; |
151 |
} |
152 |
|
153 |
close PLOTA1; close PLOTA2; close PLOTA3; |
154 |
|
155 |
open PLOTB1, "|$ploticus_chron unittype=datetime xinc='1 day' stubfmt='Www' -o ../images/players_week.png"; |
156 |
open PLOTB2, "|$ploticus_chron unittype=datetime xinc='1 day' stubfmt='Www' -o ../images/capacity_week.png"; |
157 |
open PLOTB3, "|$ploticus_chron unittype=datetime xinc='1 day' stubfmt='Www' -o ../images/usage_week.png"; |
158 |
|
159 |
foreach $date (sort keys %players_hour) { |
160 |
$meanplayer = $players_hour{$date} / 6.0; |
161 |
$meancapacity = $capacity_hour{$date} / 6.0; |
162 |
$usage = $meanplayer / $meancapacity * 100.0; |
163 |
print PLOTB1 "$date:00\t$meanplayer\n"; |
164 |
print PLOTB2 "$date:00\t$meancapacity\n"; |
165 |
print PLOTB3 "$date:00\t$usage\n"; |
166 |
} |
167 |
|
168 |
close PLOTB1; close PLOTB2; close PLOTB3; |
169 |
|
170 |
open PLOTC1, "|$ploticus_chron unittype=datetime xinc='2 hours' stubfmt='hh' -o ../images/players_day.png"; |
171 |
open PLOTC2, "|$ploticus_chron unittype=datetime xinc='2 hours' stubfmt='hh' -o ../images/capacity_day.png"; |
172 |
open PLOTC3, "|$ploticus_chron unittype=datetime xinc='2 hours' stubfmt='hh' -o ../images/usage_day.png"; |
173 |
|
174 |
foreach $date (sort keys %players_10m) { |
175 |
$meanplayer = $players_10m{$date}; |
176 |
$meancapacity = $capacity_10m{$date}; |
177 |
$usage = $meanplayer / $meancapacity * 100.0; |
178 |
print PLOTC1 "$date\t$meanplayer\n"; |
179 |
print PLOTC2 "$date\t$meancapacity\n"; |
180 |
print PLOTC3 "$date\t$usage\n"; |
181 |
} |
182 |
|
183 |
close PLOTC1; close PLOTC2; close PLOTC3; |
184 |
|
185 |
print INDEX <<END; |
186 |
<h2>Average players online</h2> |
187 |
<p>All available data, averaged over each day:<br /> |
188 |
<img src='images/players_full.png' alt='Graph' /></p> |
189 |
<p>Last 7 days, averaged over each hour:<br /> |
190 |
<img src='images/players_week.png' alt='Graph' /></p> |
191 |
<p>Last 24 hours, sampled every 10 minutes:<br /> |
192 |
<img src='images/players_day.png' alt='Graph' /></p> |
193 |
|
194 |
<h2>Average server places available</h2> |
195 |
<p><img src='images/capacity_full.png' alt='Graph' /></p> |
196 |
<p><img src='images/capacity_week.png' alt='Graph' /></p> |
197 |
<p><img src='images/capacity_day.png' alt='Graph' /></p> |
198 |
|
199 |
<h2>Percentage server places used</h2> |
200 |
<p><img src='images/usage_full.png' alt='Graph' /></p> |
201 |
<p><img src='images/usage_week.png' alt='Graph' /></p> |
202 |
<p><img src='images/usage_day.png' alt='Graph' /></p> |
203 |
|
204 |
END |
205 |
|
206 |
################################################################################ |
207 |
|
208 |
$game_types = keys %game; |
209 |
|
210 |
print INDEX <<END; |
211 |
<h2>Game type popularity</h2> |
212 |
<p><img src='images/bar.png' width='10' height='10' alt='First value' /> all available data, |
213 |
<img src='images/bar7.png' width='10' height='10' alt='second value' /> last 7 days. |
214 |
$game_types game types.</p> |
215 |
END |
216 |
|
217 |
$i = 0; |
218 |
foreach $gm (sort { $game{$b} <=> $game{$a} } keys %game) { |
219 |
$players = $game{$gm}; |
220 |
$players7 = exists $game7{$gm} ? $game7{$gm} : 0; |
221 |
$propn = $players / $grand_total; |
222 |
$propn7 = $players7 / $grand_total7; |
223 |
$max = $propn if $i == 0; |
224 |
$width = int($propn / $max * $bar_width); |
225 |
$width7 = int($propn7 / $max * $bar_width); |
226 |
$pct = sprintf "%.3g", $propn * 100; |
227 |
$pct7 = sprintf "%.3g", $propn7 * 100; |
228 |
$class = $i % 2; |
229 |
print INDEX <<END; |
230 |
<p class='bar$class'>$gm<br /> |
231 |
<img src='images/bar.png' width='$width' height='10' alt='' /> $pct%<br /> |
232 |
<img src='images/bar7.png' width='$width7' height='10' alt='' /> $pct7%</p> |
233 |
END |
234 |
$i++; |
235 |
} |
236 |
|
237 |
################################################################################ |
238 |
|
239 |
$maps = keys %map; |
240 |
|
241 |
print INDEX <<END; |
242 |
<h2>Map popularity</h2> |
243 |
<p><img src='images/bar.png' width='10' height='10' alt='First value' /> all available data, |
244 |
<img src='images/bar7.png' width='10' height='10' alt='second value' /> last 7 days. |
245 |
$maps maps. |
246 |
Follow the link to search for a map on <a href='http://www.tribes2maps.com/'>Tribes2Maps</a>.</p> |
247 |
END |
248 |
|
249 |
$i = 0; |
250 |
foreach $gmm (sort { $map{$b} <=> $map{$a} } keys %map) { |
251 |
$players = $map{$gmm}; |
252 |
$players7 = exists $map7{$gmm} ? $map7{$gmm} : 0; |
253 |
$propn = $players / $grand_total; |
254 |
$propn7 = $players7 / $grand_total7; |
255 |
$max = $propn if $i == 0; |
256 |
$width = int($propn / $max * $bar_width); |
257 |
$width7 = int($propn7 / $max * $bar_width); |
258 |
$pct = sprintf "%.3g", $propn * 100; |
259 |
$pct7 = sprintf "%.3g", $propn7 * 100; |
260 |
$class = $i % 2; |
261 |
$search = $gmm; |
262 |
$search =~ s/([^\w()'*~!.-])/sprintf '%%%02x', ord $1/eg; |
263 |
$search =~ s/^Euro2_//; |
264 |
print INDEX <<END; |
265 |
<p class='bar$class'><a href="http://www.tribes2maps.com/cgi-bin/map_search.cgi?names_only=1;search=$search">$gmm</a><br /> |
266 |
<img src='images/bar.png' width='$width' height='10' alt='' /> $pct%<br /> |
267 |
<img src='images/bar7.png' width='$width7' height='10' alt='' /> $pct7%</p> |
268 |
END |
269 |
$i++; |
270 |
} |
271 |
|
272 |
################################################################################ |
273 |
|
274 |
print INDEX <<END; |
275 |
</body> |
276 |
</html> |
277 |
END |
278 |
|
279 |
close INDEX; |
280 |
|
281 |
################################################################################ |
282 |
|