Changeset 33c6557


Ignore:
Timestamp:
Apr 27, 2017, 11:40:46 AM (10 years ago)
Author:
Joachim Langenbach <joachim.langenbach@…>
Branches:
0.5, app-cordova, debian/bullseye, debian/jessie, master
Children:
c0782d9
Parents:
368c2b8
Message:

Fixed webservice rrd processing

Location:
src/webapp
Files:
2 edited

Legend:

Unmodified
Added
Removed
  • src/webapp/webclient/javascript/main.js

    r368c2b8 r33c6557  
    11/*
    22
    3     Copyright (C) 2016 EngSaS - Engineering Solutions and Services Langenbach. All rights reserved.
     3    Copyright (C) 2016 - 2017 EngSaS - Engineering Solutions and Services Langenbach. All rights reserved.
    44
    55    This library is free software; you can redistribute it and/or
    … …  
    118118$(document).ready(function() {
    119119        displayDataGet();
    120         setInterval(displayDataGet, 5000);
     120        setInterval(displayDataGet, 10000);
    121121       
    122122        $.getJSON("../webservice/tileserver.php?/map.json", mapSetup);
  • src/webapp/webservice/index.php

    r368c2b8 r33c6557  
    11<?php
    22/*
    3     Copyright (C) 2016 EngSaS - Engineering Solutions and Services Langenbach. All rights reserved.
     3    Copyright (C) 2016 - 2017 EngSaS - Engineering Solutions and Services Langenbach. All rights reserved.
    44
    55    This program is free software: you can redistribute it and/or modify
    … …  
    3636);
    3737
    38 function addRrdData($interval, $period, &$result, &$lastTime){
     38function addRrdData($interval, $period, &$result, &$lastValid){
    3939        global $dbFile;
    4040        global $debug;
    4141        global $configRound;
     42        $lastValid = false;
    4243
    43         $data = rrd_fetch($dbFile, array( "AVERAGE", "--resolution", $interval, "--start", "-". $period, "--end", "start+". $period));
     44        $endTime = floor(time() / $interval) * $interval;
     45        $startTime = $endTime - $period;
     46        $data = rrd_fetch($dbFile, array("AVERAGE", "--resolution", $interval, "--start", $startTime, "--end", $endTime));
     47        // $data = rrd_fetch($dbFile, array("AVERAGE", "--resolution", $interval, "--start", "-". $period, "--end", "start+". $period, "--align-start"));
    4448        if($data === false){
    4549                echo json_encode($result);
    … …  
    4953                else
    5054                        error_log($message);
     55                return;
    5156        }
    5257
    … …  
    7176                echo "<p>Variables: ". count($keys) ."; Timeframes: ". count($data[$keys[0]]) ."</p>\n";
    7277        }
    73         for($i = 0; $i < count($data[$keys[0]]); $i++){
    74                 $time = array_keys($data[$keys[0]])[$i];
     78        foreach($data[$keys[0]] as $timeframe => $value){
    7579                $allValid = true;
     80                $gpsFix = false;
    7681                $tmp = array();
    7782                foreach($keys as $key){
    7883                        if($key == "gpsfix"){
    79                                 switch($data[$key][$time]){
    80                                         case 1:
     84                                switch($data[$key][$timeframe]){
     85                                        case 2:
    8186                                                $tmp[$key] = "2D";
     87                                                $gpsFix = true;
    8288                                                break;
    83                                         case 2:
     89                                        case 3:
    8490                                                $tmp[$key] = "3D";
     91                                                $gpsFix = true;
    8592                                                break;
    8693                                        default:
    … …  
    8996                        }
    9097                        else{
    91                                 $tmp[$key] = $data[$key][$time];
     98                                $tmp[$key] = $data[$key][$timeframe];
    9299                                if(!is_numeric($tmp[$key]) || is_nan($tmp[$key])){
    93100                                        $allValid = false;
    … …  
    102109                // only add the timeframe to the track, if the values are valid and we had a gps fix at that time
    103110                if($allValid){
    104                         if(!array_key_exists($time, $result["track"])){
    105                                 $result["track"][$time] = $tmp;
    106                         }
    107                         $lastTime = $time;
     111                        $lastValid = $tmp;
     112                        if($gpsFix){
     113                                if(!array_key_exists($timeframe, $result["track"])){
     114                                        $result["track"][$timeframe] = $tmp;
     115                                }
     116                        }
    108117                }
    109118                else{
    … …  
    115124                }
    116125        }
    117 
    118126        ksort($result["track"]);
    119127}
    … …  
    159167                exit;
    160168        }
    161         // Fetch entries of the last 30 seconds
    162         addRrdData("5s", "30s", $result, $lastTime);
    163         if($lastTime > -1){
    164                 $result["lastvalid"] = $result["track"][$lastTime];
     169        // Fetch entries of the last 30s with maximum (available) resolution of 2s
     170        addRrdData("2", "240", $result, $lastValid);
     171        if($lastValid){
     172                $result["lastvalid"] = $lastValid;
    165173        }
    166         addRrdData("15s", "5minutes", $result, $lastTime);
    167         addRrdData("30s", "12h", $result, $lastTime);
     174        // Fetch entries of the last 1h with maximum (available) resolution of 10s
     175        addRrdData("10", "36000", $result, $lastTime);
     176        // Fetch entries of the last 24h with maximum (available) resolution of 60s
     177        addRrdData("60", "86400", $result, $lastTime);
    168178}
    169179
    170180if($debug > 0){
    171         echo json_encode($result,  JSON_PRETTY_PRINT);
     181        echo json_encode($result,  JSON_PRETTY_PRINT) ."\n";
    172182}
    173183else{
    174         echo json_encode($result);
     184        echo json_encode($result) ."\n";
    175185}
    176186
Note: See TracChangeset for help on using the changeset viewer.