This repository was archived by the owner on Jul 12, 2024. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathstats.php
202 lines (188 loc) · 7.1 KB
/
stats.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
<!DOCTYPE html>
<?
$link = mysql_connect("127.0.0.1", "USERNAME", "PASSWORD") or die("no db connection: " . mysql_error());
mysql_select_db("carousel") or die("could not select carousel db");
function format_time($secs) {
$secs = floatval($secs);
if ($secs > 0.0) {
$usecs = $secs - floor($secs);
$hours = floor($secs / (60.0*60.0));
$rest = $secs % (60.0*60.0);
$minutes = floor($rest / (60.0));
$rest = $rest % (60.0);
$seconds = floor($rest);
$hours = $hours == 0.0 ? "" : sprintf("%02d:", $hours);
$usecs = preg_replace('/^0\./', "", sprintf("%.3f", $usecs));
return sprintf("%s%02d:%02d.%s", $hours, $minutes, $seconds, $usecs);
} else {
return "-";
}
}
function mysql_get_list($query) {
$res = mysql_query($query);
if (!$res) {die("query failed: ".mysql_error());}
$ret = Array();
while($row = mysql_fetch_object($res)) {
array_push($ret, $row);
}
return $ret;
}
$seasons = mysql_get_list("select * from seasons order by id desc");
$season = $seasons[0];
$events = mysql_get_list("select * from events where season_id=".$season->id);
$stats = Array();
foreach ($events as $event) {
# get races for the event
$races = mysql_get_list("select * from races where event_id=".$event->id);
foreach ($races as $race) {
$results = mysql_get_list("select * from results where finish_status='Finished Normally' and race_id=".$race->id);
foreach($results as $result) {
$driver = mysql_get_list("select * from drivers where id=".$result->driver_id);
$driver = $driver[0];
if (!$stats[$driver->name]) {
$stats[$driver->name] = Array();
}
if ($result->laps_completed >= $race->laps) {
if ($stats[$driver->name][$event->id]) {
if ($stats[$driver->name][$event->id]['race_time'] > $result->race_time) {
$stats[$driver->name][$event->id]['result_id'] = $result->id;
$stats[$driver->name][$event->id]['race_time'] = $result->race_time;
$stats[$driver->name][$event->id]['race_date'] = $race->race_time;
}
if ($stats[$driver->name][$event->id]['best_lap'] > $result->best_lap) {
$stats[$driver->name][$event->id]['best_lap'] = $result->best_lap;
$stats[$driver->name][$event->id]['best_date'] = $race->race_time;
}
} else {
$stats[$driver->name][$event->id] = Array();
$stats[$driver->name][$event->id]['race_time'] = $result->race_time;
$stats[$driver->name][$event->id]['result_id'] = $result->id;
$stats[$driver->name][$event->id]['best_lap'] = $result->best_lap;
$stats[$driver->name][$event->id]['race_date'] = $race->race_time;
$stats[$driver->name][$event->id]['best_date'] = $race->race_time;
}
}
}
}
}
foreach ($stats as $driver_name => $driver_stats) {
$sum = 0.0;
foreach ($driver_stats as $event_id => $driver_stat) {
$sum += $driver_stat['race_time'];
}
$stats[$driver_name]["total"] = $sum;
}
# sort
foreach ($stats as $driver_name => $driver_stats) {
$total[$driver_name] = $driver_stats['total'];
$race_num[$driver_name] = count($driver_stats);
#print "".$driver_name.": ".count($driver_stats);
}
array_multisort($race_num, SORT_DESC, $total, SORT_ASC, $stats);
?>
<html>
<head>
<title>The Eternal Track Cycle</title>
<link rel="stylesheet" href="css/blueprint/screen.css" type="text/css" media="screen, projection">
<link rel="stylesheet" href="css/blueprint/print.css" type="text/css" media="print">
<!--[if lt IE 8]>
<link rel="stylesheet" href="css/blueprint/ie.css" type="text/css" media="screen, projection">
<![endif]-->
<style type="text/css" media="screen">
table.results {
border-width: 0px;
border-style: none;
border-color: gray;
border-collapse: collapse;
background-color: white;
}
table.results th {
border-width: 2px;
padding: 2px;
border-style: solid;
border-color: white;
background-color: #fd6;
}
table.results td {
border-width: 2px;
padding: 2px;
border-style: solid;
border-color: white;
background-color: #fd6;
vertical-align: top;
}
table.results tbody td.right {
text-align: right;
}
table.results thead td {
text-align: center;
}
</style>
<script type="text/javascript" charset="utf-8" src="javascripts/jquery.js"></script>
</head>
<body>
<div class="container">
<div class="span-24 last">
<div class="span-10">
<h1>The Eternal Track Cycle</h1>
<p>
An rFactor race format prototype in the spirit of the glorious race@rfc times.
Each season runs for 2 weeks, and includes 5 tracks which run in a cycle. 5 minute qualifying, 10 laps race.
Winner is the one with the fastest aggregated times achieved on each of the tracks.
There is no limit on the number of times you can try during the season, so a bad race isn't the end of the world.
</p>
</div>
<div class="span-14 last">
<img src="images/carousel.jpg" width="530" height="196" />
</div>
</div>
<div class="span-4">
<ul>
<? foreach ($seasons as $s) { ?>
<li><a href="#" data-remote="true" data-link="stats.php?season_id=<?= $s->id ?>"><?= $s->name ?></a></li>
<? } ?>
</ul>
</div>
<div class="span-20 last">
<h2 class="">Season: <?= $season->name ?></h2>
<h3 class="">Mod: <?= $events[0]->mod ?></h3>
<p>If you want to try, hop onto the server named <span class="highlight">backmarkers.etc</span>
after installing the <a href="http://league.varjanta.com/downloads/file.php?id=507">mod</a> and the <a href="http://n2backmarkers.s3.amazonaws.com/etc_formula_armaroli_track_pack.7z">tracks</a></p>
<table class="results">
<thead>
<tr>
<td>Pos</td>
<td>Driver</td>
<? foreach ($events as $event) { ?>
<td><?= $event->track ?></td>
<? } ?>
<td class="loud"><b>Total</b></td>
</tr>
</thead>
<tbody>
<? $pos = 1 ?>
<? foreach ($stats as $driver_name => $driverstats) { ?>
<tr>
<td><?= $pos ?></td>
<td><?= $driver_name ?></td>
<? foreach ($events as $event) { ?>
<td class="right">
<?= format_time($driverstats[$event->id]['race_time']) ?> <br />
<span class="small"><?= $driverstats[$event->id]['race_date'] ?></span><br />
<span class="small">BL: <?= format_time($driverstats[$event->id]['best_lap']) ?></span><br />
<span class="small"><?= $driverstats[$event->id]['best_date'] ?></span>
</td>
<? } ?>
<td class="loud right"><b><?= format_time($driverstats['total']) ?></b></td>
<? $pos++ ?>
</tr>
<? } ?>
</tbody>
</table>
</div>
<div class="span-24 last">
The footer
</div>
</div>
</body>
</html>