/[james]/t2stats/t2stats
ViewVC logotype

Annotation of /t2stats/t2stats

Parent Directory Parent Directory | Revision Log Revision Log


Revision 29 - (hide annotations) (download)
Thu Apr 10 20:30:46 2003 UTC (21 years, 1 month ago) by james
File size: 9368 byte(s)
Move to www.omroth.com, split into subpages.

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

Properties

Name Value
svn:executable *

  ViewVC Help
Powered by ViewVC 1.1.26