def getTerminalClosedEarlyEvents(data, ballot, date, r):
    plt.ioff()
    d = str(date.eday)
    d = d.split("-")
    d2 = d[1]+'/'+d[2]+'/'+d[0]
    r.addTitle('Terminals that were closed early')
    totalEarlyList = []
    for x in data.getEntryList():
        s = x.dateTime.split(" ")
        t = s[1].split(":")
        if t[0] == '':
            continue
        elif stri.atoi(t[0]) > 7 and stri.atoi(t[0]) < 19 and (s[0] == d2):
            if x.eventNumber == '0001628':
                if x.serialNumber not in ballot.earlyVotingList and x.serialNumber not in ballot.failsafeList and ballot.machinePrecinctNumMap.has_key(x.serialNumber):
                    totalEarlyList.append((ballot.machinePrecinctNumMap[x.serialNumber], s[1], x.serialNumber, ballot.machinePrecinctNameMap[x.serialNumber]))
    totalEarlyList.sort()
    earlyTable = report.Table()
    b = True
    if len(totalEarlyList) > 0:
        if b == True:
            r.addTextBox('The following machines recorded at least one log message related to the terminal closing early.  The detailed meaning of this event is not documented.  This may indicate that a rover closed the voting machine early.  You may want to check why the machine was closed early and whether it indicates any kind of problem with the machine that should be addressed before future elections.')
            r.addTextBox(" ")
            b = False
        for y in totalEarlyList:
            earlyTable.addRow(["In %s  (#%s) " % (y[3], y[0]),  "machine %s was closed at %s" % (y[2], y[1])])
            #r.addTextBox("%s (#%s)   %s was closed at %s" % (y[3], y[2], y[0], y[1]))
    else:
        #earlyTable.addRow(["This county experienced no anomalous terminals closing early."])
        #r.addTextBox("This county experienced no anomalous terminals closing early.")
        r.addTextBox("No problems found.")
    r.addTable(earlyTable)
    return r        
Exemple #2
0
def machineOpenCloseDiff(data, ballot, el, dc, r):
    r.addTitle("Machines opened and closed with different PEBs")
    diffTable = report.Table()
    PEBmap = getPEBs(data, ballot, el, dc)
    PEBlist = []
    b = True
    for p in PEBmap:
        if ballot.machinePrecinctNumMap.has_key(p):
            PEBlist.append((ballot.machinePrecinctNumMap[p],
                            ballot.machinePrecinctNameMap[p], p, PEBmap[p]))
    PEBlist.sort()
    for p in PEBlist:
        if len(p[3]) == 2:
            if (p[3][0] != p[3][1]):
                if b == True:
                    r.addTextBox(
                        "The following machines were opened and closed with different PEBs.  You may wish to review your poll worker training manual.  "
                    )
                    r.addTextBox(" ")
                    b = False
                #r.addTextBox("In %s (#%s), machine %s was opened with PEB %s and closed with PEB %s. " % (ballot.machinePrecinctNameMap[p], ballot.machinePrecinctNumMap[p], p, PEBmap[p][0], PEBmap[p][1]))
                #diffTable.addRow(["In %s (#%s), " % (p[1], p[0]), " machine %s was opened with PEB %s and closed with PEB %s." % (p[2], p[3][0], p[3][1])])
                r.addTextBox(
                    "In %s (#%s), machine %s was opened with PEB %s and closed with PEB %s."
                    % (p[1], p[0], p[2], p[3][0], p[3][1]))
    if b == True:
        r.addTextBox("No problems found.")
    else:
        r.addTable(diffTable)
    return r
Exemple #3
0
def closedLate(parsedLog, parsedBallotImage, parsedEL68A, dateModObject):
    r = report.Report()
    r.addTitle("Machines that closed late")

    validMachines = dateModObject.valid.keys()
    mapOpenLateTime = open_late(parsedLog, parsedBallotImage, validMachines)

    #FORMAT OUTPUT
    now = datetime.datetime.now()
    r.addTextBox("<i>NOTE: This report doesn't include early voting terminals nor the precincts that were closed before 7:30 PM</i>")
    table = report.Table()
    table.addHeader("#")
    table.addHeader("Precinct")
    table.addHeader("Average close time after 7:30 PM")
    
    #sort in descending order the dictionary by value.
    thresholdValue = datetime.timedelta(hours=7, minutes=30)
    precinctMap = parsedBallotImage.getPrecinctMap()
    i = 0
    for key, value in sorted(mapOpenLateTime.iteritems(), key=lambda (k,v): (v,k), reverse = True):
        if value > thresholdValue:
            i += 1
            table.addRow([key, precinctMap[key], str(value)])

    if i == 0:
        return []

    r.addTable(table)
    return [r]
