-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathfuncs.py
72 lines (57 loc) · 1.63 KB
/
funcs.py
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
import arrow
from flask import request
from flaskapp import app
def rint(num):
"Given float, return it rounded to nearest int"
return int(round(num))
def CtoF(degC):
return 32 + (1.8 * degC)
def FtoC(degF):
return (degF - 32) / 1.8
def getUnitsTemp():
return request.cookies.get('units_temp', app.config['UNITS_TEMP'])
def getUnitsDist():
return request.cookies.get('units_dist', app.config['UNITS_DIST'])
def getUnitsSpeed():
return request.cookies.get('units_speed', app.config['UNITS_SPEED'])
def getUnitsPressure():
return request.cookies.get('units_pressure', app.config['UNITS_PRESSURE'])
def getTemperatureInUnits(degC):
units = getUnitsTemp()
return degC if units == 'C' else CtoF(degC)
def getDistInUnits(dist):
units = getUnitsDist()
if units == 'in':
return dist * 25.4
else:
return dist # mm
def getSpeedInUnits(speed):
units = getUnitsSpeed()
if units == 'mph':
return speed * 0.62;
elif units == 'knots':
return speed * 0.54;
else:
return speed # kph
def getPressureInUnits(pressure):
units = getUnitsPressure()
if units == 'mb':
return pressure
else:
return pressure
def getTime(when):
when = arrow.get(when) # convert
timeOnly = arrow.utcnow().date() == when.date()
when = when.to(app.config['TIMEZONE']) # localize
if timeOnly:
return when.format('h:mma')
else:
return when.format('YY-MM-DD h:mma')
def getColorLevel(amt, lvlG=50, lvlY=75):
"Return color according to percentage level"
if amt < lvlG:
return 'green'
elif amt < lvlY:
return 'yellow'
else:
return 'red'