a = t.split('.')
histGtd[a[0]] += 1
-if hist:
- maxlen = max(list(map(len, iter(hist.keys()))))
- maxnum = max(hist.values())
-else:
- maxlen = maxnum = 1
-
-name_len = min(maxlen, MAX_NAME_LEN)
-count_len = floor(log10(maxnum) + 1)
-
-# Tic-per-count or scale all tics proportionally
-maxtics = opt.width - name_len - count_len - 3 #magic num from line format 'ps'
-if maxnum > maxtics:
- def tics(n):
- return int(maxtics*(float(v)/maxnum))
-else:
- def tics(n):
- return n
-
-#format
-ps = '%%-%is (%%%ii)%%s' % (name_len, count_len)
#
# Show date range
#
-# Create hierarchy of tag subjects
-# re.bcon2.antenna -> (re,
-# (bcon2,
-# (antenna, base, comms)
-# )
-# )
-hier = defaultdict(dict)
-# nodes are dicts
-# end leaves are integers
-for tag in hist.keys():
- h = defaultdict(dict)
- subtags = tag.split(".")
- depth = len(subtags)
- # print(f"{tag}: {depth} : {subtags}")
-
- def update(h, tag, rest):
- h[tag] += 1
- if isinstance(rest, list):
- return update(h[tag], rest[0], rest[1:])
- else:
- return h
-
- # hier = update(hier, tag, subtags)
+# Create cumulative hierarchical sum
+#
+hier = defaultdict(int)
+for tag, count in hist.items():
+ parts = tag.split('.')
+ for i in range(1, len(parts)+1):
+ key = '.'.join(parts[:i])
+ hier[key] += count
+print()
+print(dict(hier))
+print()
#
# Display the histogram
#
-for k,v in sorted(iter(hist.items()), key=sorter):
- if v < 1: continue
+def display_histogram(hist, fullname=True):
+ maxlen = max(list(map(len, iter(hist.keys()))))
+ maxnum = max(hist.values())
+ name_len = min(maxlen, MAX_NAME_LEN)
+ count_len = floor(log10(maxnum) + 1)
+
+ # Tic-per-count or scale all tics proportionally
+ maxtics = opt.width - name_len - count_len - 3 #magic num from line format 'ps'
+ if maxnum > maxtics:
+ def tics(n):
+ return int(maxtics*(float(n)/maxnum))
+ else:
+ def tics(n):
+ return n
+
+ ps = '%%-%is (%%%ii)%%s' % (name_len, count_len)
+ for tag,v in sorted(iter(hist.items()), key=sorter):
+ if v < 1: continue
+
+ if len(tag) > MAX_NAME_LEN:
+ tag = tag[:MAX_NAME_LEN-1] + '~'
+
+ if not fullname:
+ t = tag.split('.')
+ for i in range(len(t)-1):
+ t[i] = ' ' * len(t[i])
+ tag = '.'.join(t)
+ if opt.sep == '':
+ print(ps % (tag, v, '+'*tics(v)))
+ else:
+ print(opt.sep.join((tag, str(v))))
- if len(k) > MAX_NAME_LEN:
- k = k[:MAX_NAME_LEN-1] + '~'
+ if not opt.bare:
+ print(('%%%is' % (name_len + count_len + 2)) % sum(hist.values()))
- if opt.sep == '':
- print(ps % (k, v, '+'*tics(v)))
- else:
- print(opt.sep.join((k, str(v))))
+display_histogram(hist)
+print()
+display_histogram(hier, fullname=False)
+print()
-if not opt.bare:
- print(('%%%is' % (name_len + count_len + 2)) % sum(hist.values()))
if opt.gtd: