/[james]/t2stats/t2stats
ViewVC logotype

Contents of /t2stats/t2stats

Parent Directory Parent Directory | Revision Log Revision Log


Revision 30 - (show annotations) (download)
Sun Apr 13 10:57:37 2003 UTC (21 years, 1 month ago) by james
File size: 9688 byte(s)
Update generated page, compress.

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 $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 undef $/;
109 open HEADER, '< header' or die "Failed to open header: $!";
110 $header = <HEADER>;
111
112 $menu = <<END;
113 <p class='menu'><a href='/t2stats/'>Home</a> |
114 <a href='graphs'>Graphs</a> |
115 <a href='games'>Game types</a> |
116 <a href='maps'>Map popularity</a></p>
117 END
118
119 $now = gmtime;
120
121 open INDEX, '>', 'index';
122 open GRAPHS, '>', 'graphs';
123 open GAMES, '>', 'games';
124 open MAPS, '>', 'maps';
125
126 print INDEX $header;
127 print GRAPHS $header;
128 print GAMES $header;
129 print MAPS $header;
130
131 print INDEX <<END;
132 <h1>Tribes 2 Europe Statistics</h1>
133 $menu
134 <p>Updated every hour, last update $now UTC. All times in UTC.
135 Data collected every 10 minutes by <a href='http://www.qstat.org/'>QStat</a>,
136 processed by a <a href='http://cvs.strcprstskrzkrk.co.uk/t2stats/'>script</a>,
137 and graphs plotted with <a href='http://ploticus.sourceforge.net/'>ploticus</a>.
138 Created by <a href='http://www.strcprstskrzkrk.co.uk/'>James Bursa</a>.</p>
139
140 END
141
142 ################################################################################
143
144 open PLOTA1, "|$ploticus_chron xinc='30 days' stubfmt='Mmmdd' -o images/players_full.png";
145 open PLOTA2, "|$ploticus_chron xinc='30 days' stubfmt='Mmmdd' -o images/capacity_full.png";
146 open PLOTA3, "|$ploticus_chron xinc='30 days' stubfmt='Mmmdd' -o images/usage_full.png";
147
148 foreach $date (sort keys %players_day) {
149 $meanplayer = $players_day{$date} / (6.0 * 24.0);
150 $meancapacity = $capacity_day{$date} / (6.0 * 24.0);
151 $usage = $meanplayer / $meancapacity * 100.0;
152 print PLOTA1 "$date\t$meanplayer\n";
153 print PLOTA2 "$date\t$meancapacity\n";
154 print PLOTA3 "$date\t$usage\n";
155 }
156
157 close PLOTA1; close PLOTA2; close PLOTA3;
158
159 open PLOTB1, "|$ploticus_chron unittype=datetime xinc='1 day' stubfmt='Www' -o images/players_week.png";
160 open PLOTB2, "|$ploticus_chron unittype=datetime xinc='1 day' stubfmt='Www' -o images/capacity_week.png";
161 open PLOTB3, "|$ploticus_chron unittype=datetime xinc='1 day' stubfmt='Www' -o images/usage_week.png";
162
163 foreach $date (sort keys %players_hour) {
164 $meanplayer = $players_hour{$date} / 6.0;
165 $meancapacity = $capacity_hour{$date} / 6.0;
166 $usage = $meanplayer / $meancapacity * 100.0;
167 print PLOTB1 "$date:00\t$meanplayer\n";
168 print PLOTB2 "$date:00\t$meancapacity\n";
169 print PLOTB3 "$date:00\t$usage\n";
170 }
171
172 close PLOTB1; close PLOTB2; close PLOTB3;
173
174 open PLOTC1, "|$ploticus_chron unittype=datetime xinc='2 hours' stubfmt='hh' -o images/players_day.png";
175 open PLOTC2, "|$ploticus_chron unittype=datetime xinc='2 hours' stubfmt='hh' -o images/capacity_day.png";
176 open PLOTC3, "|$ploticus_chron unittype=datetime xinc='2 hours' stubfmt='hh' -o images/usage_day.png";
177
178 foreach $date (sort keys %players_10m) {
179 $meanplayer = $players_10m{$date};
180 $meancapacity = $capacity_10m{$date};
181 $usage = $meanplayer / $meancapacity * 100.0;
182 print PLOTC1 "$date\t$meanplayer\n";
183 print PLOTC2 "$date\t$meancapacity\n";
184 print PLOTC3 "$date\t$usage\n";
185 }
186
187 close PLOTC1; close PLOTC2; close PLOTC3;
188
189 print INDEX <<END;
190 <h2>Players online</h2>
191 <p>All available data, averaged over each day. <a href='graphs'>More graphs</a>.<br>
192 <img src='images/players_full.png' alt='Graph'></p>
193 END
194
195 print GRAPHS <<END;
196 <h1>Tribes 2 Europe Statistics</h1>
197 $menu
198 <p>Graphs plotted with <a href='http://ploticus.sourceforge.net/'>ploticus</a>.</p>
199 <h2>Average players online</h2>
200 <p>All available data, averaged over each day:<br>
201 <img src='images/players_full.png' alt='Graph'></p>
202 <p>Last 7 days, averaged over each hour:<br>
203 <img src='images/players_week.png' alt='Graph'></p>
204 <p>Last 24 hours, sampled every 10 minutes:<br>
205 <img src='images/players_day.png' alt='Graph'></p>
206
207 <h2>Average server places available</h2>
208 <p><img src='images/capacity_full.png' alt='Graph'></p>
209 <p><img src='images/capacity_week.png' alt='Graph'></p>
210 <p><img src='images/capacity_day.png' alt='Graph'></p>
211
212 <h2>Percentage server places used</h2>
213 <p><img src='images/usage_full.png' alt='Graph'></p>
214 <p><img src='images/usage_week.png' alt='Graph'></p>
215 <p><img src='images/usage_day.png' alt='Graph'></p>
216
217 END
218
219 ################################################################################
220
221 $game_types = keys %game;
222
223 $key = <<END;
224 <p><img src='images/bar.png' width='10' height='10' alt='First value' />&nbsp;all available data,
225 <img src='images/bar7.png' width='10' height='10' alt='second value' />&nbsp;last 7 days.
226 $game_types game types.
227 END
228
229 print INDEX '<h2>Top 10 game types</h2>', $key, "<a href='games'>Full game type table</a>.</p>";
230 print GAMES '<h1>Game type popularity</h1>', $menu, $key, "</p>";
231
232 $i = 0;
233 foreach $gm (sort { $game{$b} <=> $game{$a} } keys %game) {
234 $players = $game{$gm};
235 $players7 = exists $game7{$gm} ? $game7{$gm} : 0;
236 $propn = $players / $grand_total;
237 $propn7 = $players7 / $grand_total7;
238 $max = $propn if $i == 0;
239 $width = int($propn / $max * $bar_width);
240 $width7 = int($propn7 / $max * $bar_width);
241 $pct = sprintf "%.3g", $propn * 100;
242 $pct7 = sprintf "%.3g", $propn7 * 100;
243 $class = $i % 2;
244 $line = <<END;
245 <p class='bar$class'>$gm<br><img src='images/bar.png' width='$width' height='10' alt=''> $pct%<br>
246 <img src='images/bar7.png' width='$width7' height='10' alt=''> $pct7%</p>
247 END
248 print INDEX $line if $i < 10;
249 print GAMES $line;
250 $i++;
251 }
252
253 ################################################################################
254
255 $maps = keys %map;
256
257 $key = <<END;
258 <p><img src='images/bar.png' width='10' height='10' alt='First value' />&nbsp;all available data,
259 <img src='images/bar7.png' width='10' height='10' alt='second value' />&nbsp;last 7 days.
260 $maps maps.
261 Follow the link to search for a map on <a href='http://www.tribes2maps.com/'>Tribes2Maps</a>.
262 END
263
264 print INDEX '<h2>Top 10 maps</h2>', $key, "<a href='maps'>Full map popularity table</a>.</p>";
265 print MAPS '<h1>Map popularity</h1>', $menu, $key, "</p>";
266
267 $i = 0;
268 foreach $gmm (sort { $map{$b} <=> $map{$a} } keys %map) {
269 $players = $map{$gmm};
270 $players7 = exists $map7{$gmm} ? $map7{$gmm} : 0;
271 $propn = $players / $grand_total;
272 $propn7 = $players7 / $grand_total7;
273 $max = $propn if $i == 0;
274 $width = int($propn / $max * $bar_width);
275 $width7 = int($propn7 / $max * $bar_width);
276 $pct = sprintf "%.3g", $propn * 100;
277 $pct7 = sprintf "%.3g", $propn7 * 100;
278 $class = $i % 2;
279 $search = $gmm;
280 $search =~ s/([^\w()'*~!.-])/sprintf '%%%02x', ord $1/eg;
281 $search =~ s/^Euro2_//;
282 $line = <<END;
283 <p class='bar$class'><a href="http://www.tribes2maps.com/cgi-bin/map_search.cgi?names_only=1;search=$search">$gmm</a><br>
284 <img src='images/bar.png' width='$width' height='10' alt=''> $pct%<br>
285 <img src='images/bar7.png' width='$width7' height='10' alt=''> $pct7%</p>
286 END
287 print INDEX $line if $i < 10;
288 print MAPS $line;
289 $i++;
290 }
291
292 ################################################################################
293
294 $footer = <<END;
295 <p class='footer'><a href='/'>Omroth</a> &#187; Tribes 2 Europe Statistics</p>
296 </body>
297 </html>
298 END
299
300 print INDEX $footer;
301 print GRAPHS $footer;
302 print GAMES $footer;
303 print MAPS $footer;
304
305 close INDEX;
306 close GRAPHS;
307 close GAMES;
308 close MAPS;
309
310 system 'gzip --best -c index > index.gz';
311 system 'gzip --best -c graphs > graphs.gz';
312 system 'gzip --best -c games > games.gz';
313 system 'gzip --best -c maps > maps.gz';
314
315 ################################################################################
316

Properties

Name Value
svn:executable *

  ViewVC Help
Powered by ViewVC 1.1.26