-#!/usr/bin/env python2
+#!/usr/bin/env python3
# Present histogram reports from timeSampler data. See "$0 -h" for more
#
startdate = LONG_AGO
else:
#convert from YYYY-MM-DD format
- d = map(int, opt.startdate.split('-'))
+ d = list(map(int, opt.startdate.split('-')))
d += [1]*(3 - len(d)) # use start of year/month if missing
startdate = dt.date(*d)
enddate = dt.date.today()
else:
#convert from YYYY-MM-DD
- enddate = dt.date(*map(int, opt.enddate.split('-')))
+ enddate = dt.date(*list(map(int, opt.enddate.split('-'))))
if opt.today and opt.yesterday:
startdate = dt.date.today() - dt.timedelta(1)
# Sorting options
#
if opt.numsort:
- def sorter(x, y, reverse=opt.reverse):
+ def sorter(x, reverse=opt.reverse):
m = -1 if reverse else 1
- return m * cmp(x[1], y[1])
+ return m * x[1]
else:
# alphabetical on key
- def sorter(x, y, reverse=opt.reverse):
+ def sorter(x, reverse=opt.reverse):
m = -1 if reverse else 1
- return m * cmp(x[0].lower(), y[0].lower())
+ return m * x[0].lower()
try:
r = m.groups()[:-1]
except:
- print line
+ print(line)
raise
ri = [int(i) for i in r]
d = dt.datetime(*ri)
histGtd[a[0]] += 1
if hist:
- maxlen = max(map(len, hist.iterkeys()))
- maxnum = max(hist.itervalues())
+ maxlen = max(list(map(len, iter(hist.keys()))))
+ maxnum = max(hist.values())
else:
maxlen = maxnum = 1
# Show date range
#
if not opt.bare:
- print 'From:', startdate.strftime('%Y-%m-%d'), ' Thru:', enddate.strftime('%Y-%m-%d')
+ print('From:', startdate.strftime('%Y-%m-%d'), ' Thru:', enddate.strftime('%Y-%m-%d'))
if False:
if opt.today and opt.yesterday:
- print 'Today (%s) and yesterday' % startdate.strftime('%Y-%m-%d')
+ print('Today (%s) and yesterday' % startdate.strftime('%Y-%m-%d'))
elif opt.yesterday:
if opt.days:
- print 'From:', startdate.strftime('%Y-%m-%d'), ' Thru',
+ print('From:', startdate.strftime('%Y-%m-%d'), ' Thru', end=' ')
- print 'Yesterday:', startdate.strftime('%Y-%m-%d')
+ print('Yesterday:', startdate.strftime('%Y-%m-%d'))
elif opt.today:
if opt.days:
- print 'From:', startdate.strftime('%Y-%m-%d'), ' Thru',
+ print('From:', startdate.strftime('%Y-%m-%d'), ' Thru', end=' ')
- print 'Today:', startdate.strftime('%Y-%m-%d')
+ print('Today:', startdate.strftime('%Y-%m-%d'))
elif startdate > LONG_AGO:
- print 'From:', startdate.strftime('%Y-%m-%d'), ' Thru:', enddate.strftime('%Y-%m-%d')
+ print('From:', startdate.strftime('%Y-%m-%d'), ' Thru:', enddate.strftime('%Y-%m-%d'))
elif enddate:
- print 'Thru:', enddate.strftime('%Y-%m-%d')
+ print('Thru:', enddate.strftime('%Y-%m-%d'))
- print '-' * opt.width
+ print('-' * opt.width)
#
keys = set()
for pat in args:
- keys |= set(fnmatch.filter(hist.keys(), pat))
+ keys |= set(fnmatch.filter(list(hist.keys()), pat))
# new dict with only matching values
hist = {k: hist[k] for k in keys}
#
# Display the histogram
#
-for k,v in sorted(hist.iteritems(), cmp=sorter):
+for k,v in sorted(iter(hist.items()), key=sorter):
if v < 1: continue
if len(k) > MAX_NAME_LEN:
k = k[:MAX_NAME_LEN-1] + '~'
if opt.sep == '':
- print ps % (k, v, '+'*tics(v))
+ print(ps % (k, v, '+'*tics(v)))
else:
- print opt.sep.join((k, str(v)))
+ print(opt.sep.join((k, str(v))))
if not opt.bare:
- print ('%%%is' % (name_len + count_len + 2)) % sum(hist.values())
+ print(('%%%is' % (name_len + count_len + 2)) % sum(hist.values()))
if opt.gtd:
if not opt.bare:
- print
- print 'Counts for GTD categories:'
- print '--------------------------'
+ print()
+ print('Counts for GTD categories:')
+ print('--------------------------')
for k in sorted(histGtd.keys()):
- print '%-5s %4i' % (k, histGtd[k])
- print 'other %4i' % (sum(hist.values()) - sum(histGtd.values()))
+ print('%-5s %4i' % (k, histGtd[k]))
+ print('other %4i' % (sum(hist.values()) - sum(histGtd.values())))
for k in sorted(histOther.keys()):
- print '%s: %3i' % (k, histOther[k])
+ print('%s: %3i' % (k, histOther[k]))