-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy pathfunctions.js
More file actions
271 lines (235 loc) · 7.18 KB
/
Copy pathfunctions.js
File metadata and controls
271 lines (235 loc) · 7.18 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
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
function pad(num, size) {
var s = num+"";
while (s.length < size) s = "0" + s;
return s;
};
function isEven(n) {
return n == parseFloat(n)? !(n%2) : void 0;
}
function dirname(){
var path = window.location.pathname;
var levels = path.split("/");
return levels[levels.length-3];
}
function daydiagram(input){
$("#spektrum").html("");
var dir = dirname();
var selector;
var now;
var m;
$("#date").html(input);
m = moment(input,'MM/DD/YYYY');
now = m.format('YYYYMMDD-');
// Unterscheide ob heutiger Tag (nicht 24h voll) oder vorherige Tage mit 24h Datensatz
if(m.isBefore(moment(),'day')){
var limit = 23;
}
else
{
var limit = moment().format('H');
}
// generieren und abrufen der Spektrendateien
for(selector=0; selector <= limit; selector++){
tnow = pad(selector,2);
var filename = dir + now + pad(selector,2) + "0201.png";
var audiofilename = dir + now + pad(selector,2) + "0201.flac";
console.log(filename);
$("#spektrum").append('<div class="spektrum-tile"><a href="../' + audiofilename + '"> <img src="../' + filename + '" /></a><div class="spektrum-tile-label">'+ tnow + ':00</div></div>');
}
// Buttons neu definieren
var start = moment('07/02/2018','MM/DD/YYYY'); // wir haben nur Daten ab 07/03/2018
if( m.subtract(1,'days').isAfter(start)){
var nextdate = m.format('L');
$("#daybefore").attr("style", "visibility:visible");
$("#daybefore").attr("onclick",'daydiagram("' + nextdate + '")' );
$("#daybefore").html(nextdate);
}
else
{
$("#daybefore").attr("style", "visibility:hidden");
}
if(m.add(2,'days').isBefore(moment())){
$("#dayafter").attr("style", "visibility: visible");
nextdate = m.format('L');
$("#dayafter").attr("onclick",'daydiagram("' + nextdate + '")' );
$("#dayafter").html(nextdate);
}
else{
$("#dayafter").attr("style", "visibility: visible");
$("#dayafter").attr("onclick",'livediagram()');
$("#dayafter").html('Liveansicht');
}
// -------------------- Temperaturkurve einbinden -------------------------------
tempDay(input);
}
// Funktion zum Anzeigen der Live-Daten
function tempLive(){
$.ajax({
url : "http://easyhive.fablab-cottbus.de/daria/test/charts.php",
type : "GET",
success : function(data){
arr = JSON.parse(data)
var time = [];
var temp_entry = [];
var temp_inside = [];
var temp_outside = [];
for(var i in arr) {
t1 = arr[i].time.split(" ")[1];
t2 = t1.split(":")[0]+":"+t1.split(":")[1];
time.push(t2);
teE1 = arr[i].temp_entry.toString();
teE2 = teE1.substr(0,2) + "." + teE1.substr(2,5);
temp_entry.push(teE2);
teI1 = arr[i].temp_inside.toString();
teI2 = teI1.substr(0,2) + "." + teI1.substr(2,5);
temp_inside.push(teI2);
teO1 = arr[i].temp_outside.toString();
teO2 = teO1.substr(0,2) + "." + teO1.substr(2,5);
temp_outside.push(teO2);
}
createGraph(time, temp_entry, temp_inside, temp_outside);
},
error : function(data) {
}
});
}
//Funktion zum Anzeigen der Temperaturkurve für ein bestimmtes Datum, das übergeben wird
function tempDay(day){
d = moment(day,'MM/DD/YYYY');
date = d.format('YYYY-MM-DD');
console.log(date);
$.ajax({
url : "http://easyhive.fablab-cottbus.de/daria/test/charts.php" + "?date=" + date,
type : "GET",
success : function(data){
console.log("SUCCESS2");
arr = JSON.parse(data)
var time = [];
var temp_entry = [];
var temp_inside = [];
var temp_outside = [];
console.log("länge: " + data.length)
for(var i in arr) {
t1 = arr[i].time.split(" ")[1];
t2 = t1.split(":")[0]+":"+t1.split(":")[1];
time.push(t2);
// todo: make this nicer! Maybe a second for loop to iterate over all columns in the array
teE1 = arr[i].temp_entry.toString();
teE2 = teE1.substr(0,2) + "." + teE1.substr(2,5);
temp_entry.push(teE2);
teI1 = arr[i].temp_inside.toString();
teI2 = teI1.substr(0,2) + "." + teI1.substr(2,5);
temp_inside.push(teI2);
teO1 = arr[i].temp_outside.toString();
teO2 = teO1.substr(0,2) + "." + teO1.substr(2,5);
temp_outside.push(teO2);
}
console.log(temp_entry)
console.log(temp_outside)
console.log(temp_inside)
createGraph(time, temp_entry, temp_inside, temp_outside);
},
error : function(data) {
}
});
}
function createGraph(time, temp_entry, temp_inside, temp_outside){
// delete the canvas element containig the graph and add it again afterwards
// reason: prevent overeffect (multiple graphs at the same time, switching by chance)
$("#myChart").remove();
$('#chart-container').append('<canvas id="myChart" ></canvas>');
console.log(temp_entry)
console.log(temp_outside)
console.log(temp_inside)
// create a new element
var chartdata = {
labels: time,
datasets: [
{
label: "temp_entry",
fill: false,
lineTension: 0.1,
backgroundColor: "rgba(255,215,0,0.5)",
borderColor: "rgba(255,215,0,1)",
pointHoverBackgroundColor: "rgba(255,215,0,1)",
pointHoverBorderColor: "rgba(255,215,0,1)",
data: temp_entry
},
{
label: "temp_inside",
fill: false,
lineTension: 0.1,
backgroundColor: "rgba(255,100,20,0.75)",
borderColor: "rgba(255,100,20,1)",
pointHoverBackgroundColor: "rgba(255,100,20,1)",
pointHoverBorderColor: "rgba(255,100,20,1)",
data: temp_inside
},
{
label: "temp_outside",
fill: false,
lineTension: 0.1,
backgroundColor: "rgba(59, 89, 152, 0.75)",
borderColor: "rgba(59, 89, 152, 1)",
pointHoverBackgroundColor: "rgba(59, 89, 152, 1)",
pointHoverBorderColor: "rgba(59, 89, 152, 1)",
data: temp_outside
}
]
};
var ctx = $("#myChart");
window.LineGraph = new Chart(ctx, {
type: 'line',
data: chartdata,
// axis labelling
options : {
responsive: true,
maintainAspectRatio: false,
scales: {
yAxes: [{
scaleLabel: {
display: true,
labelString: 'Temperature in °C'
}
}],
xAxes: [{
scaleLabel: {
display: true,
labelString: 'Time'
}
}]
}
}
})
}
function livediagram(){
$("#spektrum").html("");
var dir = dirname();
var selector;
var now;
now = moment().format('L');
$("#datum").html(now);
$("#dayafter").attr("style", "visibility:hidden");
$("#daybefore").attr("onclick",'daydiagram("' + now + '")' );
$("#daybefore").html('Tagesansicht');
for(selector=24; selector >= 0; selector--){
if(isEven(moment().format('m'))){
now = moment().subtract(selector*2+2, 'minutes').format('YYYYMMDD-HHmm01');
tnow = moment().subtract(selector*2+2, 'minutes').format('HH:mm');
}
else
{
now = moment().subtract(selector*2+1, 'minutes').format('YYYYMMDD-HHmm01');
tnow = moment().subtract(selector*2+1, 'minutes').format('HH:mm');
}
var filename = dir + now + ".png";
var audiofilename = dir + now + ".flac";
console.log(filename);
$("#spektrum").append('<div class="spektrum-tile"><a href="../' + audiofilename + '"> <img src="../' + filename + '" /></a><div class="spektrum-tile-label">'+ tnow + '</div></div>');
}
//--------------------------------------- Einbinden der temperaturkurve ---------------------------------
tempLive();
}
$(document).ready(function(){
livediagram();
});