Skip to content

Commit

Permalink
fix(utils): skip reorder columns
Browse files Browse the repository at this point in the history
The first reference summary file used to reorder columns can have missing
fields, resulting in a bug.
  • Loading branch information
chanshing committed Sep 19, 2023
1 parent c8751a4 commit 8f026cf
Showing 1 changed file with 1 addition and 2 deletions.
3 changes: 1 addition & 2 deletions src/accelerometer/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -162,6 +162,7 @@ def collateSummary(resultsDir, outputCsvFile="all-summary.csv"):
<summary CSV of all participants/files written to "data/all-summary.csv">
"""

print(f"Scanning {resultsDir} for summary files...")
# Load all *-summary.json files under resultsDir/
sumfiles = []
jdicts = []
Expand All @@ -176,8 +177,6 @@ def collateSummary(resultsDir, outputCsvFile="all-summary.csv"):
jdicts.append(json.load(f, object_pairs_hook=OrderedDict))

summary = pd.DataFrame.from_dict(jdicts) # merge to a dataframe
refColumnOrder = next((item for item in jdicts if item['quality-goodWearTime'] == 1), None)
summary = summary[list(refColumnOrder.keys())] # maintain intended column ordering
summary['eid'] = summary['file-name'].str.split('/').str[-1].str.split('.').str[0] # infer ID from filename
summary.to_csv(outputCsvFile, index=False)
print('Summary of', str(len(summary)), 'participants written to:', outputCsvFile)
Expand Down

0 comments on commit 8f026cf

Please sign in to comment.