Exemple #4
0
def mismatchVotesMachines(data, ballot, el, r):
    r.addTitle("Machines whose vote count differed between files")
    mismatchTable = report.Table()
    #r.addTextBox("The following machines were only in the event log: ")
    #for a in checkMachines(data, ballot, el):
    #    if not getVotesPerMachine(data, ballot, el).has_key(a):
    #        r.addTextBox("Machine %s had no votes on it according to the event log." % (a,))
    #    else:
    #        r.addTextBox("Machine %s had %d votes according to the event log." % (a, getVotesPerMachine(data, ballot, el)[a]))
    #r.addTextBox(" ")
    #r.addTextBox("The following machines were only in the ballot images: ")
    #for b in checkMachines2(data, ballot, el):
    #    if not ballot.machineVotesMap.has_key(b):
    #        r.addTextBox("Machine %s had no votes on it according to the ballot images." % (b,))
    #    else:
    #        r.addTextBox("Machine %s has %d votes according to the ballot images." % (b, ballot.machineVotesMap[b]))

    #for x in checkMachines(data, ballot, el):
    #    eVotes = 0
    #    bVotes = 0
    #    if getVotesPerMachine(data, ballot, el).has_key(x):
    #        eVotes = getVotesPerMachine(data, ballot, el)[x]
    #    if ballot.machineVotesMap.has_key(x):
    #        bVotes = ballot.machineVotesMap[x]
    #    mismatchTable.addRow(["%s" % (x,), "%s" % (eVotes,), "%s" % (bVotes,)])
    #for y in checkMachines2(data, ballot, el):
    #    if y in ballot.earlyVotingList or y in ballot.failsafeList:
    #        continue
    #    else:
    #        eVotes = 0
    #        bVotes = 0
    #        if getVotesPerMachine(data, ballot, el).has_key(y):
    #            eVotes = getVotesPerMachine(data, ballot, el)[y]
    #        if ballot.machineVotesMap.has_key(y):
    #            bVotes = ballot.machineVotesMap[y]
    #        mismatchTable.addRow(["%s" % (y,), "%s" % (eVotes,), "%s" % (bVotes,)])
    machineVotes = checkMachineVotes(data, ballot, el)
    b = True
    for z in machineVotes:
        if machineVotes[z][0] != machineVotes[z][1]:
            if b == True:
                r.addTextBox(
                    "The following machines appear to have inconsistencies across the audit data.  We recommend that you gather vote data from the following machines, upload it, and update the audit data.  From the data provided, we cannot infer the locations of the machines."
                )
                r.addTextBox(" ")
                mismatchTable.addHeader("Machine Serial #")
                mismatchTable.addHeader("Votes according to event log")
                mismatchTable.addHeader("Votes according to ballot images")
                b = False
            mismatchTable.addRow([
                "%s" % (z, ),
                "%s" % (machineVotes[z][0], ),
                "%s" % (machineVotes[z][1], )
            ])
    if b == True:
        r.addTextBox("No problems found.")
    else:
        r.addTable(mismatchTable)
    return r
def getUnknownEvents(data, ballot, date, r):
    d = str(date.eday)
    d = d.split("-")
    d2 = d[1]+'/'+d[2]+'/'+d[0]
    r.addTitle('Terminals with unknown events')
    unknownEvents = ['0001703', '0001704', '0001404']
    totalUnknownEventsMap = {}
    totalUnknownList = []
    totalsMap = {}
    for x in data.getEntryList():
        s = x.dateTime.split(" ")
        if x.eventNumber in unknownEvents and s[0] == d2:
            if totalUnknownEventsMap.has_key(x.serialNumber):
                if totalUnknownEventsMap[x.serialNumber][1].has_key(x.eventNumber):
                    temp = totalUnknownEventsMap[x.serialNumber][1][x.eventNumber]
                    temp = temp + 1
                    totalUnknownEventsMap[x.serialNumber][1][x.eventNumber] = temp
                else:
                    totalUnknownEventsMap[x.serialNumber][1][x.eventNumber] = 1
            else:
                tempMap = {}
                tempMap[x.eventNumber] = 1
                if ballot.machinePrecinctNumMap.has_key(x.serialNumber):
                    totalUnknownEventsMap[x.serialNumber] = ((ballot.machinePrecinctNumMap[x.serialNumber], ballot.machinePrecinctNameMap[x.serialNumber]),tempMap)
    for x2 in totalUnknownEventsMap:
        if x2 in ballot.earlyVotingList or x2 in ballot.failsafeList:
            continue
        else:
            totalUnknownList.append((ballot.machinePrecinctNumMap[x2], ballot.machinePrecinctNameMap[x2], x2))
    totalUnknownList.sort()
    for y in totalUnknownEventsMap:
        if totalsMap.has_key(y):
            for y2 in totalUnknownEventsMap[y][1]:
                totalsMap[y] += totalUnknownEventsMap[y][1][y2]
        else:
            totalsMap[y] = 0
            for y2 in totalUnknownEventsMap[y][1]:
                totalsMap[y] += totalUnknownEventsMap[y][1][y2]
    unknownTable = report.Table()
    if len(totalUnknownEventsMap) < 1:
        #unknownTable.addRow(["This county did not experience any anomalous unknown events."])
        #r.addTextBox("This county did not experience any anomalous unknown events.")
        r.addTextBox("No problems found.")
    else:
        r.addTextBox("The following machines each had at least one unknown warning event.  The unknown warning events have these descriptions: ")
        r.addTextBox(" ")
        r.addTextBox("Warning - no valid term audit data")
        r.addTextBox("Warning - PEB I/O Flag Set")
        r.addTextBox("Warning - I/O Flagged PEB will be used")
        r.addTextBox(" ")
        r.addTextBox("The meanings of these events is not documented.  You may wish to inspect these machines for potential problems.")
        r.addTextBox(" ")
        for z in totalUnknownList:
            unknownTable.addRow(["%s (#%s) " % (z[1], z[0]), "%s has %d total unknown warnings." % (z[2], totalsMap[z[2]])])
            #r.addTextBox("%s (#%s)  %s has %d total unknown warnings." % (totalUnknownEventsMap[z][0][1], totalUnknownEventsMap[z][0][0], z, totalsMap[z])) 
    r.addTable(unknownTable)
    return r
def getCalibrationEvents2(data, ballot, date, r):
    d = str(date.eday)
    d = d.split("-")
    d2 = d[1]+'/'+d[2]+'/'+d[0]
    r.addTitle("Votes cast when the voting machine screen may not have been calibrated")
    calMap = {}
    calList = []
    for x in data.getEntryList():
        s = x.dateTime.split(" ")
        t = s[1].split(":")
        if t[0] == '':
            continue
        elif stri.atoi(t[0]) > 6 and stri.atoi(t[0]) < 19 and (s[0] == d2):
            if x.eventNumber == '0001651':
                if calMap.has_key(x.serialNumber):
                    if calMap[x.serialNumber] == 0:
                        continue
                    elif calMap[x.serialNumber] == 2:
                        calMap[x.serialNumber] == 0
                else:
                    calMap[x.serialNumber] = False
            elif x.eventNumber == '0001510' or x.eventNumber == '0001511':
                if calMap.has_key(x.serialNumber):
                    if calMap[x.serialNumber] == 0:
                        calMap[x.serialNumber] = 1
            elif x.eventNumber == '0001655':
                if calMap.has_key(x.serialNumber):
                    if calMap[x.serialNumber] == 0:
                        calMap[x.serialNumber] = 2
                    elif calMap[x.serialNumber] == 1:
                        calMap[x.serialNumber] = 2
    b = True
    calTable = report.Table()
    for y in calMap:
        if calMap[y] == 1:
            if ballot.machinePrecinctNumMap.has_key(y):
                calList.append((ballot.machinePrecinctNumMap[y], ballot.machinePrecinctNameMap[y], y))
    calList.sort()
    for y2 in calList:
        if ballot.machinePrecinctNameMap.has_key(y):
            if b == True:
                r.addTextBox("The following machines may have recorded votes being cast while the terminal screen seemed to have calibration problems.  You may wish to find these machines and check whether their screen is properly calibrated and verify the votes.")
                r.addTextBox(" ")
                b = False
            calTable.addRow(["In %s (#%s), " % (y2[1], y2[0]), "machine %s had votes cast when it was possibly not calibrated." % (y2[2],)])
    if b == True:
        r.addTextBox("No problems found.")
    r.addTable(calTable)
    return r
Exemple #7
0
def dateErrors(dateclass, ballotclass):
    r = report.Report()
    t = report.Table()

    r.addTitle('Datetime Errors')

    if len(dateclass.D3) == 0:
        r.addTextBox('No date errors found')
    else:
        r.addTextBox(
            'List machines with detected date anomalies.  Includes last known "good" event as well as what event was determined to be the error and how many following events it affected.'
        )
        t.addHeader('Machine')
        t.addHeader('Last Event')
        t.addHeader('Anomalous Event')
        t.addHeader('Occurances')
        for k, v in dateclass.D3.iteritems():
            t.addRow([k, str(v[0]), str(v[1]), str(v[2])])

        r.addTable(t)

    return r
def getCalibrationEvents3(data, ballot, date, r):
    d = str(date.eday)
    d = d.split("-")
    d2 = d[1]+'/'+d[2]+'/'+d[0]
    r.addTitle("Machines with recurring display issues")
    totalCalMap = {}
    for x in data.getEntryList():
        s = x.dateTime.split(" ")
        t = s[1].split(":")
        if t[0] == '':
            continue
        elif stri.atoi(t[0]) > 7 and stri.atoi(t[0]) < 19 and (s[0] == d2):
            if x.eventNumber == '0001628':
                if x.serialNumber not in ballot.earlyVotingList and x.serialNumber not in ballot.failsafeList and ballot.machinePrecinctNumMap.has_key(x.serialNumber):
                    if totalCalMap.has_key(x.serialNumber):
                        temp = totalCalMap[x.serialNumber]
                        temp = temp + 1
                        totalCalMap[x.serialNumber] = temp
                    else:
                        totalCalMap[x.serialNumber] = 1
    totalCalList = []
    for z in totalCalMap:
        if ballot.machinePrecinctNameMap.has_key(z) and totalCalMap[z] > 3:
            totalCalList.append(ballot.machinePrecinctNumMap[z], ballot.machinePrecinctNameMap[z], z, totalCalMap[z])
    totalCalList.sort()
    calTable = report.Table()
    b = True
    if len(totalCalList) > 0:
        for y in totalCalList:
            if b == True:
                r.addTextBox('The following machines recorded at least one log message related to the calibration of the screen.  The detailed meaning of this event is not documented.  You may want to check why the machine recorded calibration errors and whether it indicates any kind of problem with the machine that should be addressed before future elections.')
                r.addTextBox(" ")
                b = False
            calTable.addRow(["In %s  (#%s) " % (y[1], y[0]),  "machine %s recorded %d calibration errors." % (y, totalCalMap[y])])
    if b == True:
        #r.addTextBox("This county experienced no anomalous calibration errors.")
        r.addTextBox("No problems found.")
    r.addTable(calTable)
    return r        
