-
Notifications
You must be signed in to change notification settings - Fork 0
Generic boundary changes #53
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
Changes from all commits
3fe54f4
7f1de6b
44fdedf
61f7a85
d7218fa
7128088
321f1bd
a596705
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -55,7 +55,22 @@ def export_sql(): | |
| JOIN organisations_organisation o ON o.id = obr.organisation_id | ||
| JOIN organisations_organisationgeography og ON og.organisation_id = o.id | ||
| WHERE | ||
| obr.id IN (963, 964) | ||
| obr.public_visibility != 'HIDDEN' | ||
| AND NOT EXISTS ( | ||
| SELECT | ||
| e.election_id | ||
| FROM | ||
| elections_election e | ||
| WHERE | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Do we want reviews to be taken out of the csv once they're a certain age. This only get's rid of them if there's a new poll.
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I've updated this filtering in fc851f5 It's now: AND NOT EXISTS (
SELECT
e.election_id
FROM
elections_election e
WHERE
e.current_status = 'Approved'
AND e.current IS NOT TRUE
AND e.organisation_id = o.id
AND e.poll_open_date >= obr.effective_date
AND e.poll_open_date <= CURRENT_DATE - INTERVAL '20 days'
LIMIT
1
)This means we exclude a boundary review if it's organisation has a non-current, approved election with a polling day that is on or after the effective date and the polling day at least 20 days ago. So it should get rid of them as elections age basically. |
||
| e.current_status = 'Approved' | ||
| AND NOT e.cancelled | ||
| AND e.current IS NOT TRUE | ||
| AND e.organisation_id = o.id | ||
| AND e.poll_open_date >= obr.effective_date | ||
| AND e.poll_open_date <= CURRENT_DATE - INTERVAL '20 days' | ||
| LIMIT | ||
| 1 | ||
| ) | ||
| ) | ||
| SELECT | ||
| r.slug, | ||
|
|
@@ -75,6 +90,25 @@ def export_sql(): | |
| d.name AS division_name, | ||
| d.official_identifier AS division_official_identifier, | ||
| st_astext (dgs.geography) AS division_boundary_wkt, | ||
| CASE | ||
| WHEN ds.id = r.old_divisionset_id THEN NULL | ||
| WHEN ds.id = r.new_divisionset_id THEN COALESCE( | ||
| ( | ||
| SELECT | ||
| json_agg(e.election_id)::text | ||
| FROM | ||
| elections_election AS e | ||
| WHERE | ||
| e.current_status = 'Approved' | ||
| AND not e.cancelled | ||
| AND e.division_id = d.id | ||
| AND d.divisionset_id = r.new_divisionset_id | ||
| AND e.poll_open_date = r.effective_date | ||
| ), | ||
| '[]' | ||
| ) | ||
| ELSE NULL | ||
| END AS division_related_ballots, | ||
|
Comment on lines
+93
to
+111
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I'm ignoring the old divisions here because the relevant ballots will only be made with the new divisions. I'm also unsure if regex matching the division names to the ballots is the best/most efficient way to do this or if there is a better optimized way.
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I'm more concerned about accuracy than efficiency here. To give a real-word example Also If we're going to do string matching, we need to be more robust about it
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. So I was wondering about this too. But I think what Chris is suggesting is probably better. There will be issues for elections which don't have a
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. So I've re-rewritten this case statement as: CASE
WHEN ds.id = r.old_divisionset_id THEN NULL
WHEN ds.id = r.new_divisionset_id THEN COALESCE(
(
SELECT
json_agg(e.election_id)::text
FROM
elections_election AS e
WHERE
e.division_id = d.id
AND d.divisionset_id = r.new_divisionset_id
AND e.poll_open_date = r.effective_date
),
'[]'
)
ELSE NULL
END AS division_related_ballots,Doing it like this has also let me remove the Sorry if this is an obvious one - I've possibly been thinking too hard about this.
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I thought the answer was 'no'. Our database doesn't entirely agree, but I think these might be errors. However the query I used probably shows some extra bits you want for the
To see if there were any cases where there were multiple ballots for a single division I did this: SELECT e1.election_id, e1.group_type, e2.election_id, e2.group_type
FROM
elections_election e1 JOIN elections_election e2
ON e1.division_id=e2.division_id
AND e1.poll_open_date = e2.poll_open_date
AND e1.election_id != e2.election_id
WHERE e1.group_type IS NULL
AND e2.group_type IS NULL
AND NOT e1.cancelled
AND NOT e2.cancelled
AND e1.current_status = 'Approved'
AND e2.current_status = 'Approved';Which I think is right. With the duplicates manually removed it gives: I'm curious why these are all in Castle Point and twice in St. Georges. Have I done something stupid in the query?
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. thanks I've got Your query looks good to me. Very weird about castle point, maybe one to check with Peter?
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Just to put the discussion we had about this yesterday down in text: A division can have more than one election on the same day |
||
| r.boundary_review_id, | ||
| CASE | ||
| WHEN ds.id = r.old_divisionset_id THEN 'old' | ||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -116,6 +116,7 @@ | |
| "division_name": glue.Schema.STRING, | ||
| "division_official_identifier": glue.Schema.STRING, | ||
| "division_boundary_wkt": glue.Schema.STRING, | ||
| "division_related_ballots": glue.Schema.STRING, | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. In aggregator api I called the field |
||
| }, | ||
| partition_keys=[ | ||
| glue.Column( | ||
|
|
||
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.
Is this the right way round?
Would
obr.public_visibility = 'MAP'be better?This might have to be updated to
obr.public_visibility IN ( 'MAP', 'NEW_VALUE'), but I guess that's better than having something come through unintentionally?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.
I sort of assumed that we'd want to include any potential future value that is not HIDDEN, and since we have to manually set the values on the records in EE anyway, we're avoid having a review pulled through before the data baker layer is ready or whatever. But maybe it's better to be explicit?