marginal tag=value pair finder

6 views
Skip to first unread message

D Gowers

unread,
Jan 25, 2017, 7:40:21 AM1/25/17
to tm...@googlegroups.com
When Paul added the new '--value VALUE' option for tags recently.
I promptly wrote a function (zsh or bash compatible, req. Python 3.x) using it, which indexes your tag=value pairs backward and forward, and reports the half which are less used, least to most. There are definitely improvements to be made (eg. option to tune exactly what proportion of data is returned; computer parsable output), but hopefully it is already useful.

I might put it up somewhere if someone wants. Right now, too sleepy.

Function follows:

tmsu-find-marginal () {
    tmsu values | python3 -c 'import sys
from subprocess import check_output
from collections import Counter
values = sys.stdin.read().splitlines()
vtotals = {}
ttotals = Counter()
vtags = {}
tvalues = {}
for v in values:
   histogram = check_output(["tmsu","tags","--value", v]).decode("utf8").splitlines()
   histogram = Counter(histogram)
   vtotals[v] = sum(histogram.values())
   vtags[v] = set(histogram.keys())
   for t in histogram.keys():
       if t not in tvalues:
           tvalues[t] = set([v])
       else:
           tvalues[t].add(v)
   ttotals.update(histogram)
vtotals = Counter(vtotals)
vmedian = vtotals.most_common()[(len(vtotals) + 1) // 2][1]
tmedian = ttotals.most_common()[(len(ttotals) + 1) // 2][1]
print("Marginal values:")
print("\n\t".join("%s : %d\t%s" % (k,v, " ".join(vtags.get(k,set()))) for k, v in reversed(vtotals.most_common()) if v < vmedian))
print("Marginal value-tags:")
print("\n\t".join("%s : %d\t%s" % (k,v, " ".join(tvalues.get(k,set()))) for k, v in reversed(ttotals.most_common()) if v < tmedian))
  '
}

Paul Ruane

unread,
Jan 25, 2017, 8:00:19 AM1/25/17
to tm...@googlegroups.com
Bear in mind that this new feature currently doesn't handle implied values!

--
You received this message because you are subscribed to the Google Groups "TMSU" group.
To unsubscribe from this group and stop receiving emails from it, send an email to tmsu+unsubscribe@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.
Reply all
Reply to author
Forward
0 new messages