diff --git a/cbpi/controller/log_file_controller.py b/cbpi/controller/log_file_controller.py index 686d5b2..05e9d32 100644 --- a/cbpi/controller/log_file_controller.py +++ b/cbpi/controller/log_file_controller.py @@ -160,7 +160,7 @@ class LogController: for id in ids: # df = pd.read_csv("./logs/sensor_%s.log" % id, parse_dates=True, date_parser=dateparse, index_col='DateTime', names=['DateTime',"Values"], header=None) # concat all logs - all_filenames = glob.glob(os.path.join(self.logsFolderPath,f"./logs/sensor_{id}.log*")) + all_filenames = glob.glob(os.path.join(self.logsFolderPath,f"sensor_{id}.log*")) df = pd.concat([pd.read_csv(f, parse_dates=True, date_parser=dateparse, index_col='DateTime', names=['DateTime', 'Values'], header=None) for f in all_filenames]) df = df.resample('60s').max() df = df.dropna() @@ -179,8 +179,7 @@ class LogController: return [os.path.basename(x) for x in os.path.join(self.logsFolderPath, f"sensor_{name}.log*")] def clear_log(self, name:str ) -> str: - - all_filenames = os.path.join(self.logsFolderPath, f"sensor_{name}.log*") + all_filenames = glob.glob(os.path.join(self.logsFolderPath, f"sensor_{name}.log*")) for f in all_filenames: os.remove(f) @@ -216,7 +215,7 @@ class LogController: """ formatted_time = strftime("%Y-%m-%d-%H_%M_%S", localtime()) - file_name = os.path.join(self.logsFolderPath, f"./logs/{formatted_time}-sensor-{name}.zip" % (formatted_time, name)) + file_name = os.path.join(self.logsFolderPath, f"{formatted_time}-sensor-{name}.zip" % (formatted_time, name)) zip = zipfile.ZipFile(file_name, 'w', zipfile.ZIP_DEFLATED) all_filenames = os.path.join(self.logsFolderPath, f"sensor_{name}.log*") for f in all_filenames: diff --git a/cbpi/http_endpoints/http_log.py b/cbpi/http_endpoints/http_log.py index e898460..f452026 100644 --- a/cbpi/http_endpoints/http_log.py +++ b/cbpi/http_endpoints/http_log.py @@ -2,6 +2,7 @@ from cbpi.utils.encoder import ComplexEncoder from aiohttp import web from cbpi.utils.utils import json_dumps from cbpi.api import request_mapping +import os import json class LogHttpEndpoints: @@ -83,7 +84,7 @@ class LogHttpEndpoints: ) await response.prepare(request) log_name = request.match_info['name'] - with open('./logs/%s.zip' % log_name, 'rb') as file: + with open(os.path.join(self.cbpi.logsFolderPath, '%s.zip' % log_name), 'rb') as file: for line in file.readlines(): await response.write(line) diff --git a/cbpi/http_endpoints/http_system.py b/cbpi/http_endpoints/http_system.py index c21c4cf..823ef6f 100644 --- a/cbpi/http_endpoints/http_system.py +++ b/cbpi/http_endpoints/http_system.py @@ -44,7 +44,7 @@ class SystemHttpEndpoints: async def http_get_log(self, request): result = [] file_pattern = re.compile("^(\w+.).log(.?\d*)") - for filename in sorted(os.listdir("./logs"), reverse=True): # + for filename in sorted(os.listdir(self.cbpi.logsFolderPath), reverse=True): if file_pattern.match(filename): result.append(filename) return web.json_response(result)