-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathrf_graph.php
142 lines (135 loc) · 4.03 KB
/
rf_graph.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
<!DOCTYPE html>
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8">
<title>Live Graph</title>
<link href="style.css" rel="stylesheet" type="text/css">
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.3/jquery.min.js"></script>
<script type="text/javascript" language="javascript" src="../flot/jquery.js"></script>
<script type="text/javascript" language="javascript" src="../flot/jquery.flot.js"></script>
<script type="text/javascript" language="javascript" src="../flot/jquery.flot.time.js"></script>
<script type="text/javascript" src="/js/flot/jquery.flot.stack.js"></script>
<script type="text/javascript" src="/js/flot/jquery.flot.symbol.js"></script>
<script type="text/javascript" src="/js/flot/jquery.flot.axislabels.js"></script>
<?php
$servername = "xxxx";
$username = "xxxx";
$password = "xxxx";
$dbname = "xxxx";
$conn = new mysqli($servername, $username, $password, $dbname);
if ($conn->connect_error){
die("Connection Failed: " . $conn->connect_error);
}
function get_Data($houseID, $ALTID, $conn)
{
$sql = "SELECT UNIX_TIMESTAMP(serverTime), readingWatts FROM powerReadings WHERE houseID = $houseID AND sensorALTID = '$ALTID' ORDER BY serverTime DESC LIMIT 450";
$result = $conn->query($sql);
if ($result)
{
while ($row=$result->fetch_assoc())
{
$data_Set[] = array($row['UNIX_TIMESTAMP(serverTime)']*1000,$row['readingWatts']);
}
}
return $data_Set;
}
function get_Data_Label($houseID, $ALTID, $conn)
{
$sql = "SELECT sensorName FROM sensorInfo WHERE houseID = $houseID AND sensorALTID = '$ALTID' ";
$result = $conn->query($sql);
if ($result)
{
while ($row=$result->fetch_assoc())
{
$data_Set_Label = $row['sensorName'];
}
}
return $data_Set_Label;
}
$houseID = $_POST["houseID"];
$ALTID = "Appliance0";
$data_Set = get_Data($houseID, $ALTID, $conn);
$data_Set_Label = get_Data_Label($houseID, $ALTID, $conn);
?>
<script type="text/javascript">
$(function(){
var dataset1 = <?php echo json_encode($data_Set); ?>;
var dataset1_Label = <?php echo json_encode($data_Set_Label); ?>;
$.plot($("#placeholder"), [ {label: dataset1_Label, data: dataset1} ], {
series: {
stack: true,
lines: {
show: true,
fill: true
}
},
xaxis: {
mode: "time",
timezone: "browser",
timeformat: "%y/%m/%d %H:%M:%S",
axisLabel: "Date",
axisLabelUseCanvas: true,
axisLabelFontSizePixels: 10,
axisLabelFontFamily: 'Verdana, Arial',
axisLabelPadding: 10
},
yaxis: {
axisLabel: "Power (Watts)",
axisLabelUseCanvas: true,
axisLabelFontSizePixels: 10,
axisLabelFontFamily: 'Verdana, Arial',
axisLabelPadding: 3
},
grid: {
hoverable: false,
borderWidth: 2,
backgroundColor: {
colors: ["#EDF5FF", "#ffffff"]
}
}
});
});
</script>
</head>
<body>
<div id="header">
<a href="http://xxx.xxx.xxx.xxx/rf_list.php">Check Sensors</a>
<a href="http://xxx.xxx.xxx.xxx/rf_status.php">Check Scripts</a>
<h2>Power
<?php
if ($_POST["houseID"]){
$sqlHead = "SELECT houseName FROM REFIT.houseInfo WHERE houseID = $houseID";
$resultHead = $conn->query($sqlHead);
while ($rowHead = $resultHead->fetch_assoc()){
echo $rowHead['houseName'];
}
}else{
echo "Nothing Selected";
}
?>
,
Aggregate
<?php
$sql2 = "SELECT houseID, houseName FROM REFIT.houseInfo";
$result2 = $conn->query($sql2);
echo "<form action=\"testlist.php\" method=\"post\">";
echo "<select name='houseID'>";
while ($row2 = $result2->fetch_assoc()) {
echo "<option value=\"{$row2['houseID']}\">";
echo $row2['houseName'];
echo "</option>";
}
echo "</select>";
echo "<input type=\"submit\" />";
echo "</form>";
$conn->close();
?>
</h2>
</div>
<div id="content">
<div class="demo-container">
<div id="placeholder" class="demo-placeholder"></div>
</div>
</div>
</body>
</html>