fn read_raw_data(&self,state:&str) -> anyhow::Result<ElectionData> {
        if self.year=="2013" { return self.read_raw_data2013(state); }
        let mut metadata = self.read_raw_metadata(state)?;
        let filename = self.name_of_vote_source(state);
        let preferences_zip_file = self.find_raw_data_file(&filename)?;
        println!("Parsing {}",&preferences_zip_file.to_string_lossy());
        metadata.source[0].files.push(filename);
        let mut parties_that_can_get_atls = vec![];
        for i in 0..metadata.parties.len() {
            if metadata.parties[i].atl_allowed { parties_that_can_get_atls.push(PartyIndex(i)); }
        }
        let mut zipfile = zip::ZipArchive::new(File::open(preferences_zip_file)?)?;
        let mut atls : HashMap<Vec<PartyIndex>,usize> = HashMap::default();
        let mut btls : HashMap<Vec<CandidateIndex>,usize> = HashMap::default();
        let mut informal = 0;
        for record in ParsedRawVoteIterator::new(&mut zipfile)? {
            let record=record?;
            let markings = RawBallotMarkings::new(&parties_that_can_get_atls,&record.markings);
            //println!("Markings {:#?}",record.markings);
            //println!("Interpretatation {:#?}",markings.interpret_vote(1,6));
            match markings.interpret_vote(1,6) {
                None => { informal+=1 }
                Some(FormalVote::Btl(btl)) => { *btls.entry(btl.candidates).or_insert(0)+=btl.n }
                Some(FormalVote::Atl(atl)) => { *atls.entry(atl.parties).or_insert(0)+=atl.n }
            }
        }
        let atl = atls.into_iter().map(|(parties,n)|ATL{ parties, n }).collect();
        let btl = btls.into_iter().map(|(candidates,n)|BTL{ candidates , n }).collect();
        Ok(ElectionData{ metadata, atl, atl_types: vec![], btl, btl_types: vec![], informal })
    }
// This below should be made more general and most of it factored out into a separate function.
This below should be made more general and most of it factored out into a separate function.
This below should be made more general and most of it factored out into a separate function .
fn read_raw_data(&self,state:&str) -> anyhow::Result<ElectionData> {
        if self.year=="2013" { return self.read_raw_data2013(state); }
        let mut metadata = self.read_raw_metadata(state)?;
        let filename = self.name_of_vote_source(state);
        let preferences_zip_file = self.find_raw_data_file(&filename)?;
        println!("Parsing {}",&preferences_zip_file.to_string_lossy());
        metadata.source[0].files.push(filename);
        let mut parties_that_can_get_atls = vec![];
        for i in 0..metadata.parties.len() {
            if metadata.parties[i].atl_allowed { parties_that_can_get_atls.push(PartyIndex(i)); }
        }
        let mut zipfile = zip::ZipArchive::new(File::open(preferences_zip_file)?)?;
        let mut atls : HashMap<Vec<PartyIndex>,usize> = HashMap::default();
        let mut btls : HashMap<Vec<CandidateIndex>,usize> = HashMap::default();
        let mut informal = 0;
        for record in ParsedRawVoteIterator::new(&mut zipfile)? {
            let record=record?;
            let markings = RawBallotMarkings::new(&parties_that_can_get_atls,&record.markings);
            //println!("Markings {:#?}",record.markings);
            //println!("Interpretatation {:#?}",markings.interpret_vote(1,6));
            match markings.interpret_vote(1,6) {
                None => { informal+=1 }
                Some(FormalVote::Btl(btl)) => { *btls.entry(btl.candidates).or_insert(0)+=btl.n }
                Some(FormalVote::Atl(atl)) => { *atls.entry(atl.parties).or_insert(0)+=atl.n }
            }
        }
        let atl = atls.into_iter().map(|(parties,n)|ATL{ parties, n }).collect();
        let btl = btls.into_iter().map(|(candidates,n)|BTL{ candidates , n }).collect();
        Ok(ElectionData{ metadata, atl, atl_types: vec![], btl, btl_types: vec![], informal })
    }
fn read_raw_data ( & self , state : & str ) -> anyhow :: Result < ElectionData > { if self . year == " " { return self . read_raw_data2013 ( state ) ; } let mut metadata = self . read_raw_metadata ( state ) ? ; let filename = self . name_of_vote_source ( state ) ; let preferences_zip_file = self . find_raw_data_file ( & filename ) ? ; println ! ( " " preferences_zip_file to_string_lossy ( ) ) ; metadata . source [ 0 ] . files . push ( filename ) ; let mut parties_that_can_get_atls = vec ! [ ] ; for i in 0 .. metadata . parties . len ( ) { if metadata . parties [ i ] . atl_allowed { parties_that_can_get_atls . push ( PartyIndex ( i ) ) ; } } let mut zipfile = zip :: ZipArchive :: new ( File :: open ( preferences_zip_file ) ? ) ? ; let mut atls : HashMap < Vec < PartyIndex > , usize > = HashMap :: default ( ) ; let mut btls : HashMap < Vec < CandidateIndex > , usize > = HashMap :: default ( ) ; let mut informal = 0 ; for record in ParsedRawVoteIterator :: new ( & mut zipfile ) ? { let record = record ? ; let markings = RawBallotMarkings :: new ( & parties_that_can_get_atls , & record . markings ) ; //println!("Markings {:#?}",record.markings); //println!("Interpretatation {:#?}",markings.interpret_vote(1,6)); match markings . interpret_vote ( 1 , 6 ) { None => { informal += 1 } Some ( FormalVote :: Btl ( btl ) ) => { * btls . entry ( btl . candidates ) . or_insert ( 0 ) += btl . n } Some ( FormalVote :: Atl ( atl ) ) => { * atls . entry ( atl . parties ) . or_insert ( 0 ) += atl . n } } } let atl = atls . into_iter ( ) . map ( | ( parties , n ) | ATL { parties , n } ) . collect ( ) ; let btl = btls . into_iter ( ) . map ( | ( candidates , n ) | BTL { candidates , n } ) . collect ( ) ; Ok ( ElectionData { metadata , atl , atl_types : vec ! [ ] , btl , btl_types : vec ! [ ] , informal } ) }
This below should be made more general and most of it factored out into a separate function.
This below should be made more general and most of it factored out into a separate function .
&self
state
&str
&self
state
&str