-
Notifications
You must be signed in to change notification settings - Fork 78
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
Support the new constituencies for the July 2024 election #941
Conversation
Sourced from the following postcode to WPC lookup table: https://geoportal.statistics.gov.uk/datasets/f60c78533aa7462cb934bb4a81afc1e0/about Generated using the following query: SELECT pconcd AS ons_code, REPLACE(pcd, ' ', '') AS example_postcode FROM ( SELECT pconcd, first_value(pcd) OVER ( PARTITION BY pconcd ORDER BY random() ) AS pcd FROM postcodes WHERE pconcd IS NOT NULL ) AS p GROUP BY ons_code, example_postcode ORDER BY ons_code;
Also adjust the uniqueness index on the slug to only apply to 'current' constituencies (i.e. records where the end_date is NULL).
If there's no lookup value then something has gone wrong.
Order the results so the old constituencies have their end_date set first so the new constituencies don't raise a duplicate value error when they have the same slug as the old constituency.
Note that we don't have to do this for `find_by_postcode` as Parliament's API will only return us the current constituency.
app/models/constituency.rb
Outdated
def between(start_date, end_date) | ||
where(start_date: ..start_date, end_date: (end_date ? ..end_date : nil)) | ||
end | ||
|
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.
Does this method require knowing the actual start dates and end dates of a given parliament or will it work if some other range within the duration of the parliament is given? I don't know off the top of my head how date ranges work in queries.
If it accepts other ranges, then what happens if the date ranges given span two or more parliaments?
I also wonder if we'd more often want to look up the constituencies on a particular date, rather than within a range. But in that case I suppose just putting the same date for start and end would work?
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.
Does this method require knowing the actual start dates and end dates of a given parliament or will it work if some other range within the duration of the parliament is given? I don't know off the top of my head how date ranges work in queries.
So we do know the start/end dates but the query as it stands doesn't work for parliaments that have closed but where the constituencies are still live (i.e. they have no end date). Going to drop this commit for now until we have a better idea of what we need (e.g. a parliaments api endpoint, etc.) for the update to the map.
07777a6
to
f27f287
Compare
This is the bare minimum to get the site working - we'll need to investigate further to see what else might be needed.