Skip to content

Instantly share code, notes, and snippets.

@johanlaidlaw
Created September 20, 2012 20:04
Show Gist options
  • Save johanlaidlaw/3758024 to your computer and use it in GitHub Desktop.
Save johanlaidlaw/3758024 to your computer and use it in GitHub Desktop.
Log file to CSV file
# It turns a very specific logfile :) into a csv file
# Take all events within a minute and calcute avg and max
# Returns csv file with same name as argument log file
import sys
popper_file = sys.argv[1]
output_file = popper_file[:-3]+"csv"
fi = open(popper_file,"r")
fo = open(output_file, "w+b")
tmp_date = ''
delays_pr_min = []
i = 1
for line in fi:
print i
i = i+1
l = line.split(",")
date_short = l[0][:16]
delayed_number = float(l[1][4:])
if tmp_date != date_short and tmp_date != '':
for d in delays_pr_min:
avg = sum(delays_pr_min) / float(len(delays_pr_min))
mx = max(delays_pr_min)
fo.write(tmp_date + ","+str(avg)+","+str(mx)+"\n")
tmp_date = date_short
del delays_pr_min[:]
delays_pr_min.append(delayed_number)
else:
tmp_date = date_short
delays_pr_min.append(delayed_number)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment