Skip to content

Commit edc1d11

Browse files
author
Martin
committed
Updated physical decoding logic to always group by data length before processing
1 parent 479353c commit edc1d11

File tree

1 file changed

+13
-15
lines changed

1 file changed

+13
-15
lines changed

dashboard-writer/utils.py

Lines changed: 13 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -127,7 +127,7 @@ def __init__(self, fs, db_list, signals=[], days_offset=None, verbose=True):
127127
self.verbose = verbose
128128
return
129129

130-
def extract_phys(self, df_raw, tp_type=None):
130+
def extract_phys(self, df_raw):
131131
"""Given df of raw data and list of decoding databases, create new def with
132132
physical values (no duplicate signals and optionally filtered/rebaselined)
133133
"""
@@ -138,15 +138,12 @@ def extract_phys(self, df_raw, tp_type=None):
138138
for db in self.db_list:
139139
df_decoder = can_decoder.DataFrameDecoder(db)
140140

141-
if tp_type != None:
142-
df_phys_tp = pd.DataFrame()
143-
for length, group in df_raw.groupby("DataLength"):
144-
df_phys_group = df_decoder.decode_frame(group)
145-
df_phys_tp = df_phys_tp.append(df_phys_group)
141+
df_phys_temp = pd.DataFrame()
142+
for length, group in df_raw.groupby("DataLength"):
143+
df_phys_group = df_decoder.decode_frame(group)
144+
df_phys_temp = df_phys_temp.append(df_phys_group)
146145

147-
df_phys = df_phys.append(df_phys_tp.sort_index())
148-
else:
149-
df_phys = df_phys.append(df_decoder.decode_frame(df_raw))
146+
df_phys = df_phys.append(df_phys_temp.sort_index())
150147

151148
# remove duplicates in case multiple DBC files contain identical signals
152149
df_phys["datetime"] = df_phys.index
@@ -155,20 +152,21 @@ def extract_phys(self, df_raw, tp_type=None):
155152

156153
# optionally filter and rebaseline the data
157154
df_phys = self.filter_signals(df_phys)
158-
df_phys = self.rebaseline_data(df_phys)
155+
156+
if not df_phys.empty and type(self.days_offset) == int:
157+
df_phys = self.rebaseline_data(df_phys)
159158

160159
return df_phys
161160

162161
def rebaseline_data(self, df_phys):
163162
"""Given a df of physical values, this offsets the timestamp
164163
to be equal to today, minus a given number of days.
165164
"""
166-
if not df_phys.empty and type(self.days_offset) == int:
167-
from datetime import datetime, timezone
168-
import pandas as pd
165+
from datetime import datetime, timezone
166+
import pandas as pd
169167

170-
delta_days = (datetime.now(timezone.utc) - df_phys.index.min()).days - self.days_offset
171-
df_phys.index = df_phys.index + pd.Timedelta(delta_days, "day")
168+
delta_days = (datetime.now(timezone.utc) - df_phys.index.min()).days - self.days_offset
169+
df_phys.index = df_phys.index + pd.Timedelta(delta_days, "day")
172170

173171
return df_phys
174172

0 commit comments

Comments
 (0)