Skip to content

Commit

Permalink
update import_data and chop_data functions to avoid error
Browse files Browse the repository at this point in the history
  • Loading branch information
Aminsinichi committed Mar 23, 2024
1 parent 968b498 commit dc6246e
Showing 1 changed file with 11 additions and 14 deletions.
25 changes: 11 additions & 14 deletions wearablehrv/individual.py
Original file line number Diff line number Diff line change
Expand Up @@ -398,20 +398,17 @@ def import_data(path, pp, devices):
data[device]["timestamp"], format="%H:%M:%S.%f"
)

# Format timestamp column as string with format hh:mm:ss.mmm
data[device]["timestamp"] = data[device]["timestamp"].apply(
lambda x: x.strftime("%H:%M:%S.%f")[:-3]
)
else:

for i in range(np.size(data[device]["timestamp"])):
timestamp_float = float(data[device].loc[i, "timestamp"])
data[device].loc[i, "timestamp"] = datetime.datetime.fromtimestamp(
timestamp_float / 1000
)
data[device]["timestamp"] = pd.to_datetime(data[device]["timestamp"])

# Format timestamp column as string with format hh:mm:ss.mmm
data[device]["timestamp"] = data[device]["timestamp"].apply(
lambda x: x.strftime("%H:%M:%S.%f")[:-3]
)

# It is alreay a string
data[device]["timestamp"] = data[device]["timestamp"].apply(
lambda x: datetime.datetime.fromtimestamp(x / 1000).strftime(
"%H:%M:%S.%f"
)[:-3]
)
print("Datasets imported succesfully")
return data

Expand Down Expand Up @@ -662,7 +659,7 @@ def chop_data(data, conditions, events, devices):
& (data[device]["timestamp"] < eventchopped[condition][1])
].copy()
filtered_rows["timestamp"] = pd.to_datetime(
filtered_rows["timestamp"]
filtered_rows["timestamp"], format="%H:%M:%S.%f"
) # convert to datetime format
data_chopped[device][
condition
Expand Down

0 comments on commit dc6246e

Please sign in to comment.