#!/bin/bash # SEPARATOR # ============================================================================== # This script takes the lm1-exhibition-all.csv and lm2-exhibition-all.csv files # and splits the readings down into daily and hourly segments. The breakdowns # are placed in their own directories and should look like the following: # data # ├── light-meter-1 # | │   ├── hourly readings directory (E.G. 2021-07-14/) # | │   |   └──hourly reading files (E.G. 2021-07-14--14.csv) # | │   └── hourly readings directory (E.G. 2021-07-15/) # | │      └── hourly reading files (E.G. 2021-07-15--17.csv) # │   └── daily readings files (E.G 2021-07-14.csv) # │   └── daily readings files (E.G 2021-07-15.csv) # ├── light-meter-2 # |    └── repeats light-meter-1 structure... # ├── lm1-exhibiton-all.csv # └── lm2-exhibiton-all.csv # # 2 directories, 2 files (I've shorted the list for brevity) # Note: Naming Format for Hourly Breakdowns (YYYY-MM-DD--HH) # ============================================================================== # The last part of the file name specifies the hour the readings were taken # from. So, '2021-07-15--17.csv' means the readings for that file were taken on # the 15th July 2021 between 17:00 and 18:00 (5pm and 6pm). hourBreakdown () { d="$1"; # Day m="$2"; # Month mtr="$3"; # Light Meter (either 1 or 2) mkdir -p "data/light-meter-$mtr/2021-$m-$d"; for hour in {0..24}; do if [[ $hour -lt 10 ]]; then echo "time,reading" \ > "data/light-meter-$mtr/2021-$m-$d/2021-$m-$d--0$hour.csv"; rg "2021-$m-$d 0$hour:" "data/light-meter-$mtr/2021-$m-$d.csv" \ >> "data/light-meter-$mtr/2021-$m-$d/2021-$m-$d--0$hour.csv"; else echo "time,reading" \ > "data/light-meter-$mtr/2021-$m-$d/2021-$m-$d--$hour.csv"; rg "2021-$m-$d $hour:" "data/light-meter-$mtr/2021-$m-$d.csv" \ >> "data/light-meter-$mtr/2021-$m-$d/2021-$m-$d--$hour.csv"; fi done } dailyBreakdown () { lm=$1; # Light Meter (either 1 or 2) mkdir -p "data/light-meter-$lm"; for month in {6..7} ; do for day in {1..31} ; do # June is 30 days long, hence the check (and skip). if [[ $day != 31 ]] && [[ $month != "06" ]]; then if [[ $day -lt 10 ]]; then touch "data/light-meter-$lm/2021-0$month-0$day.csv"; echo "time,reading" \ > "data/light-meter-$lm/2021-0$month-0$day.csv"; rg "2021-0$month-0$day" "data/lm$lm-exhibiton-all.csv" \ >> "data/light-meter-$lm/2021-0$month-0$day.csv"; if [[ $month -lt 10 ]]; then hourBreakdown "0$day" "0$month" $lm; else hourBreakdown "0$day" $month $lm; fi else touch "data/light-meter-$lm/2021-0$month-$day.csv"; echo "time,reading" \ > "data/light-meter-$lm/2021-0$month-$day.csv"; rg "2021-0$month-$day" "data/lm$lm-exhibiton-all.csv" \ >> "data/light-meter-$lm/2021-0$month-$day.csv"; if [[ $month -lt 10 ]]; then hourBreakdown $day "0$month" $lm; else hourBreakdown $day $month $lm; fi fi fi done done } removeExcessData () { for day in {1..12}; do if [[ $day -lt 10 ]]; then d="0$day"; else d=$day; fi rm -r "data/light-meter-1/2021-06-$d" rm "data/light-meter-1/2021-06-$d.csv" rm -r "data/light-meter-2/2021-06-$d" rm "data/light-meter-2/2021-06-$d.csv" done } dailyBreakdown "1"; # Light Meter 1 dailyBreakdown "2"; # Light Meter 2 removeExcessData; mkdir output # For storing charts and stuff later (with Python scripts).