Exemple #9
0
def datesUnset(dateclass, ballotclass):
    r = report.Report()
    t1 = report.Table()
    t2 = report.Table()

    r.addTitle('Incorrectly Set Dates')

    if not (len(dateclass.D1) or len(dateclass.D2)):
        r.addTextBox(
            'No dates were found to be incorrectly set after being opened for elections'
        )
    else:
        precinctMap = ballotclass.getPrecinctNameMap()
        d = {}

        r.addTextBox(
            'These machines have been identified as having incorrectly set clocks. Having invalid clocks can preclude further log analysis. The results have been catagorized into two tables'
        )

        r.addTextBox(
            '<p><b>Table 1: Precincts Manually Adjusted During Elections</b>')
        if len(dateclass.D1) == 0:
            r.addTextBox('No machines found.')
        else:
            r.addTextBox(
                '<i>List of machines by precinct with manual time adjustments during election day and after being opened for voting</i></p>'
            )
            t1.addHeader('Precinct')
            t1.addHeader('# of Machines')

            for k in dateclass.D1.keys():
                if k in precinctMap:
                    key = precinctMap[k]
                elif k in ballotclass.getEarlyVotingList():
                    key = 'Absentee'
                elif k in ballotclass.getFailsafeList():
                    key = 'Failsafe'
                else:
                    key = k

                if key in d:
                    d[key] = d[key] + 1
                else:
                    d.update({key: 1})
            for k, v in d.iteritems():
                t1.addRow([k, str(v)])

            r.addTable(t1)

        if len(dateclass.D2) != 0:
            r.addTextBox('<p><b>Table 2: Machines never set correctly</b>')
            r.addTextBox(
                '<i>List of machines that conducted election day voting start to finish with an incorrect clock.</i></p>'
            )
            t2.addHeader('Serial #')
            t2.addHeader('Open Date')
            t2.addHeader('Close Date')
            for k, v in dateclass.D2.iteritems():
                t2.addRow([str(k), str(v[0]), str(v[1])])

            r.addTable(t2)
        else:
            r.addTextBox('No machines found.')

    return r
