summaryrefslogtreecommitdiff
path: root/docker/tbp/tbpReport.sh
diff options
context:
space:
mode:
Diffstat (limited to 'docker/tbp/tbpReport.sh')
-rwxr-xr-xdocker/tbp/tbpReport.sh67
1 files changed, 67 insertions, 0 deletions
diff --git a/docker/tbp/tbpReport.sh b/docker/tbp/tbpReport.sh
new file mode 100755
index 0000000..bb7bc44
--- /dev/null
+++ b/docker/tbp/tbpReport.sh
@@ -0,0 +1,67 @@
+#!/bin/bash
+# tbpReport.sh
+# 2020/12/08
+# Write a report for the last week, month, or year.
+USAGE="Usage: $0 [-w] [-m] [-y] visitFile"
+
+if [ "$#" == "0" ]; then
+ echo $USAGE
+ exit 1
+fi
+
+# Get start time from arguments
+startTime=0
+while [ $# -gt 1 ]; do
+ case $1 in
+ -w)
+ startTime=`date --date="1 week ago" +%s`
+ ;;
+ -m)
+ startTime=`date --date="1 month ago" +%s`
+ ;;
+ -y)
+ startTime=`date --date="1 year ago" +%s`
+ ;;
+ *)
+ echo $USAGE
+ exit 1
+ ;;
+ esac
+ shift
+done
+
+# Test if visits file exists
+if [ ! -f $1 ]; then
+ echo "File $1 does not exist."
+ echo $USAGE
+ exit 1
+fi
+visitFile=$1
+
+# Process the visits file
+echo Shop report for `date +%D`
+echo Shop access since `date --date=@$startTime +%D`
+awk -F, -v t=$startTime '($1>t) {
+ dow=strftime("%w", $1);
+ counter[dow,$6]+=1;
+ counter[$6]+=1;
+ counter[$4]+=1;
+ counter[$5]+=1;
+ numVisitors+=1;
+}
+END {
+ printf("%-10s\tDowntown\tCampus\n", "");
+ printf("%-10s\t%3d\t\t%3d\n", "Sunday", counter[0, "downtown"], counter[0,"campus"]);
+ printf("%-10s\t%3d\t\t%3d\n", "Monday", counter[1, "downtown"], counter[1,"campus"]);
+ printf("%-10s\t%3d\t\t%3d\n", "Tuesday", counter[2, "downtown"], counter[2,"campus"]);
+ printf("%-10s\t%3d\t\t%3d\n", "Wednesday", counter[3, "downtown"], counter[3,"campus"]);
+ printf("%-10s\t%3d\t\t%3d\n", "Thursday", counter[4, "downtown"], counter[4,"campus"]);
+ printf("%-10s\t%3d\t\t%3d\n", "Friday", counter[5, "downtown"], counter[5,"campus"]);
+ printf("%-10s\t%3d\t\t%3d\n", "Saturday", counter[6, "downtown"], counter[6,"campus"]);
+ printf("-------------------------------------\n")
+ printf("%-10s\t%3d\t\t%3d\n", "TOTAL", counter["downtown"], counter["campus"]);
+ printf("\n")
+ printf("Total volunteer visits: %d\n", counter["volunteer"]);
+ printf("Total first visits: %d (%0.1f%%)\n", counter["First Visit"],
+ 100*counter["First Visit"]/numVisitors);
+}' $visitFile