Browse Source

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.
master
Craig Oates 1 year ago
parent
commit
1502b19fde
  1. 40
      totalilator.sh

40
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";
Loading…
Cancel
Save