Skip to content

Commit

Permalink
feat: CEEB Export Scripts and Export Merge Tool (#832)
Browse files Browse the repository at this point in the history
Co-authored-by: jon-funk <johnthomasfunk@gmail.com>
Co-authored-by: Derek Roberts <derek.roberts@gmail.com>
Co-authored-by: Ryan Rondeau <nayr974@users.noreply.github.com>
Co-authored-by: Scarlett <35635257+Scarlett-Truong@users.noreply.github.com>
Co-authored-by: dmitri-korin-bcps <108112696+dmitri-korin-bcps@users.noreply.github.com>
  • Loading branch information
6 people authored Dec 24, 2024
1 parent c1fc16e commit 89e016b
Show file tree
Hide file tree
Showing 2 changed files with 90 additions and 0 deletions.
56 changes: 56 additions & 0 deletions exports/ceeb_complaint_export.sql
Original file line number Diff line number Diff line change
@@ -0,0 +1,56 @@
-----------------------------------------------------
-- Quarterly CEEB Complaint Export query to be run for CEEB statistics
-- see https://github.com/bcgov/nr-compliance-enforcement/wiki/Data-Exports for more information
--
-- Note some extra fields are commented out of the query as these are currently part of the
-- NRIS export however they are not currently being used for reporting
-----------------------------------------------------
select
cmp.complaint_identifier as "Record ID",
TO_CHAR(((cmp.incident_reported_utc_timestmp at time zone 'UTC') at time zone 'PDT'), 'MM/DD/YYYY') as "Date Received",
CASE
WHEN cst.short_description = 'Open' THEN 'Incomplete'
WHEN cst.short_description = 'Pending Review' THEN 'Incomplete'
WHEN cst.short_description = 'Closed' THEN 'Complete'
ELSE cst.short_description
END as "Complaint Status",
cmrc.long_description as "Method Received",
--'IDIR\' || ofc.user_id as "Officer Assigned",
gfv.region_name as "Region",
--gfv.offloc_name as "Office",
goc.short_description as "City/Town",
--cmp.caller_name as "Complainant Contact",
--CASE
-- WHEN cmp.is_privacy_requested = 'Y' THEN 'Yes'
-- ELSE 'No'
--END as "Privacy Requested",
--cmp.caller_email as "Email",
--cmp.caller_phone_1 as "Telephone No.",
--cmp.location_summary_text as "Facility/Site Location",
--ST_Y(cmp.location_geometry_point) as "Latitude",
--ST_X(cmp.location_geometry_point) as "Longitude",
ac.suspect_witnesss_dtl_text as "Alleged Contravener"
from
complaint cmp
join
complaint_status_code cst on cst.complaint_status_code = cmp.complaint_status_code
join
geo_organization_unit_code goc on goc.geo_organization_unit_code = cmp.geo_organization_unit_code
join
cos_geo_org_unit_flat_vw gfv on gfv.area_code = goc.geo_organization_unit_code
left join
comp_mthd_recv_cd_agcy_cd_xref cmrcacx on cmrcacx.comp_mthd_recv_cd_agcy_cd_xref_guid = cmp.comp_mthd_recv_cd_agcy_cd_xref_guid
left join
complaint_method_received_code cmrc on cmrc.complaint_method_received_code = cmrcacx.complaint_method_received_code
left join
person_complaint_xref pcx on pcx.complaint_identifier = cmp.complaint_identifier and pcx.active_ind = true
left join
person per on per.person_guid = pcx.person_guid
left join
officer ofc on ofc.person_guid = per.person_guid
right join
allegation_complaint ac on ac.complaint_identifier = cmp.complaint_identifier
where
cmp.incident_reported_utc_timestmp >= CURRENT_DATE - INTERVAL '1 year'
order by
cmp.complaint_identifier asc
34 changes: 34 additions & 0 deletions exports/merge_exports.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
# This script merges two CSV files based on the 'Record ID' column.
# Setup Instructions:
# 1. Ensure Python is installed and added to your system PATH.
# 2. Add the 'Scripts' directory from the Python installation to the PATH (for pip).
# 3. Install required packages by running: pip install pandas
# 4. Place 'complaints.csv' and 'cases.csv' in the same folder as this script.
# 5. Run the script using: python merge_exports.py

import pandas as pd

def main():
# Define filenames
complaint_file = "complaints.csv"
case_file = "cases.csv"
output_file = "NatCom_Export.csv"
merge_column = "Record ID" # CEEB = "Record ID" COS = "Complaint Identifier"

try:
# Load data from both files
complaint_df = pd.read_csv(complaint_file)
case_df = pd.read_csv(case_file)

# Merge data on 'Record ID' with validation
combined_df = pd.merge(complaint_df, case_df, on=merge_column, how="outer", validate="many_to_many")

# Save the merged data to a new CSV file
combined_df.to_csv(output_file, index=False, encoding='utf-8-sig')
print(f"Data successfully merged into {output_file}")

except FileNotFoundError as e:
print(f"Error: {e}\nPlease ensure both files exist in the correct directory.")

if __name__ == "__main__":
main()

0 comments on commit 89e016b

Please sign in to comment.