nice cleanup of script to generate report with functions.
[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_depth()
9 {
10   local dir="$1"; shift
11   find "$dir" -type f -exec echo \"{}\" ';' |  grep -v "\.svn" | grep -v "\.git"| grep -v "\.basket" | grep -v "\.version" | grep -v "\.keep" | wc -l | tr -d ' '
12 }
13
14 # calculates the size in kilobytes of all the note files in a hierarchy.
15 # this is just a raw statistic for how much content all those notes make up.  since
16 # we have not separated out all the to-dos in some files (most notably the metaverse
17 # backlogs and to-do lists), it's good to also know what kind of girth the notes have.
18 function calculate_weight()
19 {
20   local dir="$1"; shift
21   find "$dir" -type f -exec echo \"{}\" ';' |  grep -v "\.svn" | grep -v "\.git"| grep -v "\.basket" | grep -v "\.version" | grep -v "\.keep" | xargs ls -al | awk '{ print $5 }' | paste -sd+ | bc
22 }
23
24 # produces a report line in our format.
25 function format_report_line()
26 {
27   local depth="$1"; shift
28   local weight="$1"; shift
29   weight=$((weight / 1024))
30   echo "  $depth\t${weight}kb\t$*\n"
31 }
32
33 # two parameters are needed: the directory to sum up and the label to use for it in the report.
34 # this will calculate the depth and weight for a hierarchy of notes, and then produce a
35 # line of reporting for those.
36 function analyze_hierarchy_and_report()
37 {
38   local dir="$1"; shift
39   local label="$1"; shift
40   local depth=$(calculate_depth "$dir")
41   total_overload=$(($depth + $total_overload))
42   local weight=$(calculate_weight "$dir")
43   total_weight=$(($total_weight + $weight))
44   full_report+=$(format_report_line "$depth" "$weight" "$label")
45 }
46
47 # scans through items in the notes folder that begin with a pattern.
48 # each of those is treated as an aggregable portion of the report.
49 # first parameter is the title in the report, second and so on are
50 # a list of directory patterns to scan and aggregate.
51 function analyze_by_dir_patterns()
52 {
53   local title="$1"; shift
54   local hier_depth=0
55   local hier_weight=0
56   for i in $@; do
57     temp_depth=$(calculate_depth $i)
58     hier_depth=$(($hier_depth + $temp_depth))
59     temp_weight=$(calculate_weight $i)
60     hier_weight=$(($hier_weight + $temp_weight))
61   done
62   total_overload=$(($hier_depth + $total_overload))
63   total_weight=$(($total_weight + $hier_weight))
64   full_report+=$(format_report_line "$hier_depth" "$hier_weight" "$title")
65 }
66
67 ##############
68
69 # reset these before we add anything...
70 total_overload=0
71 total_weight=0
72
73 # start out the report with a header.
74 full_report="\
75 \n\
76 Current information overload consists of:\n\
77 \n\
78 "
79
80 # notes are individual files of tasks, usually, although some are combined.
81 analyze_hierarchy_and_report ~/cloud/grunty_notes "grunty notes"
82
83 #hmmm: make an html todo scanning function from this.
84 # scan web documents for to-do lists.  individual items are marked with <li>.
85 # we do this one a bit differently since we have different criteria for html to-do items.
86 html_item_depth=$(find ~/cloud/grunty_notes/ -type f -iname "*.html" -exec grep "<li" "{}" ';' | wc -l | tr -d ' ')
87 total_overload=$(($html_item_depth + $total_overload))
88 html_item_weight=$(find ~/cloud/grunty_notes/ -type f -iname "*.html" -exec grep "<li" "{}" ';' | wc -c | tr -d ' ')
89 total_weight=$(($total_weight + $html_item_weight))
90 full_report+="$(format_report_line "$html_item_depth" "$html_item_weight" "to-do notes in html")"
91
92 # is that things that are intended are not always followed up on right away.  this catches us
93 # being too hopeful and makes sure nothing seems to be getting done that's lagging.
94 analyze_by_dir_patterns "active items" ~/cloud/*active*
95
96 # scan across all appropriately named project or research folders that live in the "cloud".
97 analyze_by_dir_patterns "project files" ~/cloud/*project* ~/cloud/*research*
98
99 # source examples need to be sucked into other places, other codebases.  they are not
100 # supposed to pile up here.
101 analyze_hierarchy_and_report ~/cloud/example_source "source examples"
102
103 # also snag the files labelled as trivia, since they're still to-dos...
104 analyze_by_dir_patterns "trivial notes" ~/cloud/*trivia*
105
106 # and then count up the things that we think will be cleaned soon, but one thing we have learned
107 # unsorted files haven't been categorized yet.
108 analyze_hierarchy_and_report ~/cloud/unsorted "unsorted files"
109
110 full_report+="\n\
111   =====================================\n\
112 "
113 full_report+="$(format_report_line "$total_overload" "$total_weight" "Total Overload")"
114 full_report+="\n\
115 [gathered on $(date)]\n\n\
116 ##############"
117
118 echo -e "$full_report" | tee -a "$REPORT_FILE"
119