seepark_web.js: use our new sensors API instead of the random data
authorgregor herrmann <gregor@toastfreeware.priv.at>
Wed, 13 Jun 2018 17:09:30 +0000 (19:09 +0200)
committergregor herrmann <gregor@toastfreeware.priv.at>
Wed, 13 Jun 2018 17:09:30 +0000 (19:09 +0200)
web/static/seepark_web.js

index 904810a0cb536c1e904825f9e77e2b614f4cd39d..025aefae6ad79d8dd1feaae944135444f48fc11f 100644 (file)
@@ -1,3 +1,5 @@
+var api_base_url = '/api/1/sensor/type/Wassertemperatur?mode=consolidated&format=c3';
+
 var chart = c3.generate({
        bindto: '#chart',
        transition: {
@@ -7,7 +9,8 @@ var chart = c3.generate({
                text: 'Der See'
        },
        data: {
-               url: '/data/', // redirects to /data/1
+//             url: '/data/', // redirects to /data/1
+               url: api_base_url + beginend(1),
                mimeType: 'json',
                xs: {
                        '0316a2193bff': '0316a2193bff_x',
@@ -87,7 +90,15 @@ var chart = c3.generate({
 
 function loaddays(days) {
        chart.load({
-               url: '/data/' + days,
+//             url: '/data/' + days,
+               url: api_base_url + beginend(days),
                mimeType: 'json'
        });
 }
+
+function beginend(days) {
+       var now = Date.now();
+       var end = new Date(now).toISOString().substr(0, 19); // 2018-06-13T16:52:30.995Z
+       var begin = new Date(now - days * 60*60*24 * 1000).toISOString().substr(0, 19);
+       return '&begin=' + begin + '&end=' + end;
+}