def __init__(self, configfilename): """ This is the docstring. """ print("READ FROM '%s'" % (configfilename)) filetoread = open(configfilename) self._lines = filetoread.readlines() if len(self._lines) < 6: print('ERROR: not enough configuration information') print('need date, open, close, late, and counties') exit(0) self._counties = [] # here and below we trim away the newline self._datapath = self._lines[0].replace('\n', '') self._date = self._lines[1].replace('\n', '') self._openingtime = self._lines[2].replace('\n', '') self._closingtime = self._lines[3].replace('\n', '') self._earlytime = self._lines[4].replace('\n', '') self._latetime = self._lines[5].replace('\n', '') self._beginelectiondayepoch = globalconverttimetoepoch(self._date, '00:00:00') self._endelectiondayepoch = self._beginelectiondayepoch + 93600 # 2 am the next day for countysub in range(6, len(self._lines)): # here and below we trim away the newline if len(self._lines[countysub].strip()) == 0: break self._counties.append(self._lines[countysub].replace('\n', ''))
def writeopeningtimes(self, filenameprefix, county): """ This is the docstring. """ local_s = '' noopenignorecount = 0 earlyignorecount = 0 lateignorecount = 0 earlys = '' lates = '' noopens = '' opentimes = [] for ivonumber, ivo in sorted(globalivos.items()): ivoopeningtime = ivo.getdatetimeopening() if ivoopeningtime[0] == DUMMYDATE: noopens += 'NO OPENING IGNORE %s\n' % (ivo) noopenignorecount += 1 continue thistime = globalconverttimetoepoch(ivoopeningtime[0], ivoopeningtime[1]) if thistime <= self._beginelectiondayepoch: earlys += 'EARLY OPENING IGNORE %s\n' % (ivo) earlyignorecount += 1 elif thistime >= self._endelectiondayepoch: lates += 'LATE OPENING IGNORE %s\n' % (ivo) lateignorecount += 1 else: opentimes.append(thistime - self._beginelectiondayepoch) opentimes = sorted(opentimes) local_s += noopens local_s += '\n' local_s += earlys local_s += '\n' local_s += lates local_s += '\n' considercount = len(globalivos) - noopenignorecount - earlyignorecount - lateignorecount local_s += 'Total ivo count ignored (noopen): %3d\n' % (noopenignorecount) local_s += 'Total ivo count ignored (early): %3d\n' % (earlyignorecount) local_s += 'Total ivo count ignored (late): %3d\n' % (lateignorecount) local_s += 'Total ivo count considered: %d\n\n' % (considercount) timeblocks = globalcreatetimeblocks(opentimes) local_s += '%s' % (globaldisplaytimeblocks(timeblocks, \ considercount, 'OPENING TIME')) local_s += '\n' # num_bins = 13 # thetitle = 'Ivo opening times -- %s' % (county) # n, bins, patches = plt.hist(opentimes, num_bins, normed=0, facecolor='green', alpha=0.5) # plt.xlabel('Opening Times') # plt.ylabel('Ivos Open') # plt.title(thetitle) # plt.subplots_adjust(left=0.15) # plt.show() return local_s
def writelastvotetimes(self, filenameprefix, county): """ This is the docstring. """ local_s = '' novotesignorecount = 0 earlyignorecount = 0 lateignorecount = 0 novotess = '' earlys = '' lates = '' lastvotetimes = [] for ivonumber, ivo in sorted(globalivos.items()): ivolastvote = ivo.getlastvote() if (DUMMYDATE == ivolastvote[0]) or (DUMMYDATE == ivolastvote[1]): novotess += 'NO VOTES IGNORE %s\n' % (ivo) novotesignorecount += 1 continue thistime = globalconverttimetoepoch(ivolastvote[0], ivolastvote[1]) if thistime <= self._beginelectiondayepoch: earlys += 'EARLY LAST VOTE IGNORE %s\n' % (ivo) earlyignorecount += 1 elif thistime >= self._endelectiondayepoch: lates += 'LATE LAST VOTE IGNORE %s\n' % (ivo) lateignorecount += 1 else: lastvotetimes.append(thistime - self._beginelectiondayepoch) lastvotetimes = sorted(lastvotetimes) local_s += novotess local_s += '\n' local_s += earlys local_s += '\n' local_s += lates local_s += '\n' considercount = len(globalivos) - earlyignorecount - \ lateignorecount - novotesignorecount local_s += 'Total ivo count ignored (no votes): %3d\n' % \ (novotesignorecount) local_s += 'Total ivo count ignored (early): %3d\n' % \ (earlyignorecount) local_s += 'Total ivo count ignored (late): %3d\n' % \ (lateignorecount) local_s += 'Total ivo count considered: %d\n\n' % (considercount) timeblocks = globalcreatetimeblocks(lastvotetimes) local_s += '%s' % (globaldisplaytimeblocks(timeblocks, \ considercount, 'LAST VOTE TIME')) local_s += '\n' return local_s
def getivoslateopen(self, date, openingtime): """ This is the docstring. """ latelist = [] openingtimeepoch = globalconverttimetoepoch(date, openingtime) for ivonumber, ivo in sorted(globalivos.items()): datetime = ivo.getdatetimeopening() pctnumbersset = sorted(ivo.getpctnumbers()) pctnumberslist = [] # convert set to list for sorting for pctnumber in sorted(pctnumbersset): pctnumberslist.append(pctnumber) pctnumberslist = sorted(pctnumberslist) if 0 == len(pctnumberslist): pctnumberslist.append('NNNN') latekey = pctnumberslist[0] if datetime[0] == DUMMYDATE: continue if ('NNNN' != latekey) and (latekey >= '0750'): continue thistimeepoch = globalconverttimetoepoch(datetime[0], datetime[1]) # if (datetime[0] != date) or (datetime[1] > openingtime): if thistimeepoch > openingtimeepoch: latelist.append([latekey, \ 'LATE OPENTIME %s\n' % (ivo)]) count = 0 local_s = '' local_s += 'Ivos with late opening time\n' for key, value in sorted(latelist): local_s += value count += 1 local_s += 'Number of such ivos: %d\n\n' % (count) return local_s
def getivosearlyclose(self, date, earlytime): """ This is the docstring. """ earlylist = [] # print 'epoch conversion', date, earlytime earlytimeepoch = globalconverttimetoepoch(date, earlytime) for ivonumber, ivo in sorted(globalivos.items()): datetime = ivo.getdatetimeclosing() pctnumbersset = ivo.getpctnumbers() pctnumberslist = [] # convert set to list for sorting for pctnumber in pctnumbersset: pctnumberslist.append(pctnumber) pctnumberslist = sorted(pctnumberslist) if 0 == len(pctnumberslist): pctnumberslist.append('NNNN') earlykey = pctnumberslist[0] if datetime[0] == DUMMYDATE: continue if ('NNNN' != earlykey) and (earlykey >= '0750'): continue thistimeepoch = globalconverttimetoepoch(datetime[0], datetime[1]) # if (datetime[0] != date) or (datetime[1] < earlytime): if thistimeepoch < earlytimeepoch: earlylist.append([earlykey, 'EARLY CLOSETIME %s\n' % (ivo)]) count = 0 local_s = '' local_s += 'Ivos with early closing time\n' for key, value in sorted(earlylist): local_s += value count += 1 local_s += 'Number of such ivos: %d\n\n' % (count) return local_s
def writeclosingtimes(self, filenameprefix, county): """ This is the docstring. """ local_s = '' nocloseignorecount = 0 earlyignorecount = 0 lateignorecount = 0 earlys = '' lates = '' nocloses = '' closetimes = [] for ivonumber, ivo in sorted(globalivos.items()): ivoclosingtime = ivo.getdatetimeclosing() if ivoclosingtime[0] == DUMMYDATE: nocloses += 'NO CLOSING IGNORE %s\n' % (ivo) nocloseignorecount += 1 continue thistime = globalconverttimetoepoch(ivoclosingtime[0], ivoclosingtime[1]) if thistime <= self._beginelectiondayepoch: earlys += 'EARLY CLOSING IGNORE %s\n' % (ivo) earlyignorecount += 1 elif thistime >= self._endelectiondayepoch: lates += 'LATE CLOSING IGNORE %s\n' % (ivo) lateignorecount += 1 else: closetimes.append(thistime - self._beginelectiondayepoch) closetimes = sorted(closetimes) local_s += nocloses local_s += '\n' local_s += earlys local_s += '\n' local_s += lates local_s += '\n' considercount = len(globalivos) - nocloseignorecount - earlyignorecount - lateignorecount local_s += 'Total ivo count ignored (no close): %3d\n' % (nocloseignorecount) local_s += 'Total ivo count ignored (early): %3d\n' % (earlyignorecount) local_s += 'Total ivo count ignored (late): %3d\n' % (lateignorecount) local_s += 'Total ivo count considered: %d\n\n' % (considercount) timeblocks = globalcreatetimeblocks(closetimes) local_s += '%s' % (globaldisplaytimeblocks(timeblocks, \ considercount, 'CLOSING TIME')) local_s += '\n' return local_s
def updateivofromevents(self, date, configuration): """ This is the docstring. """ # print('UPDATE IVO FROM EVENTS', self._ivonumber) self._configdate = configuration.getdate() self._configopening = configuration.getopeningtime() timeblockdata = [] for event in self._events: # print('EVENT', event) ivonumber = event.getivonumber() pebnumber = event.getpebnumber() date152 = event.getdate152() reformatteddate152 = self.reformatdate(date152) # reformatteddate152 = self.reformatdateKANSAS(date152) # specificllay for Ellis County time152 = event.gettime152() code152 = event.getcode152() ########################################################## ## this ivo is in the 152 file, or else we would not get ## to this part of the program self._foundin152 = True self._eventcounts[code152] += 1 ########################################################## ## update the reset of date and time if code152 == '0000117': openingtimeepoch = globalconverttimetoepoch( self._configdate, self._configopening) thiseventtimeepoch = globalconverttimetoepoch( reformatteddate152, time152) # print('TIMERESET', self._ivonumber, self._configdate, # self._configopening, reformatteddate152, time152, # openingtimeepoch, thiseventtimeepoch) if thiseventtimeepoch >= openingtimeepoch: # print('YES RESET') self._timeresetonelectionday = True ########################################################## ## add to or update the PEB dictionary ## and record open and close peb if pebnumber in globalpebs: thispeb = globalpebs[pebnumber] else: pebtype = event.getpebtype() thispeb = OnePEB(pebnumber, pebtype, '155') thispeb.setfoundin152(True) if '0001672' == code152: self._pebnumberopening = pebnumber self._datetimeopening = [reformatteddate152, time152] # print('USEDFOROPENING %s %s' % (ivonumber, pebnumber)) if '0001673' == code152: thispeb.setusedforclosing(True) self._pebnumberclosing = pebnumber self._datetimeclosing = [reformatteddate152, time152] # print('USEDFORCLOSING %s %s' % (ivonumber, pebnumber)) thispeb.addtoivoset(ivonumber) globalpebs[pebnumber] = thispeb ########################################################## ## record first and last vote and vote counts ## and create the time block data for votes cast votecastcodes = ['0001510', '0001511', '0001512', \ '0002900', '0002901', '0002902', '0002903', '0002905', \ '0002906', '0002908', '0002909', '0002911', '0002912', \ '0002915'] if code152 in votecastcodes: self._votescast152 += 1 self._votetimes.append([reformatteddate152, time152]) self._lastvote = [reformatteddate152, time152] if DUMMYDATE == self._firstvote[0]: self._firstvote = [reformatteddate152, time152] ## it would be here that we add to the late vote count ########################################################## ## create the time block data if code152 in votecastcodes: # if self._ivonumber == '5125222': # print 'PROCESS VOTE EVENT', reformatteddate152, time152, code152 votetime = globalconverttimetoepoch(reformatteddate152, time152) timeblockdata.append(votetime - configuration.getbeginelectiondayepoch()) # label = 'VOTE TIME BLOCK %s: ' % (self._ivonumber) # print('TIME BLOCK DATA %s: ' % (timeblockdata)) self._votetimeblocks = globalcreatetimeblocks(timeblockdata)