Example #1
0
    def merge(self, merged_output):
        """
        # Concatenate the two input files together along with a generated
        #  audit header. Dump the result in yaml and xml formats
        """

        # Create an audit header
        a = audit_header.AuditHeader()
        a.set_fields('tabulator_aggregation', 'Pito Salas',
                     'TTV Tabulator TAB02', 'TTV Tabulator 0.1 JUL-1-2008',
                     self.new_prov)

        # Dump merge into a file in yaml format
        with open(''.join([merged_output, '.yml']), 'w') as stream:
            stream.write(a.serialize_yaml())
            yaml.dump_all(self.b1, stream)
            stream.write('---\n')
            yaml.dump_all(self.b2, stream)

        # Dump merge into a file in xml format
        with open(''.join([merged_output, '.xml']), 'w') as stream:
            stream.write(a.serialize_xml())
            for file in (self.b1, self.b2):
                for record in file:
                    stream.writelines(xml_serialize(record, 0))
Example #2
0
    def merge(self, merged_output):
        """
        # Concatenate the two input files together along with a generated
        #  audit header. Dump the result in yaml and xml formats
        """

        # Create an audit header
        a = audit_header.AuditHeader()
        a.set_fields('tabulator_aggregation',
                     'Pito Salas', 'TTV Tabulator TAB02', 
                     'TTV Tabulator 0.1 JUL-1-2008', self.new_prov)

        # Dump merge into a file in yaml format
        with open(''.join([merged_output,'.yml']), 'w') as stream:
            stream.write(a.serialize_yaml())
            yaml.dump_all(self.b1, stream)
            stream.write('---\n')
            yaml.dump_all(self.b2, stream)

        # Dump merge into a file in xml format        
        with open(''.join([merged_output,'.xml']), 'w') as stream:
            stream.write(a.serialize_xml())
            for file in (self.b1, self.b2):
                for record in file:
                    stream.writelines(xml_serialize(record, 0))
Example #3
0
    def __init__(self, args):
        self.precs = 0
        # Load ballot records from yaml file
        self.input = args[0]
        try:
            stream = open(''.join([self.input, '.yml']), 'r')
        except IOError:
            print(''.join(['Unable to open ', self.input, '\n']))
            raise
        else:
            a = audit_header.AuditHeader()
            a.load_from_file(stream)
            self.b = list(yaml.load_all(stream))

        # Load the jurisdiction slate or precinct contestlist template
        try:
            stream = open(''.join([args[1], '.yml']), 'r')
        except IOError:
            print(''.join(['Unable to open ', self.input, '\n']))
            raise
        else:
            a = audit_header.AuditHeader()
            a.load_from_file(stream)
            self.template_type = a.type
            self.templ = yaml.load(stream)

        # Add the vote counts of candidates with the same ID# using
        #  sumation(). Write the vote totals for each candidate to the
        #  report stream.
        d = date.today()
        self.header = '\n'.join([
            'Election Summary Report,,',
            'Generated by TrustTheVote Tabulation and Reporting Module,,',
            'Report generated on, %d-%d-%d,\n' % (d.month, d.day, d.year)
        ])

        b = self.sumation()
        self.serialize_csv_pvt_html(b)

        # Dump output into a file in yaml format
        with open(''.join([self.input, '_report.yml']), 'w') as stream:
            yaml.dump(b, stream)

        # Dump output into a file in XML file
        with open(''.join([self.input, '_report.xml']), 'w') as stream:
            stream.writelines(xml_serialize(b, 0))
Example #4
0
    def __init__(self, args):
        self.precs = 0
        # Load ballot records from yaml file
        self.input = args[0]
        try:
            stream = open(''.join([self.input,'.yml']), 'r')
        except IOError:
            print(''.join(['Unable to open ',self.input,'\n']))
            raise
        else:
            a = audit_header.AuditHeader()
            a.load_from_file(stream)
            self.b = list(yaml.load_all(stream))

        # Load the jurisdiction slate or precinct contestlist template
        try:
            stream = open(''.join([args[1],'.yml']), 'r')
        except IOError:
            print(''.join(['Unable to open ',self.input,'\n']))
            raise
        else:
            a = audit_header.AuditHeader()
            a.load_from_file(stream)
            self.template_type = a.type
            self.templ = yaml.load(stream)

        # Add the vote counts of candidates with the same ID# using
        #  sumation(). Write the vote totals for each candidate to the
        #  report stream.
        d = date.today()
        self.header = '\n'.join(['Election Summary Report,,',
         'Generated by TrustTheVote Tabulation and Reporting Module,,',
         'Report generated on, %d-%d-%d,\n' % (d.month, d.day, d.year)])

        b = self.sumation()
        self.serialize_csv_pvt_html(b)

        # Dump output into a file in yaml format
        with open(''.join([self.input,'_report.yml']), 'w') as stream:
            yaml.dump(b, stream)

        # Dump output into a file in XML file
        with open(''.join([self.input,'_report.xml']), 'w') as stream:
            stream.writelines(xml_serialize(b, 0))
    def __init__(self, args):
        # These variables are used to ensure that if the same random
        #  data is generated in some circumstances, it will not appear
        #  twice in the template.
        self.already_used_streps = []
        self.already_used_dreps = []
        self.already_used_names = []
        self.already_used_cand_idents = []
        self.already_used_dist_names = []
        self.already_used_supreme = False
        self.fname_list = []
        self.lname_list = []

        self.args = args
        self.params = {}
        for arg in self.process_flags():
            self.args.remove(arg)

        self.type = self.args[0]
        if self.type == 'jurisdiction':
        # Generate a sample jurisdiction_slate and output it to the
        #  location specified by the user in the command line, in yaml
        #  and xml formats.
            b = {}

            # Give each file its own audit header, generate data
            a = audit_header.AuditHeader()
            a.set_fields('jurisdiction_slate',
                         'Pito Salas', 'TTV Tabulator TAB02', 
                         'TTV Tabulator 0.1 JUL-1-2008', [])
            b = self.make_juris()
            b['jurisdiction_display_name'] = (self.args[1]\
             [self.args[1].rfind('/') + 1:len(self.args[1])]).encode("ascii")

            # Dump output into a file in yaml format
            with open(''.join([self.args[1],'.yml']), 'w') as stream:
                stream.write(a.serialize_yaml())
                yaml.dump(b, stream)

            # Dump output into a file in XML file
            with open(''.join([self.args[1],'.xml']), 'w') as stream:
                stream.write(a.serialize_xml())
                stream.writelines(xml_serialize(b, 0))

        elif self.type == 'contestlist':
        # Generate a sample election and output it to the location
        #  specified by the user in the command line, in yaml and xml
        #  formats.
            b = {}

            # Give each file its own audit header, generate data
            a = audit_header.AuditHeader()
            a.set_fields('precinct_contestlist',
                         'Pito Salas', 'TTV Tabulator TAB02', 
                         'TTV Tabulator 0.1 JUL-1-2008', [])
            b = self.random_elec()

            # Dump output into a file in yaml format
            with open(''.join([self.args[1],'.yml']), 'w') as stream:
                stream.write(a.serialize_yaml())
                yaml.dump(b, stream)

            # Dump output into a file in XML file
            with open(''.join([self.args[1], '.xml']), 'w') as stream:
                stream.write(a.serialize_xml())
                stream.writelines(xml_serialize(b, 0))

        elif self.type == 'counts':
            r_min = self.params['counts_min']
            r_max = self.params['counts_max']
            
            # Load election specs from given file in yaml format
            with open(''.join([self.args[2],'.yml']), 'r') as stream:
                for i in range(0,8):  # Ignore the audit header
                    stream.readline()
                e = yaml.load(stream)

            # Make the number of random ballot_info records specified by
            #  the user. Use the loaded election specs as a template,
            #  assign the vote counts of each candidate a value between 
            #  0 and 99.
            b_list = []
            for i in range(int(self.args[1])):
                b = {}
                for key in e.keys():
                    if key not in ['contest_list', 'precinct_list',
                     'jurisdiction_display_name']:
                        b[key] = e[key]
                b['contest_list'] = []
                prec_num = random.randint(0, e['number_of_precincts'] - 1)
                b['prec_ident'] = e['precinct_list'][prec_num]['ident']
                if e.has_key('precinct_list'):
                    b['registered_voters'] = \
                     e['precinct_list'][prec_num-1]['registered_voters']
                for j in range(len(e['contest_list'])):
                    # If the template was a jurisdiction_slate, then
                    #  do not include contests that were not generated
                    #  in a district in this precinct.
                    if e.has_key('precinct_list'):
                        valid_contest = False
                        for prec in e['precinct_list']:
                            if prec['ident'] == b['prec_ident']:
                                for dist in prec['district_list']:
                                    if dist['ident'] == \
                                     e['contest_list'][j]['district_ident']:
                                        valid_contest = True
                                        break
                        if not valid_contest:
                            continue
                    b['contest_list'].append(copy.deepcopy(e['contest_list'][j]))
                    cont = b['contest_list'][-1]
                    if not cont.has_key('total_votes'):
                        cont['total_votes'] = 0
                        cont['uncounted_ballots'] = {}
                        cont['uncounted_ballots']['blank_votes'] = 0
                        cont['uncounted_ballots']['over_votes'] = 0
                        cont['voting_method_ident'] = ''.join(['VOTM-',
                         str(random.randint(1,5))])
                    for cand in cont['candidates']:
                        if cand['display_name'] == 'Write-In Votes':
                            cand['count'] = random.randint(r_min, r_max)
                        else:
                            cand['count'] = random.randint(r_min, r_max)
                        cont['total_votes'] += cand['count']
                    cont['uncounted_ballots']['blank_votes'] = \
                     random.randint(r_min,r_max)
                    cont['uncounted_ballots']['over_votes'] = \
                     random.randint(r_min,r_max)

                # Generate a random polling type for this session
                r = random.randint(0,3)
                if r == 0:
                    b['vote_type'] = 'Polling'
                elif r == 1:
                    b['vote_type'] = 'Early Voting'
                elif r == 2:
                    b['vote_type'] = 'Absentee'
                else:
                    b['vote_type'] = 'Other'

                b_list.append(b)

            # Give each file its own audit header
            a = audit_header.AuditHeader()
            a.set_fields('ballot_counter_total',
                         'Pito Salas', 'TTV Tabulator TAB02', 
                         'TTV Tabulator 0.1 JUL-1-2008', [])

            # Dump output into a file in yaml format
            with open(''.join([self.args[3],'.yml']), 'w') as stream:
                stream.write(a.serialize_yaml())
                yaml.dump_all(b_list, stream)

            # Dump output into a file in XML file
            with open(''.join([self.args[3],'.xml']), 'w') as stream:
                stream.write(a.serialize_xml())
                for record in b_list:
                    stream.writelines(xml_serialize(record, 0))
        else:
            raise StandardError('Incorrect data generation type')