@@ -72,18 +72,31 @@ def list_log_files(fs, devices, start_times, verbose=True, passwords={}):
72
72
73
73
return log_files
74
74
75
- def restructure_data (df_phys , res , full_col_names = False , pgn_names = False ):
76
- import pandas as pd
75
+ def add_signal_prefix (df_phys , can_id_prefix = False , pgn_prefix = False ):
76
+ """Rename Signal names by prefixing the full
77
+ CAN ID (in hex) and/or J1939 PGN
78
+ """
79
+ from J1939_PGN import J1939_PGN
77
80
78
- df_phys_join = pd .DataFrame ({"TimeStamp" : []})
81
+ if can_id_prefix == True and pgn_prefix == False :
82
+ df_phys ["Signal" ] = df_phys ["CAN ID" ].apply (lambda x : f"{ hex (int (x ))[2 :].upper ()} " ) + "." + df_phys ["Signal" ]
83
+ elif can_id_prefix == True and pgn_prefix == True :
84
+ df_phys ["Signal" ] = df_phys ["CAN ID" ].apply (lambda x : f"{ hex (int (x ))[2 :].upper ()} .{ J1939_PGN (int (x )).pgn } " ) + "." + df_phys ["Signal" ]
85
+ elif can_id_prefix == False and pgn_prefix == True :
86
+ df_phys ["Signal" ] = df_phys ["CAN ID" ].apply (lambda x : f"{ J1939_PGN (int (x )).pgn } " ) + "." + df_phys ["Signal" ]
79
87
80
- if res == "" :
81
- print ("Warning: You must set a resampling frequency (e.g. 5S)" )
88
+ return df_phys
82
89
83
- if not df_phys .empty :
84
- df_phys_join = df_phys .pivot_table (values = "Physical Value" , index = pd .Grouper (freq = "S" ), columns = "Signal" )
90
+ def restructure_data (df_phys , res ):
91
+ """Restructure the decoded data to a resampled
92
+ format where each column reflects a Signal
93
+ """
94
+ import pandas as pd
95
+
96
+ if not df_phys .empty and res != "" :
97
+ df_phys = df_phys .pivot_table (values = "Physical Value" , index = pd .Grouper (freq = res ), columns = "Signal" )
85
98
86
- return df_phys_join
99
+ return df_phys
87
100
88
101
89
102
def test_signal_threshold (df_phys , signal , threshold ):
0 commit comments