Skip to content

Commit

Permalink
Misc minor changes, including addition of add_signal_prefix function …
Browse files Browse the repository at this point in the history
…(to replace renaming functionality of the restructure_data function)
  • Loading branch information
MatinF committed Jan 1, 2023
1 parent 3d9cc26 commit 4e658f3
Show file tree
Hide file tree
Showing 3 changed files with 25 additions and 12 deletions.
4 changes: 3 additions & 1 deletion aws_lambda_example/lambda_function.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import s3fs
from utils import setup_fs, load_dbc_files, list_log_files, ProcessData, MultiFrameDecoder
from utils import setup_fs, load_dbc_files, list_log_files, ProcessData, MultiFrameDecoder, restructure_data
from utils_db import SetupInflux
import inputs as inp

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

df_phys = restructure_data(df_phys,inp.res)

influx.write_signals(device_id, df_phys)
4 changes: 1 addition & 3 deletions main.py
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,5 @@
df_phys = proc.extract_phys(df_raw)
proc.print_log_summary(device_id, log_file, df_phys)

if inp.res != "":
df_phys = restructure_data(df_phys,inp.res)

df_phys = restructure_data(df_phys,inp.res)
influx.write_signals(device_id, df_phys)
29 changes: 21 additions & 8 deletions utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -72,18 +72,31 @@ def list_log_files(fs, devices, start_times, verbose=True, passwords={}):

return log_files

def restructure_data(df_phys, res, full_col_names=False, pgn_names=False):
import pandas as pd
def add_signal_prefix(df_phys, can_id_prefix=False, pgn_prefix=False):
"""Rename Signal names by prefixing the full
CAN ID (in hex) and/or J1939 PGN
"""
from J1939_PGN import J1939_PGN

df_phys_join = pd.DataFrame({"TimeStamp": []})
if can_id_prefix == True and pgn_prefix == False:
df_phys["Signal"] = df_phys["CAN ID"].apply(lambda x: f"{hex(int(x))[2:].upper()}") + "." + df_phys["Signal"]
elif can_id_prefix == True and pgn_prefix == True:
df_phys["Signal"] = df_phys["CAN ID"].apply(lambda x: f"{hex(int(x))[2:].upper()}.{J1939_PGN(int(x)).pgn}") + "." + df_phys["Signal"]
elif can_id_prefix == False and pgn_prefix == True:
df_phys["Signal"] = df_phys["CAN ID"].apply(lambda x: f"{J1939_PGN(int(x)).pgn}") + "." + df_phys["Signal"]

if res == "":
print("Warning: You must set a resampling frequency (e.g. 5S)")
return df_phys

if not df_phys.empty:
df_phys_join = df_phys.pivot_table(values="Physical Value", index=pd.Grouper(freq="S"), columns="Signal")
def restructure_data(df_phys, res):
"""Restructure the decoded data to a resampled
format where each column reflects a Signal
"""
import pandas as pd

if not df_phys.empty and res != "":
df_phys = df_phys.pivot_table(values="Physical Value", index=pd.Grouper(freq=res), columns="Signal")

return df_phys_join
return df_phys


def test_signal_threshold(df_phys, signal, threshold):
Expand Down

0 comments on commit 4e658f3

Please sign in to comment.