changed react and python server for Download

This commit is contained in:
2024-07-08 19:38:15 +02:00
parent 409e79f362
commit e124141d0b
44 changed files with 1629 additions and 233 deletions

View File

@@ -5,13 +5,18 @@ import uuid
from flask import jsonify
import json
from marshmallow import EXCLUDE
from marshmallow import EXCLUDE, ValidationError
#from vrpmdvcreatemoncmd import VRPMDV_CreateMonCmd
#from vrpmdvcreatemonschema import VRPMDV_CreateMonSchema
#from vrpmdvdeletemoncmd import VRPMDV_DeleteMonCmd
#from vrpmdvdeletemonschema import VRPMDV_DeleteMonSchema
from vrpmdvmonfilescompleteschema import VRPMDV_MonfilesCompleteSchema
from vrpmdvmonfilter import VRPMDV_MonFilter
from vrpmdvmonfilterschema import VRPMDV_MonFilterSchema
from vrpmdvmonsensorschema import VRPMDV_MonSensorSchema
from vrpmdvmonchannelschema import VRPMDV_MonChannelSchema
from vrpmdvmonfilesschema import VRPMDV_MonfilesSchema
from vrpmdvmonitoring import VRPMDV_Monitoring
from vrpmdvmonitoring import VRPMDV_Monitoring
from vrpmdvmonitoringschema import VRPMDV_MonitoringSchema
from vrpmdvmonreqschema import VRPMDV_MonReqSchema
# from vrpmdvntlink import trySend
@@ -35,7 +40,7 @@ class VRPMDV_Data:
self.rtservice.initCoproFW("home/root/elffile","zephyr_openamp_rsc_table.elf")
self.logTask = None #createCoproLoggingTask()
self.loaded = self.loadFile()
self.monfilespath = '/home/markus/monfiles/'
self.monfilespath = '/home/root/monfiles/'
#start the monitorings
time.sleep(1)
self.startMons();
@@ -346,7 +351,7 @@ class VRPMDV_Data:
try:
return next(x for x in self.mons if str(x.id) == id)
except:
return "no Item found"
return None #"no Item found"
def getMonitoring2files(self):
#search in the given directory
@@ -354,32 +359,36 @@ class VRPMDV_Data:
#return for the filter
def getMonitoringfiles(self, id):
def getMonitoringfiles(self, id, params):
#search in the given directory
dirname = os.path.dirname(self.monfilespath)
dirs = []
for d in os.listdir(dirname) :
# if os.path.isdir(d) :
dirs.append(d)
#dirs = [d for d in os.listdir(dirname) if os.path.isdir(d)]
id = '0'
#currently we return the first one
for dir in dirs:
mon = self.findMonitoring(dir)
id = mon.id
monId = params.get('monId')
logging.basicConfig(format=format, level=logging.INFO, datefmt="%H:%M:%S")
logging.info("getMonitoringfiles: monId:%s", monId)
if (monId == None):
return None
complete = False
mons = self.getMonofMonfiles(monId)
logging.info("getMonitoringfiles: mons.length:%d", len(mons))
if (len(mons) == 0) :
return None
else :
#TODO ML: only one monitoring
monId = mons[0].id
#TODO ML change to array
#for file in files:
filename = self.monfilespath + str(id) + '/'
monfiles = self.loadMonfiles(filename)
filename = self.monfilespath + str(monId) + '/'
monfiles = self.loadMonfiles(filename, complete)
schema = VRPMDV_MonfilesSchema()
result = schema.dumps(monfiles, many=True)
return result
def loadMonfiles(self, id):
def loadMonfiles(self, id, complete):
#files = [f for f in os.listdir() if os.path.isfile(f)]
logging.info("loadMonfiles: monId:%s", id)
completeMonPath = os.path.dirname(id)
monfiles = []
for f in os.listdir(completeMonPath) :
@@ -387,18 +396,77 @@ class VRPMDV_Data:
try:
completeFilepath = id + str(f)
with open(completeFilepath, 'r') as f:
logging.info("loadMonfiles: before fmonfile:%s", completeFilepath)
fmonfile = f.read()
logging.info("loadMonfiles: after fmonfile:%s", completeFilepath)
if fmonfile:
# if (complete):
# schema = VRPMDV_MonfilesCompleteSchema()
# else :
logging.info("loadMonfiles: before schemaload")
schema = VRPMDV_MonfilesSchema()
monfile = schema.loads(fmonfile, unknown=EXCLUDE)
try:
monfile = schema.loads(fmonfile, unknown=EXCLUDE)
except ValidationError as err:
logging.info("SchemaError: %s",err.messages) # => {"email": ['"foo" is not a valid email address.']}
logging.info("Data: %s",err.valid_data) # => {"name": "John"}
monfiles.append(monfile)
except:
#nothing todo ML we should create a file later the database
print("file not found")
logging.info("loadMonfiles: file not found:%s", completeFilepath)
return monfiles
def getMonsDFAvalable(self):
monfilters = []
mons = self.getMonofMonfiles(0)
if (len(mons) == 0):
return None
else:
schema = VRPMDV_MonFilterSchema()
for mon in mons:
monfilter = VRPMDV_MonFilter(str(mon.id), mon.name)
monfilters.append(monfilter)
return schema.dumps(monfilters, many=True)
def getMonofMonfiles(self, monId) :
dirname = os.path.dirname(self.monfilespath)
dirs = []
for d in os.listdir(dirname) :
path_file = self.monfilespath + d #os.sep.join([self.monfilespath, d])
if os.path.isdir(path_file) :
dirs.append(d)
mons = []
for dir in dirs:
mon = self.findMonitoring(dir)
if ((mon != None) and ((monId == 0 ) or (monId == str(mon.id)))):
mons.append(mon)
# monId = mon.id
# else:
# return None
return mons
def getMFDownload(self, params):
#search in the given directory
monId = params.get('monId')
if (monId == None):
return None
fileId = params.get('fileid')
mons = self.getMonofMonfiles(monId)
#TODO ML change to array
#for file in files:
filename = self.monfilespath + str(monId) + '/'
monfiles = self.loadMonfiles(filename, True)
schema = VRPMDV_MonfilesCompleteSchema()
result = schema.dumps(monfiles, many=True)
return result
# This is to get the directory that the program
# is currently running in.