close Warning: AdminModule failed with TracError: Unable to instantiate component <class 'trac.ticket.admin.VersionAdminPanel'> (super(type, obj): obj (type VersionAdminPanel) is not an instance or subtype of type (Markup).)

Changeset 8a5cdba for src/webservice


Ignore:
Timestamp:
Sep 8, 2015, 8:47:09 PM (11 years ago)
Author:
Joachim Langenbach <joachim.langenbach@…>
Branches:
master
Children:
d83a844
Parents:
7271978
Message:
  • WebserviceApi::stationsRegister() now creates rrd file for station
    • WebserviceConfig::dataDirectory now adds a slash at the end, if needed
Location:
src/webservice/htdocs/SiWeather/Webservice
Files:
2 edited

Legend:

Unmodified
Added
Removed
  • src/webservice/htdocs/SiWeather/Webservice/WebserviceApi.php

    r7271978 r8a5cdba  
    8080
    8181        /**
    82         * @brief Registers a new weather station
    83         *
    84         * @note Call this function with a big timeout > 2seconds, because we use another webservice
    85         *       to fetch location data. This fetch runs already 2seconds.
    86                 * @note Requires php-pecl-uuid
    87         */
     82          * @brief Registers a new weather station
     83          *
     84          * @note Call this function with a big timeout > 2seconds, because we use another webservice
     85          *       to fetch location data. This fetch runs already max. 2 seconds.
     86          * @note Requires php-pecl-uuid
     87          * @note Requires php-pecl-rrd
     88          */
    8889        public static function stationsRegister(){
    8990                $geoLocationRadius = 5;
    … …  
    9798
    9899                        if(!function_exists("uuid_create")){
     100                                error_log("pecl uuid extension not installed!");
    99101                                echo json_encode
    100102                                (
    … …  
    102104                                                "result" => "missinguuidcreate",
    103105                                                "message" => "The function uuid_create() from pecl package http://pecl.php.net/package/uuid is not installed, but needed!",
     106                                        ]
     107                                );
     108                                return;
     109                        }
     110
     111                        if(!function_exists("rrd_create") || !function_exists("rrd_update")){
     112                                error_log("pecl rrd extension not installed!");
     113                                echo json_encode
     114                                (
     115                                        [
     116                                                "result" => "missingrrd",
     117                                                "message" => "The function rrd_create() or rrd_update() from pecl package http://pecl.php.net/package/rrd is not installed, but needed!",
    104118                                        ]
    105119                                );
    … …  
    305319                        }
    306320
     321                        // creating rrd file
     322                        $webserviceConfig = new WebserviceConfig();
     323                        $rrdFileName = $webserviceConfig->dataDirectory() . $uuid .".rrd";
     324                        $rrdCreator = new \RRDCreator($rrdFileName, "now", 900);
     325                        $rrdCreator->addDataSource("Temp:GAUGE:1320:-100:100");
     326                        $rrdCreator->addDataSource("Humidity:GAUGE:1320:0:100");
     327                        $rrdCreator->addDataSource("Pressure:GAUGE:1320:800:1200");
     328                        $rrdCreator->addDataSource("WindSpeed:GAUGE:1320:0:999");
     329                        $rrdCreator->addDataSource("Winddirection:GAUGE:1320:1:360");
     330                        $rrdCreator->addDataSource("Rainfall:GAUGE:1320:0:999");
     331                        $rrdCreator->addArchive("AVERAGE:0.5:1:96");
     332                        $rrdCreator->addArchive("AVERAGE:0.5:4:96");
     333                        $rrdCreator->addArchive("AVERAGE:0.5:8:360");
     334                        $rrdCreator->addArchive("AVERAGE:0.5:16:2190");
     335                        $rrdCreator->addArchive("AVERAGE:0.5:24:146000");
     336                        $rrdCreator->addArchive("AVERAGE:0.5:48:146000");
     337                        $rrdCreator->addArchive("AVERAGE:0.5:96:146000");
     338                        $rrdCreator->addArchive("MIN:0.5:4:96");
     339                        $rrdCreator->addArchive("MIN:0.5:8:360");
     340                        $rrdCreator->addArchive("MIN:0.5:16:2190");
     341                        $rrdCreator->addArchive("MIN:0.5:24:146000");
     342                        $rrdCreator->addArchive("MIN:0.5:48:146000");
     343                        $rrdCreator->addArchive("MIN:0.5:96:146000");
     344                        $rrdCreator->addArchive("MAX:0.5:4:96");
     345                        $rrdCreator->addArchive("MAX:0.5:8:360");
     346                        $rrdCreator->addArchive("MAX:0.5:16:2190");
     347                        $rrdCreator->addArchive("MAX:0.5:24:146000");
     348                        $rrdCreator->addArchive("MAX:0.5:48:146000");
     349                        $rrdCreator->addArchive("MAX:0.5:96:146000");
     350                        if(!$rrdCreator->save()){
     351                                $db->query("ROLLBACK");
     352                                $errorMessage = rrd_error();
     353                                echo json_encode
     354                                (
     355                                        [
     356                                                "result" => "failed",
     357                                                "message" => "Could not create rrd files for this station: ". $errorMessage,
     358                                        ]
     359                                );
     360                                return;
     361                        }
     362
    307363                        // finish transaction
    308364                        $db->exec("COMMIT");
  • src/webservice/htdocs/SiWeather/Webservice/WebserviceConfig.php

    r7271978 r8a5cdba  
    6666
    6767        public function dataDirectory(){
    68                 return __DIR__ ."/../../../". $this->_config["dataDirectory"];
     68                $directory = __DIR__ ."/../../../". $this->_config["dataDirectory"];
     69                if(substr($directory, strlen($directory) - 1, 1) != "/"){
     70                        $directory .= "/";
     71                }
     72                return $directory;
    6973        }
    7074       
Note: See TracChangeset for help on using the changeset viewer.