This repository has been archived by the owner on Nov 3, 2021. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 1
/
results_functions.php
77 lines (64 loc) · 1.78 KB
/
results_functions.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
<?
$race_status = array("OK", "Did not finish", "Disqualified", "Did not start");
$race_status_s = array("OK", "DNF", "DQ", "DNS");
define("RACE_NEW", 0x0);
define("RACE_QUALIFYING", 0x1);
define("RACE_RACE", 0x2);
function time_hr($time) {
$hour = floor($time / 3600000);
$time = $time % 3600000;
$min = floor($time / 60000);
$time = $time % 60000;
$sec = floor($time / 1000);
$ms = $time % 1000;
if($hour > 0)
return sprintf("%d:%02d:%02d.%03d", $hour, $min, $sec, $ms);
else
return sprintf("%02d:%02d.%03d", $min, $sec, $ms);
}
function points_race($position, $ruleset) {
if($position < 1 || $position > 15) return 0;
$race = array();
for($x = 1; $x <= 15; $x++) {
eval('$race[' . $x . '] = $ruleset[\'rp' . $x . '\'];');
}
return $race[$position];
}
function points_qualifying($position, $ruleset) {
if($position < 1 || $position > 5) return 0;
$qual = array();
for($x = 1; $x <= 5; $x++) {
eval('$qual[' . $x . '] = $ruleset[\'qp' . $x . '\'];');
}
return $qual[$position];
}
function points_fl($fl, $ruleset) {
if($fl == 1 || $fl == true)
return $ruleset['fl'];
else
return 0;
}
function points_total($race, $grid, $fl, $ruleset_race) {
$total = 0;
$total += points_race($race, $ruleset_race);
$total += points_qualifying($grid, $ruleset_race);
$total += points_fl($fl, $ruleset_race);
return $total;
}
function point_sort($a, $b) {
if($a['points'] == $b['points']) {
if($a['name'] == $b['name'])
return 0;
return $a['name'] > $b['name'] ? 1 : -1;
}
return $a['points'] < $b['points'] ? 1 : -1;
}
function point_sort_qual($a, $b) {
if($a['pointsqualifying'] == $b['pointsqualifying']) {
if($a['name'] == $b['name'])
return 0;
return $a['name'] > $b['name'] ? 1 : -1;
}
return $a['pointsqualifying'] < $b['pointsqualifying'] ? 1 : -1;
}
?>