Skip to content

Instantly share code, notes, and snippets.

@debedb
Created November 20, 2020 04:07
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save debedb/4b6249bebea8cd69366096aa85b4a088 to your computer and use it in GitHub Desktop.
Save debedb/4b6249bebea8cd69366096aa85b4a088 to your computer and use it in GitHub Desktop.
import arrow
def perc(n):
try:
return "%0.1f" % (float(n)/tot*100)
except Exception, e:
raise Exception("Error in %s (%s): %s" % (n, type(n), e))
f = open('/tmp/rows.csv')
tot = 0
nosent = 0
noreturn = 0
one = 0
zero = 0
neg = 0
first = True
for line in f:
if first:
first = False
continue
line = line.strip()
try:
(county,party,dob,appl_type,appl_approved_on,appl_returned_on,ballot_sent_date,ballot_returned_date,pa_house,pa_senate,cong) = line.split(",")
except Exception, e:
print "Error parsing line %s: %s: %s" % (tot+1, line, e)
continue
tot += 1
ballot_sent_date = ballot_sent_date.strip();
if not ballot_sent_date:
nosent += 1
continue
ballot_returned_date = ballot_returned_date.strip()
if not ballot_returned_date:
noreturn += 1
continue
senton = arrow.get(ballot_sent_date, 'MM/DD/YYYY')
returnedon = arrow.get(ballot_returned_date, 'MM/DD/YYYY')
diff = (returnedon - senton).days
if diff == 1:
one += 1
elif diff == 0:
zero += 1
elif diff < 0:
# print "%s-%s=%s" % (returnedon, senton, diff)
neg += 1
print """Total: %s
No sent date provided: %s (%s%%)
No return date provided %s (%s%%)
One day after: %s (%s%%)
Zero days: %s (%s%%)
Negative days: %s (%s%%) """ % (tot, nosent, perc(nosent), noreturn, perc(noreturn), one, perc(one), zero, perc(zero), neg, perc(neg))
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment