Skip to content

Instantly share code, notes, and snippets.

@AdamISZ
Created October 13, 2015 16:47
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 1 You must be signed in to fork a gist
  • Save AdamISZ/b4b8d58e82b13d5cf1c0 to your computer and use it in GitHub Desktop.
Save AdamISZ/b4b8d58e82b13d5cf1c0 to your computer and use it in GitHub Desktop.
For joinmarket pit analysis
import time
from datetime import datetime, timedelta
from calendar import timegm
def write_activity_log(lfn):
with open(lfn,'rb') as f:
loglines = f.readlines()
loglines = [x for x in loglines if 'pubmsg' in x]
x = {}
for l in loglines:
dt = l.split(']')[0][1:]
z = timegm(time.strptime(dt, "%Y/%m/%d %H:%M:%S"))
a = datetime.fromtimestamp(z)
m, d, hr = (a.month, a.day, a.hour)
if not (m, d, hr) in x.keys():
x[(m, d, hr)] = 1
else:
x[(m, d, hr)] += 1
with open('output.csv','ab') as f:
for k,v in x.iteritems():
f.write(','.join([','.join([str(t) for t in k]),str(v)])+'\n')
if __name__ == '__main__':
import sys
for lfn in sys.argv[1:]:
write_activity_log(lfn)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment