From 35b3714bdcb2a8c615a880567abf90835748ae12 Mon Sep 17 00:00:00 2001
From: Jiri Kalvoda <jirikalvoda@kam.mff.cuni.cz>
Date: Fri, 19 Jul 2024 10:00:13 +0200
Subject: [PATCH] Communication: debug option

---
 prog/communication.py | 6 ++++++
 prog/data_utils.py    | 9 ++++++---
 2 files changed, 12 insertions(+), 3 deletions(-)

diff --git a/prog/communication.py b/prog/communication.py
index da2cab9..5c3e609 100644
--- a/prog/communication.py
+++ b/prog/communication.py
@@ -10,6 +10,8 @@ from pathlib import Path
 
 from utils import *
 
+debug = False
+
 def eprint(*args):
     print(*args, file=sys.stderr, flush=True)
 
@@ -195,7 +197,11 @@ class FuncCaller():
         return cbor_dump({'return': r})
 
     async def _client_caller_(self, func_name, *args, **kwargs):
+        if debug:
+            eprint("ASK:", func_name, args, kwargs)
         in_head, in_data_raw = await self._client_.question({'func_name': func_name}, cbor_dump({'args': args, 'kwargs': kwargs}))
+        if debug:
+            eprint("DONE", func_name, args, kwargs)
         in_data = cbor2.loads(in_data_raw)
         return in_data["return"]
 
diff --git a/prog/data_utils.py b/prog/data_utils.py
index 199eeef..845a232 100644
--- a/prog/data_utils.py
+++ b/prog/data_utils.py
@@ -200,10 +200,13 @@ class TripHistory:
                ...
                 # tps_new[-1][2]["without_data"] += 1
 
-    def add_preprocessed_data(self, data):
+    def add_preprocessed_data(self, data, dt_from=dt_minf, dt_to=dt_pinf):
         for x in data["history"]:
-            self.history.append(HistoryPointFromPreprocessed(x))
-            self.history.sort(key=lambda hp: hp.first_captured)
+            hp = HistoryPointFromPreprocessed(x)
+            print(dt_from, dt_to, hp.first_captured, hp.last_captured)
+            if dt_from <= hp.last_captured and hp.first_captured < dt_to:
+                self.history.append(HistoryPointFromPreprocessed(x))
+        self.history.sort(key=lambda hp: hp.first_captured)
 
 
 
-- 
GitLab