-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathindex.html
More file actions
152 lines (137 loc) · 3.79 KB
/
index.html
File metadata and controls
152 lines (137 loc) · 3.79 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
142
143
144
145
146
147
148
149
150
151
152
<!DOCTYPE html>
<html>
<style>
.btn-group {
background-color: #4CAF50; /* Green background */
border: 1px solid green; /* Green border */
color: white; /* White text */
padding: 10px 24px; /* Some padding */
cursor: pointer; /* Pointer/hand icon */
width: 50%; /* Set a width if needed */
display: block; /* Make the buttons appear below each other */
}
.btn-group button:not(:last-child) {
border-bottom: none; /* Prevent double borders */
}
/* Add a background color on hover */
.btn-group button:hover {
background-color: #3e8e41;
}
</style>
<Head >
<script type="text/javascript" src="http://code.jquery.com/jquery-1.7.1.min.js"></script>
<Title>
Plant Portal
</Title>
</Head>
<body style="background-color:powderblue;">
<h1>
Plant Information
</h1>
<h2> My Plants <h2>
<div id="my_plants" class="btn-group">
<button id="1" onclick="update_graphs(this.id)">Plant 1 real plant</button>
<button id="2" onclick="update_graphs(this.id)">Plant 2 fake plant</button>
<button onclick="refresh_graphs()">Refresh Plant 1</button>
<a href='/data.csv' target="_blank">Download Spreadsheet(CSV format)</a>
</div>
<h2 >Plant Graphs</h2>
<div id="graphs_section" ></div>
</body>
<div id="csv_data" style="font-size:10px"></div>
<script>
function add_button(plant_id, button_text)
{
var button = document.createElement("button");
var location = document.getElementById("my_plants");
button.setAttribute('type', 'button');
button.setAttribute('value', button_text);
button.setAttribute('class', 'btn-group');
button.setAttribute('id', plant_id);
location.appendChild(button);
}
function refresh_graphs()
{
GraphHTTPRequest("/generate_light_graph.php");
GraphHTTPRequest("/generate_moisture_graph.php");
update_graphs(1);
}
function update_graphs(id_of_plant)
{
//Run python graph.py to create
while (document.getElementById("graphs_image") != null)
{
var graph = document.getElementById("graphs_image");
var graph_parent = document.getElementById("graphs_section");
graph_parent.removeChild(graph);
}
if (id_of_plant == 1) //real plant
{
addpic("LightGraph.png")
addpic("MoistureGraph.png")
}
if (id_of_plant == 2) //fake plant
{
addpic("FAKEMoistureLevelGraphImage.png")
addpic("FAKELightLevelGraphImage.png")
}
}
function addtext(text)
{
var node = document.createElement("p");
var textnode = document.createTextNode(text);
node.appendChild(textnode);
document.body.appendChild(node);
}
function addpic(picture)
{
var img = document.createElement("IMG");
img.setAttribute("src",picture);
img.setAttribute("width", "1050");
img.setAttribute("height", "375");
img.setAttribute("id", "graphs_image")
var location = document.getElementById("graphs_section");
location.appendChild(img);
}
function readTextFile(file)
{
var data = [];
var rawFile = new XMLHttpRequest();
rawFile.open("GET", file, false);
rawFile.onreadystatechange = function ()
{
if(rawFile.readyState === 4)
{
if(rawFile.status === 200 || rawFile.status == 0)
{
var allText = rawFile.responseText;
data = allText.replace(/\,/g, "<br />");
}
}
}
rawFile.send(null);
document.getElementById("csv_data").innerHTML = data;
}
function GraphHTTPRequest(URL)
{
try
{
var xmlHttp = new XMLHttpRequest();
xmlHttp.open( "GET", URL, false ); // false for synchronous request
xmlHttp.send( null );
console.log(xmlHttp.responseText);
}
catch(err) {
console.log("Error with sending HTTP request for");
console.log(URL)
}
}
function startup()
{
//update_graphs(1);
//readTextFile("data.csv")
update_graphs(1);
}
startup();
</script>
</html>