pub(crate) fn read_from_senate_group_voting_tickets_download_file2013(builder: &mut CandidateAndGroupInformationBuilder, path:&Path, state:&str) -> anyhow::Result<()> {
    fn add_ticket(builder: &mut CandidateAndGroupInformationBuilder,current_ticket : &Vec<usize>,current_ticket_owner:&Option<String>) {
        let party = builder.group_from_group_id(current_ticket_owner.as_ref().unwrap()).unwrap();
        let mut real_ticket = vec![CandidateIndex(999999);builder.candidates.len()];
        for (candidate_index,preference_no) in current_ticket.iter().enumerate() { real_ticket[preference_no-1]=CandidateIndex(candidate_index);}
        builder.parties[party.0].tickets.push(real_ticket);
    }
    let mut rdr = csv::Reader::from_reader(skip_first_line_of_file(path)?);
    let mut first_party_ticket_owner : Option<String> = None; // first party ticket indicates that this is the first time candidates/parties seen.
    let mut candidate_id_to_index : HashMap<String,CandidateIndex> = HashMap::default();
    let mut current_ticket : Vec<usize> = vec![]; // vec of preference numbers. current_ticket[c] is the mark the owning party wants for candidate c.
    let mut current_ticket_owner : Option<String> = None;
    let mut current_ticket_no : usize = 0;
    for result in rdr.records() {
        let record = result?;
        if state==&record[0] { // right state
            let party_ticket_owner = &record[3]; // something like A, B, or UG
            if first_party_ticket_owner == None { first_party_ticket_owner = Some(party_ticket_owner.to_string()) };
            let ticket_no = record[4].parse::<usize>()?; // 1 means first

            // see if a ticket has ended
            if current_ticket_owner.is_none() || current_ticket_owner.as_ref().unwrap()!=party_ticket_owner || current_ticket_no!=ticket_no {
                if current_ticket_owner.is_some() {
                    add_ticket(builder,&current_ticket,&current_ticket_owner);
                    current_ticket.clear();
                }
                current_ticket_owner=Some(party_ticket_owner.to_string());
                current_ticket_no=ticket_no;
            }


            let group_id = &record[6]; // something like A, B, or UG
            let candidate_id = &record[5]; // something like 32847
            let position_in_ticket = record[9].parse::<usize>()?; // 1 means first
            let preference_no = record[12].parse::<usize>()?; // the preference given to said candidate by party_ticket_owner.
            if first_party_ticket_owner.as_ref().unwrap() == party_ticket_owner && ticket_no == 1 { // Defining candidates/parties.
                if builder.parties.len() == 0 || &builder.parties[builder.parties.len() - 1].group_id != group_id { // define a new party.
                    let party_name = &record[11];
                    let party_abreviation = &record[10];
                    let abbreviation = if party_abreviation.is_empty() { None } else { Some(party_abreviation.to_string()) };
                    builder.parties.push(GroupBuilder { name: party_name.to_string(), abbreviation, group_id: group_id.to_string(), ticket_id: None, tickets: vec![] });
                }
                if position_in_ticket != 0 { // real candidate.
                    candidate_id_to_index.insert(candidate_id.to_string(), CandidateIndex(builder.candidates.len()));
                    let name = record[7].to_string() + ", " + &record[8];
                    builder.candidates.push(Candidate {
                        name,
                        ec_id: Some(candidate_id.to_string()),
                        party: Some(PartyIndex(builder.parties.len() - 1)),
                        position: Some(position_in_ticket)
                    })
                }
            }
            current_ticket.push(preference_no);
        }
    }
    add_ticket(builder,&current_ticket,&current_ticket_owner);
    Ok(())
}
/// Read from a file "SenateGroupVotingTicketsDownload which defines candidates, parties and tickets.
/// Used in 2013.
Read from a file "SenateGroupVotingTicketsDownload which defines candidates, parties and tickets.
Read from a file " SenateGroupVotingTicketsDownload which defines candidates parties and tickets .
pub(crate) fn read_from_senate_group_voting_tickets_download_file2013(builder: &mut CandidateAndGroupInformationBuilder, path:&Path, state:&str) -> anyhow::Result<()> {
    fn add_ticket(builder: &mut CandidateAndGroupInformationBuilder,current_ticket : &Vec<usize>,current_ticket_owner:&Option<String>) {
        let party = builder.group_from_group_id(current_ticket_owner.as_ref().unwrap()).unwrap();
        let mut real_ticket = vec![CandidateIndex(999999);builder.candidates.len()];
        for (candidate_index,preference_no) in current_ticket.iter().enumerate() { real_ticket[preference_no-1]=CandidateIndex(candidate_index);}
        builder.parties[party.0].tickets.push(real_ticket);
    }
    let mut rdr = csv::Reader::from_reader(skip_first_line_of_file(path)?);
    let mut first_party_ticket_owner : Option<String> = None; // first party ticket indicates that this is the first time candidates/parties seen.
    let mut candidate_id_to_index : HashMap<String,CandidateIndex> = HashMap::default();
    let mut current_ticket : Vec<usize> = vec![]; // vec of preference numbers. current_ticket[c] is the mark the owning party wants for candidate c.
    let mut current_ticket_owner : Option<String> = None;
    let mut current_ticket_no : usize = 0;
    for result in rdr.records() {
        let record = result?;
        if state==&record[0] { // right state
            let party_ticket_owner = &record[3]; // something like A, B, or UG
            if first_party_ticket_owner == None { first_party_ticket_owner = Some(party_ticket_owner.to_string()) };
            let ticket_no = record[4].parse::<usize>()?; // 1 means first
            // see if a ticket has ended
            if current_ticket_owner.is_none() || current_ticket_owner.as_ref().unwrap()!=party_ticket_owner || current_ticket_no!=ticket_no {
                if current_ticket_owner.is_some() {
                    add_ticket(builder,&current_ticket,&current_ticket_owner);
                    current_ticket.clear();
                }
                current_ticket_owner=Some(party_ticket_owner.to_string());
                current_ticket_no=ticket_no;
            }
            let group_id = &record[6]; // something like A, B, or UG
            let candidate_id = &record[5]; // something like 32847
            let position_in_ticket = record[9].parse::<usize>()?; // 1 means first
            let preference_no = record[12].parse::<usize>()?; // the preference given to said candidate by party_ticket_owner.
            if first_party_ticket_owner.as_ref().unwrap() == party_ticket_owner && ticket_no == 1 { // Defining candidates/parties.
                if builder.parties.len() == 0 || &builder.parties[builder.parties.len() - 1].group_id != group_id { // define a new party.
                    let party_name = &record[11];
                    let party_abreviation = &record[10];
                    let abbreviation = if party_abreviation.is_empty() { None } else { Some(party_abreviation.to_string()) };
                    builder.parties.push(GroupBuilder { name: party_name.to_string(), abbreviation, group_id: group_id.to_string(), ticket_id: None, tickets: vec![] });
                }
                if position_in_ticket != 0 { // real candidate.
                    candidate_id_to_index.insert(candidate_id.to_string(), CandidateIndex(builder.candidates.len()));
                    let name = record[7].to_string() + ", " + &record[8];
                    builder.candidates.push(Candidate {
                        name,
                        ec_id: Some(candidate_id.to_string()),
                        party: Some(PartyIndex(builder.parties.len() - 1)),
                        position: Some(position_in_ticket)
                    })
                }
            }
            current_ticket.push(preference_no);
        }
    }
    add_ticket(builder,&current_ticket,&current_ticket_owner);
    Ok(())
}
pub ( crate ) fn read_from_senate_group_voting_tickets_download_file2013 ( builder : & mut CandidateAndGroupInformationBuilder , path : & Path , state : & str ) -> anyhow :: Result < ( ) > { fn add_ticket ( builder : & mut CandidateAndGroupInformationBuilder , current_ticket : & Vec < usize > , current_ticket_owner : & Option < String > ) { let party = builder . group_from_group_id ( current_ticket_owner . as_ref ( ) . unwrap ( ) ) . unwrap ( ) ; let mut real_ticket = vec ! [ CandidateIndex ( 999999 ) builder candidates len ( ) ] ; for ( candidate_index , preference_no ) in current_ticket . iter ( ) . enumerate ( ) { real_ticket [ preference_no - 1 ] = CandidateIndex ( candidate_index ) ; } builder . parties [ party . 0 ] . tickets . push ( real_ticket ) ; } let mut rdr = csv :: Reader :: from_reader ( skip_first_line_of_file ( path ) ? ) ; let mut first_party_ticket_owner : Option < String > = None ; // first party ticket indicates that this is the first time candidates/parties seen. let mut candidate_id_to_index : HashMap < String , CandidateIndex > = HashMap :: default ( ) ; let mut current_ticket : Vec < usize > = vec ! [ ] ; // vec of preference numbers. current_ticket[c] is the mark the owning party wants for candidate c. let mut current_ticket_owner : Option < String > = None ; let mut current_ticket_no : usize = 0 ; for result in rdr . records ( ) { let record = result ? ; if state == & record [ 0 ] { // right state let party_ticket_owner = & record [ 3 ] ; // something like A, B, or UG if first_party_ticket_owner == None { first_party_ticket_owner = Some ( party_ticket_owner . to_string ( ) ) } ; let ticket_no = record [ 4 ] . parse :: < usize > ( ) ? ; // 1 means first // see if a ticket has ended if current_ticket_owner . is_none ( ) || current_ticket_owner . as_ref ( ) . unwrap ( ) != party_ticket_owner || current_ticket_no != ticket_no { if current_ticket_owner . is_some ( ) { add_ticket ( builder , & current_ticket , & current_ticket_owner ) ; current_ticket . clear ( ) ; } current_ticket_owner = Some ( party_ticket_owner . to_string ( ) ) ; current_ticket_no = ticket_no ; } let group_id = & record [ 6 ] ; // something like A, B, or UG let candidate_id = & record [ 5 ] ; // something like 32847 let position_in_ticket = record [ 9 ] . parse :: < usize > ( ) ? ; // 1 means first let preference_no = record [ 12 ] . parse :: < usize > ( ) ? ; // the preference given to said candidate by party_ticket_owner. if first_party_ticket_owner . as_ref ( ) . unwrap ( ) == party_ticket_owner && ticket_no == 1 { // Defining candidates/parties. if builder . parties . len ( ) == 0 || & builder . parties [ builder . parties . len ( ) - 1 ] . group_id != group_id { // define a new party. let party_name = & record [ 11 ] ; let party_abreviation = & record [ 10 ] ; let abbreviation = if party_abreviation . is_empty ( ) { None } else { Some ( party_abreviation . to_string ( ) ) } ; builder . parties . push ( GroupBuilder { name : party_name . to_string ( ) , abbreviation , group_id : group_id . to_string ( ) , ticket_id : None , tickets : vec ! [ ] } ) ; } if position_in_ticket != 0 { // real candidate. candidate_id_to_index . insert ( candidate_id . to_string ( ) , CandidateIndex ( builder . candidates . len ( ) ) ) ; let name = record [ 7 ] . to_string ( ) + " " + & record [ 8 ] ; builder . candidates . push ( Candidate { name , ec_id : Some ( candidate_id . to_string ( ) ) , party : Some ( PartyIndex ( builder . parties . len ( ) - 1 ) ) , position : Some ( position_in_ticket ) } ) } } current_ticket . push ( preference_no ) ; } } add_ticket ( builder , & current_ticket , & current_ticket_owner ) ; Ok ( ( ) ) }
Read from a file "SenateGroupVotingTicketsDownload which defines candidates, parties and tickets.
Read from a file " SenateGroupVotingTicketsDownload which defines candidates parties and tickets .
builder
&mut CandidateAndGroupInformationBuilder
path
&Path
state
&str
builder
&mut CandidateAndGroupInformationBuilder
path
&Path
state
&str