changed react and python server for Download
This commit is contained in:
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
@@ -0,0 +1 @@
|
||||
/union.cpython-310.pyc
|
||||
@@ -0,0 +1,26 @@
|
||||
# encoding: utf-8
|
||||
"""
|
||||
Marshmallow fields
|
||||
------------------
|
||||
|
||||
Extension on the already available marshmallow fields
|
||||
"""
|
||||
from marshmallow import ValidationError, fields
|
||||
|
||||
|
||||
class UnionField(fields.Field):
|
||||
"""Field that deserializes multi-type input data to app-level objects."""
|
||||
def __init__(self, types: list = [], *args, **kwargs) -> None:
|
||||
super().__init__(*args, **kwargs)
|
||||
if types:
|
||||
self.types = types
|
||||
else:
|
||||
raise AttributeError('No types provided on union field')
|
||||
|
||||
def _deserialize(self, value, attr, data, **kwargs):
|
||||
if bool([isinstance(value, i) for i in self.types if isinstance(value, i)]):
|
||||
return value
|
||||
else:
|
||||
raise ValidationError(
|
||||
f'Field shoud be any of the following types: [{", ".join([str(i) for i in self.types])}]'
|
||||
)
|
||||
+90
-22
@@ -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.
|
||||
|
||||
@@ -0,0 +1,9 @@
|
||||
import datetime as dt
|
||||
|
||||
|
||||
|
||||
class VRPMDV_MonChannels:
|
||||
def __init__(self, name , valuetype):
|
||||
self.name = name
|
||||
self.valuetype = valuetype
|
||||
|
||||
@@ -0,0 +1,18 @@
|
||||
import uuid
|
||||
import datetime as dt
|
||||
from marshmallow import Schema, fields, post_load, EXCLUDE
|
||||
|
||||
from vrpmdvmonchannels import VRPMDV_MonChannels
|
||||
|
||||
|
||||
|
||||
class VRPMDV_MonChannelSchema(Schema):
|
||||
name = fields.String()
|
||||
valuetype = fields.String()
|
||||
#value = fields.Number()
|
||||
|
||||
@post_load
|
||||
def make_vrpmdv_MonfilesChannelSchema(self, data, **kwargs):
|
||||
return VRPMDV_MonChannels(**data)
|
||||
|
||||
|
||||
@@ -3,12 +3,13 @@ import datetime as dt
|
||||
|
||||
|
||||
class VRPMDV_Monfiles:
|
||||
def __init__(self, id, name , samplerate, sampleperiod, downtime, timestamp) :
|
||||
def __init__(self, id, monid, name , samplerate, sampleperiod, downtime, timestamp, hwdescription) :
|
||||
self.id = id
|
||||
self.monid = monid
|
||||
self.name = name
|
||||
self.samplerate = samplerate
|
||||
self.sampleperiod = sampleperiod
|
||||
self.downtime = downtime
|
||||
self.timestamp = timestamp
|
||||
|
||||
self.hwdescription = hwdescription
|
||||
|
||||
|
||||
@@ -0,0 +1,19 @@
|
||||
import datetime as dt
|
||||
|
||||
from vrpmdvmonfiles import VRPMDV_Monfiles
|
||||
|
||||
|
||||
|
||||
|
||||
class VRPMDV_MonfilesComplete(VRPMDV_Monfiles):
|
||||
def __init__(self, id, monid, name , samplerate, sampleperiod, downtime, timestamp, hwdescription, values) :
|
||||
self.id = id
|
||||
self.monid = monid
|
||||
self.name = name
|
||||
self.samplerate = samplerate
|
||||
self.sampleperiod = sampleperiod
|
||||
self.downtime = downtime
|
||||
self.timestamp = timestamp
|
||||
self.hwdescription = hwdescription
|
||||
self.values = values
|
||||
|
||||
@@ -0,0 +1,39 @@
|
||||
import uuid
|
||||
import datetime as dt
|
||||
from marshmallow import Schema, fields, post_load, EXCLUDE
|
||||
from utilities.union import UnionField
|
||||
from vrpmdvmonfilescomplete import VRPMDV_MonfilesComplete
|
||||
from vrpmdvmonfilesschema import VRPMDV_MonfilesSchema
|
||||
|
||||
|
||||
|
||||
|
||||
# books = fields.List(fields.Nested("BookSchema", exclude=("author",)))
|
||||
|
||||
class VRPMDV_MonfilesCompleteSchema(Schema):
|
||||
id = fields.String(required=True)
|
||||
monid = fields.String(required=True)
|
||||
name = fields.String(required=True)
|
||||
samplerate = fields.Integer(required=True)
|
||||
sampleperiod = fields.Integer(required=True)
|
||||
downtime = fields.Integer(required=True)
|
||||
timestamp = fields.Integer(required=True)
|
||||
hwdescription = fields.List(fields.Nested("VRPMDV_MonSensorSchema"))
|
||||
values = fields.List(UnionField(
|
||||
types=[int, float],
|
||||
metadata={
|
||||
"description": "Multiple types.",
|
||||
},
|
||||
))
|
||||
|
||||
@post_load
|
||||
def make_vrpmdv_MonfilesCompleteSchema(self, data, **kwargs):
|
||||
return VRPMDV_MonfilesComplete(**data)
|
||||
|
||||
|
||||
# some_field = UnionField(
|
||||
# types=[str, int, float, dict, list, bool, set, tuple],
|
||||
# metadata={
|
||||
# "description": "Multiple types.",
|
||||
# },
|
||||
# )
|
||||
@@ -1,22 +1,24 @@
|
||||
import uuid
|
||||
import datetime as dt
|
||||
from marshmallow import Schema, fields, post_load, EXCLUDE
|
||||
|
||||
from vrpmdvmonfiles import VRPMDV_Monfiles
|
||||
|
||||
|
||||
|
||||
|
||||
class VRPMDV_MonfilesSchema(Schema):
|
||||
id = fields.String(required=True)
|
||||
id = fields.String(required=True)
|
||||
monid = fields.String(required=True)
|
||||
name = fields.String(required=True)
|
||||
samplerate = fields.Integer(required=True)
|
||||
sampleperiod = fields.Integer(required=True)
|
||||
downtime = fields.Integer(required=True)
|
||||
timestamp = fields.Integer(required=True)
|
||||
#samples = fields.List()
|
||||
hwdescription = fields.List(fields.Nested("VRPMDV_MonSensorSchema"))
|
||||
|
||||
|
||||
@post_load
|
||||
def make_vrpmdv_Monfiles(self, data, **kwargs):
|
||||
return VRPMDV_Monfiles(**data)
|
||||
|
||||
|
||||
|
||||
|
||||
@@ -0,0 +1,10 @@
|
||||
import datetime as dt
|
||||
|
||||
|
||||
|
||||
class VRPMDV_MonFilter:
|
||||
def __init__(self, id, name ) :
|
||||
self.id = id
|
||||
self.name = name
|
||||
|
||||
|
||||
@@ -0,0 +1,16 @@
|
||||
import uuid
|
||||
import datetime as dt
|
||||
from marshmallow import Schema, fields, post_load
|
||||
from vrpmdvmonfilter import VRPMDV_MonFilter
|
||||
|
||||
|
||||
class VRPMDV_MonFilterSchema(Schema):
|
||||
id = fields.String()
|
||||
name = fields.String()
|
||||
|
||||
@post_load
|
||||
def make_vrpmdv_MonFilter(self, data, **kwargs):
|
||||
return VRPMDV_MonFilter(**data)
|
||||
|
||||
|
||||
|
||||
@@ -0,0 +1,15 @@
|
||||
import datetime as dt
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
class VRPMDV_MonValues:
|
||||
def __init__(self, values):
|
||||
self.values = values
|
||||
|
||||
#class VRPMDV_MonSamples:
|
||||
# def __init__(self, sensors):
|
||||
# self.sensors = sensors
|
||||
|
||||
@@ -0,0 +1,17 @@
|
||||
import uuid
|
||||
import datetime as dt
|
||||
from marshmallow import Schema, fields, post_load, EXCLUDE
|
||||
|
||||
from vrpmdvmonsamples import VRPMDV_MonSamples
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
class VRPMDV_MonfilesSampleSchema(Schema):
|
||||
# sensors = fields.List(fields.Nested("VRPMDV_MonfilesSensorSchema"))
|
||||
values = fields.List();
|
||||
|
||||
@post_load
|
||||
def make_vrpmdv_MonfilesSampleSchema(self, data, **kwargs):
|
||||
return VRPMDV_MonSamples(**data)
|
||||
@@ -0,0 +1,11 @@
|
||||
import datetime as dt
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
class VRPMDV_MonSensor:
|
||||
def __init__(self, name , channels):
|
||||
self.name = name
|
||||
self.channels = channels
|
||||
|
||||
@@ -0,0 +1,16 @@
|
||||
import uuid
|
||||
import datetime as dt
|
||||
from marshmallow import Schema, fields, post_load, EXCLUDE
|
||||
|
||||
from vrpmdvmonsensor import VRPMDV_MonSensor
|
||||
|
||||
|
||||
class VRPMDV_MonSensorSchema(Schema):
|
||||
name = fields.String()
|
||||
channels = fields.List(fields.Nested("VRPMDV_MonChannelSchema"))
|
||||
|
||||
@post_load
|
||||
def make_vrpmdv_MonfilesSensorSchema(self, data, **kwargs):
|
||||
return VRPMDV_MonSensor(**data)
|
||||
|
||||
|
||||
@@ -79,15 +79,39 @@ def setStatus(id):
|
||||
return resp
|
||||
|
||||
|
||||
@app.route('/vrpmdvapi/1_0/monitoringfiles', methods=['GET'])
|
||||
def get_monitoringfiles():
|
||||
#vrpmreq = VRPMDV_MonReqSchema().load(request.get_json())
|
||||
#data = vrpmdvdata.createMonitoring(vrpmreq)
|
||||
data = vrpmdvdata.getMonitoringfiles(0)
|
||||
resp = Response(data, status=200, mimetype='application/json')
|
||||
@app.route('/vrpmdvapi/1_0/monitoring/mondfaivalable', methods=['GET'])
|
||||
def get_mondfaivalable():
|
||||
data = vrpmdvdata.getMonsDFAvalable()
|
||||
if (data == None):
|
||||
resp = Response("no Item found", status=404, mimetype='application/json')
|
||||
else:
|
||||
resp = Response(data, status=200, mimetype='application/json')
|
||||
return resp
|
||||
|
||||
|
||||
@app.route('/vrpmdvapi/1_0/monitoringfiles', methods=['GET'])
|
||||
def get_monitoringfiles():
|
||||
vrpmreqjson = request.args
|
||||
#vrpmreq = VRPMDV_MonReqSchema().load(request.get_json())
|
||||
#data = vrpmdvdata.createMonitoring(vrpmreq)
|
||||
data = vrpmdvdata.getMonitoringfiles(0, request.args)
|
||||
if (data == None):
|
||||
resp = Response("no Item found", status=404, mimetype='application/json')
|
||||
else:
|
||||
resp = Response(data, status=200, mimetype='application/json')
|
||||
return resp
|
||||
|
||||
@app.route('/vrpmdvapi/1_0/monitoringfiles/download', methods=['GET'])
|
||||
def get_mfDownload():
|
||||
vrpmreqjson = request.args
|
||||
|
||||
data = vrpmdvdata.getMFDownload(request.args)
|
||||
if (data == None):
|
||||
resp = Response("no Item found", status=404, mimetype='application/json')
|
||||
else:
|
||||
resp = Response(data, status=200, mimetype='application/json')
|
||||
return resp
|
||||
|
||||
|
||||
|
||||
if __name__ == "__main__":
|
||||
|
||||
Reference in New Issue
Block a user