Skip to content

Commit 850e3e1

Browse files
committed
Add null at the starttime so the graph doesn't auto scale
1 parent 3e657c8 commit 850e3e1

File tree

2 files changed

+23
-56
lines changed

2 files changed

+23
-56
lines changed

web/data.php

Lines changed: 18 additions & 42 deletions
Original file line numberDiff line numberDiff line change
@@ -114,7 +114,7 @@ function getWho($reason)
114114
$query = "SELECT * FROM ( SELECT @row := @row +1 AS rownum, UNIX_TIMESTAMP(whentime) * 1000 as whentimes,DATE_FORMAT(whentime, '%H:%i') as wttime,".
115115
"DATE_FORMAT(whentime, '%Y-%m-%d %H:%i') as wtdt, temperature, humidity, feelslike, rssi, airconon FROM ( SELECT @row :=0) r, sensibo ".
116116
"WHERE uid='$uid' AND UNIX_TIMESTAMP(whentime) * 1000 >= $startTS AND UNIX_TIMESTAMP(whentime) * 1000 <= $startTS + $period ORDER BY whentime ASC".
117-
") ranked WHERE rownum % 30 = 0";
117+
") ranked WHERE rownum % 15 = 0";
118118
}
119119

120120
if($period == 31536000000)
@@ -123,51 +123,27 @@ function getWho($reason)
123123
$res = mysqli_query($link, $query);
124124
while($row = mysqli_fetch_assoc($res))
125125
{
126-
$query1 = "SELECT UNIX_TIMESTAMP(whentime) * 1000 as whentimes,DATE_FORMAT(whentime, '%H:%i') as wttime, DATE_FORMAT(whentime, '%Y-%m-%d %H:%i') as wtdt, temperature, humidity, feelslike, rssi, ".
127-
"airconon FROM sensibo WHERE uid='$uid' and whentime LIKE '${row['wtdate']}%' LIMIT 1";
128-
126+
$query1 = "SELECT count(uid) as c FROM sensibo WHERE uid='$uid' and whentime LIKE '${row['wtdate']}%'";
129127
$res1 = mysqli_query($link, $query1);
130-
$row1 = mysqli_fetch_assoc($res1);
131-
132-
if(doubleval($row1['whentimes']) > 0)
133-
{
134-
$dataPoints1[] = array('x' => doubleval($row1['whentimes']), 'y' => floatval($row1['temperature']));
135-
$dataPoints2[] = array('x' => doubleval($row1['whentimes']), 'y' => intval($row1['humidity']));
136-
$dataPoints3[] = array('x' => doubleval($row1['whentimes']), 'y' => round(floatval($row1['feelslike']) * 10.0) / 10.0);
137-
$dataPoints4[] = array('x' => doubleval($row1['whentimes']), 'y' => intval($row1['rssi']));
138-
}
139-
128+
$rc = mysqli_fetch_assoc($res1)['c'];
140129
mysqli_free_result($res1);
141-
142-
$query2 = "SELECT UNIX_TIMESTAMP(whentime) * 1000 as whentimes,DATE_FORMAT(whentime, '%H:%i') as wttime, DATE_FORMAT(whentime, '%Y-%m-%d %H:%i') as wtdt, temperature, humidity, feelslike, rssi, ".
143-
"airconon FROM sensibo WHERE uid='$uid' and whentime LIKE '${row['wtdate']}%' LIMIT 1 OFFSET 320";
144-
$res2 = mysqli_query($link, $query2);
145-
$row2 = mysqli_fetch_assoc($res2);
146-
147-
if(doubleval($row2['whentimes']) > 0)
130+
for($i = 0; $i <= $rc; $i += 64)
148131
{
149-
$dataPoints1[] = array('x' => doubleval($row2['whentimes']), 'y' => floatval($row2['temperature']));
150-
$dataPoints2[] = array('x' => doubleval($row2['whentimes']), 'y' => intval($row2['humidity']));
151-
$dataPoints3[] = array('x' => doubleval($row2['whentimes']), 'y' => round(floatval($row2['feelslike']) * 10.0) / 10.0);
152-
$dataPoints4[] = array('x' => doubleval($row2['whentimes']), 'y' => intval($row2['rssi']));
153-
}
154-
155-
mysqli_free_result($res2);
156-
157-
$query3 = "SELECT UNIX_TIMESTAMP(whentime) * 1000 as whentimes,DATE_FORMAT(whentime, '%H:%i') as wttime, DATE_FORMAT(whentime, '%Y-%m-%d %H:%i') as wtdt, temperature, humidity, feelslike, rssi, ".
158-
"airconon FROM sensibo WHERE uid='$uid' and whentime LIKE '${row['wtdate']}%' LIMIT 1 OFFSET 640";
159-
$res3 = mysqli_query($link, $query3);
160-
$row3 = mysqli_fetch_assoc($res3);
161-
162-
if(doubleval($row3['whentimes']) > 0)
163-
{
164-
$dataPoints1[] = array('x' => doubleval($row3['whentimes']), 'y' => floatval($row3['temperature']));
165-
$dataPoints2[] = array('x' => doubleval($row3['whentimes']), 'y' => intval($row3['humidity']));
166-
$dataPoints3[] = array('x' => doubleval($row3['whentimes']), 'y' => round(floatval($row3['feelslike']) * 10.0) / 10.0);
167-
$dataPoints4[] = array('x' => doubleval($row3['whentimes']), 'y' => intval($row3['rssi']));
132+
$query1 = "SELECT row.whentimes, row.airconon, ROUND(AVG(row.temperature), 1) AS temperature, ROUND(AVG(row.humidity), 1) AS humidity, ROUND(AVG(row.feelslike), 1) AS feelslike, ".
133+
" AVG(row.rssi) AS rssi FROM (SELECT whentime, UNIX_TIMESTAMP(whentime) * 1000 as whentimes, airconon, temperature, humidity, feelslike, rssi FROM sensibo ".
134+
"WHERE uid='$uid' and whentime LIKE '${row['wtdate']}%' LIMIT $i, 64) row";
135+
$res1 = mysqli_query($link, $query1);
136+
$row1 = mysqli_fetch_assoc($res1);
137+
mysqli_free_result($res1);
138+
139+
if(doubleval($row1['whentimes']) > 0)
140+
{
141+
$dataPoints1[] = array('x' => doubleval($row1['whentimes']), 'y' => floatval($row1['temperature']));
142+
$dataPoints2[] = array('x' => doubleval($row1['whentimes']), 'y' => intval($row1['humidity']));
143+
$dataPoints3[] = array('x' => doubleval($row1['whentimes']), 'y' => round(floatval($row1['feelslike']) * 10.0) / 10.0);
144+
$dataPoints4[] = array('x' => doubleval($row1['whentimes']), 'y' => intval($row1['rssi']));
145+
}
168146
}
169-
170-
mysqli_free_result($res3);
171147
}
172148

