Skip to content

Commit

Permalink
Allow blank values for choice fields, fix some bad field aliasing
Browse files Browse the repository at this point in the history
  • Loading branch information
gordonje committed Dec 2, 2016
1 parent 409744d commit 4398572
Show file tree
Hide file tree
Showing 9 changed files with 232 additions and 182 deletions.
8 changes: 4 additions & 4 deletions calaccess_processed/sql/load_form460scheduleditem_model.sql
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ INSERT INTO calaccess_processed_form460scheduleditem (
check_number,
transaction_id,
memo_reference_number,
office_sought_held,
support_oppose_code,
ballot_measure_jurisdiction,
ballot_measure_name,
ballot_measure_num,
Expand All @@ -39,7 +39,7 @@ INSERT INTO calaccess_processed_form460scheduleditem (
candidate_name_suffix,
office_code,
office_description,
support_oppose_code
office_sought_held
)
SELECT
filing.filing_id,
Expand Down Expand Up @@ -69,7 +69,7 @@ SELECT
item_version.check_number,
item_version.transaction_id,
item_version.memo_reference_number,
item_version.office_sought_held,
item_version.support_oppose_code,
item_version.ballot_measure_jurisdiction,
item_version.ballot_measure_name,
item_version.ballot_measure_num,
Expand All @@ -82,7 +82,7 @@ SELECT
item_version.candidate_name_suffix,
item_version.office_code,
item_version.office_description,
item_version.support_oppose_code
item_version.office_sought_held
FROM calaccess_processed_form460filing filing
JOIN calaccess_processed_form460filingversion filing_version
ON filing.filing_id = filing_version.filing_id
Expand Down
94 changes: 53 additions & 41 deletions calaccess_processed/sql/load_form460scheduleditemversion_model.sql
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ INSERT INTO calaccess_processed_form460scheduleditemversion (
check_number,
transaction_id,
memo_reference_number,
office_sought_held,
support_oppose_code,
ballot_measure_jurisdiction,
ballot_measure_name,
ballot_measure_num,
Expand All @@ -39,7 +39,7 @@ INSERT INTO calaccess_processed_form460scheduleditemversion (
candidate_name_suffix,
office_code,
office_description,
support_oppose_code
office_sought_held
)
SELECT
filing_version.id AS filing_version_id,
Expand All @@ -55,7 +55,8 @@ SELECT
'OTH',
'PTY',
'RCP',
'SCC'
'SCC',
''
) THEN UPPER(expn."ENTITY_CD")
ELSE '???'
END AS payee_code,
Expand Down Expand Up @@ -118,7 +119,8 @@ SELECT
'TRS',
'TSF',
'VOT',
'WEB'
'WEB',
''
) THEN UPPER(expn."EXPN_CODE")
ELSE '???'
END AS payment_code,
Expand All @@ -130,7 +132,14 @@ SELECT
expn."EXPN_CHKNO" AS check_number,
expn."TRAN_ID" AS transaction_id,
expn."MEMO_REFNO" AS memo_reference_number,
UPPER(expn."SUP_OPP_CD") AS office_sought_held,
CASE
WHEN UPPER(expn."SUP_OPP_CD") IN (
'S',
'O',
''
) THEN UPPER(expn."SUP_OPP_CD")
ELSE '?'
END AS support_oppose_code,
UPPER(expn."BAL_JURIS") AS ballot_measure_jurisdiction,
UPPER(expn."BAL_NAME") AS ballot_measure_name,
UPPER(expn."BAL_NUM") AS ballot_measure_num,
Expand All @@ -144,7 +153,8 @@ SELECT
'LOC',
'OTH',
'SEN',
'STW'
'STW',
''
) THEN UPPER(expn."JURIS_CD")
ELSE '???'
END AS candidate_jurisdiction_code,
Expand All @@ -155,37 +165,38 @@ SELECT
UPPER(expn."CAND_NAMS") AS candidate_name_suffix,
CASE
WHEN UPPER(expn."OFFICE_CD") IN (
'APP'
'ASM'
'ASR'
'ATT'
'BED'
'BOE'
'BSU'
'CAT'
'CCB'
'CCM'
'CON'
'COU'
'CSU'
'CTR'
'DAT'
'GOV'
'INS'
'LTG'
'MAY'
'OTH'
'PDR'
'PER'
'PLN'
'SCJ'
'SEN'
'SHC'
'SOS'
'SPM'
'SUP'
'TRE'
'TRS'
'APP',
'ASM',
'ASR',
'ATT',
'BED',
'BOE',
'BSU',
'CAT',
'CCB',
'CCM',
'CON',
'COU',
'CSU',
'CTR',
'DAT',
'GOV',
'INS',
'LTG',
'MAY',
'OTH',
'PDR',
'PER',
'PLN',
'SCJ',
'SEN',
'SHC',
'SOS',
'SPM',
'SUP',
'TRE',
'TRS',
''
) THEN UPPER(expn."OFFICE_CD")
WHEN UPPER(expn."OFFICE_CD") = 'LEG' THEN 'ASM'
WHEN UPPER(expn."OFFICE_CD") = 'OF' THEN 'ASM'
Expand All @@ -195,12 +206,13 @@ SELECT
END AS office_code,
UPPER(expn."OFFIC_DSCR") AS office_description,
CASE
WHEN UPPER(expn."OFFIC_DSCR") IN (
WHEN UPPER(expn."OFF_S_H_CD") IN (
'S',
'H'
) THEN UPPER(expn."OFFIC_DSCR")
'H',
''
) THEN UPPER(expn."OFF_S_H_CD")
ELSE '?'
END AS support_oppose_code
END AS office_sought_held
FROM "EXPN_CD" expn
JOIN calaccess_processed_form460filingversion filing_version
ON expn."FILING_ID" = filing_version.filing_id
Expand Down
8 changes: 4 additions & 4 deletions calaccess_processed/sql/load_form460scheduleeitem_model.sql
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ INSERT INTO calaccess_processed_form460scheduleeitem (
check_number,
transaction_id,
memo_reference_number,
office_sought_held,
support_oppose_code,
ballot_measure_jurisdiction,
ballot_measure_name,
ballot_measure_num,
Expand All @@ -38,7 +38,7 @@ INSERT INTO calaccess_processed_form460scheduleeitem (
candidate_name_suffix,
office_code,
office_description,
support_oppose_code
office_sought_held
)
SELECT
filing.filing_id,
Expand Down Expand Up @@ -67,7 +67,7 @@ SELECT
item_version.check_number,
item_version.transaction_id,
item_version.memo_reference_number,
item_version.office_sought_held,
item_version.support_oppose_code,
item_version.ballot_measure_jurisdiction,
item_version.ballot_measure_name,
item_version.ballot_measure_num,
Expand All @@ -80,7 +80,7 @@ SELECT
item_version.candidate_name_suffix,
item_version.office_code,
item_version.office_description,
item_version.support_oppose_code
item_version.office_sought_held
FROM calaccess_processed_form460filing filing
JOIN calaccess_processed_form460filingversion filing_version
ON filing.filing_id = filing_version.filing_id
Expand Down
94 changes: 53 additions & 41 deletions calaccess_processed/sql/load_form460scheduleeitemversion_model.sql
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ INSERT INTO calaccess_processed_form460scheduleeitemversion (
check_number,
transaction_id,
memo_reference_number,
office_sought_held,
support_oppose_code,
ballot_measure_jurisdiction,
ballot_measure_name,
ballot_measure_num,
Expand All @@ -38,7 +38,7 @@ INSERT INTO calaccess_processed_form460scheduleeitemversion (
candidate_name_suffix,
office_code,
office_description,
support_oppose_code
office_sought_held
)
SELECT
filing_version.id AS filing_version_id,
Expand All @@ -54,7 +54,8 @@ SELECT
'OTH',
'PTY',
'RCP',
'SCC'
'SCC',
''
) THEN UPPER(expn."ENTITY_CD")
ELSE '???'
END AS payee_code,
Expand Down Expand Up @@ -117,7 +118,8 @@ SELECT
'TRS',
'TSF',
'VOT',
'WEB'
'WEB',
''
) THEN UPPER(expn."EXPN_CODE")
ELSE '???'
END AS payment_code,
Expand All @@ -128,7 +130,14 @@ SELECT
expn."EXPN_CHKNO" AS check_number,
expn."TRAN_ID" AS transaction_id,
expn."MEMO_REFNO" AS memo_reference_number,
UPPER(expn."SUP_OPP_CD") AS office_sought_held,
CASE
WHEN UPPER(expn."SUP_OPP_CD") IN (
'S',
'O',
''
) THEN UPPER(expn."SUP_OPP_CD")
ELSE '?'
END AS support_oppose_code,
UPPER(expn."BAL_JURIS") AS ballot_measure_jurisdiction,
UPPER(expn."BAL_NAME") AS ballot_measure_name,
UPPER(expn."BAL_NUM") AS ballot_measure_num,
Expand All @@ -142,7 +151,8 @@ SELECT
'LOC',
'OTH',
'SEN',
'STW'
'STW',
''
) THEN UPPER(expn."JURIS_CD")
ELSE '???'
END AS candidate_jurisdiction_code,
Expand All @@ -153,37 +163,38 @@ SELECT
UPPER(expn."CAND_NAMS") AS candidate_name_suffix,
CASE
WHEN UPPER(expn."OFFICE_CD") IN (
'APP'
'ASM'
'ASR'
'ATT'
'BED'
'BOE'
'BSU'
'CAT'
'CCB'
'CCM'
'CON'
'COU'
'CSU'
'CTR'
'DAT'
'GOV'
'INS'
'LTG'
'MAY'
'OTH'
'PDR'
'PER'
'PLN'
'SCJ'
'SEN'
'SHC'
'SOS'
'SPM'
'SUP'
'TRE'
'TRS'
'APP',
'ASM',
'ASR',
'ATT',
'BED',
'BOE',
'BSU',
'CAT',
'CCB',
'CCM',
'CON',
'COU',
'CSU',
'CTR',
'DAT',
'GOV',
'INS',
'LTG',
'MAY',
'OTH',
'PDR',
'PER',
'PLN',
'SCJ',
'SEN',
'SHC',
'SOS',
'SPM',
'SUP',
'TRE',
'TRS',
''
) THEN UPPER(expn."OFFICE_CD")
WHEN UPPER(expn."OFFICE_CD") = 'LEG' THEN 'ASM'
WHEN UPPER(expn."OFFICE_CD") = 'OF' THEN 'ASM'
Expand All @@ -193,12 +204,13 @@ SELECT
END AS office_code,
UPPER(expn."OFFIC_DSCR") AS office_description,
CASE
WHEN UPPER(expn."OFFIC_DSCR") IN (
WHEN UPPER(expn."OFF_S_H_CD") IN (
'S',
'H'
) THEN UPPER(expn."OFFIC_DSCR")
'H',
''
) THEN UPPER(expn."OFF_S_H_CD")
ELSE '?'
END AS support_oppose_code
END AS office_sought_held
FROM "EXPN_CD" expn
JOIN calaccess_processed_form460filingversion filing_version
ON expn."FILING_ID" = filing_version.filing_id
Expand Down
Loading

0 comments on commit 4398572

Please sign in to comment.