Created
October 13, 2015 16:47
-
-
Save AdamISZ/b4b8d58e82b13d5cf1c0 to your computer and use it in GitHub Desktop.
For joinmarket pit analysis
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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