def getVoteCancelledEvents(data,ballot, date, r):
    plt.ioff()
    d = str(date.eday)
    d = d.split("-")
    d2 = d[1]+'/'+d[2]+'/'+d[0]
    r.addTitle('Anomalous vote cancelled events')
    vcMap = {}
    vcNumMap = {}
    list1513 = []
    list1514 = []
    list1515 = []
    list1516 = []
    list1517 = []
    list1518 = []
    list1519 = []
    totalList = []
    minorTicks = (.5,)
    maxNumOccurrences = 0
    avg = 0
    count = 0
    stdev = 0.00000000
    ssum = 0.00000000
    ssum2 = 0.00000000
    vcEvents = ['0001513', '0001514', '0001515', '0001516', '0001517', '0001518', '0001519']
    for x in data.getEntryList():
        s = x.dateTime.split(" ")
        t = s[1].split(":")
        if t[0] == '':
            continue
        if stri.atoi(t[0]) > 7 and stri.atoi(t[0]) < 19 and s[0] == d2:
            if x.eventNumber in vcEvents:
                if vcMap.has_key(x.serialNumber):
                    if vcMap[x.serialNumber].has_key(x.eventNumber):
                        temp = vcMap[x.serialNumber][x.eventNumber]
                        temp = temp + 1
                        vcMap[x.serialNumber][x.eventNumber] = temp
                    else:
                        tempMap = vcMap[x.serialNumber]
                        tempMap[x.eventNumber] = 1
                        vcMap[x.serialNumber] = tempMap
                else:
                    tempMap = {}
                    tempMap[x.eventNumber] = 1
                    vcMap[x.serialNumber] = tempMap
    for y in vcMap:
        temp = 0
        for y2 in vcMap[y]:
            temp = temp + vcMap[y][y2]
        vcNumMap[y] = temp
    #print vcNumMap
    vcTable = report.Table()
    if len(vcMap) < 1:
        #vcTable.addRow(["This county experienced no Vote Cancelled events."])
        r.addTextBox("No problems found.")
    else:
        for z in vcMap:
            for z2 in vcMap[z]:
                precinctNum = None
                precinctName = None
                if ballot.machinePrecinctNumMap.has_key(z):
                    precinctNum = ballot.machinePrecinctNumMap[z]
                    precinctName = ballot.machinePrecinctNameMap[z]
                elif z in ballot.earlyVotingList:
                    precinctNum = '750'
                    precinctName = 'Absentee'
                elif z in ballot.failsafeList:
                    precinctNum = '850'
                    precinctName = 'Absentee'
                totalList.append((precinctNum, z, precinctName, vcMap[z][z2], z2, data.getEventDescription(z2)))
                if vcMap[z][z2] > maxNumOccurrences:
                    maxNumOccurrences = vcMap[z][z2] 
                if z2 == '0001513':
                    list1513.append(vcMap[z][z2])
                elif z2 == '0001514':
                    list1514.append(vcMap[z][z2])
                elif z2 == '0001515':
                    list1515.append(vcMap[z][z2])
                elif z2 == '0001516':
                    list1516.append(vcMap[z][z2])
                elif z2 == '0001517':
                    list1517.append(vcMap[z][z2])
                elif z2 == '0001518':
                    list1518.append(vcMap[z][z2])
                elif z2 == '0001519':
                    list1519.append(vcMap[z][z2])
        for w in totalList:
            avg = avg + w[3]
        avg = avg/len(totalList)
        for w2 in totalList:
            ssum = ssum + ((w2[3]-avg)**2)
        ssum2 = ssum/len(totalList)
        stdev = math.sqrt(ssum2)
        totalList2 = []
        for w3 in totalList:
            if w3[3] > (avg + (4*stdev)):
                totalList2.append(w3)
        totalList2.sort()
        b = True
        b2 = True
        vcTable2 = report.Table()
        b3 = True
        vcTable3 = report.Table()
        b4 = True
        vcTable4 = report.Table()
        b5 = True
        vcTable5 = report.Table()
        b6 = True
        vcTable6 = report.Table()
        b7 = True
        vcTable7 = report.Table()
        for w4 in totalList2:
            if w4[4] == '0001513':
                if b == True:
                    r.addTextBox("The following machines had an unusually large number of votes cancelled due to having the wrong ballot.  You may wish to review this section of the poll worker training manual.")
                    b = False
                #r.addTextBox("Machine %s had %d occurrences (in %s)" % (w4[0], w4[3], w4[2]))
                vcTable.addRow(["In %s, " % (w4[2],), "machine %s had %d vote cancellations." % (w4[1], w4[3])])
                #vcTable.addRow(["Machine %s had %d vote cancellation events  " % (w4[0], w4[3]), " (in %s)." % (w4[2],)])
        r.addTable(vcTable)
        for w4 in totalList2:
            if w4[4] == '0001514':
                if b2 == True:
                    r.addTextBox(" ")
                    r.addTextBox("The following machines had an unusually large number of votes cancelled because the voter left after the ballot was issued.  You may wish to inspect this machine for issues that would cause a voter not to vote.")
                    b2 = False
                #r.addTextBox("Machine %s had %d vote cancellation events (in %s)" % (w4[0], w4[3], w4[2]))
                #vcTable2.addRow(["Machine %s had %d vote cancellation events  " % (w4[0], w4[3]), " (in %s)." % (w4[2],)])
                vcTable2.addRow(["In %s, " % (w4[2],), "machine %s had %d vote cancellations." % (w4[1], w4[3])])
        r.addTable(vcTable2)
        for w4 in totalList2:
            if w4[4] == '0001515':
                if b3 == True:
                    r.addTextBox(" ")
                    r.addTextBox("The following machines had an unusually large number of votes cancelled because the voter left before the ballot was issued.  You may wish to inspect this machine for issues that would cause a voter not to vote.")
                    b3 = False
                #r.addTextBox("Machine %s had %d vote cancellation events (in %s)" % (w4[0], w4[3], w4[2]))
                #vcTable3.addRow(["Machine %s had %d vote cancellation events  " % (w4[0], w4[3]), " (in %s)." % (w4[2],)])
                vcTable3.addRow(["In %s, " % (w4[2],), "machine %s had %d vote cancellations." % (w4[1], w4[3])])
        r.addTable(vcTable3)
        for w4 in totalList2:
            if w4[4] == '0001516':
                if b4 == True:
                    r.addTextBox(" ")
                    r.addTextBox("The following machines had an unusually large number of votes cancelled by a voter.  You may wish to inspect this machine for issues that would cause a voter not to vote.")
                    b4 = False
                #r.addTextBox("Machine %s had %d vote cancellation events (in %s)" % (w4[0], w4[3], w4[2]))
                #vcTable4.addRow(["Machine %s had %d vote cancellation events  " % (w4[0], w4[3]), " (in %s)." % (w4[2],)])
                vcTable4.addRow(["In %s, " % (w4[2],), "machine %s had %d vote cancellations." % (w4[1], w4[3])])
        r.addTable(vcTable4)
        for w4 in totalList2:
            if w4[4] == '0001517':
                if b5 == True:
                    r.addTextBox(" ")
                    r.addTextBox("The following machines had an unusually large number of votes cancelled due to a printer problem.  You may wish to inspect the machine for potential problems.  ")
                    b5 = False
                #r.addTextBox("Machine %s had %d vote cancellation events (in %s)" % (w4[0], w4[3], w4[2]))
                #vcTable5.addRow(["Machine %s had %d vote cancellation events  " % (w4[0], w4[3]), " (in %s)." % (w4[2],)])
                vcTable5.addRow(["In %s, " % (w4[2],), "machine %s had %d vote cancellations." % (w4[1], w4[3])])
        r.addTable(vcTable5)
        for w4 in totalList2:
            if w4[4] == '0001518':
                if b6 == True:
                    r.addTextBox(" ")
                    r.addTextBox("The following machines had an unusually large number of votes cancelled due to a terminal problem.  You may wish to inspect the machine for potential problems.  ")
                    b6 = False
                #r.addTextBox("Machine %s had %d vote cancellation events (in %s)" % (w4[0], w4[3], w4[2]))
               # vcTable6.addRow(["Machine %s had %d vote cancellation events  " % (w4[0], w4[3]), " (in %s)." % (w4[2],)])
                vcTable6.addRow(["In %s, " % (w4[2],), "machine %s had %d vote cancellations." % (w4[1], w4[3])])
        r.addTable(vcTable6)
        for w4 in totalList2:
            if w4[4] == '0001519':
                if b7 == True:
                    r.addTextBox(" ")
                    r.addTextBox("The following machines had an unusually large number of votes cancelled for an unknown reason.  You may wish to consult with the poll workers and maintenance staff at the following precincts.  ")
                    b7 = False
                #r.addTextBox("Machine %s had %d vote cancellation events (in %s)" % (w4[0], w4[3], w4[2]))
                #vcTable7.addRow(["Machine %s had %d vote cancellation events  " % (w4[0], w4[3]), " (in %s)." % (w4[2],)])
                vcTable7.addRow(["In %s, " % (w4[2],), "machine %s had %d vote cancellations." % (w4[1], w4[3])])
        r.addTable(vcTable7)
        avg2 = 0
        ssum3 = 0.00000000
        ssum4 = 0.00000000
        stdev2 = 0.00000000
        for w in vcNumMap.values():
            avg2 = avg2 + w
        avg2 = avg2/len(vcNumMap.values())
        for w2 in vcNumMap.values():
            ssum3 = ssum3 + ((w2-avg2)**2)
        ssum4 = ssum3/len(vcNumMap.values())
        stdev2 = math.sqrt(ssum4)   
        outliers = []
        for u in vcNumMap:
            if vcNumMap[u] > (3*stdev2):
                if ballot.machinePrecinctNameMap.has_key(u):
                    outliers.append((ballot.machinePrecinctNumMap[u], u, ballot.machinePrecinctNameMap[u], vcNumMap[u]))     
        outliers.sort()
        b8 = True
        vcTable8 = report.Table()
        for w5 in outliers:
            if b8 == True:
                r.addTextBox(" ")
                r.addTextBox("The following machines had an unusually large number of vote cancellations in total.")  
                b8 = False  
            #r.addTextBox("Machine %s had %d vote cancellation events (in %s)." % (w5[0], w5[2], w5[1]))
            #vcTable8.addRow(["Machine %s had %d vote cancellation events " % (w5[0], w5[2]), " (in %s)." % (w5[1],)])
            vcTable8.addRow(["In %s, " % (w5[2],), "machine %s had %d vote cancellations." % (w5[1], w5[3])])
        r.addTable(vcTable8)
    return r
