Skip to content

Commit

Permalink
Fix start and end times for reading csv files (#51)
Browse files Browse the repository at this point in the history
* Provide start and end times for reading CSV files if info json files don't contain these two timestamps.

---------

Co-authored-by: “Aidan <“abeiku17@gmail.com”>
  • Loading branch information
aidanacquah and “Aidan authored Jul 16, 2024
1 parent 949236d commit e3e7684
Showing 1 changed file with 5 additions and 2 deletions.
7 changes: 5 additions & 2 deletions src/asleep/get_sleep.py
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,9 @@
NON_WEAR_THRESHOLD = 3 # H
NON_WEAR_PREDICTION_FLAG = -1

START_TIME_IDX = 0
END_TIME_IDX = -1


def load_model(model_path, force_download=False):
""" Load trained model. Download if not exists. """
Expand Down Expand Up @@ -69,8 +72,8 @@ def get_parsed_data(raw_data_path, info_data_path, resample_hz, args):
data = data.reset_index()

# apply time shift
start_time = pd.to_datetime(info['StartTime'])
end_time = pd.to_datetime(info['EndTime'])
start_time = pd.to_datetime(info.get("StartTime", data["time"].iloc[START_TIME_IDX]))
end_time = pd.to_datetime(info.get("EndTime", data["time"].iloc[END_TIME_IDX]))
info['StartTime'] = start_time + datetime.timedelta(hours=time_shift)
info['EndTime'] = end_time + datetime.timedelta(hours=time_shift)
info['StartTime'] = info['StartTime'].strftime('%Y-%m-%d %H:%M:%S')
Expand Down

0 comments on commit e3e7684

Please sign in to comment.