Adds DS data reading
This commit is contained in:
parent
5f03efb2cb
commit
7a68c14813
30
main.py
30
main.py
|
|
@ -50,6 +50,7 @@ latest_data: Dict[str, Any] = {
|
||||||
"PU_1": None,
|
"PU_1": None,
|
||||||
"PU_2": None,
|
"PU_2": None,
|
||||||
"PU_3": None,
|
"PU_3": None,
|
||||||
|
"DS" : None,
|
||||||
"PatientSkid": {"QSkid": 0.0},
|
"PatientSkid": {"QSkid": 0.0},
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -70,7 +71,7 @@ last_flush_time = datetime.datetime.now()
|
||||||
## LOGGING
|
## LOGGING
|
||||||
|
|
||||||
|
|
||||||
def format_data(data):
|
def format_PU_data(data):
|
||||||
return {
|
return {
|
||||||
"timestamp": datetime.datetime.now().isoformat(),
|
"timestamp": datetime.datetime.now().isoformat(),
|
||||||
"Qperm": np.round(data.get("FM2", 0.0), 1),
|
"Qperm": np.round(data.get("FM2", 0.0), 1),
|
||||||
|
|
@ -101,6 +102,17 @@ def format_data(data):
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
def format_DS_data(data):
|
||||||
|
return {
|
||||||
|
"timestamp": datetime.datetime.now().isoformat(),
|
||||||
|
"Q_conso_filt": np.round(data.get("Qdrain_sp", 0.0), 1),
|
||||||
|
"TankLevel": np.round(data.get("TankLevel", 0.0), 1),
|
||||||
|
"Qinlet": np.round(data.get("Inlet_flow", 0.0), 1),
|
||||||
|
"Qoutlet": np.round(data.get("Outlet_flow", 0.0), 1),
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
# CREDENTIALS
|
# CREDENTIALS
|
||||||
|
|
||||||
# Load users from JSON file at startup
|
# Load users from JSON file at startup
|
||||||
|
|
@ -241,12 +253,16 @@ def get_pu_status():
|
||||||
async def update_latest_data():
|
async def update_latest_data():
|
||||||
global active_PUs
|
global active_PUs
|
||||||
while True:
|
while True:
|
||||||
for pu in active_PUs: # TODO: test
|
# PUs
|
||||||
|
for pu in active_PUs:
|
||||||
data = can_backend.get_latest_data(pu_number=pu)
|
data = can_backend.get_latest_data(pu_number=pu)
|
||||||
latest_data[f"PU_{pu}"] = format_data(data)
|
latest_data[f"PU_{pu}"] = format_PU_data(data)
|
||||||
current_data = latest_data[f"PU_{pu}"]
|
logging.debug(f"[MONITOR BUFFER] PU{pu}: {latest_data[f"PU_{pu}"]}")
|
||||||
logging.debug(f"[MONITOR BUFFER] PU{pu}: {current_data}")
|
#DS
|
||||||
# logging.info(f"[MONITOR BUFFER] latest_data: {latest_data}")
|
data = can_backend.get_latest_data(pu_number=0)
|
||||||
|
latest_data[f"DS"] = format_DS_data(data)
|
||||||
|
|
||||||
|
logging.debug(f"[MONITOR DS BUFFER] latest_DS_data: {latest_data}")
|
||||||
await asyncio.sleep(0.05)
|
await asyncio.sleep(0.05)
|
||||||
|
|
||||||
|
|
||||||
|
|
@ -285,7 +301,7 @@ async def start_recording():
|
||||||
filepath = os.path.join("recordings", filename)
|
filepath = os.path.join("recordings", filename)
|
||||||
|
|
||||||
recording_file = open(filepath, "w", newline="")
|
recording_file = open(filepath, "w", newline="")
|
||||||
fieldnames = ["timestamp", "pu", "QSkid"] + list(format_data({}).keys())
|
fieldnames = ["timestamp", "pu", "QSkid"] + list(format_PU_data({}).keys())
|
||||||
recording_writer = csv.DictWriter(recording_file, fieldnames=fieldnames)
|
recording_writer = csv.DictWriter(recording_file, fieldnames=fieldnames)
|
||||||
recording_writer.writeheader()
|
recording_writer.writeheader()
|
||||||
|
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue
Block a user