Added sleep.csv. Added merged.csv. Renamed steps.sh
This commit is contained in:
26
merge.sh
Executable file
26
merge.sh
Executable file
@@ -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
|
||||
21
sleep-day.sh
Executable file
21
sleep-day.sh
Executable file
@@ -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
|
||||
4
export-to-steps-csv.sh → steps-day.sh
Normal file → Executable file
4
export-to-steps-csv.sh → steps-day.sh
Normal file → Executable file
@@ -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
|
||||
Reference in New Issue
Block a user