Skip to content

Instantly share code, notes, and snippets.

@iwillig
Created March 28, 2011 21:03
Show Gist options
  • Select an option

  • Save iwillig/891277 to your computer and use it in GitHub Desktop.

Select an option

Save iwillig/891277 to your computer and use it in GitHub Desktop.
from collections import defaultdict
from datetime import datetime
from gateway.models import PrimaryLog
from gateway.models import Meter
from gateway.models import Circuit
from gateway.models import initialize_sql
from gateway.models import DBSession
from urlparse import parse_qs
import compactsms
db_string = "postgresql://postgres:password@localhost:5432/gateway"
initialize_sql(db_string)
session = DBSession()
meter = session.query(Meter).get(4)
logs = meter.getLogs()
by_days = defaultdict(list)
for log in logs:
if log.circuit is not None: # only return logs with real circits.
by_days[log.date.strftime('%Y.%m.%d.%H')].append(log)
total = 0
wrong = 0
if __name__ == '__main__':
for day in sorted(by_days.iterkeys()):
print('++++++++++++++++++++++++++++++++++++++++')
print(day)
print('++++++++++++++++++++++++++++++++++++++++')
sorted_logs = by_days[day]
print(len(sorted_logs))
deflatedlogs = compactsms.deflatelogs(map(str, sorted_logs))
inflatedlogs = compactsms.inflatelogs(deflatedlogs)
for log in inflatedlogs:
total = total + 1
cid = parse_qs(log)['cid'][0]
old_log = filter(lambda log: log.circuit.ip_address == cid,
sorted_logs)
if len(old_log) == 1:
equalp = parse_qs(log) == parse_qs(str(old_log[0]))
if equalp == False:
print('----------------------------------------')
print("origin message")
print(parse_qs(str(old_log[0])))
print("new message")
print(parse_qs(log))
print('-----------------------------------------')
wrong = wrong + 1
print "Out of %s logs were %s different" % (total, wrong)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment