Add fixed_cols for epoch segment function
parent
9eaa48c7dd
commit
5a32050295
|
@ -9,7 +9,7 @@ metrics = snakemake.params["metrics"]
|
||||||
if battery_data.empty:
|
if battery_data.empty:
|
||||||
battery_features = pd.DataFrame(columns=["local_date"] + ["battery_" + day_segment + "_" + x for x in metrics])
|
battery_features = pd.DataFrame(columns=["local_date"] + ["battery_" + day_segment + "_" + x for x in metrics])
|
||||||
else:
|
else:
|
||||||
battery_data = splitOvernightEpisodes(battery_data, ["battery_diff"])
|
battery_data = splitOvernightEpisodes(battery_data, ["battery_diff"], [])
|
||||||
|
|
||||||
if day_segment != "daily":
|
if day_segment != "daily":
|
||||||
battery_data = splitMultiSegmentEpisodes(battery_data, day_segment, ["battery_diff"])
|
battery_data = splitMultiSegmentEpisodes(battery_data, day_segment, ["battery_diff"])
|
||||||
|
|
|
@ -20,13 +20,13 @@ def computeTruncatedDifferences(df, extra_cols):
|
||||||
df.rename(columns={"truncated_time_diff": "time_diff"}, inplace=True)
|
df.rename(columns={"truncated_time_diff": "time_diff"}, inplace=True)
|
||||||
return df
|
return df
|
||||||
|
|
||||||
def splitOvernightEpisodes(sensor_deltas, extra_cols):
|
def splitOvernightEpisodes(sensor_deltas, extra_cols, fixed_cols):
|
||||||
overnight = sensor_deltas[(sensor_deltas["local_start_date"] + timedelta(days=1)) == sensor_deltas["local_end_date"]]
|
overnight = sensor_deltas[(sensor_deltas["local_start_date"] + timedelta(days=1)) == sensor_deltas["local_end_date"]]
|
||||||
not_overnight = sensor_deltas[sensor_deltas["local_start_date"] == sensor_deltas["local_end_date"]]
|
not_overnight = sensor_deltas[sensor_deltas["local_start_date"] == sensor_deltas["local_end_date"]]
|
||||||
|
|
||||||
if not overnight.empty:
|
if not overnight.empty:
|
||||||
today = overnight[extra_cols + ["time_diff", "local_start_date_time", "local_start_date", "local_start_day_segment"]].copy()
|
today = overnight[extra_cols + fixed_cols + ["time_diff", "local_start_date_time", "local_start_date", "local_start_day_segment"]].copy()
|
||||||
tomorrow = overnight[extra_cols + ["time_diff", "local_end_date_time", "local_end_date", "local_end_day_segment"]].copy()
|
tomorrow = overnight[extra_cols + fixed_cols + ["time_diff", "local_end_date_time", "local_end_date", "local_end_day_segment"]].copy()
|
||||||
|
|
||||||
# truncate the end time of all overnight periods to midnight
|
# truncate the end time of all overnight periods to midnight
|
||||||
today = truncateTime(today, "local_end_day_segment", "evening", "local_end_date_time", "local_start_date", time(23,59,59))
|
today = truncateTime(today, "local_end_day_segment", "evening", "local_end_date_time", "local_start_date", time(23,59,59))
|
||||||
|
@ -67,7 +67,6 @@ def splitMultiSegmentEpisodes(sensor_deltas, day_segment, extra_cols):
|
||||||
|
|
||||||
if not within_segments.empty:
|
if not within_segments.empty:
|
||||||
within_segments = truncateTime(within_segments, "local_start_day_segment", day_segment, "local_start_date_time", "local_start_date", time(EPOCH_TIMES[day_segment][0],0,0))
|
within_segments = truncateTime(within_segments, "local_start_day_segment", day_segment, "local_start_date_time", "local_start_date", time(EPOCH_TIMES[day_segment][0],0,0))
|
||||||
|
|
||||||
within_segments = truncateTime(within_segments, "local_end_day_segment", day_segment, "local_end_date_time", "local_end_date", time(EPOCH_TIMES[day_segment][1],59,59))
|
within_segments = truncateTime(within_segments, "local_end_day_segment", day_segment, "local_end_date_time", "local_end_date", time(EPOCH_TIMES[day_segment][1],59,59))
|
||||||
|
|
||||||
across_segments = pd.concat([start_segment, end_segment, within_segments], axis=0, sort=False)
|
across_segments = pd.concat([start_segment, end_segment, within_segments], axis=0, sort=False)
|
||||||
|
|
Loading…
Reference in New Issue