moved some stuff around, probably outdated overload report.
[feisty_meow.git] / scripts / notes / info_overload_report.sh
1
2 # these metrics are how bogged down we are in to-do type items.
3
4 REPORT_FILE="$HOME/cloud/overload_history.txt"
5
6 # given a path, this will find how many items are under it, ignoring svn and git files, plus
7 # other patterns we happen to notice are not useful.
8 function calculate_count()
9 {
10   local dir="$1"; shift
11   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 ' ')
12   if [ -z "$count" ]; then echo 0; else echo "$count"; fi
13 }
14
15 # calculates the size in kilobytes of all the note files in a hierarchy.
16 # this is just a raw statistic for how much content all those notes make up.  since
17 # we have not separated out all the to-dos in some files (most notably the metaverse
18 # backlogs and to-do lists), it's good to also know what kind of girth the notes have.
19 function calculate_weight()
20 {
21   local dir="$1"; shift
22   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)
23   if [ -z "$weight" ]; then echo 0; else echo "$weight"; fi
24 }
25
26 # calculate_complexity gets a very simple metric of how many directory components are
27 # present at the target location and below.
28 function calculate_complexity()
29 {
30   local dir="$1"; shift
31   complexity=$(find "$dir" -type d | wc -l)
32   if [ -z "$complexity" ]; then echo 0; else echo "$complexity"; fi
33 }
34
35 # produces a report line in our format.
36 function format_report_line()
37 {
38   local count="$1"; shift
39   local weight="$1"; shift
40   weight=$((weight / 1024))
41   local complexity="$1"; shift
42   echo "$count\t${weight}\t\t${complexity}\t\t$*\n"
43 }
44
45 # two parameters are needed: the directory to sum up and the label to use for it in the report.
46 # this will calculate the count and weight for a hierarchy of notes, and then produce a
47 # line of reporting for those.
48 function analyze_hierarchy_and_report()
49 {
50   local dir="$1"; shift
51   local label="$1"; shift
52   local count=$(calculate_count "$dir")
53   total_overload=$(($count + $total_overload))
54   local weight=$(calculate_weight "$dir")
55   total_weight=$(($total_weight + $weight))
56   local complexity=$(calculate_complexity "$dir")
57   total_complexity=$(($total_complexity + $complexity))
58   full_report+=$(format_report_line "$count" "$weight" "$complexity" "$label")
59 }
60
61 # scans through items in the notes folder that begin with a pattern.
62 # each of those is treated as an aggregable portion of the report.
63 # first parameter is the title in the report, second and so on are
64 # a list of directory patterns to scan and aggregate.
65 function analyze_by_dir_patterns()
66 {
67   local title="$1"; shift
68   local hier_count=0
69   local hier_weight=0
70 #  full_report+=$(format_report_line "$hier_count" "$hier_weight" "$hier_complexity" "$title")
71   for i in $@; do
72     temp_count=$(calculate_count $i)
73     hier_count=$(($hier_count + $temp_count))
74     temp_weight=$(calculate_weight $i)
75     hier_weight=$(($hier_weight + $temp_weight))
76     temp_complexity=$(calculate_complexity $i)
77     hier_complexity=$(($hier_complexity + $temp_complexity))
78   done
79   total_overload=$(($hier_count + $total_overload))
80   total_weight=$(($total_weight + $hier_weight))
81   total_complexity=$(($total_complexity + $hier_complexity))
82   full_report+=$(format_report_line "$hier_count" "$hier_weight" "$hier_complexity" "$title")
83 }
84
85 ##############
86
87 # reset these before we add anything...
88 total_overload=0
89 total_weight=0
90
91 # start out the report with a header.
92 full_report="\
93 \n\
94 current information overload consists of:\n\
95 \n\
96 "
97 full_report+="count\tweight (kb)\tcomplexity\tcategory\n\
98 ================================================================\n\
99 "
100
101 # notes are individual files of tasks, usually, although some are combined.
102 analyze_hierarchy_and_report ~/cloud/grunty_notes "grunty notes"
103
104 # feisty notes are about feisty meow(r) concerns ltd codebase development.
105 analyze_hierarchy_and_report ~/cloud/feisty_notes "feisty meow notes"
106
107 # scan all the items declared as active projects.
108 analyze_by_dir_patterns "active items" ~/cloud/*active*
109
110 # scan across all appropriately named project or research folders that live in the "cloud".
111 analyze_by_dir_patterns "project files" ~/cloud/*project* ~/cloud/*research*
112
113 # scan all the trivial project folders.
114 analyze_by_dir_patterns "trivial items" ~/cloud/*trivia*
115
116 # source examples need to be sucked into other places, other codebases.  they are not
117 # supposed to pile up here.
118 analyze_hierarchy_and_report ~/cloud/example_source "source examples"
119
120 # and then count up the things that we think will be cleaned soon, but one thing we have learned
121 # unsorted files haven't been categorized yet.
122 analyze_hierarchy_and_report ~/cloud/unsorted "unsorted files"
123
124 # we now consider the backlog of things to read to be a relevant fact.  this is going to hose
125 # up our weight accounting considerably.
126 analyze_hierarchy_and_report ~/cloud/reading "reading list"
127
128 full_report+="================================================================\n\
129 "
130 full_report+="$(format_report_line "$total_overload" "$total_weight" "$total_complexity" "total overload")"
131 full_report+="\n\
132 [gathered on $(date)]\n\n\
133 ##############"
134
135 echo -e "$full_report" | tee -a "$REPORT_FILE"
136