def lowBatteryMachines(data, ballot, date, r):
    plt.ioff()
    d = str(date.eday)
    d = d.split("-")
    d2 = d[1]+'/'+d[2]+'/'+d[0]
    r.addTitle('Machines with possible low batteries')
    lowBatteryList = []
    lowBatteryMap = {}
    totalList = []
    avg = 0
    ssum = 0.00000000
    ssum2 = 0.00000000
    stdev = 0.00000000
    for x in data.getEntryList():
        s = x.dateTime.split(" ")
        t = s[1].split(":")
        if t[0] == '':
            continue
        elif x.eventNumber == '0001635' and (s[0] == d2) and stri.atoi(t[0]) > 7 and stri.atoi(t[0]) < 19:
            if x.serialNumber not in lowBatteryList and not lowBatteryMap.has_key(x.serialNumber):
                lowBatteryList.append(x.serialNumber)
                lowBatteryMap[x.serialNumber] = 1
            elif lowBatteryMap.has_key(x.serialNumber):
                temp = lowBatteryMap[x.serialNumber]
                temp = temp + 1
                lowBatteryMap[x.serialNumber] = temp
    if len(lowBatteryMap) < 1:
        #lowBatteryTable.addRow('This county shows no indication of machines with low battery.')
        #r.addTextBox("This county shows no indication of machines with low battery.")
        r.addTextBox("No problems found.")
    else:
        lowBatteryTable = report.Table()
        for n in lowBatteryMap.values():
            avg = avg + n
        avg = avg/len(lowBatteryMap.values())
        for n2 in lowBatteryMap.values():
                ssum = ssum + ((n2-avg)**2)
        ssum2 = ssum/len(lowBatteryMap.values())
        stdev = math.sqrt(ssum2)
        #print avg
        #print stdev
        for l in lowBatteryMap:
            precinctNum = None
            precinctName = None
            if ballot.machinePrecinctNumMap.has_key(l):
                precinctNum = ballot.machinePrecinctNumMap[l]
                precinctName = ballot.machinePrecinctNameMap[l]
            elif l in ballot.earlyVotingList:
                precinctNum = '750'
                precinctName = 'Absentee'
            elif l in ballot.failsafeList:
                precinctNum = '850'            
                precinctName = 'Failsafe'
            if lowBatteryMap[l] >= (avg + (3*stdev)):
                totalList.append((precinctNum, l, precinctName, lowBatteryMap[l], '0001635', data.getEventDescription('0001635')))
        totalList.sort()        
        r.addTextBox("The following voting machines have an unusually large number of log messages related to their Internal Power Supply.  The meaning of these messages is not documented.  This might indicate potential battery or power supply issues.  You may wish to check whether the battery of these machines is in good working condition.")
        r.addTextBox(" ")
        for t in totalList:
            lowBatteryTable.addRow(['In %s (#%s), ' % (t[2], t[0]), '   ', ' machine %s had %d power-related events.' % (t[1], t[3])])
        r.addTable(lowBatteryTable)
    return r
