-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathgraph.py
132 lines (125 loc) · 4.69 KB
/
graph.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
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
from mod_python import util
from aliases import *
BASE_URL = "http://data.mountainsensing.org/feshie/data/data.py"
BASE_TITLE = "Feshie Mountain Sensing: "
def index(req):
parameters = util.FieldStorage(req, keep_blank_values=1)
url = BASE_URL
if not "sensor" in parameters.keys():
return "Must specify sensor type"
sensor = parameters.getfirst("sensor")
if sensor in TEMPERATURE_ALIASES:
url = BASE_URL + "?sensor=temp"
title = BASE_TITLE + "Temperature"
elif sensor in BATTERY_ALIASES:
url = BASE_URL + "?sensor=batt"
title = BASE_TITLE + "Battery"
elif sensor in MPPT_ALIASES:
url = BASE_URL + "?sensor=mppt"
title = BASE_TITLE + "Power Point Tracking"
elif sensor in SOC_ALIASES:
url = BASE_URL + "?sensor=soc"
title = BASE_TITLE + "State of Charge"
elif sensor in SOLAR_CURRENT_ALIASES:
url = BASE_URL + "?sensor=solar"
title = BASE_TITLE + "Solar Charge Current"
elif sensor in ACCELEROMETER_ALIASES:
if not "node" in parameters.keys():
return "Must specify node for this sensor type"
node = parameters.getfirst("node")
url = BASE_URL + "?sensor=accel&node=" + node
title = "Accelerometer:" + node
elif sensor in ADC_ALIASES:
if not "adc_id" in parameters.keys():
return "Must specify adc_id for this sensor type"
adc = parameters.getfirst("adc_id")
title = "ADC %s" % adc
url = BASE_URL + "?sensor=adc&adc_id=" + adc
elif sensor in ONE_WIRE_ALISES:
if not "node" in parameters.keys():
return "Must specify node for this sensor type"
node = parameters.getfirst("node")
title = "One Wire:" + node
url = BASE_URL + "?sensor=ow&node=" + node
elif sensor in WATER_ALIASES:
if not "node" in parameters.keys():
return "Must specify node for this sensor type"
node = parameters.getfirst("node")
title = "Water pressure:" + node
url = BASE_URL + "?sensor=wp&node=" + node
elif sensor in CHAIN_ALIASES:
if not "node" in parameters.keys():
return "Must specify node for this sensor type"
node = parameters.getfirst("node")
title = "Chain data:" + node
url = BASE_URL + "?sensor=chain&node=" + node
elif sensor in CHAIN_TEMPERATURE_ALIASES:
if not "node" in parameters.keys():
return "Must specify node for this sensor type"
node = parameters.getfirst("node")
title = "Chain Temperature data:" + node
url = BASE_URL + "?sensor=chain-temperature&node=" + node
elif sensor in MOISTURE_ALIASES:
url = BASE_URL + "?sensor=moisture"
title = BASE_TITLE + "Moisture Data"
elif sensor in RAIN_ALIASES:
url = BASE_URL + "?sensor=rain"
title = BASE_TITLE + "Rain Data"
else:
return "Unknown sensor type"
if "test" in parameters.keys():
url += "&test"
output = ""
output += """
<!DOCTYPE html>
<html>
<head>
<meta charset="UTF-8">
<meta http-equiv="X-UA-Compatible" content="IE=EmulateIE7; IE=EmulateIE9">
<!--[if IE]><script src="excanvas.js"></script><![endif]-->
<title> """
output += title
output += """
</title>
<script type="text/javascript"
src="dygraph-combined.js"></script>
</head>
<body>
<h1>"""
output += title
output +="""</h1>
<p>To zoom on the graph highlight the region you would like to zoom in on, this works with both the X and Y axis. To return the graph to showing all data double click on it</p>
<div id="tempdiv"></div>
<script type="text/javascript">
g = new Dygraph(
document.getElementById("tempdiv"),\""""
output += url
output += """\",{
xlabel: "Date",
height: 600,
width: 800,
lengend: "always",
showRoller: true,
ylabel:"""
if sensor in TEMPERATURE_ALIASES + ONE_WIRE_ALISES + CHAIN_TEMPERATURE_ALIASES:
output += "\"Temperature (c)\",\n"
elif sensor in BATTERY_ALIASES:
output += "\"Voltage (V)\",\n"
elif sensor in WATER_ALIASES:
output += "\"Pressure (mb)\",\n"
elif sensor in ACCELEROMETER_ALIASES:
output +="\"Angle (degrees)\",\n"
elif sensor in RAIN_ALIASES:
output += "\"Rainfall (mm/h)\",\n"
elif sensor in CHAIN_ALIASES:
output += "\"Angle (degrees)\",\n"
output += "series: {'Temp 1':{axis:'y2'}, 'Temp 2':{axis:'y2'}, 'Temp 3':{axis:'y2'}, 'Temp 4':{axis: 'y2'},},axes:{y2:{labelsKMB: true}},y2label: 'Temperature (C)',"
else:
output += "\"counts\",\n"
output +=""" }
);
</script>
</body>
</html>
"""
return output