def getivosnoopenclose(self):
        """ This is the docstring.
        """
        notimelist = []

        for ivonumber, ivo in sorted(globalivos.items()):
            datetime = ivo.getdatetimeopening()
            if (datetime[0] == DUMMYDATE) or (datetime[1] == DUMMYOPENTIME):

                notimelist.append('NO OPENTIME %s' % (ivo))
        local_s = ''
        local_s += 'Ivos with no opening time\n'
        for item in notimelist:
            local_s += item
        local_s += 'Number of such ivos: %d\n\n' % (len(notimelist))

        notimelist = []
        for ivonumber, ivo in sorted(globalivos.items()):
            datetime = ivo.getdatetimeclosing()
            if (datetime[0] == DUMMYDATE) or (datetime[1] == DUMMYCLOSETIME):
                notimelist.append('NO CLOSETIME %s' % (ivo))

        local_s = ''
        local_s += 'Ivos with no closing time\n'
        for item in notimelist:
            local_s += item
        local_s += 'Number of such ivos: %d\n\n' % (len(notimelist))

        return local_s
    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 getivosnotin68a(self):
        """ This is the docstring.
        """
        local_s = ''
        count = 0
        for ivonumber, ivo in sorted(globalivos.items()):
            if 0 == len(ivo.getmemorycollectiontime()):
                local_s += '%s\n' % (ivo)
        local_s += 'Number of such ivos: %d\n' % (count)

        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 getivoexceptions(self):
        """ This is the docstring.
        """
        local_s = ''

        local_s += 'Ivos found only in 152 and not in 155\n'
        count = 0
        for ivonumber, ivo in sorted(globalivos.items()):
            if (ivo.getfoundin152()) and (not ivo.getfoundin155()):
                local_s += '%s: %s\n' % (ivonumber, ivo)
                count += 1
        local_s += 'Number of such ivos: %d\n' % (count)

        local_s += '\n'
        local_s += 'Ivos found only in 155 and not in 152\n'
        count = 0
        for ivonumber, ivo in sorted(globalivos.items()):
            if (not ivo.getfoundin152()) and (ivo.getfoundin155()):
                local_s += '%s: %s\n' % (ivonumber, ivo)
                count += 1
        local_s += 'Number of such ivos: %d\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
Exemple #7
0
    def writememorycards(self, filenameprefix, county):
        """ This is the docstring.
        """
        if filenameprefix == 'stdout':
            outfile = sys.stdout
        else:
            outfile = open(filenameprefix + 'MemoryCards.txt', 'w')
        outfile.write('Memory card collection times for %s\n\n' % (county))

        outputlist = []
        for ivonumber, ivo in sorted(globalivos.items()):
            local_s = '%s %s' % (ivo.getmemorycollectiontime(), ivonumber)
            outputlist.append(local_s)

        for local_s in sorted(outputlist):
            outfile.write('%s\n' % (local_s))
    def getfirstcollectiontimes(self):
        """ This is the docstring.
        """
        collectionfreq = defaultdict(int)
        for ivonumber, ivo in sorted(globalivos.items()):
            colltime = ivo.getmemorycollectiontime()
            if 0 == len(colltime):
                firstcolltime = 'NULL NULL'
            else:
                firstcolltime = colltime[0]
            firstcolldate = firstcolltime.split()[0]
            collectionfreq[firstcolldate] += 1

        local_s = ''
        for time, count in sorted(collectionfreq.items()):
            local_s += '%7d %10s\n' % (count, time)
        return local_s
    def getopencloseexceptions(self):
        """ This is the docstring.
        """
        local_s = ''

        count = 0
        for ivonumber, ivo in sorted(globalivos.items()):
            openingpeb = ivo.getpebnumberopening()
            closingpeb = ivo.getpebnumberclosing()
            if openingpeb != closingpeb:
                pctnumbers = ivo.getpctnumbers()
                count += 1
                local_s += 'Opening PEB %s not closing PEB %s (%s)\n' % \
                            (openingpeb, closingpeb, \
                            self.convertsettostring(pctnumbers))
        local_s += 'Number of such ivos: %d\n' % (count)

        return local_s
