forked from DottoreTozzi/iSpindel-TCP-Server
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathplato.php
executable file
·274 lines (252 loc) · 9.49 KB
/
plato.php
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
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
<?php
// Show the Density/Temperature chart
// GET Parameters:
// hours = number of hours before now() to be displayed
// days = hours x 24
// weeks = days x 7
// name = iSpindle name
// DB config values will be pulled from differtent location and user can personalize this file: common_db_config.php
// If file does not exist, values will be pulled from default file
if ((include_once './config/common_db_config.php') == FALSE){
include_once("./config/common_db_default.php");
}
include_once("include/common_db_query.php");
// Check GET parameters (for now: Spindle name and Timeframe to display)
if(!isset($_GET['hours'])) $_GET['hours'] = 0; else $_GET['hours'] = $_GET['hours'];
if(!isset($_GET['name'])) $_GET['name'] = 'iSpindel001'; else $_GET['name'] = $_GET['name'];
if(!isset($_GET['reset'])) $_GET['reset'] = defaultReset; else $_GET['reset'] = $_GET['reset'];
if(!isset($_GET['days'])) $_GET['days'] = 0; else $_GET['days'] = $_GET['days'];
if(!isset($_GET['weeks'])) $_GET['weeks'] = 0; else $_GET['weeks'] = $_GET['weeks'];
// Calculate Timeframe in Hours
$timeFrame = $_GET['hours'] + ($_GET['days'] * 24) + ($_GET['weeks'] * 168);
if($timeFrame == 0) $timeFrame = defaultTimePeriod;
$tftemp = $timeFrame;
$tfweeks = floor($tftemp / 168);
$tftemp -= $tfweeks * 168;
$tfdays = floor($tftemp / 24);
$tftemp -= $tfdays * 24;
$tfhours = $tftemp;
list($angle, $temperature, $dens) = getChartValuesPlato($conn, $_GET['name'], $timeFrame, $_GET['reset']);
list($RecipeName, $show) = getCurrentRecipeName($conn, $_GET['name'], $timeFrame, $_GET['reset']);
// Get fields from database in language selected in settings
$file = "plato";
$recipe_name = get_field_from_sql($conn,'diagram',"recipe_name");
$first_y = get_field_from_sql($conn,$file,"first_y");
$second_y = get_field_from_sql($conn,$file,"second_y");
$x_axis = get_field_from_sql($conn,$file,"x_axis");
$subheader = get_field_from_sql($conn,$file,"timetext");
$subheader_reset = get_field_from_sql($conn,$file,"timetext_reset");
$subheader_weeks = get_field_from_sql($conn,'diagram',"timetext_weeks");
$subheader_days = get_field_from_sql($conn,'diagram',"timetext_days");
$subheader_hours = get_field_from_sql($conn,'diagram',"timetext_hours");
$header_no_data_1 = get_field_from_sql($conn,'diagram',"header_no_data_1");
$header_no_data_2 = get_field_from_sql($conn,'diagram',"header_no_data_2");
$header_no_data_3 = get_field_from_sql($conn,'diagram',"header_no_data_3");
$tooltip_at = get_field_from_sql($conn,'diagram',"tooltip_at");
$tooltip_time = get_field_from_sql($conn,'diagram',"tooltip_time");
// define header displayed in diagram depending on value for recipe
if ($RecipeName <> '') {
$Header=$_GET['name'].' | ' . $recipe_name .' ' . $RecipeName;
}
else {
$Header='iSpindel: ' . $_GET['name'];
}
// Header will show, that there is no data available, and displays timeframe user needs to go back to see data in diagram
if (!$_GET['reset'])
{
$DataAvailable=isDataAvailable($conn, $_GET['name'], $timeFrame);
if($DataAvailable[0]=='0')
{
$Header='iSpindel: ' . $header_no_data_1 . ' ' . $_GET['name']. ' ' . $header_no_data_2 . ' ' .$DataAvailable[1]. ' ' . $header_no_data_3;
}
}
// define subheader to be displayed in diagram
$timetext = $subheader . ' ';
if($_GET['reset']) {
$timetext = $subheader_reset . ' ';
}
if($tfweeks != 0) {
$timetext .= $tfweeks . ' ' . $subheader_weeks;
}
if($tfdays != 0) {
$timetext .= $tfdays . ' ' . $subheader_days;
}
$timetext .= $tfhours . ' ' . $subheader_hours;
?>
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
<title>iSpindle Data</title>
<meta http-equiv="refresh" content="120">
<meta name="Keywords" content="iSpindle, iSpindel, Chart, genericTCP">
<meta name="Description" content="iSpindle Fermentation Chart">
<script src="include/jquery-3.1.1.min.js"></script>
<script src="include/moment.min.js"></script>
<script src="include/moment-timezone-with-data.js"></script>
<script type="text/javascript">
// define constants for data in chart. Allows for mor than two variables. Recipe information is included here and can be displayed in tooltip
const chartDens=[<?php echo $dens;?>]
const chartTemp=[<?php echo $temperature;?>]
// define constants to be displayed in diagram -> no php code needed in chart
const recipe_name=[<?php echo "'".$recipe_name."'";?>]
const first_y=[<?php echo "'".$first_y."'";?>]
const second_y=[<?php echo "'".$second_y."'";?>]
const x_axis=[<?php echo "'".$x_axis."'";?>]
const chart_header=[<?php echo "'" . $Header . "'";?>]
const chart_subheader=[<?php echo "'" . $timetext . "'";?>]
const tooltip_at=[<?php echo "'".$tooltip_at."'";?>]
const tooltip_time=[<?php echo "'".$tooltip_time."'";?>]
$(function ()
{
var chart;
$(document).ready(function()
{
Highcharts.setOptions({
global: {
timezone: 'Europe/Berlin'
}
});
chart = new Highcharts.Chart(
{
chart:
{
renderTo: 'container'
},
title:
{
text: chart_header
},
subtitle:
{ text: chart_subheader
},
xAxis:
{
type: 'datetime',
gridLineWidth: 1,
title:
{
text: x_axis
}
},
yAxis: [
{
startOnTick: false,
endOnTick: false,
min: 0,
max: 25,
title:
{
text: first_y
},
labels:
{
align: 'left',
x: 3,
y: 16,
formatter: function()
{
return this.value + '°P'
}
},
showFirstLabel: false
},{
// linkedTo: 0,
startOnTick: false,
endOnTick: false,
min: -5,
max: 35,
gridLineWidth: 0,
opposite: true,
title: {
text: second_y
},
labels: {
align: 'right',
x: -3,
y: 16,
formatter: function()
{
return this.value +'°C'
}
},
showFirstLabel: false
}
],
tooltip:
{
crosshairs: [true, true],
formatter: function()
{
if(this.series.name == second_y) {
const pointData = chartTemp.find(row => row.timestamp === this.point.x)
return '<b>' + recipe_name + ' </b>'+pointData.recipe+'<br>'+'<b>'+ this.series.name + ' </b>' + tooltip_at + ' ' + Highcharts.dateFormat('%H:%M', new Date(this.x)) + ' ' + tooltip_time + ' ' + this.y.toFixed(2) +'°C';
} else {
const pointData = chartDens.find(row => row.timestamp === this.point.x)
return '<b>' + recipe_name + ' </b>'+pointData.recipe+'<br>'+'<b>'+ this.series.name + ' </b>' + tooltip_at + ' ' + Highcharts.dateFormat('%H:%M', new Date(this.x)) + ' ' + tooltip_time + ' ' + this.y.toFixed(2) +'%';
}
}
},
legend:
{
enabled: true
},
credits:
{
enabled: false
},
series:
[
{
name: first_y,
color: '#FF0000',
data: chartDens.map(row => [row.timestamp, row.value]),
marker:
{
symbol: 'square',
enabled: false,
states:
{
hover:
{
symbol: 'square',
enabled: true,
radius: 8
}
}
}
},
{
name: second_y,
yAxis: 1,
color: '#0000FF',
data: chartTemp.map(row => [row.timestamp, row.value]),
marker:
{
symbol: 'square',
enabled: false,
states:
{
hover:
{
symbol: 'square',
enabled: true,
radius: 8
}
}
}
}
] //series
});
});
});
</script>
</head>
<body>
<a href=/iSpindle/index.php><img src=include/icons8-home-26.png></a>
<div id="wrapper">
<script src="include/highcharts.js"></script>
<div id="container" style="width:98%; height:98%; position:absolute"></div>
</div>
</body>
</html>