From 46b88a4168b75b0821a1989c502534e3490b4330 Mon Sep 17 00:00:00 2001
From: root <root@sv3.lisha.ufsc.br>
Date: Tue, 21 Nov 2023 21:44:26 -0300
Subject: [PATCH] Fixing #5 and #6

---
 bin/smartdata/Backend.php | 23 +++++++++--------------
 bin/smartdata/Series.php  |  6 +++---
 2 files changed, 12 insertions(+), 17 deletions(-)

diff --git a/bin/smartdata/Backend.php b/bin/smartdata/Backend.php
index d3f69bf..d078601 100644
--- a/bin/smartdata/Backend.php
+++ b/bin/smartdata/Backend.php
@@ -1238,7 +1238,6 @@ class Backend_V1_0 extends Backend_Common
                 $session->close();
             $conn = null;
         }
-
         return $response_json;
     }
 
@@ -2797,9 +2796,6 @@ class Backend_V1_1 extends Backend_Common
                     $result_page = $session->execute($cass_select_stmt,
                         array('arguments' => array($id_set, new \Cassandra\Varint($series->t0), new \Cassandra\Varint($series->t1))));
                 }
-                //ini_set('memory_limit', '-1'); // check this
-                //ini_set('max_execution_time', 300); // check this
-
                 $index = 0;
                 $aggregator = ($this->internal()) ? null : Aggregator::new($aggr);
                 
@@ -3101,7 +3097,6 @@ class Backend_V1_1 extends Backend_Common
 
             $query = "SELECT * FROM {$table}
                       WHERE version = :version AND unit = :unit AND signature = :signature AND dev = :dev AND type = :type AND t0 <= :t1 AND t1 >= :t0 ";
-
             if($series->period != null && $series->period > 0){
                 $parameters = array_merge($parameters, array(':period' => $series->period));
                 $query .= ' AND period = :period ';
@@ -3162,7 +3157,7 @@ class Backend_V1_1 extends Backend_Common
             } else {
                 $mv_type = ($series->unit & 0x60000000) >> 28;
             }
-            Logger::debug('Type: '.$type.' isDigital: '.$is_digital.' unit: '.$series->unit);
+            Logger::debug('Type: '.$mv_type.' isDigital: '.$is_digital.' unit: '.$series->unit);
             while($result_page && $sd_count < Config::config()::POINTS_LIMIT) {
                 foreach ($result_page as $column) {
                     $row_id = (int)$column['id'];
@@ -3170,13 +3165,13 @@ class Backend_V1_1 extends Backend_Common
                     $x = $entry->get('x');
                     $y = $entry->get('y');
                     $z = $entry->get('z');
-                    $time  = (string)$column['timestamp']->value(); //bigint
+		    $time  = (string)$column['timestamp']->value(); //bigint
                     if (! $series->contains_point($x, $y, $z)) {
                         continue;
                     }
                     if($is_digital and ($series->type != 'TTH')){
                         $value_blob = $entry->get('value')->toBinaryString();
-                        switch ($type) {
+                        switch ($series->type) {
                             case Unit::I32:
                                 $value = Unpack::uInt32($value_blob);
                                 break;
@@ -3234,7 +3229,7 @@ class Backend_V1_1 extends Backend_Common
                                 break;
                             }
                         }
-                    } else {
+		    } else {
                         if (!$downSample || ($point_number % $step) == 0) {
                             $time  = (string)$column['timestamp']->value(); //bigint
                             if ($is_digital) {
@@ -3243,7 +3238,7 @@ class Backend_V1_1 extends Backend_Common
                                 $value = (double)$entry->get('value'); // double
                             }
                             $point_number += 1;
-                        } else {
+			} else {
                             $point_number += 1;
                             continue;
                         }
@@ -3259,7 +3254,7 @@ class Backend_V1_1 extends Backend_Common
                                 $smartdata = new StaticSmartData($series->unit,$value,$error,$conf,$x,$y,$z,$time,$d,$gw);
                                 break;
                             case SmartData::MOBILE_VERSION:
-                                $smartdata = new MobileSmartData($series->unit,$value,$error,$conf,$x,$y,$z,$time,$d,$gw, null);
+                                $smartdata = new MobileSmartData($series->unit,$value,$error,$conf,$x,$y,$z,$time,$d,$gw, $series->signature);
                                 break;
                             default:
                                 continue 2;
@@ -3269,7 +3264,7 @@ class Backend_V1_1 extends Backend_Common
                     if($aggregator != null && !$downSample) {
                         $smartdata = $aggregator->aggregate($smartdata);
                     }
-                    if($smartdata != null) {
+		    if($smartdata != null) {
                         if(is_array($smartdata)){
                             if ($series->type === 'TTH') {
                                 $md = array();
@@ -3330,13 +3325,13 @@ class Backend_V1_1 extends Backend_Common
             if (isset($session))
                 $session->close();
             $conn = null;
-        }
+	}
         $workflow = $series->workflow ?? 0;
         if($response_json !== NULL && $workflow !== 0) {
             self::debug_X('Enter output workflow');
             $_response_json = $response_json;
             $response_json = $this->_workflow_output($_response_json, $workflow, $series);
-        }
+	}
         return $response_json;
     }
     
diff --git a/bin/smartdata/Series.php b/bin/smartdata/Series.php
index 54a9135..5e619ab 100644
--- a/bin/smartdata/Series.php
+++ b/bin/smartdata/Series.php
@@ -221,9 +221,9 @@ class Series
         return new self(
                 $json->version,
                 $json->unit,
-                $json->x,
-                $json->y,
-                $json->z,
+                $json->x ?? 0,
+                $json->y ?? 0,
+                $json->z ?? 0,
                 $json->r ?? 0,
                 $json->t0 ?? 0,
                 $json->t1 ?? ($json->tf ?? 0),
-- 
GitLab