-
Notifications
You must be signed in to change notification settings - Fork 0
/
device2_tsa.php
172 lines (148 loc) · 4.76 KB
/
device2_tsa.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
<?php
$title = 'Smart Home | TSA of Device 2';
include $_SERVER["DOCUMENT_ROOT"].'/home/core/init.php';
f_protect_page();
include $_SERVER["DOCUMENT_ROOT"].'/home/includes/overall/header.php';
?>
<style> /* set the CSS */
body { font: 12px Arial;}
path {
stroke: steelblue;
stroke-width: 2;
fill: none;
}
.axis path,
.axis line {
fill: none;
stroke: grey;
stroke-width: 1;
shape-rendering: crispEdges;
}
</style>
<script src="http://d3js.org/d3.v3.min.js"></script>
<div class="container">
<div class="row">
<center><h2>Time Series Analysis of Appliance 2</h2></center><br/><br/>
<div class="col-lg-4">
<!-- something -->
</div>
<div class="col-lg-4">
<fieldset id="device2">
<div class="form-group">
<div class="col-lg-12">
<label class="control-label" for="focusedInput">From Date</label>
<input type="text" class="form-control" name="from_date" id="from_date" required />
</div>
</div><br/><br/><br/>
<div class="form-group">
<div class="col-lg-12">
<label class="control-label" for="focusedInput"><br/>To Date</label>
<input type="text" class="form-control" name="to_date" id="to_date" required />
</div>
</div><br/><br/><br/>
<div class="form-group">
<center><br/><br/><br/><button type="submit" id="submit" value="submit" onclick="myFunction()" name="submit" class="btn btn-primary">Submit</button></center>
</div>
</fieldset>
</div>
<div class="col-lg-4">
<!-- something -->
</div>
</div>
</div>
<div class="container">
<div class="row">
<div class="col-lg-2">
<!-- some data -->
</div>
<div class="col-lg-8">
<script type="text/javascript">
function myFunction() {
var from_date= document.getElementById("from_date").value;;
var to_date= document.getElementById("to_date").value;;
$.post("device2_tsa_json_enc.php",
{
fromdate: from_date,
todate: to_date
},
function(datad, statuses){
console.log(datad);
d3.select("svg")
.remove();
// Set the dimensions of the canvas / graph
var margin = {top: 30, right: 20, bottom: 30, left: 50},
width = 1280 - margin.left - margin.right,
height = 768 - margin.top - margin.bottom;
// Parse the date / time
var parseDate = d3.time.format("%Y-%m-%d").parse;
// Set the ranges
var x = d3.time.scale().range([0, width]);
var y = d3.scale.linear().range([height, 0]);
// Define the axes
var xAxis = d3.svg.axis().scale(x)
.orient("bottom").ticks(5);
var yAxis = d3.svg.axis().scale(y)
.orient("left").ticks(5);
// Define the line
var valueline = d3.svg.line()
.x(function(d) { return x(d.lsdate); })
.y(function(d) { return y(d.units); });
// Adds the svg canvas
var svg = d3.select("body")
.append("svg")
.attr("width", width + margin.left + margin.right)
.attr("height", height + margin.top + margin.bottom)
.append("g")
.attr("transform",
"translate(" + margin.left + "," + margin.top + ")");
// Get the data
d3.json("device2_tsa_json_results.json", function(error, data) {
data.forEach(function(d) {
d.lsdate = parseDate(d.lsdate);
d.units = +d.units;
});
// Scale the range of the data
x.domain(d3.extent(data, function(d) { return d.lsdate; }));
y.domain([0, d3.max(data, function(d) { return d.units; })]);
// Add the valueline path.
svg.append("path")
.attr("class", "line")
.attr("d", valueline(data));
svg.append("g") // Add the X Axis
.attr("class", "x axis")
.attr("transform", "translate(0," + height + ")")
.style("fill", "white")
.call(xAxis);
// Add the text label for the x axis
svg.append("text")
.attr("transform", "translate(" + (width / 2) + " ," + (height + margin.bottom) + ")")
.style("text-anchor", "middle")
.style("fill", "white")
.text("X-Axis --> Date");
svg.append("g") // Add the Y Axis
.attr("class", "y axis")
.style("fill", "white")
.call(yAxis);
// Add the text label for the Y axis
svg.append("text")
.attr("transform", "rotate(-90)")
.attr("y", 0 - margin.left)
.attr("x",0 - (height / 2))
.attr("dy", "1.5em")
.style("text-anchor", "middle")
.style("fill", "white")
.text("Y-Axis --> Units (in KWH)");
});
});
}
</script>
</div>
<div class="col-lg-2">
<!-- some data -->
</div>
</div>
</div>
</div>
<?php
include $_SERVER["DOCUMENT_ROOT"].'/swift/includes/overall/footer.php';
?>