-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathspeed_calc.html
161 lines (148 loc) · 5.15 KB
/
speed_calc.html
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
<html>
<head>
<style>
table { border: 1px solid #333; }
tr:nth-child(even) {background: #CCC}
tr:nth-child(odd) {background: #FFF}
</style>
<script language="javascript">
var t
function fixnan(i) {
if(isNaN(i)) {
return 0
} else {
return i
}
}
function formatDecimal(num, numPlaces) {
var snum = new String(parseFloat(num))
var i = z = 0
var sout = ch = ""
while(i<snum.length && ch != '.' ) {
ch = snum.charAt(i++)
sout+=ch
}
while(i<snum.length && z++<numPlaces) {
ch = snum.charAt(i++)
sout+=ch
}
if(snum.indexOf('.')==-1)sout+='.'
while(z++<numPlaces)sout+='0'
return sout
}
// hard-coded to pad to 2 digits
function pad(num) {
var s = num+""
while (s.length < 2) s = "0" + s
return s
}
function calculateTimes(){
var dist=document.showtimes.distance.value
var multi=document.showtimes.multiplier.value
var out = document.getElementById('results')
var myTable = document.createElement('table');
var myTr = document.createElement('tr');
var col1 = document.createElement('th');
var col2 = document.createElement('th');
var col3 = document.createElement('th');
myTr.appendChild(col1);
myTr.appendChild(col2);
myTr.appendChild(col3);
col1.innerHTML = 'Speed';
col2.innerHTML = 'Bogie';
col3.innerHTML = 'Target';
myTable.appendChild(myTr);
var speeds = [75,70,65,60,55,50,45,40,35,30,25,20,15,10,5];
var speedCount = speeds.length;
for (var i = 0; i < speedCount; i++) {
var times = calculateTime(dist, speeds[i], multi);
myTr = document.createElement('tr');
col1 = document.createElement('td');
col2 = document.createElement('td');
col3 = document.createElement('td');
myTr.appendChild(col1);
myTr.appendChild(col2);
myTr.appendChild(col3);
col1.innerHTML= speeds[i];
col2.innerHTML=times.bogie;
col3.innerHTML=times.target;
myTable.appendChild(myTr);
}
out.replaceChild(myTable, out.childNodes[0]);
}
function calculateTime(nDist, nSpeed, nMulti){
var nDistMetres, SpeedMetersPerSec, SecondsRequired;
var hours, minutes , secs, remainder;
var bogie, target;
// Convert all miles & mph to meters & mps
nDistMetres = nDist * 1609.344;
SpeedMetersPerSec = nSpeed / 2.2369363;
nDistMetres=fixnan(nDistMetres)
SpeedMetersPerSec=fixnan( SpeedMetersPerSec)
// return 0 if no data
if( nDistMetres == 0 || SpeedMetersPerSec == 0){
return( {
bogie : "00:00:00.00",
target: "00:00:00.00"
} )
return ;
}
// and get our times - first bogie
SecondsRequired = nDistMetres / SpeedMetersPerSec;
SecondsRequired = parseFloat(formatDecimal(SecondsRequired,8))
hours = fixnan(parseInt(SecondsRequired / 3600))
// avoids embarassing problem where 20mph for 20 miles doesn't come
// to exactly 1 hr because spurious extra numbers after decimal point
// can add minutes!!!
remainder = fixnan(parseFloat(formatDecimal(SecondsRequired - (hours * 3600.0),4)))
minutes = fixnan(parseInt(remainder / 60.0))
secs = remainder - (minutes * 60.0)
if( secs<= 0.0001 ) secs=0
secs=fixnan(parseFloat(secs))
bogie = parseInt(hours) + ":" + pad(parseInt(minutes)) + ":" + formatDecimal(secs, 1)
mdinutes = pad(minutes)
// and then target time
SecondsRequired = (nDistMetres / SpeedMetersPerSec) * fixnan(nMulti)
SecondsRequired = parseFloat(formatDecimal(SecondsRequired,8))
hours = fixnan(parseInt(SecondsRequired / 3600))
// avoids embarassing problem where 20mph for 20 miles doesn't come
// to exactly 1 hr because spurious extra numbers after decimal point
// can add minutes!!!
remainder = fixnan(parseFloat(formatDecimal(SecondsRequired - (hours * 3600.0),4)))
minutes = fixnan(parseInt(remainder / 60.0))
secs = remainder - (minutes * 60.0)
if( secs<= 0.0001 ) secs=0
secs=fixnan(parseFloat(secs))
target = parseInt(hours) + ":" + pad(parseInt(minutes)) + ":" + formatDecimal(secs, 1)
return( {
bogie : bogie,
target: target
} )
}
</script>
</head>
<body>
<h1>Quick'n'Dirty Stage Times</h1>
<dl>
<dt>Rallies
<dd>On wholey sealed surfaces: max average speed = 75mph (R 28.2.1)</dd>
<dd>On partially/wholey unsealed surfaces: max average speed = 70mph (R 28.2.2)</dd>
<dd>(Target Time probably set at 30mph)</dd>
<dt>Cross Country (P 11.3.2)</dt>
<dd>Safari-plus & Hill Rally: max average speed = 50mph</dd>
<dd>Comp Safari: max average speed = 30mph</dd>
<dd>(Target Time probably 3 times Bogie)</dd>
</dl>
<p>Change the distance or the multiplier, and the times will change automatically.</p>
<form name="showtimes">
<b>Distance (miles): </b>
<input TYPE="text" NAME="distance" VALUE="" SIZE=5 onChange="calculateTimes()" onkeyup="calculateTimes()" onFocus="this.select();this.focus();" />
<b>Target Time Miltiplier: </b>
<input TYPE="text" NAME="multiplier" VALUE="3" SIZE=3 onChange="calculateTimes()" onkeyup="calculateTimes()" onFocus="this.select();this.focus();" /> <br />
</form>
<div id='results'><span /></div>
<p>(this page is completely javascript, and completely client-side)</p>
<p>(this page is on gitlab: <a href='https://github.com/perllaghu/max_ave_times' title='GitHUB pager' target='_blank'>https://github.com/perllaghu/max_ave_times</a> - and is open to improvemnt)</p>
<p>(Anyone fancy making an android app of this?)</p>
</body>
</html>