Skip to content

Commit

Permalink
fix: restore fixing nonincr timestamps
Browse files Browse the repository at this point in the history
Undoes part of a7de38b
  • Loading branch information
chanshing committed Sep 26, 2023
1 parent aed92ce commit 1d2dd85
Showing 1 changed file with 12 additions and 0 deletions.
12 changes: 12 additions & 0 deletions src/actipy/reader.py
Original file line number Diff line number Diff line change
Expand Up @@ -209,6 +209,18 @@ def _read_device(input_file, verbose=True):
data['time'] = pd.to_datetime(data_mmap['time'], unit='ms')
data = pd.DataFrame(data, copy=False)

# Check for non-increasing timestamps. This is rare but can happen with
# buggy devices. TODO: Parser should do this.
errs = (data['time'].diff() <= pd.Timedelta(0)).sum()
if errs > 0:
print("Found non-increasing data timestamps. Fixing...")
data = data[data['time']
.cummax()
.diff()
.fillna(pd.Timedelta(1))
> pd.Timedelta(0)]
info['ReadErrors'] += int(np.ceil(errs / info['SampleRate']))

# Start/end times, wear time, interrupts
t = data['time']
tol = pd.Timedelta('1s')
Expand Down

0 comments on commit 1d2dd85

Please sign in to comment.