Skip to content

Commit

Permalink
fix: early exit if no data to process
Browse files Browse the repository at this point in the history
  • Loading branch information
chanshing committed Nov 6, 2024
1 parent f6a0f82 commit 322858c
Showing 1 changed file with 15 additions and 0 deletions.
15 changes: 15 additions & 0 deletions src/stepcount/stepcount.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import warnings
import os
import sys
import pathlib
import urllib
import shutil
Expand Down Expand Up @@ -101,6 +102,20 @@ def main():
# Update wear time stats after exclusions
info.update(utils.calculate_wear_stats(data))

# If no data, save Info.json and exit
if len(data) == 0 or data.isna().any(axis=1).all(): # TODO: check na only on x,y,z cols?
# Save Info.json
with open(f"{outdir}/{basename}-Info.json", 'w') as f:
json.dump(info, f, indent=4, cls=utils.NpEncoder)
# Print
print("\nSummary\n-------")
print(json.dumps(
{k: v for k, v in info.items() if not re.search(r'_Weekend|_Weekday|_Hour\d{2}', k)},
indent=4, cls=utils.NpEncoder
))
print("No data to process. Exiting early...")
sys.exit(0)

# Run model
if verbose:
print("Loading model...")
Expand Down

0 comments on commit 322858c

Please sign in to comment.