From 1502b19fdef737bc17b1bf9a41a3c414b05e2299 Mon Sep 17 00:00:00 2001 From: Craig Oates Date: Tue, 21 Mar 2023 00:33:51 +0000 Subject: [PATCH] create totalilator.sh script. This script processes the files in the light-meter-1/ and light-meter-2/ directories in the data/ directory. It tallies up the total readings taken for a given day and the individual hours in a given day. Note: You must run this code after you've ran the separator.sh script. --- totalilator.sh | 40 ++++++++++++++++++++++++++++++++++++++++ 1 file changed, 40 insertions(+) create mode 100755 totalilator.sh diff --git a/totalilator.sh b/totalilator.sh new file mode 100755 index 0000000..fe752b7 --- /dev/null +++ b/totalilator.sh @@ -0,0 +1,40 @@ +#!/bin/bash + +getDailyReadingTotals () { + mtr=$1; + echo "date,reading" > "data/light-meter-$mtr-daily-totals.csv"; + for month in {6..8} ; do + for day in {1..31} ; do + if [[ $day -lt 10 ]]; then d="0$day"; else d="$day"; fi + if [[ $month -lt 10 ]]; then m="0$month"; else m=$month; fi + echo "2021-$m-$d, $(awk 'END{print NR-1}' "data/light-meter-$mtr/2021-$m-$d.csv")" \ + >> "data/light-meter-$mtr-daily-totals.csv"; + done + done +} + +getHourlyReadingTotals () { + mtr=$1; + mkdir -p "data/light-meter-$mtr-hourly-totals"; + for month in {6..8} ; do + if [[ $month -lt 10 ]]; then m="0$month"; else m=$month; fi + mkdir -p "data/light-meter-$mtr-hourly-totals/2021-$m" + for day in {1..31} ; do + if [[ $day -lt 10 ]]; then d="0$day"; else d="$day"; fi + echo "hour,reading" > "data/light-meter-$mtr-hourly-totals/2021-$m/2021-$m-$d.csv"; + for hour in {0..24} ; do + if [[ $hour -lt 10 ]]; then h="0$hour"; else h=$hour; fi + echo "$h, $(awk 'END{print NR-1}' "data/light-meter-$mtr/2021-$m-$d/2021-$m-$d--$h.csv")" \ + >> "data/light-meter-$mtr-hourly-totals/2021-$m/2021-$m-$d.csv"; + done + done + done +} + +# Process Light Meter 1 first... +getDailyReadingTotals "1"; +getHourlyReadingTotals "1"; + +# Process Light Meter 2 second... +getDailyReadingTotals "2"; +getHourlyReadingTotals "2";