def getCalibrationEvents(data, ballot, r):
    plt.ioff()
    r.addTitle('Terminals with Callibration Problems')
    numOccurrencesWarningMap = {}
    numOccurrencesRecalibrationMap = {}
    timeOccurrencesMap = {}
    totalWarningList = []
    totalRecalibrationList = []
    avg = 0
    stdev = 0.00000000
    ssum = 0.00000000
    ssum2 = 0.00000000
    for x in data.getEntryList():
        s = x.dateTime.split(" ")
        t = s[1].split(":")
        if t[0] == '':
            continue
        elif stri.atoi(t[0]) > 6 and stri.atoi(t[0]) < 19 and (s[0] == '11/02/2010' or s[0] == '06/08/2010'):
            if x.eventNumber == '0001651':
                if numOccurrencesWarningMap.has_key(x.serialNumber):
                    temp = numOccurrencesWarningMap[x.serialNumber]
                    temp = temp + 1
                    numOccurrencesWarningMap[x.serialNumber] = temp
                else:
                    totalWarningList.append((x.serialNumber, ballot.machinePrecinctNumMap[x.serialNumber], ballot.machinePrecinctNameMap[x.serialNumber]))
                    numOccurrencesWarningMap[x.serialNumber] = 1
            elif x.eventNumber == '0001655':
                if numOccurrencesRecalibrationMap.has_key(x.serialNumber):
                    temp = numOccurrencesRecalibrationMap[x.serialNumber]
                    temp = temp + 1
                    numOccurrencesRecalibrationMap[x.serialNumber] = temp
                else:
                    if not ballot.machinePrecinctNumMap.has_key(x.serialNumber):
                        totalRecalibrationList.append((x.serialNumber, " ", " "))
                    else:
                        totalRecalibrationList.append((x.serialNumber, ballot.machinePrecinctNumMap[x.serialNumber], ballot.machinePrecinctNameMap[x.serialNumber]))
                    numOccurrencesRecalibrationMap[x.serialNumber] = 1
    warningTable = report.Table()
    if len(numOccurrencesWarningMap) < 1:
        warningTable.addRow("This county experienced no callibration problems.")
        #r.addTextBox("This county experienced no callibration problems.")
    else:
        for w in numOccurrencesWarningMap.values():
            avg = avg + w
        avg = avg/len(numOccurrencesWarningMap.values())
        for w2 in numOccurrencesWarningMap.values():
            ssum = ssum + ((w2-avg)**2)
        ssum2 = ssum/len(numOccurrencesWarningMap.values())
        stdev = math.sqrt(ssum2)
        b = True
        for y in numOccurrencesWarningMap:
            if numOccurrencesWarningMap[y] > (avg + (2.5*stdev)):
                for y2 in totalWarningList:
                    if y2[0] == y:
                        if b == True:
                            r.addTextBox("The following machines have an unusually large number of log messages related to an uncalibrated screen.  The meaning of these messages is not documented.  It is possible that they might indicate a problem with the terminal touch screen.  You may wish to check if the machine is calibrated or if the touch screen is in good working condition.")
                            r.addTextBox(" ")
                            b = False
                        warningTable.addRow(["%s (#%s) " % (y2[2], y2[1]), "  %s had %d occurrences of this event." % (y2[0], numOccurrencesWarningMap[y])])
                        #r.addTextBox("%s (#%s)   %s had %d occurrences of this event." % (y2[2], y2[1], y2[0], numOccurrencesWarningMap[y]))
        warningTable2 = report.Table()
        b2 = True
        for z in numOccurrencesWarningMap:
            if numOccurrencesRecalibrationMap.has_key(z):
                if numOccurrencesWarningMap[z] != numOccurrencesRecalibrationMap[z]:
                    for z2 in totalRecalibrationList:
                        for z3 in totalWarningList:
                            if z2[0] == z == z3[0]:
                                if b2 == True:
                                    r.addTextBox(" ")
                                    r.addTextBox("The following machines experienced screen calibration issues and were not always recalibrated.  You may wish to check if the screen is calibrated.")
                                    r.addTextBox(" ")
                                    b2 = False
                                warningTable2.addRow(["%s (#%s) " % (z3[2], z3[1]), "  %s experienced %d events warning about calibration, but it was only recalibrated %d time(s)." % (z3[0], numOccurrencesWarningMap[z], numOccurrencesRecalibrationMap[z])])
                                #r.addTextBox("%s (#%s)   %s experienced %d events warning about calibration, but it was only recalibrated %d time(s)." % (z3[2], z3[1], z3[0], numOccurrencesWarningMap[z], numOccurrencesRecalibrationMap[z]))
            else:
                for z4 in totalWarningList:
                    if z4[0] == z:
                        if b2 == True:
                            r.addTextBox(" ")
                            r.addTextBox("The following machines experienced screen calibration issues and were not always recalibrated.  You may wish to check if the screen is calibrated.")
                            r.addTextBox(" ")
                            b2 = False
                        warningTable2.addRow(["%s (#%s)  " % (z4[2], z4[1]), "  %s experienced %d events warning about calibration, but it was never recalibrated." % (z4[0], numOccurrencesWarningMap[z])])
                        #r.addTextBox("%s (#%s)   %s experienced %d events warning about calibration, but it was never recalibrated." % (z4[2], z4[1], z4[0], numOccurrencesWarningMap[z]))
        r.addTable(warningTable)
        r.addTable(warningTable2)
    return r
Exemple #13
0
    def executeSQL(self, path):
        begTime = time.time()
        print("\n【线程%d %s】开始分析SQL文件'%s'" %
              (self.threadID, time.strftime('%Y-%m-%d %H:%M:%S'), path))
        with open(path, "r", encoding=self.enCode) as f:
            sqls = f.read()
        sqls = noComment(sqls)

        sqls = sqls.replace(";'", "<fenhaoyinhao>")

        sqls = sqls.rstrip().rstrip(";")
        sqlList = sqls.split(";")

        sqlList1 = []
        for sql in sqlList:
            sql = sql.replace("<fenhaoyinhao>", ";'")
            sqlList1.append(sql)

        del sqlList
        sqlList = sqlList1[:]
        del sqlList1

        length = len(sqlList)
        print(
            "\n【线程%d %s】SQL文件'%s'共包含%d个SQL语句" %
            (self.threadID, time.strftime('%Y-%m-%d %H:%M:%S'), path, length))
        sqlNo = 0
        wrongNo = 0
        errInfo = ""

        for sql in sqlList:
            sqlNo += 1
            #print("\n【线程%d %s】执行SQL文件'%s'中第%d条SQL:\n%s" % (self.threadID, time.strftime('%Y-%m-%d %H:%M:%S'), path, sqlNo, sql))
            try:
                self.cr.execute(sql)
                res = self.cr.fetchall()
                rpt = report.Report()
                rpt.appendH4("数据检查结果")
                tb = report.Table()
                tb.addHead("大类", "小类", "规则", "等级", "数据量")
                cont = ""
                c = "大类\t\t\t\t小类\t\t\t\t规则\t\t\t\t等级\t\t\t\t数据量"
                cont = cont + c + "\n"
                #print(c)
                for row in res:
                    li = list()
                    i = 0
                    tmp = ""
                    for fld in row:
                        tmp = tmp + str(fld) + "\t\t\t\t"
                        li.append(str(fld))
                        i += 1
                    #print(tmp)
                    cont = cont + tmp + "\n"
                    tb.addRow(li[0], li[1], li[2], li[3], li[4])
                cont = cont + "\n\nSQL:\n" + sql
                print(cont)
                strTemp = tb.makeTable("数据检查结果")
                rpt.appendHTML(strTemp)
                rpt.appendH4("检查SQL")
                rpt.appendParagraph(sql)
                rpt.makeRpt()

            except Exception as E:
                errInfo = E
                print("\n【线程%d %s】SQL执行失败:%s" %
                      (self.threadID, time.strftime('%Y-%m-%d %H:%M:%S'),
                       errInfo))
                wrongNo = sqlNo
                break

        endTime = time.time()

        exTime = endTime - begTime

        if (wrongNo == 0):
            logText = "\n【线程%d %s】SQL文件'%s'所有SQL执行成功,耗时%.2f秒" % (
                self.threadID, time.strftime('%Y-%m-%d %H:%M:%S'), path,
                exTime)
            print(logText)
            with open("EasyOM_DataQC_Report.log", "a+",
                      encoding="utf-8") as fa:
                fa.write("%s\n" % (logText))

        else:
            logText = "\n【线程%d %s】SQL文件'%s'第%d条SQL执行失败,报错信息为:%s" % (
                self.threadID, time.strftime('%Y-%m-%d %H:%M:%S'), path,
                wrongNo, errInfo)
            print(logText)
            with open("EasyOM_DataQC_Report.log", "a+",
                      encoding="utf-8") as fa:
                fa.write("%s\n" % (logText))
            with open("error.log", "a+", encoding="utf-8") as fa:
                fa.write("%s\n" % (logText))
            print("\n【线程%d %s】SQL文件'%s'执行已中止,耗时%.2f秒" %
                  (self.threadID, time.strftime('%Y-%m-%d %H:%M:%S'), path,
                   exTime))