Skip to content
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

Merged
merged 7 commits into from
Jun 4, 2024

Conversation

pixeltrix
Copy link
Contributor

This is the bare minimum to get the site working - we'll need to investigate further to see what else might be needed.

pixeltrix added 7 commits June 3, 2024 07:16
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.
Comment on lines 68 to 71
def between(start_date, end_date)
where(start_date: ..start_date, end_date: (end_date ? ..end_date : nil))
end

Copy link
Contributor

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?

Copy link
Contributor Author

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.

@pixeltrix pixeltrix force-pushed the update-for-new-constituencies branch from 07777a6 to f27f287 Compare June 4, 2024 08:25
@pixeltrix pixeltrix merged commit 956a853 into master Jun 4, 2024
12 checks passed
@pixeltrix pixeltrix deleted the update-for-new-constituencies branch June 4, 2024 08:41
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants