-
Notifications
You must be signed in to change notification settings - Fork 0
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
1 parent
a79149f
commit 6764893
Showing
2 changed files
with
138 additions
and
87 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,97 +1,147 @@ | ||
{% macro generate_office_subtitle(state, office_name, election_scope, district_type, district, school_district, hospital_district, seat, county, municipality) %} | ||
|
||
concat( | ||
CASE WHEN state, | ||
' - ', | ||
office_name, | ||
' - ', | ||
CASE WHEN county is not null THEN concat(county,' County - ') END, | ||
CASE WHEN district is not null THEN concat(district,' - ') END, | ||
CASE | ||
WHEN seat is NULL THEN '' | ||
WHEN seat ILIKE 'At Large' THEN concat(seat,' - ') | ||
ELSE concat(seat,' - ') | ||
END, | ||
CASE WHEN is_special_election = TRUE THEN 'Special Election - ' ELSE '' END, | ||
CASE | ||
WHEN race_type = 'primary' THEN concat( | ||
'Primary - ', party | ||
) | ||
WHEN race_type = 'general' THEN 'General' | ||
ELSE '' END, | ||
' - ', | ||
'2024' -- TODO: Update this to be dynamic | ||
) AS title, | ||
|
||
|
||
|
||
|
||
|
||
|
||
|
||
CASE -- test election_scope | ||
WHEN {{ election_scope }} = 'state' THEN | ||
CASE | ||
WHEN {{ office_name }} = 'U.S. Senate' OR ({{ district }} IS null AND {{ seat }} IS null) THEN | ||
-- use full state name when there is no district or seat, or if U.S. Senate | ||
SELECT name FROM us_states WHERE code ILIKE {{ state }} | ||
-- 'Minnesota' | ||
WHEN {{ seat }} ILIKE '%At Large%' THEN | ||
concat({{ state }}, ' - ', {{ seat }}) | ||
ELSE | ||
concat({{ state }}, ' - Seat ', {{ seat }}) | ||
END | ||
WHEN {{ election_scope }} = 'county' THEN | ||
CASE | ||
WHEN {{ district }} IS null THEN | ||
concat({{ county }}, ' County, ', {{ state }}) | ||
ELSE | ||
concat({{ county }}, ' County, ', {{ state }}, ' - District ', {{ district }}) | ||
END | ||
WHEN {{ election_scope }} = 'city' THEN | ||
CASE -- this list of municipalities have dupes so must add the county | ||
WHEN {{ municipality }} IN ('Beaver Township', 'Becker Township', 'Clover Township', | ||
'Cornish Township', 'Fairview Township', 'Hillman Township', | ||
'Lawrence Township', 'Long Lake Township', 'Louisville Township', | ||
'Moose Lake Township', 'Stokes Township', 'Twin Lakes Township') THEN | ||
concat( | ||
{{ municipality }}, | ||
' - ', | ||
{{ county }}, | ||
' County, ', | ||
{{ state }}, | ||
CASE | ||
WHEN {{ seat }} IS null THEN '' | ||
WHEN {{ seat }} ILIKE '%At Large%' THEN ' - ' || {{ seat }} | ||
ELSE ' - Seat ' || {{ seat }} | ||
END | ||
) | ||
ELSE | ||
concat( | ||
{{ municipality }}, | ||
', ', | ||
{{ state }}, | ||
CASE | ||
WHEN {{ seat }} IS null THEN '' | ||
WHEN {{ seat }} ILIKE '%At Large%' THEN ' - ' || {{ seat }} | ||
ELSE ' - Seat ' || {{ seat }} | ||
END | ||
) | ||
END | ||
WHEN {{ election_scope }} = 'district' THEN | ||
CASE -- test district_types | ||
WHEN {{ district_type }} = 'us_congressional' THEN concat({{ state }}, ' - District ', {{ district }}) | ||
WHEN {{ district_type }} = 'state_house' THEN concat({{ state }}, ' - House District ', {{ district }}) | ||
WHEN {{ district_type }} = 'state_senate' THEN concat({{ state }}, ' - Senate District ', {{ district }}) | ||
WHEN {{ district_type }} = 'county' THEN concat({{ county }}, ' County, ', {{ state }}, ' - District ', {{ district }}) | ||
|
||
WHEN {{ district_type }} = 'city' THEN | ||
CASE -- any numbers mean add 'District' before it, otherwise add whatever is in District (no offices with seats here) | ||
WHEN {{ district }} ~ '^\d+$' THEN concat({{ municipality }}, ', ', {{ state }}, ' - District ', {{ district }}) | ||
ELSE concat({{ municipality }}, ', ', {{ state }}, ' - ', {{ district }}) | ||
END | ||
|
||
WHEN {{ district_type }} = 'school' THEN | ||
CASE -- tests if District exists, and then tests if Seat exists for each case | ||
WHEN {{ district }} IS null THEN | ||
-- e.g. "MN - ISD #508 - At Large" | ||
concat( | ||
{{ state }}, | ||
' - ', | ||
{{ school_district }}, | ||
CASE | ||
WHEN {{ seat }} IS null THEN '' | ||
WHEN {{ seat }} ILIKE '%At Large%' THEN ' - ' || {{ seat }} | ||
ELSE ' - Seat ' || {{ seat }} | ||
END | ||
) | ||
WHEN {{ district }} ~ '^\d+$' THEN | ||
-- e.g. "MN - ISD #709 - District 3" | ||
concat( | ||
{{ state }}, | ||
' - ', | ||
{{ school_district }}, | ||
' - District ', | ||
{{ district }}, | ||
CASE | ||
WHEN {{ seat }} IS null THEN '' | ||
WHEN {{ seat }} ILIKE '%At Large%' THEN ' - ' || {{ seat }} | ||
ELSE ' - Seat ' || {{ seat }} | ||
END | ||
) | ||
ELSE | ||
-- e.g. "MN - ISD #2365 - Gibbon District" | ||
concat( | ||
{{ state }}, | ||
' - ', | ||
{{ school_district }}, | ||
' - ', | ||
{{ district }}, | ||
CASE | ||
WHEN {{ seat }} IS null THEN '' | ||
WHEN {{ seat }} ILIKE '%At Large%' THEN ' - ' || {{ seat }} | ||
ELSE ' - Seat ' || {{ seat }} | ||
END | ||
) | ||
END | ||
|
||
WHEN {{ district_type }} = 'judicial' THEN concat({{ state }}, ' - Seat ', {{ seat }}) | ||
|
||
DECLARE @subtitle AS TEXT = '' | ||
WHEN {{ district_type }} = 'hospital' THEN | ||
CASE | ||
WHEN {{ district }} IS null THEN | ||
-- e.g. "Canby Community - At Large" | ||
concat( | ||
{{ hospital_district }}, | ||
CASE | ||
WHEN {{ seat }} IS null THEN '' | ||
WHEN {{ seat }} ILIKE '%At Large%' THEN ' - ' || {{ seat }} | ||
ELSE ' - Seat ' || {{ seat }} | ||
END | ||
) | ||
WHEN {{ district }} ~ '^\d+$' THEN | ||
-- e.g. "Cook County - District 1" | ||
concat( | ||
{{ hospital_district }}, | ||
' - District ', | ||
{{ district }}, | ||
CASE | ||
WHEN {{ seat }} IS null THEN '' | ||
WHEN {{ seat }} ILIKE '%At Large%' THEN ' - ' || {{ seat }} | ||
ELSE ' - Seat ' || {{ seat }} | ||
END | ||
) | ||
END | ||
|
||
CASE -- test election_scope | ||
-- state | ||
WHEN {{ election_scope }} = 'state' | ||
THEN | ||
CASE | ||
WHEN {{ district }} is null AND {{ seat }} is null -- ignore for U.S. Senate, seat is used for Class | ||
THEN | ||
concat(@subtitle, 'Minnesota') -- use full state name | ||
WHEN {{ district_type }} = 'soil_and_water' THEN concat({{ county }}, ' County, ', {{ state }}, ' - District ', {{ district }}) | ||
|
||
ELSE | ||
CASE | ||
WHEN {{ district }} = number | ||
THEN | ||
concat(@subtitle, ) | ||
-- if (district and seat = null then use full state name | ||
-- else use two letter abbreviation of state | ||
-- if district is just a number add 'District' before | ||
-- if name is State House add 'House District' before | ||
-- if name is State Senate add 'Senate District' before | ||
-- districts and seats | ||
-- hospital district, judges, justices, school board | ||
-- maybe city council | ||
concat({{ state }}, ' - ', {{ district }}, ' ', {{ seat }})) | ||
-- county | ||
WHEN {{ election_scope }} = 'county' | ||
THEN | ||
slugify(concat('mn', ' ', REPLACE({{ office_name }},'&','and'), ' ', {{ county }}, ' county ', {{ district }}, ' ', {{ seat }} )) | ||
-- city | ||
WHEN {{ election_scope }} = 'city' | ||
THEN | ||
slugify(concat('mn', ' ', REPLACE({{ office_name }},'&','and'), ' ', REPLACE({{ municipality }},'Township','Twp'), ' ', {{ county }}, ' county ', {{ school_district }}, ' ', {{ district }}, ' ', {{ seat }} )) | ||
-- district | ||
WHEN {{ election_scope }} = 'district' | ||
THEN | ||
CASE -- test district_types | ||
WHEN {{ district_type }} = 'county' | ||
THEN | ||
slugify(concat('mn', ' ', {{ office_name }}, ' ', {{ county }}, ' county ', {{ district }}, ' ', {{ seat }} )) | ||
WHEN {{ district_type }} = 'city' | ||
THEN | ||
slugify(concat('mn', ' ', REPLACE({{ office_name }},'&','and'), ' ', REPLACE({{ municipality }},'Township','Twp'), ' ', {{ county }}, ' county ', {{ district }}, ' ', {{ seat }} )) | ||
WHEN {{ district_type }} = 'school' | ||
THEN | ||
slugify(concat('mn', ' ', {{ office_name }}, ' ', {{ school_district }}, ' ', {{ district }}, ' ', {{ seat }} )) | ||
WHEN {{ district_type }} = 'judicial' | ||
THEN | ||
slugify(concat('mn', ' ', {{ office_name }}, ' ', {{ district }}, ' ', {{ seat }} )) | ||
WHEN {{ district_type }} = 'hospital' | ||
THEN | ||
slugify(concat('mn', ' ', {{ office_name }}, ' ', hospital_district, ' ',{{ district }}, ' ', {{ seat }} )) | ||
WHEN {{ district_type }} = 'soil_and_water' | ||
THEN | ||
slugify(concat('mn', ' ', {{ office_name }}, ' ', {{ county }}, ' county ', {{ district }}, ' ', {{ seat }} )) | ||
ELSE -- us_congressional, state_house, state_senate | ||
slugify(concat('mn', ' ', {{ office_name }}, ' ', {{ district }}, ' ', {{ seat }} )) | ||
null | ||
END | ||
ELSE -- national | ||
'' | ||
END | ||
|
||
ELSE -- national | ||
null | ||
END | ||
|
||
{% endmacro %} |
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