-
Notifications
You must be signed in to change notification settings - Fork 30
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Out of council boundary imports #7764
Draft
GeoWill
wants to merge
1
commit into
master
Choose a base branch
from
feature/out-of-boundary-imports
base: master
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Draft
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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"] |
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This approach won't work, because the polling stations aren't saved in the DB yet.