Коррекция названий флагов существ.
[cswow.git] / module / stat / stat.php
blob61e03b87c6ebd43ae4fc4303758eea6184d95e24
1 <?php
2 include_once("include/functions.php");
3 include_once("include/simple_cacher.php");
4 // Путь к модулю, для картинок
5 $module_path = "module/stat";
6 function days($time)
8 $d = floor( $time / (3600*24) );
9 $time = $time - $d*3600*24;
10 $h = floor( $time / 3600 );
11 $time = $time - $h*3600;
12 $m = floor( $time / 60 );
13 return sprintf("%d дней. %02d ч. %02d м.", $d, $h, $m);
16 function renderClassStat($list, $data, $total)
18 global $module_path;
19 echo "<table class=stat cellSpacing=0 cellPadding=0><tbody><tr class=stat_top>";
20 foreach ($list as $c)
22 $pct = $total ? $data[$c]/$total * 100 :0;
23 $height = $pct * 4;
24 $pct = sprintf("%0.2f%%", $pct);
25 echo "<td class=st_data>{$pct}<br><img src=\"{$module_path}/img/column.gif\" width=\"44\" height=\"$height\" alt=\"{$pct}\"/></td>";
27 echo "</tr><tr class=stat_bot>";
28 foreach ($list as $c)
29 echo "<td class=st_data><img src=".getClassImage($c)." width=32px><br>".$data[$c]."</td>";
30 echo "</tr></table>";
33 function renderRaceStat($list, $data, $total)
35 global $module_path;
36 echo "<table class=stat cellSpacing=0 cellPadding=0><tbody><tr class=stat_top>";
37 foreach ($list as $r)
39 $pct = $total ? $data[$r]/$total * 100 :0;
40 $height = $pct * 4;
41 $pct = sprintf("%0.2f%%", $pct);
42 echo "<td class=st_data>{$pct}<br><img src=\"{$module_path}/img/column.gif\" width=\"79\" height=\"$height\" alt=\"{$pct}\"/></td>";
44 echo "</tr><tr class=stat_bot>";
45 foreach ($list as $r)
46 echo "<td class=st_data><img src=".getRaceImage($r, rand()%2)." width=32px><br>".$data[$r]."</td>";
47 echo "</tr>";
48 echo "</tbody></table>";
51 $cacheFilename = 'statistic_'.$config['lang'].'.html';
52 if (checkUseCacheHtml($cacheFilename, 60*60*24))
54 //******************************************************************************
55 // Основные настройки статистики
56 //******************************************************************************
57 $alliance_race = array(1, 3, 4, 7, 11); // Список рас альянса
58 $horde_race = array(2, 5, 6, 8, 10); // Список рас орды
59 $class = array(11,5,4,1,8,9,2,3,7,6); // Классы по которым собираем статистику
61 // Статистика аккаунтов
62 $accs = $rDB->selectcell("SELECT count(`id`) FROM `account`;");
64 // Статистика онлайн
65 $onlineal = $cDB->selectcell("SELECT count(`guid`) FROM `characters` WHERE (`online` > '0' AND `race` IN (?a))", $alliance_race);
66 $onlinehr = $cDB->selectcell("SELECT count(`guid`) FROM `characters` WHERE (`online` > '0' AND `race` IN (?a))", $horde_race);
67 $onlinePl = $onlineal + $onlinehr;
69 // Получаем статистику по клаасам из базы
70 $calliance = array(); // Количество игроков альянса по классам
71 $chorde = array(); // Количество игроков орды по классам
72 $allside = array(); // Количество игроков (орды и альянса) по классам
73 $craces = array(); // Данные распределения по расам
74 $alliance = 0; // Всего игроков из альянса
75 $horde = 0; // Всего игроков из орды
76 $chrs = 0; // Всего игроков
77 foreach ($class as $c)
79 $calliance[$c] = $cDB->selectcell("SELECT count(`guid`) FROM `characters` WHERE (`race` IN (?a) AND `class`=?d)", $alliance_race, $c);
80 $chorde[$c] = $cDB->selectcell("SELECT count(`guid`) FROM `characters` WHERE (`race` IN (?a) AND `class`=?d)", $horde_race, $c);
81 $alliance += $calliance[$c];
82 $horde += $chorde[$c];
83 $allside[$c] = $calliance[$c] + $chorde[$c];
85 $chrs = $alliance + $horde;
87 // Получаем статистику по расам из базы
88 $race = array_merge($alliance_race, $horde_race);
89 foreach ($race as $r)
91 $craces[$r] = $cDB->selectcell("SELECT count(`guid`) FROM `characters` WHERE `race`=?d", $r);
94 // Получаем данные из uptime
95 $uptime = $rDB->selectRow(
96 "SELECT
97 AVG(uptime) AS `avg`,
98 MAX(uptime) AS `max_uptime`,
99 MAX(maxplayers) AS `max_online`,
100 (100*SUM(uptime)/(UNIX_TIMESTAMP()-MIN(starttime))) AS `total`
101 FROM uptime");
102 $cur_uptame = $rDB->selectRow(
103 "SELECT
104 uptime AS 'cur_uptame'
105 FROM uptime ORDER BY starttime DESC");
107 //******************************************************************************
108 // Вывод общей статистики
109 //******************************************************************************
110 echo "<table class=report width=100%>";
111 echo "<tr><td colspan=2 class=head>".$lang['stat_total']."</td></tr>";
112 echo "<tr><td>".$lang['stat_online']."</td><td>".$onlinePl."</td></tr>";
113 echo "<tr><td>".$lang['stat_maxonline']."</td><td>".$uptime['max_online']."</td></tr>";
114 echo "<tr><td>".$lang['stat_uptime']."</td><td>".days($cur_uptame['cur_uptame'])."</td></tr>";
115 echo "<tr><td>".$lang['stat_maxuptime']."</td><td>".days($uptime['max_uptime'])."</td></tr>";
116 echo "<tr><td>".$lang['stat_total_acc']."</td><td>".$accs."</td></tr>";
117 echo "<tr><td>".$lang['stat_total_chr']."</td><td>".$chrs."</td></tr>";
118 echo "</table>";
120 //******************************************************************************
121 // Вывод статистики альянса и орды
122 //******************************************************************************
123 echo "<br><table class=report width=100%><tbody>";
124 echo "<tr><td class=head colSpan=3>".$lang['stat_sides']."</td></tr>";
125 echo "<tr>";
126 echo "<td align=center><br><img src=\"module/stat/img/alliance.gif\"><br>".$lang['stat_total_pl']." $alliance<br>".$lang['stat_online']." $onlineal</td>";
127 echo "<td width=6px></td>";
128 echo "<td align=center><br><img src=\"module/stat/img/horde.gif\"><br>".$lang['stat_total_pl']." $horde<br>".$lang['stat_online']." $onlinehr</td>";
129 echo "</tr>";
131 // Распределение по классам
132 echo "<tr><td class=head colspan=3>".$lang['stat_classes']."</td></tr>";
133 echo "<tr>";
134 echo "<td class=stat_data align=center>";renderClassStat($class, $calliance, $alliance);echo "</td>";
135 echo "<td></td>";
136 echo "<td class=stat_data align=center>";renderClassStat($class, $chorde, $horde);echo "</td>";
137 echo "</tr>";
139 // распределение по расам
140 echo "<tr><td class=head colspan=3>".$lang['stat_races']."</td></tr>";
141 echo "<tr>";
142 echo "<td class=stat_data align=center>";renderRaceStat($alliance_race, $craces, $chrs);echo "</td>";
143 echo "<td></td>";
144 echo "<td class=stat_data align=center>";renderRaceStat($horde_race, $craces, $chrs);echo "</td>";
145 echo "</tr>";
147 echo "</tbody></table>";
148 flushHtmlCache($cacheFilename);