From 2c13b3c62f8c9fe5246f348bfb95b6dd5b834e6d Mon Sep 17 00:00:00 2001 From: avollkopf <43980694+avollkopf@users.noreply.github.com> Date: Wed, 8 Mar 2023 21:39:07 +0100 Subject: [PATCH] catch nen existing logfile for analytics page --- cbpi/__init__.py | 2 +- cbpi/controller/log_file_controller.py | 13 ++++++++----- cbpi/http_endpoints/http_log.py | 4 +++- 3 files changed, 12 insertions(+), 7 deletions(-) diff --git a/cbpi/__init__.py b/cbpi/__init__.py index 82ae046..db0e8e4 100644 --- a/cbpi/__init__.py +++ b/cbpi/__init__.py @@ -1,3 +1,3 @@ -__version__ = "4.1.6.b5" +__version__ = "4.1.6.b6" __codename__ = "Groundhog Day" diff --git a/cbpi/controller/log_file_controller.py b/cbpi/controller/log_file_controller.py index 9e8c9a0..1a93fb1 100644 --- a/cbpi/controller/log_file_controller.py +++ b/cbpi/controller/log_file_controller.py @@ -158,11 +158,14 @@ class LogController: dateparse = lambda dates: [datetime.datetime.strptime(d, '%Y-%m-%d %H:%M:%S') for d in dates] result = dict() for id in ids: - all_filenames = glob.glob(os.path.join(self.logsFolderPath,f"sensor_{id}.log*")) - df = pd.concat([pd.read_csv(f, parse_dates=['DateTime'], date_parser=dateparse, index_col='DateTime', names=['DateTime', 'Values'], header=None) for f in all_filenames]) - df = df.resample('60s').max() - df = df.dropna() - result[id] = {"time": df.index.astype(str).tolist(), "value":df.Values.tolist()} + try: + all_filenames = glob.glob(os.path.join(self.logsFolderPath,f"sensor_{id}.log*")) + df = pd.concat([pd.read_csv(f, parse_dates=['DateTime'], date_parser=dateparse, index_col='DateTime', names=['DateTime', 'Values'], header=None) for f in all_filenames]) + df = df.resample('60s').max() + df = df.dropna() + result[id] = {"time": df.index.astype(str).tolist(), "value":df.Values.tolist()} + except: + pass return result diff --git a/cbpi/http_endpoints/http_log.py b/cbpi/http_endpoints/http_log.py index 8183edb..44cac80 100644 --- a/cbpi/http_endpoints/http_log.py +++ b/cbpi/http_endpoints/http_log.py @@ -4,6 +4,7 @@ from cbpi.utils.utils import json_dumps from cbpi.api import request_mapping import os import json +import logging class LogHttpEndpoints: def __init__(self,cbpi): @@ -189,7 +190,8 @@ class LogHttpEndpoints: description: successful operation. """ data = await request.json() - return web.json_response(await self.cbpi.log.get_data2(data), dumps=json_dumps) + values = await self.cbpi.log.get_data2(data) + return web.json_response(values, dumps=json_dumps) @request_mapping(path="/{name}", method="DELETE", auth_required=False)