Skip to content

Commit 4e658f3

Browse files
committed
Misc minor changes, including addition of add_signal_prefix function (to replace renaming functionality of the restructure_data function)
1 parent 3d9cc26 commit 4e658f3

File tree

3 files changed

+25
-12
lines changed

3 files changed

+25
-12
lines changed

aws_lambda_example/lambda_function.py

+3-1
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
import s3fs
2-
from utils import setup_fs, load_dbc_files, list_log_files, ProcessData, MultiFrameDecoder
2+
from utils import setup_fs, load_dbc_files, list_log_files, ProcessData, MultiFrameDecoder, restructure_data
33
from utils_db import SetupInflux
44
import inputs as inp
55

@@ -28,4 +28,6 @@ def lambda_handler(event, context=None):
2828
df_phys = proc.extract_phys(df_raw)
2929
proc.print_log_summary(device_id, log_file, df_phys)
3030

31+
df_phys = restructure_data(df_phys,inp.res)
32+
3133
influx.write_signals(device_id, df_phys)

main.py

+1-3
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,5 @@
3131
df_phys = proc.extract_phys(df_raw)
3232
proc.print_log_summary(device_id, log_file, df_phys)
3333

34-
if inp.res != "":
35-
df_phys = restructure_data(df_phys,inp.res)
36-
34+
df_phys = restructure_data(df_phys,inp.res)
3735
influx.write_signals(device_id, df_phys)

utils.py

+21-8
Original file line numberDiff line numberDiff line change
@@ -72,18 +72,31 @@ def list_log_files(fs, devices, start_times, verbose=True, passwords={}):
7272

7373
return log_files
7474

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
7780

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"]
7987

80-
if res == "":
81-
print("Warning: You must set a resampling frequency (e.g. 5S)")
88+
return df_phys
8289

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")
8598

86-
return df_phys_join
99+
return df_phys
87100

88101

89102
def test_signal_threshold(df_phys, signal, threshold):

0 commit comments

Comments
 (0)