Bug fix for monitoring
This commit is contained in:
parent
c1ce7da3d8
commit
4769323230
5
.gitignore
vendored
5
.gitignore
vendored
|
|
@ -1 +1,6 @@
|
|||
__pycache__/main.cpython-311.pyc
|
||||
recordings/recording_20250716_145535.csv
|
||||
recordings/recording_20250716_143101.csv
|
||||
recordings/recording_20250716_143537.csv
|
||||
recordings/recording_20250716_150700.csv
|
||||
recordings/recording_20250716_181008.csv
|
||||
|
|
|
|||
42
classCAN.py
42
classCAN.py
|
|
@ -85,13 +85,13 @@ class CANBackend:
|
|||
mv07Cmd = node.sdo[0x2015][1].raw
|
||||
mv08Cmd = node.sdo[0x2022][1].raw
|
||||
|
||||
mv02fb = node.sdo[0x3000][2].raw
|
||||
mv03fb = node.sdo[0x3000][3].raw
|
||||
mv04fb = node.sdo[0x3000][4].raw
|
||||
mv05fb = node.sdo[0x3000][5].raw
|
||||
mv06fb = node.sdo[0x3000][6].raw
|
||||
mv07fb = node.sdo[0x3000][7].raw
|
||||
mv08fb = node.sdo[0x3000][8].raw
|
||||
# mv02fb = node.sdo[0x3000][2].raw
|
||||
# mv03fb = node.sdo[0x3000][3].raw
|
||||
# mv04fb = node.sdo[0x3000][4].raw
|
||||
# mv05fb = node.sdo[0x3000][5].raw
|
||||
# mv06fb = node.sdo[0x3000][6].raw
|
||||
# mv07fb = node.sdo[0x3000][7].raw
|
||||
# mv08fb = node.sdo[0x3000][8].raw
|
||||
|
||||
self.latest_data[pu_number] = {
|
||||
"FM1": (fm1 / 100.0) * 60.0,
|
||||
|
|
@ -104,21 +104,21 @@ class CANBackend:
|
|||
"PS3": ps3 / 1000.0,
|
||||
"PS4": ps4 / 1000.0,
|
||||
|
||||
"MV02_sp" : mv02Cmd,
|
||||
"MV03_sp" : mv03Cmd,
|
||||
"MV04_sp" : mv04Cmd,
|
||||
"MV05_sp" : mv05Cmd,
|
||||
"MV06_sp" : mv06Cmd,
|
||||
"MV07_sp" : mv07Cmd,
|
||||
"MV08_sp" : mv08Cmd,
|
||||
"MV02_sp" : mv02Cmd / 100.0,
|
||||
"MV03_sp" : mv03Cmd / 100.0,
|
||||
"MV04_sp" : mv04Cmd / 100.0,
|
||||
"MV05_sp" : mv05Cmd / 100.0,
|
||||
"MV06_sp" : mv06Cmd / 100.0,
|
||||
"MV07_sp" : mv07Cmd / 100.0,
|
||||
"MV08_sp" : mv08Cmd / 100.0,
|
||||
|
||||
"MV02" : mv02fb,
|
||||
"MV03" : mv03fb,
|
||||
"MV04" : mv04fb,
|
||||
"MV05" : mv05fb,
|
||||
"MV06" : mv06fb,
|
||||
"MV07" : mv07fb,
|
||||
"MV08" : mv08fb,
|
||||
# "MV02" : mv02fb,
|
||||
# "MV03" : mv03fb,
|
||||
# "MV04" : mv04fb,
|
||||
# "MV05" : mv05fb,
|
||||
# "MV06" : mv06fb,
|
||||
# "MV07" : mv07fb,
|
||||
# "MV08" : mv08fb,
|
||||
}
|
||||
|
||||
print(f"[PU{pu_number}] FM1: {fm1}, PS1: {ps1}")
|
||||
|
|
|
|||
51
main.py
51
main.py
|
|
@ -73,28 +73,28 @@ async def update_latest_flow():
|
|||
def format_data(data):
|
||||
return {
|
||||
"timestamp": datetime.datetime.now().isoformat(),
|
||||
"Qperm": np.round(data.get("FM2", 0.0), 1),
|
||||
"Qdilute": np.round(data.get("FM1", 0.0), 1),
|
||||
"Qdrain": np.round(data.get("FM4", 0.0), 1),
|
||||
"Qrecirc": np.round(data.get("FM3", 0.0), 1),
|
||||
"Pro": np.round(data.get("PS1", 0.0), 1),
|
||||
"Pdilute": np.round(data.get("PS3", 0.0), 1),
|
||||
"Prentate": np.round(data.get("PS2", 0.0), 1),
|
||||
"Conductivity": np.round(data.get("Cond", 0.0), 1),
|
||||
"MV02": np.round(data.get("MV02", 0.0), 1),
|
||||
"MV02_sp": np.round(data.get("MV02_sp", 0.0), 1),
|
||||
"MV03": np.round(data.get("MV03", 0.0), 1),
|
||||
"MV03_sp": np.round(data.get("MV03_sp", 0.0), 1),
|
||||
"MV04": np.round(data.get("MV05", 0.0), 1),
|
||||
"MV04_sp": np.round(data.get("MV05_sp", 0.0), 1),
|
||||
"MV05": np.round(data.get("MV05", 0.0), 1),
|
||||
"MV05_sp": np.round(data.get("MV05_sp", 0.0), 1),
|
||||
"MV06": np.round(data.get("MV06", 0.0), 1),
|
||||
"MV06_sp": np.round(data.get("MV06_sp", 0.0), 1),
|
||||
"MV07": np.round(data.get("MV07", 0.0), 1),
|
||||
"MV07_sp": np.round(data.get("MV07_sp", 0.0), 1),
|
||||
"MV08": np.round(data.get("MV08", 0.0), 1),
|
||||
"MV08_sp": np.round(data.get("MV08_sp", 0.0), 1),
|
||||
"Qperm": data.get("FM2", 0.0),
|
||||
"Qdilute": data.get("FM1", 0.0),
|
||||
"Qdrain": data.get("FM4", 0.0),
|
||||
"Qrecirc": data.get("FM3", 0.0),
|
||||
"Pro": data.get("PS1", 0.0),
|
||||
"Pdilute": data.get("PS3", 0.0),
|
||||
"Prentate": data.get("PS2", 0.0),
|
||||
"Conductivity": data.get("Cond", 0.0),
|
||||
"MV02": data.get("MV02", 0.0),
|
||||
"MV02_sp": data.get("MV02_sp", 0.0),
|
||||
"MV03": data.get("MV03", 0.0),
|
||||
"MV03_sp": data.get("MV03_sp", 0.0),
|
||||
"MV04": data.get("MV05", 0.0),
|
||||
"MV04_sp": data.get("MV05_sp", 0.0),
|
||||
"MV05": data.get("MV05", 0.0),
|
||||
"MV05_sp": data.get("MV05_sp", 0.0),
|
||||
"MV06": data.get("MV06", 0.0),
|
||||
"MV06_sp": data.get("MV06_sp", 0.0),
|
||||
"MV07": data.get("MV07", 0.0),
|
||||
"MV07_sp": data.get("MV07_sp", 0.0),
|
||||
"MV08": data.get("MV08", 0.0),
|
||||
"MV08_sp": data.get("MV08_sp", 0.0),
|
||||
}
|
||||
|
||||
# CREDENTIALS
|
||||
|
|
@ -235,10 +235,12 @@ async def update_latest_data():
|
|||
|
||||
|
||||
@app.get("/monitor")
|
||||
async def get_monitor_data(pu_number: Optional[int] = Query(None)):
|
||||
async def get_monitor_data(pu_number: Optional[float] = Query(None)):
|
||||
print(f"pu_number is {pu_number}")
|
||||
if pu_number is not None:
|
||||
return latest_data.get(f"PU_{pu_number}", {})
|
||||
else:
|
||||
# print(latest_data)
|
||||
return latest_data
|
||||
|
||||
|
||||
|
|
@ -275,7 +277,7 @@ async def start_recording():
|
|||
filepath = os.path.join("recordings", filename)
|
||||
|
||||
recording_file = open(filepath, "w", newline="")
|
||||
fieldnames = ["timestamp", "pu"] + list(format_data({}).keys())
|
||||
fieldnames = ["timestamp", "pu", "QSkid"] + list(format_data({}).keys())
|
||||
recording_writer = csv.DictWriter(recording_file, fieldnames=fieldnames)
|
||||
recording_writer.writeheader()
|
||||
|
||||
|
|
@ -313,6 +315,7 @@ async def record_data_loop():
|
|||
timestamp = datetime.datetime.now().isoformat()
|
||||
for pu, data in latest_data.items():
|
||||
if data:
|
||||
print("record_data",data)
|
||||
row = {
|
||||
"timestamp": timestamp,
|
||||
"pu": pu,
|
||||
|
|
|
|||
Loading…
Reference in New Issue
Block a user