OSDN Git Service

[modify]小数点以下切り捨てをSQLで行う
[hengband/web.git] / score / popularity_ranking.php
1 <?php
2 //ini_set('display_errors', 'On');
3
4 ini_set('log_errors', 'On');
5 ini_set('error_log', 'errors/'.pathinfo(__FILE__, PATHINFO_FILENAME).'.log');
6
7 ini_set('zlib.output_compression', 'On');
8
9 require_once "db_common.inc";
10 require_once "web_template.inc";
11
12 function print_popularity_table($fp, $stat, $id_name, $name)
13 {
14     fwrite($fp, <<<EOM
15 <div id="{$id_name}">
16 <table class="tablesorter score statistics_table">
17 <thead>
18 <tr>
19 <th>$name</th>
20
21 EOM
22     );
23     
24     foreach ([
25         '計', '男性', '女性', '勝利', '平均スコア', '最大スコア',
26     ] as $name) {
27         fwrite($fp, "<th>${name}</th>\n");
28     }
29     fwrite($fp, "</tr>\n".
30            "</thead>\n");
31
32     foreach ($stat as $k => $s) {
33         $name_link = "<a href='score_ranking.php?{$id_name}={$s['id']}'>{$s['name']}</a></td>";
34         fwrite($fp, <<<EOM
35 <tr>
36 <td>$name_link</td>
37 <td class="number">{$s['total_count']}</td>
38 <td class="number">{$s['male_count']}</td>
39 <td class="number">{$s['female_count']}</td>
40 <td class="number">{$s['winner_count']}</td>
41 <td class="number">{$s['average_score']}</td>
42 <td class="number">{$s['max_score']}</td>
43 </tr>
44
45 EOM
46         );
47     }
48
49     fwrite($fp, "</table>\n".
50            "</div>\n");
51 }
52
53 function print_realm_popularity_table($fp, $stat, $id_name)
54 {
55     // 魔法領域の統計を職業ごとにグループ分け
56     $class_ids = array_unique(array_column($stat, "class_id"));
57     $class_realm_stat_list = array_fill_keys($class_ids, []);
58
59     foreach ($stat as $s) {
60         $class_realm_stat_list[intval($s["class_id"])][] = $s;
61     }
62
63     fwrite($fp, "<div id=\"{$id_name}\">");
64
65     // 職業ごとにテーブルを表示
66     foreach ($class_realm_stat_list as $class_id => $class_realm_stat) {
67         if (count($class_realm_stat) <= 1) continue; // 領域固定の職業は飛ばす
68
69         $class_name = $class_realm_stat[0]['class_name'];
70
71         fwrite($fp, <<<EOM
72 <table class="tablesorter score statistics_table" id="${id_name}">
73 <thead>
74 <tr>
75 <th>{$class_name}</th>
76
77 EOM
78         );
79         foreach ([
80             '計', '男性', '女性', '勝利', '平均スコア', '最大スコア',
81         ] as $th_name) {
82             fwrite($fp, "<th>${th_name}</th>\n");
83         }
84         fwrite($fp, "</tr>\n".
85                "</thead>\n");
86
87         foreach ($class_realm_stat as $realm) {
88             $name_link = "<a href='score_ranking.php?class_id={$class_id}&{$id_name}={$realm['realm_id']}'>{$realm['realm_name']}</a></td>";
89             fwrite($fp, <<<EOM
90 <tr>
91 <td>$name_link</td>
92 <td class="number">{$realm['total_count']}</td>
93 <td class="number">{$realm['male_count']}</td>
94 <td class="number">{$realm['female_count']}</td>
95 <td class="number">{$realm['winner_count']}</td>
96 <td class="number">{$realm['average_score']}</td>
97 <td class="number">{$realm['max_score']}</td>
98 </tr>
99
100 EOM
101             );
102         }
103
104         fwrite($fp, "</table>\n");
105     }
106     fwrite($fp, "</div>\n");
107 }
108
109 $db = new ScoreDB();
110
111 $time_start = microtime(true);
112
113 $statistics = $db->get_statistics_tables('total_count');
114
115 $query_time = microtime(true) - $time_start;
116
117 $wt = new WebTemplate();
118
119 $wt->add_head_contents('<link rel="stylesheet" type="text/css" href="css/score-table.css">');
120 $wt->add_head_contents('<link rel="stylesheet" type="text/css" href="tablesorter-theme/style.css">');
121 $wt->add_head_contents(
122     <<<EOM
123 <script
124 src="https://code.jquery.com/jquery-3.3.1.min.js"
125 integrity="sha256-FgpCb/KJQlLNfOu91ta32o/NMZxltwRo8QtmkMRdAu8="
126 crossorigin="anonymous"></script>
127 EOM
128 );
129 $wt->add_head_contents('<script src="jquery.tablesorter.min.js" type="text/javascript"></script>');
130 $wt->add_head_contents('<script src="popularity_ranking.js" type="text/javascript"></script>');
131 $wt->set_title("変愚蛮怒 スコアランキング 人気のある種族・職業・性格・魔法領域");
132
133 $fp = $wt->main_contents_fp();
134 fwrite($fp, "<h2>人気のある種族・職業・性格・魔法領域</h2>\n");
135 //fprintf($fp, "<small>(%.2f 秒)</small>", $query_time);
136 fwrite($fp, <<<EOM
137 <nobr>[ <a href="javascript:void(0)" class="table_select" id="race_id">種族</a> | <a href="javascript:void(0)" class="table_select" id="class_id">職業</a> | <a href="javascript:void(0)" class="table_select" id="personality_id">性格</a> ] [ <a href="javascript:void(0)" class="table_select" id="realm_id1">魔法領域1</a> | <a href="javascript:void(0)" class="table_select" id="realm_id2">魔法領域2</a> ]</nobr>
138
139 EOM
140
141 );
142
143 print_popularity_table($fp, $statistics['race'], 'race_id', "種族");
144 print_popularity_table($fp, $statistics['class'], 'class_id', "職業");
145 print_popularity_table($fp, $statistics['personality'], 'personality_id', "性格");
146 print_realm_popularity_table($fp, $statistics['realm1'], 'realm_id1');
147 print_realm_popularity_table($fp, $statistics['realm2'], 'realm_id2');
148
149 $wt->print_page();