-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathF1Helper.php
More file actions
141 lines (129 loc) · 4.32 KB
/
F1Helper.php
File metadata and controls
141 lines (129 loc) · 4.32 KB
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
class F1Helper {
// 2010 races
public static function getRaces($year) {
switch($year) {
case 2010:
return array(0 => "Bahrain",
1 => "Melbourne - Australia",
2 => "Sepang - Malaysia",
3 => "Shanghai - China",
4 => "Barcelona - Spain",
5 => "Monte Carlo - Monaco",
6 => "Istanbul - Turkey",
7 => "Montreal - Canada",
8 => "Valencia - Europe",
9 => "Silverstone - Britain",
10 => "Hockenheim - Germany",
11 => "Budapest - Hungary",
12 => "Spa - Belgium",
13 => "Monza - Italy",
14 => "Singapore",
15 => "Suzuka - Japan",
16 => "Yeongam - Korea",
17 => "Interlagos - Brazil",
18 => "Abu Dhabi");
case 2011:
return array(0 => "Melbourne - Australia",
1 => "Kuala Lumpur - Malaysia",
2 => "Shanghai - China",
3 => "Istanbul - Turkey",
4 => "Catalunya - Spain",
5 => "Monte Carlo - Monaco",
6 => "Montreal - Canada",
7 => "Valencia - Europe",
8 => "Silverstone - Great Britain",
9 => "Nürburgring - Germany",
10 => "Budapest - Hungary",
11 => "Spa-Francorchamps - Belgium",
12 => "Monza - Italy",
13 => "Singapore",
14 => "Suzuka - Japan",
15 => "Yeongam - Korea",
16 => "New Delhi - India",
17 => "Yas Marina Circuit - Abu Dhabi",
18 => "Sao Paulo - Brazil");
}
}
// Race types
public static function getTypes() {
return array(0 => "Practice", 1 => "Qualifying", 2 => "Race", 3 => "TimeTrial");
}
public static function getStandardType() {
return 3;
}
// Tyre types
public static function getTyres() {
return array(0 => "Option", 1 => "Prime", 2 => "Intermediate", 3 => "Wet");
}
// Cars
public static function getCars($year) {
switch($year) {
case 2010:
return array(0 => "RBR-Renault",
1 => "McLaren-Mercedes",
2 => "Ferrari",
3 => "Mercedes-GP",
4 => "Renault",
5 => "Williams-Cosworth",
6 => "Force India-Mercedes",
7 => "BMW Sauber-Ferrari",
8 => "STR-Ferrari",
9 => "Lotus-Cosworth",
10 => "HRT-Cosworth",
11 => "Virgin-Cosworth",
12 => "TimeTrial car");
case 2011:
return array(0 => "RBR-Renault",
1 => "McLaren-Mercedes",
2 => "Ferrari",
3 => "Mercedes",
4 => "Renault",
5 => "Force India-Mercedes",
6 => "Sauber-Ferrari",
7 => "STR-Ferrari",
8 => "Williams-Cosworth",
9 => "Lotus-Renault",
10 => "HRT-Cosworth",
11 => "Virgin-Cosworth",
12 => "TimeTrial car");
}
}
public static function getStandardCar() {
return 12;
}
public static function strtodate($time) {
return date("d/m-Y G:i", $time);
}
/**
* Return a formatted time string based on a time in milliseconds.
* @param type $time
* @return type
*/
public static function getTimeString($time) {
$minutes = $time / 60000;
$seconds = ($time % 60000) / 1000;
$split_seconds = ($time % 1000);
return sprintf('%d:%02d.%03d', $minutes, $seconds, $split_seconds);
}
/**
* Returns the time in milliseconds
* @param type $time
* @return type
*/
public static function parseTimeString($time) {
if ( preg_match('/^(\d+):(\d{2})\.(\d{3})$/', $time, $regs) ) {
if ( ((int)$regs[2]) >= 60 ) {
// Only 60 seconds in a minute
return -1;
}
$ms = (int)$regs[1] * 60000;
$ms += (int)$regs[2] * 1000;
$ms += (int)$regs[3];
return $ms;
} else {
return -1;
}
}
}
?>