forked from spider312/mtgas
/
sealed_top.php
228 lines (224 loc) · 7.73 KB
/
sealed_top.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
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
<?php
include 'lib.php' ;
include 'includes/db.php' ;
include 'includes/card.php' ;
$order = param($_GET, 'order', 'score_ratio') ;
$report = param($_GET, 'report', '') ;
$type = param($_GET, 'type', '') ;
$color = param($_GET, 'color', '') ;
$rarity = param($_GET, 'rarity', '') ;
html_head(
'Inclusion and performance statistics',
array('style.css', 'options.css', 'mtg.css', 'sealed_top.css'),
array('../variables.js.php', 'html.js', 'math.js', 'image.js', 'options.js')
) ;
?>
<body onload="start()">
<script language="javascript">
function start() { // On page load
game = {} ;
game.options = new Options(true) ;
}
</script>
<?php
html_menu() ;
?>
<div class="section">
<h1>Inclusion in sealed and performance statistics</h1>
<h2>Report</h2>
<form>
Report :
<select name="report">
<?php
$reports = array_reverse(sorted_scandir('stats')) ;
foreach ( $reports as $r )
if ( ( $r != '.' ) && ( $r != '..' ) ) {
echo ' <option ' ;
option_value($r, $report) ;
echo '>'.$r.' (updated '.date ("F d Y H:i:s.", filemtime('stats/'.$r)).')</option>'."\n" ;
}
?>
</select>
<input type="submit" value="Select">
<?php
if ( $report == '' )
die('</form>') ;
$report = json_decode(file_get_contents('stats/'.$report)) ;
echo ' <ul>' ;
if ( isset($report->date) )
echo "<li>Selection by date : {$report->date}</li>" ;
if ( isset($report->exts) && ( count($report->exts) > 0 ) )
echo "<li>Selection by extensions : ".implode(', ', $report->exts)."</li>" ;
if ( isset($report->mask) )
echo "<li>Selection by name mask : {$report->mask}</li>" ;
if ( isset($report->imask) )
echo "<li>Selection by name ignore mask : {$report->imask}</li>" ;
?>
</ul>
<h2>Display</h2>
Sort :
<select name="order">
<option <?php option_value("opened", $order) ; ?>>Opened</option>
<option <?php option_value("played", $order) ; ?>>Played</option>
<option <?php option_value("scored", $order) ; ?>>Scored</option>
<option <?php option_value("play_ratio", $order) ; ?>>Play ratio</option>
<option <?php option_value("score_ratio", $order) ; ?>>Score ratio</option>
<option <?php option_value("play_score_ratio", $order) ; ?>>Score ratio (played)</option>
</select>
<br>
Filter :
<select name="type">
<option <?php option_value("", $type) ; ?>>All types</option>
<option <?php option_value("land", $type) ; ?>>Land</option>
<option <?php option_value("artifact", $type) ; ?>>Artifact</option>
<option <?php option_value("enchantment", $type) ; ?>>Enchant</option>
<option <?php option_value("creature", $type) ; ?>>Creature</option>
<option <?php option_value("planeswalker", $type) ; ?>>Planeswalker</option>
<option <?php option_value("sorcery", $type) ; ?>>Sorcery</option>
<option <?php option_value("instant", $type) ; ?>>Instant</option>
<option <?php option_value("tribal", $type) ; ?>>Tribal</option>
</select>
<select name="color">
<option <?php option_value("", $color) ; ?>>All colors</option>
<option <?php option_value("X", $color) ; ?>>None</option>
<option <?php option_value("W", $color) ; ?>>White</option>
<option <?php option_value("U", $color) ; ?>>Blue</option>
<option <?php option_value("B", $color) ; ?>>Black</option>
<option <?php option_value("R", $color) ; ?>>Red</option>
<option <?php option_value("G", $color) ; ?>>Green</option>
</select>
<select name="rarity">
<option <?php option_value("", $rarity) ; ?>>All rarities</option>
<option <?php option_value("M", $rarity) ; ?>>Mythics</option>
<option <?php option_value("R", $rarity) ; ?>>Rares</option>
<option <?php option_value("U", $rarity) ; ?>>Uncos</option>
<option <?php option_value("C", $rarity) ; ?>>Commons</option>
<option <?php option_value("S", $rarity) ; ?>>Specials</option>
</select>
<br>
<input type="submit" value="Apply">
</form>
<?php
$card_connection = card_connect() ;
$p = array() ; ;
foreach ( $report->cards as $i => $card ) {
$c = query_oneshot("SELECT `name`, `attrs`, `text` FROM `card` WHERE `id` = $i", 'Pick', $card_connection) ;
$card->name = $c->name ;
$card->attrs = $c->attrs ;
$card->text = $c->text ;
if ( $card->opened != 0 ) {
$card->play_ratio = $card->played / $card->opened ;
$card->score_ratio = $card->scored / $card->opened / 2 ;
} else {
$card->play_ratio = 0 ;
$card->score_ratio = 0 ;
}
if ( $card->played != 0 )
$card->play_score_ratio = $card->scored / $card->played / 2 ;
else
$card->play_score_ratio = 0 ;
$p[] = $card ;
}
usort($p, 'sort_'.$order) ;
$totalgames = $report->starter_won + $report->starter_lost ;
$winpct = $report->starter_won / $totalgames ;
?>
<h2>Stats</h2>
<ul>
<li><?=count((array)$report->tournaments);?> tournament parsed</li>
<li>Starter won <?=$report->starter_won;?> (<?=round(100*$winpct, 2);?>%) and lost <?=$report->starter_lost;?> in <?=$totalgames;?> games</li>
</ul>
<h2>List</h2>
<table>
<tr>
<th title="Ranking in selection / absolutely">#</th>
<th title="Most found card's rarity in played extensions. Mouse over to get details">R</th>
<th title="Card's name">Name</th>
<th title="Card's cost">Cost</th>
<th title="Number of times card was opened">Opened</th>
<th title="Number of times card have been inserted in a deck">Played</th>
<th title="Number of games won with this card in deck">Scored</th>
<th title="Played / Opened">Play ratio</th>
<th title="Scored / Opened">Score ratio</th>
<th title="Scored / Played">Score ratio (played)</th>
</tr>
<?php
$nb = 0 ;
foreach ( $p as $i => $c ) {
// Rarity
$crarity = 'S' ;
$nrarity = 0 ;
$rdisp = '' ;
foreach ( $c->rarity as $r => $rnb ) {
$rdisp .= $r.' : '.$rnb.' ' ;
if ( $rnb > $nrarity ) {
$crarity = $r ;
$nrarity = $rnb ;
}
}
// Filters
if ( ( $rarity != '' ) && ( $crarity != $rarity ) )
continue ;
$d = json_decode($c->attrs) ;
if ( ( $color != '' ) && is_string($d->color) && ( strpos($d->color, $color) === false ) )
continue ;
if ( ( $type != '' ) && is_array($d->types) && ( array_search($type, $d->types) === false ) )
continue ;
echo ' <tr title="'.htmlentities((count($d->manas)>0 ? implode($d->manas)."\n" : '').$c->text).'">
<td>'.$nb++.'/'.$i.'</td>
<td class="bg_r_'.$crarity.'" title="'.$rdisp.'">'.$crarity.'</td>
<td><a href="http://magiccards.info/query?q=!'.$c->name.'">'.$c->name.'</a></td>
<td>'.manas2html($d->manas).'</td>
<td>'.$c->opened.'</td>
<td>'.$c->played.'</td>
<td>'.$c->scored.'</td>
<td>'.round($c->play_ratio*100, 2).'%</td>
<td>'.round($c->score_ratio*100, 2).'%</td>
<td>'.round($c->play_score_ratio*100, 2).'%</td>
</tr>'."\n" ;
}
// Caption
$caption = count($p).' cards' ;
$crit = array() ;
if ( $type != '' ) $crit[] = 'type="'.$type.'"' ;
if ( $color != '' ) $crit[] = 'color="'.$color.'"' ;
if ( $rarity != '' ) $crit[] = 'rarity="'.$rarity.'"' ;
if ( count($crit) > 0 )
$caption = $nb.' / '.$caption.' with '.implode(', ', $crit) ;
echo ' <caption>'.$caption.'</caption>' ;
?>
</table>
</div>
</body>
</html>
<?php
function sort_by($field, $a, $b) {
$res = $b->$field - $a->$field ;
if ( $res == 0 )
return 0 ;
return $res / abs($res) ;
}
function sort_opened($a, $b) {
return sort_by('opened', $a, $b) ;
}
function sort_played($a, $b) {
return sort_by('played', $a, $b) ;
}
function sort_scored($a, $b) {
return sort_by('scored', $a, $b) ;
}
function sort_play_ratio($a, $b) {
return sort_by('play_ratio', $a, $b) ;
}
function sort_score_ratio($a, $b) {
return sort_by('score_ratio', $a, $b) ;
}
function sort_play_score_ratio($a, $b) {
return sort_by('play_score_ratio', $a, $b) ;
}
function option_value($value, $default) {
echo 'value="'.$value.'"' ;
if ( $value == $default )
echo ' selected' ;
}
?>