Exemple #10
0
    def writeivodetail(self, filenameprefix, county):
        """ This is the docstring.
        """
        if filenameprefix == 'stdout':
            outfile = sys.stdout
        else:
            outfile = open(filenameprefix + 'IvoDetail.txt', 'w')
        outfile.write('iVotronic data for %d iVos in %s\n\n' %
                      (len(globalivos), county))

        firsttime = True
        for ivonumber, ivo in sorted(globalivos.items()):
            if firsttime:
                outfile.write('%s' % (ivo.headerstring()))
                firsttime = False
            outfile.write('%s\n' % (ivo))

        outfile.write('Total number of iVotronics: %d\n\n' % (len(globalivos)))
Exemple #11
0
    def writeeventlogs(self, filenameprefix, county):
        """ This is the docstring.
        """
        totaleventcount = 0
        if filenameprefix == 'stdout':
            outfile = sys.stdout
        else:
            outfile = open(filenameprefix + 'EventLogs.txt', 'w')
        outfile.write('Event logs for %s\n\n' % (county))

        for ivonumber, ivo in sorted(globalivos.items()):
            for event in ivo.getevents():
                outfile.write('%s\n' % (event))
            outfile.write('\n')
            totaleventcount += len(ivo.getevents())

        outfile.write('Total number of iVos dumped: %d\n' % (len(globalivos)))
        outfile.write('Total number of events dumped: %d\n' %
                      (totaleventcount))
    def writeworking(self, filenameprefix, county):
        """ This is the docstring.
        """
        local_s = ''

        timeblocks = globalcreatetimeblocks([])
#        print 'ZORK', sorted(timeblocks)

        for ivonumber, ivo in sorted(globalivos.items()):
            ivotimeblocks = ivo.getvotetimeblocks()
            for time, count in sorted(ivotimeblocks.items()):
#                if time == '24:00':
#                    print 'ZORK', time, count
                if count > 0:
                    timeblocks[time] += 1
#                    print 'ZZZZ', time, count, timeblocks[time]

        label = 'WORKING '
        for block, count in sorted(timeblocks.items()):
            local_s += '%s %s : %6d\n' % (label, block, count)
        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
Exemple #15
0
    def writeeventcounts(self, filenameprefix, county):
        """ This is the docstring.
        """
        totaleventcount = 0
        if filenameprefix == 'stdout':
            outfile = sys.stdout
        else:
            outfile = open(filenameprefix + 'EventCounts.txt', 'w')
        outfile.write('Event logs for %s\n\n' % (county))

        for ivonumber, ivo in sorted(globalivos.items()):
            eventfreq = defaultdict(int)
            totaleventcount += len(ivo.getevents())
            for event in ivo.getevents():
                eventfreq[event.getcode152()] += 1

            for code, freq in sorted(eventfreq.items()):
                outfile.write('%s %3d %s %s\n' % (ivonumber, freq, code, \
                                                  globaltextforcode[code]))
            outfile.write('\n')

        outfile.write('Total number of iVos dumped: %d\n' % (len(globalivos)))
        outfile.write('Total number of events dumped: %d\n' %
                      (totaleventcount))
Exemple #16
0
def main():
    """
    Main program used only to hide local variables.
    """
    ## check arguments and open the output file
    checkargs(2, "usage: a.out configfilename")
    ##
    theconfig = Configuration(sys.argv[1])
    print(theconfig)

    counties = theconfig.getcounties()
    outputfunctions = OutputFunctions()

    print('DRIVER: this date %s' % (theconfig.getdate()))
    print('DRIVER: this year %s' % (theconfig.getyearfromdate()))
    print('DRIVER: this counties %s' % (counties))

    ## loop on the counties and do the computation
    for county in counties:
        globalresetglobals()
        infilenameprefix = createinfilenameprefix(theconfig.getdatapath(), \
                                                  county)
        print('DRIVER: in prefix: %s' % (infilenameprefix))
        outfilenameprefix = createoutfilenameprefix(county,
                                                    theconfig.getdate())
        print('DRIVER: out prefix:%s' % (outfilenameprefix))

        print('DRIVER: read 152')
        f152 = F152(infilenameprefix, theconfig)
        print('DRIVER: done read 152')

        #  Update the ivos based on the events.
        #  This code used to be further down but has been moved here on the
        #  assumption that it doesn't need 155 or 68A information.
        for ivonumber, ivo in sorted(globalivos.items()):
            #            print('DRIVER: ivo#,ivo: %s %s' % (ivonumber, ivo))
            ivo.updateivofromevents(theconfig.getdate(), theconfig)

        #  We can now write the actual log files.
