-
Notifications
You must be signed in to change notification settings - Fork 30
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
5 changed files
with
116 additions
and
95 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
60 changes: 9 additions & 51 deletions
60
polling_stations/apps/data_importers/management/commands/import_aberdeenshire.py
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,56 +1,14 @@ | ||
from addressbase.models import UprnToCouncil | ||
from data_importers.management.commands import BaseHalaroseCsvImporter | ||
|
||
|
||
class Command(BaseHalaroseCsvImporter): | ||
council_id = "ABD" | ||
addresses_name = "2022-05-05/2022-04-12T10:11:25.128402/polling_station_export-2022-04-07.edited.csv" | ||
stations_name = "2022-05-05/2022-04-12T10:11:25.128402/polling_station_export-2022-04-07.edited.csv" | ||
elections = ["2022-05-05"] | ||
|
||
def pre_import(self): | ||
# We need to consider rows that don't have a uprn when importing data. | ||
# However there are lots of rows for other councils in this file. | ||
# So build a list of stations from rows that do have UPRNS | ||
# and then use that list of stations to make sure we check relevant rows, even if they don't have a UPRN | ||
|
||
council_uprns = set( | ||
UprnToCouncil.objects.filter(lad=self.council.geography.gss).values_list( | ||
"uprn", flat=True | ||
) | ||
) | ||
self.COUNCIL_STATIONS = set() | ||
data = self.get_addresses() | ||
|
||
for record in data: | ||
if record.uprn in council_uprns: | ||
self.COUNCIL_STATIONS.add(self.get_station_hash(record)) | ||
|
||
def address_record_to_dict(self, record): | ||
if self.get_station_hash(record) not in self.COUNCIL_STATIONS: | ||
return None | ||
|
||
if record.housepostcode in [ | ||
"AB39 2UJ", | ||
"AB30 1SL", | ||
"AB43 7LN", | ||
"AB42 5JB", | ||
"AB51 8XH", | ||
"AB41 7UA", | ||
"AB51 5DU", | ||
"AB21 0QJ", | ||
"AB35 5PR", | ||
]: | ||
return None | ||
|
||
return super().address_record_to_dict(record) | ||
|
||
def station_record_to_dict(self, record): | ||
station_hash = self.get_station_hash(record) | ||
if station_hash not in self.COUNCIL_STATIONS: | ||
return None | ||
|
||
if station_hash == "74-hanover-community-centre": | ||
return None | ||
|
||
return super().station_record_to_dict(record) | ||
addresses_name = ( | ||
"2024-07-04/2024-06-07T15:42:14.722645/Eros_SQL_Output002 - Aberdeenshire.csv" | ||
) | ||
stations_name = ( | ||
"2024-07-04/2024-06-07T15:42:14.722645/Eros_SQL_Output002 - Aberdeenshire.csv" | ||
) | ||
elections = ["2024-07-04"] | ||
|
||
# additional_report_councils = ["MRY"] |