Add Monitoring files in Python and Mui/React

This commit is contained in:
2024-06-29 17:12:58 +02:00
parent 5285f8b26e
commit dbae0a776d
23 changed files with 726 additions and 102 deletions

Binary file not shown.

View File

@@ -1 +1 @@
[{"no": 0, "id": "cb842c0d-51fc-433f-baf4-0f45af0fc0c5", "created_at": "06/14/2024, 16:30", "name": "MM1", "samplerate": 500, "sampleperiod": 1, "downtime": 10, "owner": "ML", "status": "stopped"}]
[{"no": 0, "id": "cb842c0d-51fc-433f-baf4-0f45af0fc0c5", "created_at": "06/14/2024, 16:30", "name": "MM1", "samplerate": 500, "sampleperiod": 1, "downtime": 10, "owner": "ML", "status": "stopped"}, {"no": 0, "id": "a1931936-5e6d-4286-851a-7c1327495139", "created_at": "06/27/2024, 13:42", "name": "MM2", "samplerate": 3750, "sampleperiod": 1, "downtime": 10, "owner": "ML", "status": "stopped"}]

View File

@@ -1,16 +1,20 @@
import os
import time
from uuid import uuid4
import uuid
from flask import jsonify
import json
from marshmallow import EXCLUDE
#from vrpmdvcreatemoncmd import VRPMDV_CreateMonCmd
#from vrpmdvcreatemonschema import VRPMDV_CreateMonSchema
#from vrpmdvdeletemoncmd import VRPMDV_DeleteMonCmd
#from vrpmdvdeletemonschema import VRPMDV_DeleteMonSchema
from vrpmdvmonfilesschema import VRPMDV_MonfilesSchema
from vrpmdvmonitoring import VRPMDV_Monitoring
from vrpmdvmonitoringschema import VRPMDV_MonitoringSchema
from vrpmdvmonreqschema import VRPMDV_MonReqSchema
from vrpmdvntlink import trySend
# from vrpmdvntlink import trySend
from extensions.rt_service import rt_service as rts
from vrpmdvmonitoringState import VRPMDVMonitoringState
@@ -25,10 +29,13 @@ class VRPMDV_Data:
format = "%(asctime)s: %(message)s"
logging.basicConfig(format=format, level=logging.INFO, datefmt="%H:%M:%S")
self.mons:list = []
self.rtservice = rts.RT_Service()
self.rtservice.initCoproFW("home/root/elffile","zephyr_openamp_rsc_table.elf")
#TODO ML: uncomment this lines
self.rtservice = None #rts.RT_Service()
if (self.rtservice != None):
self.rtservice.initCoproFW("home/root/elffile","zephyr_openamp_rsc_table.elf")
self.logTask = None #createCoproLoggingTask()
self.loaded = self.loadFile()
self.monfilespath = '/home/markus/monfiles/'
#start the monitorings
time.sleep(1)
self.startMons();
@@ -341,3 +348,66 @@ class VRPMDV_Data:
except:
return "no Item found"
def getMonitoring2files(self):
#search in the given directory
dirs = [d for d in os.listdir(self.monfilespath) if os.path.isdir(d)]
#return for the filter
def getMonitoringfiles(self, id):
#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
#TODO ML change to array
#for file in files:
filename = self.monfilespath + str(id) + '/'
monfiles = self.loadMonfiles(filename)
schema = VRPMDV_MonfilesSchema()
result = schema.dumps(monfiles, many=True)
return result
def loadMonfiles(self, id):
#files = [f for f in os.listdir() if os.path.isfile(f)]
completeMonPath = os.path.dirname(id)
monfiles = []
for f in os.listdir(completeMonPath) :
# if (os.path.isfile(f)) :
try:
completeFilepath = id + str(f)
with open(completeFilepath, 'r') as f:
fmonfile = f.read()
if fmonfile:
schema = VRPMDV_MonfilesSchema()
monfile = schema.loads(fmonfile, unknown=EXCLUDE)
monfiles.append(monfile)
except:
#nothing todo ML we should create a file later the database
print("file not found")
return monfiles
# This is to get the directory that the program
# is currently running in.
# dir_path = os.path.dirname(os.path.realpath(__file__))
# for root, dirs, files in os.walk(dir_path):
# for file in files:
# # change the extension from '.mp3' to
# # the one of your choice.
# if file.endswith('.mp3'):
# print (root+'/'+str(file))

View File

@@ -0,0 +1,14 @@
import datetime as dt
class VRPMDV_Monfiles:
def __init__(self, id, name , samplerate, sampleperiod, downtime, timestamp) :
self.id = id
self.name = name
self.samplerate = samplerate
self.sampleperiod = sampleperiod
self.downtime = downtime
self.timestamp = timestamp

View File

@@ -0,0 +1,22 @@
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)
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()
@post_load
def make_vrpmdv_Monfiles(self, data, **kwargs):
return VRPMDV_Monfiles(**data)

View File

@@ -10,7 +10,7 @@ from vrpmdvmonreq import VRPMDV_MonReq
from extensions.rt_service import rt_service as rts
from vrpmdvmonitoringState import VRPMDVMonitoringState
from vrpmdvmondata import createCoproLoggingTask
from vrpmdvntlink import trySend
# from vrpmdvntlink import trySend
import logging
import threading
import time
@@ -78,8 +78,9 @@ class VRPMDV_Monitoring(VRPMDV_MonReq):
self.no = no
self.id = id
self.created_at = created_at
self.rtservice = rts.RT_Service()
self.rtMon = rts.RTSMonitoringTask()
#TODO ML: uncomment
self.rtservice = None #rts.RT_Service()
self.rtMon = None #rts.RTSMonitoringTask()
self.monTask = None
self.run_thread = False
self.fdesc = -1
@@ -95,7 +96,9 @@ class VRPMDV_Monitoring(VRPMDV_MonReq):
logging.info("MainThread: createMonOnDevice => before schemaCreateCmd")
schemaCreateCmd = VRPMDV_CreateMonSchema()
logging.info("MainThread: try send start monitoring starting %s", schemaCreateCmd.dumps(vrpmdCreateCmd))
res = trySend(schemaCreateCmd.dumps(vrpmdCreateCmd))
# TODO ML: uncomment this
# res = trySend(schemaCreateCmd.dumps(vrpmdCreateCmd))
res = 'Test'
logging.info("MainThread: try send start monitoring done %s", res)
# start the receiving thread
@@ -132,8 +135,10 @@ class VRPMDV_Monitoring(VRPMDV_MonReq):
logging.info("MainThread: stopped Mon Thread %s ", self.id)
vrpmdDeleteCmd = VRPMDV_DeleteMonCmd(self.no)
schemaDeleteCmd = VRPMDV_DeleteMonSchema()
res = trySend(schemaDeleteCmd.dumps(vrpmdDeleteCmd))
schemaDeleteCmd = VRPMDV_DeleteMonSchema()
# TODO ML: uncomment this
# res = trySend(schemaDeleteCmd.dumps(vrpmdDeleteCmd))
res = 'Stop'
logging.info("MainThread: try send stop monitoring done %s", res)
# if (isstopped) :

View File

@@ -79,6 +79,15 @@ 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')
return resp
if __name__ == "__main__":