forked from versx/ShinyStatsPHP
-
Notifications
You must be signed in to change notification settings - Fork 0
/
index.php
141 lines (123 loc) · 3.25 KB
/
index.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
<?php
require 'config.php';
require 'Medoo.php';
require 'pokedex.php';
use Medoo\Medoo;
// Initialize
$db = new Medoo($config['db']);
if ($db === NULL) { die(); }
$timeZoneSet = date_default_timezone_set($config['timezone']);
if ($timeZoneSet === false) {
echo "Failed to set timezone";
}
$today = date('Y-m-d');
$shinyStats = $db->select('pokemon_shiny_stats', [
'date',
'pokemon_id',
'count' => Medoo::raw('SUM(`count`)')
], [
'date' => $today,
'count[>]' => 0,
'GROUP' => 'pokemon_id'
]);
$totalStats = $db->select('pokemon_iv_stats', [
'date',
'pokemon_id',
'count' => Medoo::raw('SUM(`count`)')
], [
'date' => $today,
'GROUP' => 'pokemon_id'
]);
$html = '
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="utf-8">
<meta http-equiv="x-ua-compatible" content="ie=edge">
<meta name="viewport" content="width=device-width, initial-scale=1, shrink-to-fit=no">
<link rel="stylesheet" href="https://stackpath.bootstrapcdn.com/bootstrap/4.3.1/css/bootstrap.min.css" integrity="sha384-ggOyR0iXCbMQv3Xipma34MD+dH/1fQ784/j6cY/iJTQUOhcWr7x9JvoRxT2MZw1T" crossorigin="anonymous">
<script src="https://cdnjs.cloudflare.com/ajax/libs/jquery/3.4.1/jquery.min.js"></script>
<title>Live shiny stats for Pokémon Go</title>
<style>
.icon {
width: 60px;
height: 60px;
}
#header {
font-weight: bold;
font-size: 25px;
text-align: center;
margin: 10px 0 0 0;
}
#event, #data_period {
font-size: 15px;
text-align: center;
margin: 10px;
}
#event_name {
font-weight: bold;
}
.table > thead > tr > th {
vertical-align: middle;
}
.table > tbody > tr > td {
vertical-align: middle;
}
#footer {
font-size: 13px;
text-align: center;
margin: 10px;
}
</style>
</head>
<body>
<div id="header">
Live Shiny Stats for Pokémon Go
</div>
<div id="data_period">
Data from the last 24 hours.
</div>
<div id="shiny_table">
<table class="table table-striped table-hover table-sm">
<thead class="thead-dark">
<tr>
<th scope="col"> </th>
<th scope="col">Pokemon</th>
<th scope="col">Shiny Rate</th>
<th scope="col">Shiny / Total</th>
</tr>
</thead>
<tbody id="table_body">';
for ($i = 0; $i < count($shinyStats); $i++) {
$row = $shinyStats[$i];
$pokemonId = $row['pokemon_id'];
$name = $pokedex[$pokemonId];
$shiny = $row['count'];
$total = getTotalCount($totalStats, $pokemonId);
$rate = round($total / $shiny);
$pokemonImageUrl = sprintf($config['images'], $pokemonId);
$html .= '<tr>';
$html .= '<td><img src="' . $pokemonImageUrl . '" width="48" height="48"/></td>';
$html .= '<td>' . $name . ' (#' . $pokemonId . ')</td>';
$html .= '<td>1/' . $rate . '</td>';
$html .= '<td>' . number_format($shiny) . '/' . number_format($total) . '</td>';
$html .= '</tr>';
}
$html .= '</tbody>
</table>
</div>
<div id="footer"></div>
</body>
</html>
';
echo $html;
function getTotalCount($pokemon, $pokemonId) {
for ($i = 0; $i < count($pokemon); $i++) {
$row = $pokemon[$i];
if ($row['pokemon_id'] === $pokemonId) {
return $row['count'];
}
}
return 0;
}
?>