#        outputfunctions.writeeventlogs('152dump_', county)
#        outputfunctions.writeeventtexts('152dump_', county)
#        outputfunctions.writeeventcounts('152dump_', county)

# And we can dump what data we have from only the 152.
# The global dump of the 152 is the three outputs above and
#     these two below.
#        outputfunctions.writeivodetail('152dump_', county)
#        outputfunctions.writepebdetail('152dump_', county)
#   sys.exit()

        print('DRIVER: read 155')
        f155 = F155()
        f155.readdata(infilenameprefix, theconfig.getdate())
        # And we can dump what data we have from the 152 and 155.
        # The global dump of the 155 is these three outputs below.
        #        globaldump155()
        #        outputfunctions.writeivodetail('155dump_', county)
        #        outputfunctions.writepebdetail('155dump_', county)
        #        outputfunctions.writepctdetail('155dump_', county)
        print('DRIVER: done read 155')

        print('DRIVER: read 68A')
        f68a = F68A()
        f68a.readdata(infilenameprefix, theconfig.getdate())
        # We now dump what data we have from the 152, 155, and 68A.
        # The global dump of the 68A is the three outputs above and
        #     these two below.
        #        globaldump68A()
        #        outputfunctions.writeivodetail('68Adump_', county)
        #        outputfunctions.writepebdetail('68Adump_', county)
        #        outputfunctions.writepctdetail('68Adump_', county)
        print('DRIVER: done read 68A')

        print('DRIVER: read 30A')
        f30a = F30A(infilenameprefix, theconfig.getdate(), county)
        print('DRIVER: done read 30A')

        #        for ivonumber, ivo in sorted(globalivos.items()):
        ##            print('DRIVER: ivo#,ivo: %s %s' % (ivonumber, ivo))
        #            ivo.updateivofromevents(theconfig.getdate(), theconfig)

        ## now update for each pct the pebs used for closing for each ivo
        for pctnumber, pct in sorted(globalpcts.items()):
            for ivonumber in pct.getivos():
                ivo = globalivos[ivonumber]
                pct.addtoopeningpebs(ivo.getpebnumberopening())
                pct.addtoclosingpebs(ivo.getpebnumberclosing())
                pct.addtovotescast155(ivo.getvotescast155(), \
                                      ivo.getvotescast155bypct(pctnumber))
        #sys.exit()

        print('DRIVER: %s' % (f152))
        print('DRIVER: %s' % (f155))
        print('DRIVER: %s' % (f68a))
        print('DRIVER: %s' % (f30a))

        outputfunctions = OutputFunctions()
        outputfunctions.writeivodetail(outfilenameprefix, county)
        outputfunctions.writepebdetail(outfilenameprefix, county)
        outputfunctions.writepctdetail(outfilenameprefix, county)
        outputfunctions.writememorycards(outfilenameprefix, county)
        outputfunctions.writeeventlogs(outfilenameprefix, county)
        outputfunctions.writeeventtexts(outfilenameprefix, county)
        outputfunctions.writeeventcounts(outfilenameprefix, county)

        print('DRIVER: WRITE FIRST FILES DONE')

        results = Results()
        results.writeresults(outfilenameprefix, county)

        print('DRIVER: WRITE RESULTS FILES DONE')

        exceptions = Exceptions()
        exceptions.writeexceptions(outfilenameprefix, county, theconfig)

        print('DRIVER: WRITE EXCEPTIONS FILES DONE')

        firstlastworking = FirstLastWorking()
        firstlastworking.writefirstlastworking(outfilenameprefix, county,
                                               theconfig)

        print('DRIVER: WRITE FIRSTLASTWORKING FILES DONE')

        outputfunctions.writeivosandpcts(outfilenameprefix, county)
        outputfunctions.writeballotstyles(outfilenameprefix, county)

        print('DRIVER: DONE!!!')