173149
mysqli_free_result($res);

web/graphs.php

Lines changed: 5 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -442,31 +442,22 @@ function changeState($podUID, $changes)
442442
xValueType: "dateTime",
443443
markerSize: 0,
444444
showInLegend: true,
445-
titleFontColor: "<?=$FLColour?>",
446-
lineColor: "<?=$FLColour?>",
447-
labelFontColor: "<?=$FLColour?>",
448-
tickColor: "<?=$FLColour?>",
445+
color: "<?=$FLColour?>",
449446
},{
450447
type: "line",
451448
axisYType: "secondary",
452449
name: "Humidity [%]",
453450
xValueType: "dateTime",
454451
markerSize: 0,
455452
showInLegend: true,
456-
titleFontColor: "<?=$humidColour?>",
457-
lineColor: "<?=$humidColour?>",
458-
labelFontColor: "<?=$humidColour?>",
459-
tickColor: "<?=$humidColour?>",
453+
color: "<?=$humidColour?>",
460454
},{
461455
type: "line",
462456
name: "Temperature [°C]",
463457
xValueType: "dateTime",
464458
markerSize: 0,
465459
showInLegend: true,
466-
titleFontColor: "<?=$tempColour?>",
467-
lineColor: "<?=$tempColour?>",
468-
labelFontColor: "<?=$tempColour?>",
469-
tickColor: "<?=$tempColour?>",
460+
color: "<?=$tempColour?>",
470461
}
471462
],
472463
});
@@ -523,6 +514,7 @@ function changeState($podUID, $changes)
523514
xValueType: "dateTime",
524515
markerSize: 0,
525516
showInLegend: true,
517+
color: "<?=$wifiColour?>",
526518
}]
527519
});
528520

@@ -579,11 +571,11 @@ function changeState($podUID, $changes)
579571
data:
580572
[{
581573
type: "column",
582-
color: "<?=$costColour?>",
583574
name: "Cost [$]",
584575
xValueType: "dateTime",
585576
markerSize: 0,
586577
showInLegend: true,
578+
color: "<?=$costColour?>",
587579
}],
588580
});
589581

@@ -670,7 +662,6 @@ function toggleDataSeries(e)
670662
if(period == 86400000)
671663
{
672664
chart1.options.axisX.intervalType = 'hour';
673-
// chart1.options.scales.x.time.unit = 'week';
674665
chart2.options.axisX.intervalType = 'hour';
675666
chart3.options.axisX.intervalType = 'hour';
676667
}

0 commit comments

Comments
 (0)