Advertisement
j0h

logPlot

j0h
Jan 28th, 2025
51
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 3.20 KB | None | 0 0
  1. #!/usr/bin/env python3
  2. import pandas as pd
  3. import csv # being lazy
  4. #import matplotlib
  5. #matplotlib.use('TkAgg')
  6. import matplotlib.pyplot as plt
  7. from mpl_toolkits.mplot3d import Axes3D
  8. from PyQt5 import QtCore, QtWidgets, QtGui
  9. 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"
  10. OGVALUES_list = OGVALUES.split(',')
  11. '''
  12. sudo apt remove python3-matplotlib  # FIXED Axes3d warnings
  13. including pyqt5 lib disapated wayland warnings which is fine as I want to add a highlighter anyway.
  14.  
  15. Todo: add a highlighter to show current position in log playback
  16.  
  17. '''
  18.  
  19. # Verify we are laoding a PLC log file.
  20. def check_Log(csv_file):
  21.     with open(csv_file, 'r') as infile:
  22.         reader = csv.reader(infile)
  23.         actual_header = next(reader)  # Read the first row as header
  24.         # Check if the actual header matches the expected header
  25.         if actual_header != OGVALUES_list:
  26.             print("Header Mismatch", "The selected file does not have the correct header format.")
  27.             # return # uncomment to debug log file input
  28.             sys.exit(1)
  29.         else:
  30.             print("Header looks like a valid PLC log file")
  31.  
  32. def plot_analog_values(csv_file):
  33.  
  34.     # Check header
  35.     check_Log(csv_file)
  36.     # Read the CSV file
  37.     df = pd.read_csv(csv_file)
  38.    
  39.     # Get list of analog values to plot
  40.     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(',')
  41.    
  42.     # Create a figure with a reasonable size
  43.     plt.figure(figsize=(15, 10))
  44.    
  45.     # Create a plot for each analog value
  46.     for col in analog_cols:
  47.         if col in df.columns:
  48.             plt.plot(df.index, df[col], label=col, linewidth=1)
  49.    
  50.     # Customize the plot
  51.     plt.title(f'Analog Values over Time {sys.argv[1]}', fontsize=14)
  52.     plt.xlabel('Time (samples)', fontsize=12)
  53.     plt.ylabel('Value', fontsize=12)
  54.     plt.grid(True, linestyle='--', alpha=0.7)
  55.    
  56.     # Add legend with a reasonable layout
  57.     plt.legend(bbox_to_anchor=(1.05, 1), loc='upper left', borderaxespad=0.)
  58.    
  59.     # Adjust layout to prevent legend cutoff
  60.     plt.tight_layout()
  61.    
  62.     # Show the plot
  63.     plt.show()
  64.  
  65. if __name__ == "__main__":
  66.     import sys
  67.    
  68.     if len(sys.argv) != 2:
  69.         print("Usage: python script.py <path_to_csv_file>")
  70.         sys.exit(1)
  71.        
  72.     csv_file = sys.argv[1]
  73.     plot_analog_values(csv_file)
  74.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement