catch nen existing logfile for analytics page

This commit is contained in:
avollkopf 2023-03-08 21:39:07 +01:00
parent f5e6b22f01
commit 2c13b3c62f
3 changed files with 12 additions and 7 deletions

View file

@ -1,3 +1,3 @@
__version__ = "4.1.6.b5"
__version__ = "4.1.6.b6"
__codename__ = "Groundhog Day"

View file

@ -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:
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

View file

@ -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)