+ local count=$(find "$dir" -type f -exec echo \"{}\" ';' 2>/dev/null | grep -v "\.svn" | grep -v "\.git"| grep -v "\.basket" | grep -v "\.version" | grep -v "\.keep" | wc -l | tr -d ' ')
+ if [ -z "$count" ]; then echo 0; else echo "$count"; fi
+}
+
+# calculates the size in kilobytes of all the note files in a hierarchy.
+# this is just a raw statistic for how much content all those notes make up. since
+# we have not separated out all the to-dos in some files (most notably the metaverse
+# backlogs and to-do lists), it's good to also know what kind of girth the notes have.
+function calculate_weight()
+{
+ local dir="$1"; shift
+ local weight=$(find "$dir" -type f -exec echo \"{}\" ';' 2>/dev/null | grep -v "\.svn" | grep -v "\.git"| grep -v "\.basket" | grep -v "\.version" | grep -v "\.keep" | xargs ls -al | awk '{ print $5 }' | paste -sd+ | bc 2>/dev/null)
+ if [ -z "$weight" ]; then echo 0; else echo "$weight"; fi
+}
+
+# calculate_complexity gets a very simple metric of how many directory components are
+# present at the target location and below.
+function calculate_complexity()
+{
+ local dir="$1"; shift
+ local complexity=$(find "$dir" -type d | wc -l)
+ if [ -z "$complexity" ]; then echo 0; else echo "$complexity"; fi
+}
+
+# produces a report line in our format.
+function format_report_line()
+{
+ local count="$1"; shift
+ local weight="$1"; shift
+ weight=$((weight / 1024))
+ local complexity="$1"; shift
+ echo "$count\t${complexity}\t\t${weight}\t\t$*\n"
+}
+
+# two parameters are needed: the directory to sum up and the label to use for it in the report.
+# this will calculate the count and weight for a hierarchy of notes, and then produce a
+# line of reporting for those.
+function analyze_hierarchy_and_report()
+{
+ local dir="$1"; shift
+ local label="$1"; shift
+ local count=$(calculate_count "$dir")
+ total_overload=$(($count + $total_overload))
+ local weight=$(calculate_weight "$dir")
+ total_weight=$(($total_weight + $weight))
+ local complexity=$(calculate_complexity "$dir")
+ total_complexity=$(($total_complexity + $complexity))
+ full_report+=$(format_report_line "$count" "$weight" "$complexity" "$label")
+}
+
+# scans through items in the notes folder that begin with a pattern.
+# each of those is treated as an aggregable portion of the report.
+# first parameter is the title in the report, second and so on are
+# a list of directory patterns to scan and aggregate.
+function analyze_by_dir_patterns()
+{
+ local title="$1"; shift
+ local hier_count=0
+ local hier_weight=0
+ local hier_complexity=0
+ for folder in $@; do
+ temp_count=$(calculate_count $folder)
+ hier_count=$(($hier_count + $temp_count))
+ temp_weight=$(calculate_weight $folder)
+ hier_weight=$(($hier_weight + $temp_weight))
+ temp_complexity=$(calculate_complexity $folder)
+ hier_complexity=$(($hier_complexity + $temp_complexity))
+ done
+ total_overload=$(($hier_count + $total_overload))
+ total_weight=$(($total_weight + $hier_weight))
+ total_complexity=$(($total_complexity + $hier_complexity))
+ full_report+=$(format_report_line "$hier_count" "$hier_weight" "$hier_complexity" "$title")