From f8d3efab55f03e9d80b9d6e5304b2e3f00a26277 Mon Sep 17 00:00:00 2001 From: Scott Carroll Date: Sun, 21 Jul 2024 17:15:20 +0100 Subject: [PATCH] Added sleep.csv. Added merged.csv. Renamed steps.sh --- merge.sh | 26 ++++++++++++++++++++++++++ sleep-day.sh | 21 +++++++++++++++++++++ export-to-steps-csv.sh => steps-day.sh | 4 ++-- 3 files changed, 49 insertions(+), 2 deletions(-) create mode 100755 merge.sh create mode 100755 sleep-day.sh rename export-to-steps-csv.sh => steps-day.sh (90%) mode change 100644 => 100755 diff --git a/merge.sh b/merge.sh new file mode 100755 index 0000000..97075b7 --- /dev/null +++ b/merge.sh @@ -0,0 +1,26 @@ +#! /bin/bash + +# Script to merge output from other files in this repo into a single csv + +SOURCES="steps.csv sleep-mins.csv" + +# Write header +echo -n "Date" +for s in $SOURCES +do + echo -n , + echo -n $s | cut -z -d. -f1 +done +echo "" + +# For each unique date... +cat $SOURCES | cut -d, -f1 | sort -u | while read d +do + LINE="$d" + # ...collect the result from each source + for s in $SOURCES + do + LINE="$LINE,"`grep $d $s | cut -d, -f 2` + done + echo $LINE +done diff --git a/sleep-day.sh b/sleep-day.sh new file mode 100755 index 0000000..3208381 --- /dev/null +++ b/sleep-day.sh @@ -0,0 +1,21 @@ +#! /bin/bash + +# Script to extract Huawei watch sleep time from Apple Health full export +# into a csv file + +cat export.xml | + grep 2024- | + grep 'type="HKCategoryTypeIdentifierSleepAnalysis" sourceName="HUAWEI Health"' | + egrep -o 'startDate[^ ]+ [^ ]+ [^ ]+ [^ ]+ [^ ]+ [^ ]+ ' | + while read line + do + START=`echo $line | cut -d\" -f2` + END=`echo $line | cut -d\" -f4` + START_TS=`date --date="$START" +"%s"` + END_TS=`date --date="$END" +"%s"` + TIME=`expr $END_TS - $START_TS` + DATE=`echo $START | cut -d\ -f1` + echo $DATE $TIME + done | + awk '{ sleep[$1]=sleep[$1]+$2 } END { for (date in sleep) { print date "," sleep[date] / 60} }' | + sort >sleep-mins.csv diff --git a/export-to-steps-csv.sh b/steps-day.sh old mode 100644 new mode 100755 similarity index 90% rename from export-to-steps-csv.sh rename to steps-day.sh index 4813b13..0c61e6a --- a/export-to-steps-csv.sh +++ b/steps-day.sh @@ -3,11 +3,11 @@ # Script to extract Huawei watch steps from Apple Health full export # into a csv file -echo '"Date","Steps"' cat export.xml | + grep 2024- | grep 'type="HKQuantityTypeIdentifierStepCount" sourceName="HUAWEI Health"' | cut -d\" -f 14,16 | tr \" \ | cut -d\ -f 1,4 | awk '{ steps[$1]=steps[$1]+$2 } END { for (date in steps) { print date "," steps[date] } }' | - sort + sort >steps.csv