u
[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 ####
84 #hmmm: make an html todo scanning function from this.
85 # scan web documents for to-do lists.  individual items are marked with <li>.
86 # we do this one a bit differently since we have different criteria for html to-do items.
87 html_item_depth=$(find ~/cloud/grunty_notes/ -type f -iname "*.html" -exec grep "<li" "{}" ';' | wc -l | tr -d ' ')
88 total_overload=$(($html_item_depth + $total_overload))
89 html_item_weight=$(find ~/cloud/grunty_notes/ -type f -iname "*.html" -exec grep "<li" "{}" ';' | wc -c | tr -d ' ')
90 total_weight=$(($total_weight + $html_item_weight))
91 full_report+="$(format_report_line "$html_item_depth" "$html_item_weight" "to-do notes in html")"
92 ####
93
94 # scan all the items declared as active projects.
95 analyze_by_dir_patterns "active items" ~/cloud/*active*
96
97 # scan across all appropriately named project or research folders that live in the "cloud".
98 analyze_by_dir_patterns "project files" ~/cloud/*project* ~/cloud/*research*
99
100 # source examples need to be sucked into other places, other codebases.  they are not
101 # supposed to pile up here.
102 analyze_hierarchy_and_report ~/cloud/example_source "source examples"
103
104 # and then count up the things that we think will be cleaned soon, but one thing we have learned
105 # unsorted files haven't been categorized yet.
106 analyze_hierarchy_and_report ~/cloud/unsorted "unsorted files"
107
108 # we now consider the backlog of things to read to be a relevant fact.  this is going to hose
109 # up our weight accounting considerably.
110 analyze_hierarchy_and_report ~/cloud/reading "reading list"
111
112 full_report+="\n\
113   =====================================\n\
114 "
115 full_report+="$(format_report_line "$total_overload" "$total_weight" "Total Overload")"
116 full_report+="\n\
117 [gathered on $(date)]\n\n\
118 ##############"
119
120 echo -e "$full_report" | tee -a "$REPORT_FILE"
121