Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #!/usr/bin/env python3
- import pandas as pd
- import csv # being lazy
- #import matplotlib
- #matplotlib.use('TkAgg')
- import matplotlib.pyplot as plt
- from mpl_toolkits.mplot3d import Axes3D
- from PyQt5 import QtCore, QtWidgets, QtGui
- OGVALUES = "Time,Cycle_Status,I0000,I0001,I0002,I0003,I0004,I0005,I0006,I0007,Pump,Blower,LLSV,Compressor,Condenser_Heat,Evap_Heat,HGBV,Alarm_Relay,Tank_Probe_Fahr_W,Cond_LWT_Fahr_W,Cond_EWT_Fahr_W,SLT_Fahr_W,AMB_Fahr_W,Evap1_Fahr_W,Evap2_Fahr_W,HOT_Sensor_Fahr_W,Cond_GPM_F,HP_Raw_W,LP_Raw_W,Alarm_Register_1,Alarm_Register_2,Alarm_Register_3,SH_F,Pump_Down,Heat_Call,Demand_Mode,Tank_Demand_Cut_In,Heat_Call_Cut_Out,MP_HC_Cut_In,MP_HC_Cut_Out,BMS_Heat_Call,MasterHeatCallRgstr,Master_Comm_Status,Member_Unit_Status,Unit_number,Cond_Flow_Verif,Flow_Valve_Verif,PID_Start,Valve_Pos_Set_F,Pump_OFF_Delay,HGBV_Max,Post_HGBV_Fan,Defrost,Defrost_Enable,Defrost_Max,defrost_max_timer,Defrost_Fan_Call,Post_Def_Fan_Call,Manual_LLSV,Manual_HGBV,Manual_Evap_Heat,Manual_COND_Heat,LP_SIM,HP_SIM,Manual_Valve"
- OGVALUES_list = OGVALUES.split(',')
- '''
- sudo apt remove python3-matplotlib # FIXED Axes3d warnings
- including pyqt5 lib disapated wayland warnings which is fine as I want to add a highlighter anyway.
- Todo: add a highlighter to show current position in log playback
- '''
- # Verify we are laoding a PLC log file.
- def check_Log(csv_file):
- with open(csv_file, 'r') as infile:
- reader = csv.reader(infile)
- actual_header = next(reader) # Read the first row as header
- # Check if the actual header matches the expected header
- if actual_header != OGVALUES_list:
- print("Header Mismatch", "The selected file does not have the correct header format.")
- # return # uncomment to debug log file input
- sys.exit(1)
- else:
- print("Header looks like a valid PLC log file")
- def plot_analog_values(csv_file):
- # Check header
- check_Log(csv_file)
- # Read the CSV file
- df = pd.read_csv(csv_file)
- # Get list of analog values to plot
- analog_cols = "Tank_Probe_Fahr_W,Cond_LWT_Fahr_W,Cond_EWT_Fahr_W,SLT_Fahr_W,AMB_Fahr_W,Evap1_Fahr_W,Evap2_Fahr_W,HOT_Sensor_Fahr_W,Cond_GPM_F,HP_Raw_W,LP_Raw_W,SH_F,MasterHeatCallRgstr,Valve_Pos_Set_F".split(',')
- # Create a figure with a reasonable size
- plt.figure(figsize=(15, 10))
- # Create a plot for each analog value
- for col in analog_cols:
- if col in df.columns:
- plt.plot(df.index, df[col], label=col, linewidth=1)
- # Customize the plot
- plt.title(f'Analog Values over Time {sys.argv[1]}', fontsize=14)
- plt.xlabel('Time (samples)', fontsize=12)
- plt.ylabel('Value', fontsize=12)
- plt.grid(True, linestyle='--', alpha=0.7)
- # Add legend with a reasonable layout
- plt.legend(bbox_to_anchor=(1.05, 1), loc='upper left', borderaxespad=0.)
- # Adjust layout to prevent legend cutoff
- plt.tight_layout()
- # Show the plot
- plt.show()
- if __name__ == "__main__":
- import sys
- if len(sys.argv) != 2:
- print("Usage: python script.py <path_to_csv_file>")
- sys.exit(1)
- csv_file = sys.argv[1]
- plot_analog_values(csv_file)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement