|
|
|
|
#!/bin/bash
|
|
|
|
|
|
|
|
|
|
# TOTALILATOR
|
|
|
|
|
# ==============================================================================
|
|
|
|
|
# NOTE: Must run after separator.sh script.
|
|
|
|
|
|
|
|
|
|
# This script parses the files in:
|
|
|
|
|
|
|
|
|
|
# - data/light-meter-1/
|
|
|
|
|
# - data/light-meter-2/
|
|
|
|
|
|
|
|
|
|
# and creates new CSV files which includes the total number of readings on a
|
|
|
|
|
# given day and hour (of that day). The daily totals are stored at the top the
|
|
|
|
|
# data/ directory at:
|
|
|
|
|
|
|
|
|
|
# - data/light-meter-1-daily-totals.csv
|
|
|
|
|
# - data/light-meter-2-daily-totals.csv
|
|
|
|
|
|
|
|
|
|
# and the hourly breakdowns are stored in :
|
|
|
|
|
|
|
|
|
|
# - light-meter-1-hourly-totals
|
|
|
|
|
# - light-meter-2-hourly-totals
|
|
|
|
|
|
|
|
|
|
# Because of the amount of files produced, I've made the script seperate each
|
|
|
|
|
# hourly-based file into a directory corresponding to the month the readings
|
|
|
|
|
# where taken. So, you should see a file structure similar to this,
|
|
|
|
|
|
|
|
|
|
# data/
|
|
|
|
|
# └── light-meter-1-hourly-totals/
|
|
|
|
|
# ├── 2021-06
|
|
|
|
|
# │ ├── 2021-06-01.csv
|
|
|
|
|
# │ ├── 2021-06-02.csv
|
|
|
|
|
# │ ├── 2021-06-03.csv
|
|
|
|
|
# │ ├── 2021-06-30.csv
|
|
|
|
|
# │ └── 2021-06-31.csv
|
|
|
|
|
# ├── 2021-07
|
|
|
|
|
# │ ├── 2021-07-01.csv
|
|
|
|
|
# │ ├── 2021-07-02.csv
|
|
|
|
|
# │ ├── 2021-07-03.csv
|
|
|
|
|
# │ ├── 2021-07-30.csv
|
|
|
|
|
# │ └── 2021-07-31.csv
|
|
|
|
|
# └── 2021-08
|
|
|
|
|
# ├── 2021-08-01.csv
|
|
|
|
|
# ├── 2021-08-02.csv
|
|
|
|
|
# ├── 2021-08-03.csv
|
|
|
|
|
# ├── 2021-08-29.csv
|
|
|
|
|
# ├── 2021-08-30.csv
|
|
|
|
|
# └── 2021-08-31.csv
|
|
|
|
|
|
|
|
|
|
# 3 directories, 93 files (I've shorted the list for brevity)
|
|
|
|
|
|
|
|
|
|
# Note: Repetitive use of file names
|
|
|
|
|
# ==============================================================================
|
|
|
|
|
|
|
|
|
|
# You will find I've used the date of the readings as the go-to naming
|
|
|
|
|
# convention for naming files. Basically, I'm relying on the system's directory
|
|
|
|
|
# structure to provide the context for the data in each file. I didn't want the
|
|
|
|
|
# file names to carry the 'folder structure' and end up with longer file names
|
|
|
|
|
# the deeper into the data/ directory you go. The trade-off is when viewing
|
|
|
|
|
# files on their own, their file names don't provide enough context and can be
|
|
|
|
|
# confusing when dealing with them in isolation (outside of the projects
|
|
|
|
|
# directory structure).
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
getDailyReadingTotals () {
|
|
|
|
|
mtr=$1; # Light Meter
|
|
|
|
|
echo "date,reading" > "data/light-meter-$mtr-daily-totals.csv";
|
|
|
|
|
for month in {6..7} ; do
|
|
|
|
|
for day in {1..31} ; do
|
|
|
|
|
if [[ $month -eq 6 ]] && [[ $day -lt 13 ]]; then
|
|
|
|
|
:
|
|
|
|
|
else
|
|
|
|
|
if [[ $day != 31 ]] && [[ $month != "06" ]]; then
|
|
|
|
|
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";
|
|
|
|
|
fi
|
|
|
|
|
fi
|
|
|
|
|
done
|
|
|
|
|
done
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
getHourlyReadingTotals () {
|
|
|
|
|
mtr=$1; # Light Meter
|
|
|
|
|
mkdir -p "data/light-meter-$mtr-hourly-totals";
|
|
|
|
|
for month in {6..7} ; 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 [[ $month -eq 6 ]] && [[ $day -lt 13 ]]; then
|
|
|
|
|
:
|
|
|
|
|
else
|
|
|
|
|
if [[ $day != 31 ]] && [[ $month != "06" ]]; then
|
|
|
|
|
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
|
|
|
|
|
fi
|
|
|
|
|
fi
|
|
|
|
|
done
|
|
|
|
|
done
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
# Process Light Meter 1 first...
|
|
|
|
|
getDailyReadingTotals "1";
|
|
|
|
|
getHourlyReadingTotals "1";
|
|
|
|
|
|
|
|
|
|
# Process Light Meter 2 second...
|
|
|
|
|
getDailyReadingTotals "2";
|
|
|
|
|
getHourlyReadingTotals "2";
|