Skip to content

Instantly share code, notes, and snippets.

@mmattice
Last active September 5, 2016 21:17
Show Gist options
  • Save mmattice/1567e60553504a0934eb9eb908844cb7 to your computer and use it in GitHub Desktop.
Save mmattice/1567e60553504a0934eb9eb908844cb7 to your computer and use it in GitHub Desktop.
Create a 5 minute bucket histogram of input apache-style timestamps
import fileinput
from datetime import datetime
counts = dict()
for i in range(288):
counts[i] = 0
for line in fileinput.input():
dt = datetime.strptime(line.strip(), '%d/%b/%Y:%H:%M:%S')
bucket = (dt.hour*60+dt.minute)/5
counts[bucket] += 1
for k, v in counts.iteritems():
print "%02i:%02i\t%i" % (k*5/60, k*5%60, v)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment