Esempio n. 1
0
    def load_federal_legislative_seats(self):
        seats = []
        with load_pickled_data(
            "data/{}/federal-legislative-seats.pkl".format(self.year)
        ) as pklfile:
            for d in pickle.load(pklfile):
                if d["seat_type"] == "house":
                    seats.append(HouseSeat(**d))
                elif d["seat_type"] == "senate":
                    seats.append(SenateSeat(**d))

        sorted_seats = sorted(
            seats,
            key=lambda x: int(getattr(x, "district", "0"))
            if hasattr(x, "district") and x.district is not None
            else 0,
        )
        sorted_seats = sorted(
            sorted_seats, key=lambda x: len(getattr(x, "senate_class", "IIII"))
        )
        sorted_seats = sorted(sorted_seats, key=lambda x: x.state.name)
        sorted_seats = sorted(
            sorted_seats, key=lambda x: CHAMBER_ORDER.index(x.seat_type)
        )

        return self.assign_parties_to_seats(
            ChamberFilterableList(sorted_seats)
        )
Esempio n. 2
0
    def load_state_executive_seats(self, state_abbr):
        seats = ExecutiveSeatFilterableList()
        with load_pickled_data(
            "data/{}/{}-executive-seats.pkl".format(self.year, state_abbr)
        ) as pklfile:
            for d in pickle.load(pklfile):
                if d["office"] == "governor":
                    seats.append(HeadOfGovernmentSeat(**d))
                else:
                    seats.append(ExecutiveSeat(**d))

        return self.assign_parties_to_seats(seats)
Esempio n. 3
0
    def load_federal_executive_seats(self):
        seats = ExecutiveSeatFilterableList()
        with load_pickled_data(
            "data/{}/federal-executive-seats.pkl".format(self.year)
        ) as pklfile:
            for d in pickle.load(pklfile):
                if d["office"] == "president":
                    seats.append(HeadOfGovernmentSeat(**d))
                else:
                    seats.append(ExecutiveSeat(**d))

        seats = self.assign_parties_to_seats(seats)

        return seats
Esempio n. 4
0
    def load_state_legislative_seats(self, state_abbr):
        seats = []
        with load_pickled_data(
            "data/{}/{}-legislative-seats.pkl".format(self.year, state_abbr)
        ) as pklfile:
            for d in pickle.load(pklfile):
                if d["seat_type"] == "house":
                    seats.append(HouseSeat(**d))
                elif d["seat_type"] == "senate":
                    seats.append(SenateSeat(**d))

        sorted_seats = sorted(
            seats, key=lambda x: CHAMBER_ORDER.index(x.seat_type)
        )

        return self.assign_parties_to_seats(
            ChamberFilterableList(sorted_seats)
        )
Esempio n. 5
0
    def load_electoral_votes(self):
        if self.election_year_type != PRESIDENTIAL_YEAR_TYPE:
            raise ValueError(
                "Only presidential election years have electoral votes."
            )

        vote_zones = ElectoralVoteFilterableList()
        with load_pickled_data(
            "data/{}/electoral-votes.pkl".format(self.year)
        ) as pklfile:
            for d in pickle.load(pklfile):
                if d["type"] == "statewide":
                    vote_zones.add_zone(StateElectoralZone(**d))
                else:
                    vote_zones.add_zone(DistrictElectoralZone(**d))

        # vote_zones = self.assign_states_to_vote_zones(vote_zones)

        return vote_zones
Esempio n. 6
0
    def load_elections(self):
        elections = []

        with load_pickled_data(
            "data/{}/elections.pkl".format(self.year)
        ) as pklfile:
            for d in pickle.load(pklfile, encoding="latin1"):
                if d["election_type"] == "general":
                    elections.append(GeneralElection(**d))
                elif d["election_type"] == "primary":
                    if d["election_party"] == "dem":
                        if d["election_date"] is not None:
                            elections.append(DemocraticPrimaryElection(**d))
                        if d["runoff_election_date"] is not None:
                            elections.append(
                                DemocraticPrimaryRunoffElection(**d)
                            )
                    elif d["election_party"] == "gop":
                        if d["election_date"] is not None:
                            elections.append(RepublicanPrimaryElection(**d))
                        if d["runoff_election_date"] is not None:
                            elections.append(
                                RepublicanPrimaryRunoffElection(**d)
                            )
                    else:
                        if d["election_date"] is not None:
                            elections.append(PrimaryElection(**d))
                        if d["runoff_election_date"] is not None:
                            elections.append(PrimaryRunoffElection(**d))

        sorted_elections = sorted(elections, key=lambda x: x.state.name)
        sorted_elections = sorted(
            sorted_elections, key=lambda x: x.election_date
        )

        return ElectionTypeFilterableList(sorted_elections)
Esempio n. 7
0
def load_years():
    years = []
    with load_pickled_data("data/years.pkl") as pklfile:
        for d in pickle.load(pklfile):
            years.append(d)
    return years
Esempio n. 8
0
 def load_parties(self):
     parties = []
     with load_pickled_data("data/parties.pkl") as pklfile:
         for d in pickle.load(pklfile):
             parties.append(Party(**d))
     return parties