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

Adds NIBRS Endpoints for Regions #699

Open
wants to merge 5 commits into
base: master
Choose a base branch
from
Open
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
Fix to Region NIBRS MV Scripts
Jacob Wentz committed Feb 28, 2018
commit f7d8c33a610ba595b7f4bc1812f6e4756c8d10c4
61 changes: 0 additions & 61 deletions dba/create_new/offender_nibrs_rollup_mv.sql
Original file line number Diff line number Diff line change
@@ -174,67 +174,6 @@ coalesce(sum(case when age_range = '90-99' then count end), 0) as range_90_99,
coalesce(sum(case when age_range = 'UNKNOWN' then count end), 0) as unknown
from public.nibrs_offender_count group by agency_id, ori, offense_name, data_year;

CREATE MATERIALIZED VIEW nibrs_region_denorm_offender_sex AS
select region_code as region_code,
region_name as region_name,
offense_name as offense_name,
data_year as data_year,
coalesce(sum(case when sex_code = 'M' then count end), 0) as male_count,
coalesce(sum(case when sex_code = 'F' then count end), 0) as female_count,
coalesce(sum(case when sex_code = 'U' then count end), 0) as unknown_count
from public.nibrs_offender_count group by region_code, region_name, offense_name, data_year;

CREATE MATERIALIZED VIEW nibrs_region_denorm_offender_count AS
select region_code as region_code,
region_name as region_name,
offense_name as offense_name,
data_year as data_year,
sum(count) as count
from public.nibrs_offender_count group by region_code, region_name, offense_name, data_year;

CREATE MATERIALIZED VIEW nibrs_region_denorm_offender_race AS
select region_code as region_code,
region_name as region_name,
offense_name as offense_name,
data_year as data_year,
coalesce(sum(case when race_desc = 'Asian' then count end), 0) as asian,
coalesce(sum(case when race_desc = 'Native Hawaiian or Pacific Islander' then count end), 0) as native_hawaiian,
coalesce(sum(case when race_desc = 'Black or African American' then count end), 0) as black,
coalesce(sum(case when race_desc = 'American Indian or Alaska Native' then count end), 0) as american_indian,
coalesce(sum(case when race_desc = 'Unknown' then count end), 0) as unknown,
coalesce(sum(case when race_desc = 'White' then count end), 0) as white
from public.nibrs_offender_count group by region_code, region_name, offense_name, data_year;

CREATE MATERIALIZED VIEW nibrs_region_denorm_offender_ethnicity AS
select region_code as region_code,
region_name as region_name,
offense_name as offense_name,
data_year as data_year,
coalesce(sum(case when ethnicity_name = 'Hispanic or Latino' then count end), 0) as hispanic,
coalesce(sum(case when ethnicity_name = 'Multiple' then count end), 0) as multiple,
coalesce(sum(case when ethnicity_name = 'Not Hispanic or Latino' then count end), 0) as not_Hispanic,
coalesce(sum(case when ethnicity_name = 'Unknown' then count end), 0) as unknown
from public.nibrs_offender_count group by region_code, region_name, offense_name, data_year;

CREATE MATERIALIZED VIEW nibrs_region_denorm_offender_age AS
select region_code as region_code,
region_name as region_name,
offense_name as offense_name,
data_year as data_year,
coalesce(sum(case when age_range = '0-9' then count end), 0) as range_0_9,
coalesce(sum(case when age_range = '10-19' then count end), 0) as range_10_19,
coalesce(sum(case when age_range = '20-29' then count end), 0) as range_20_29,
coalesce(sum(case when age_range = '30-39' then count end), 0) as range_30_39,
coalesce(sum(case when age_range = '40-49' then count end), 0) as range_40_49,
coalesce(sum(case when age_range = '50-59' then count end), 0) as range_50_59,
coalesce(sum(case when age_range = '60-69' then count end), 0) as range_60_69,
coalesce(sum(case when age_range = '70-79' then count end), 0) as range_70_79,
coalesce(sum(case when age_range = '80-89' then count end), 0) as range_80_89,
coalesce(sum(case when age_range = '90-99' then count end), 0) as range_90_99,
coalesce(sum(case when age_range = 'UNKNOWN' then count end), 0) as unknown
from public.nibrs_offender_count group by region_code, region_name, offense_name, data_year;


--Region
CREATE MATERIALIZED VIEW nibrs_region_denorm_offender_sex AS
select s.region_code as region_code,
56 changes: 28 additions & 28 deletions dba/create_new/victim_offender_relationship_mv.sql
Original file line number Diff line number Diff line change
@@ -70,35 +70,35 @@ select s.region_code as region_code,
r.region_name as region_name,
n.offense_name as offense_name,
n.data_year as data_year,
coalesce(sum(case when n.relationship = 'Victim Was Acquaintance' then count end), 0) as acquaintance,
coalesce(sum(case when n.relationship = 'Victim Was Babysittee' then count end), 0) as babysittee,
coalesce(sum(case when n.relationship = 'Victim Was Boyfriend/Girlfriend' then count end), 0) as boyfriend_girlfriend,
coalesce(sum(case when n.relationship = 'Victim Was Child of Boyfriend or Girlfriend' then count end), 0) as child_boyfriend_girlfriend,
coalesce(sum(case when n.relationship = 'Victim Was Child' then count end), 0) as child,
coalesce(sum(case when n.relationship = 'Victim Was Common-Law Spouse' then count end), 0) as common_law_spouse,
coalesce(sum(case when n.relationship = 'Victim was Employee' then count end), 0) as employee,
coalesce(sum(case when n.relationship = 'Victim was Employer' then count end), 0) as employer,
coalesce(sum(case when n.relationship = 'Victim Was Friend' then count end), 0) as friend,
coalesce(sum(case when n.relationship = 'Victim Was Grandchild' then count end), 0) as grandchild,
coalesce(sum(case when n.relationship = 'Victim Was Grandparent' then count end), 0) as grandparent,
coalesce(sum(case when n.relationship = 'Homosexual Relationship' then count end), 0) as homosexual_relationship,
coalesce(sum(case when n.relationship = 'Victim Was In-law' then count end), 0) as in_law,
coalesce(sum(case when n.relationship = 'Victim Was Neighbor' then count end), 0) as neighbor,
coalesce(sum(case when n.relationship = 'Victim Was Other Family Member' then count end), 0) as other_family_member,
coalesce(sum(case when n.relationship = 'Victim was Otherwise Known' then count end), 0) as otherwise_known,
coalesce(sum(case when n.relationship = 'Victim Was Parent' then count end), 0) as parent,
coalesce(sum(case when n.relationship = 'Relationship Unknown' then count end), 0) as relationship_unknown,
coalesce(sum(case when n.relationship = 'Victim Was Sibling' then count end), 0) as sibling,
coalesce(sum(case when n.relationship = 'Victim Was Stepchild' then count end), 0) as stepchild,
coalesce(sum(case when n.relationship = 'Victim Was Spouse' then count end), 0) as spouse,
coalesce(sum(case when n.relationship = 'Victim Was Stepparent' then count end), 0) as stepparent,
coalesce(sum(case when n.relationship = 'Victim Was Stepsibling' then count end), 0) as stepsibling,
coalesce(sum(case when n.relationship = 'Victim Was Stranger' then count end), 0) as stranger,
coalesce(sum(case when n.relationship = 'Victim Was Offender' then count end), 0) as offender,
coalesce(sum(case when n.relationship = 'Victim was Ex-Spouse' then count end), 0) as ex_spouse
from public.nibrs_victim_to_offender_relationship_count n, public.state_lk s,public.region_lk r
sum(n.acquaintance) as acquaintance,
sum(n.babysittee) as babysittee,
sum(n.boyfriend_girlfriend) as boyfriend_girlfriend,
sum(n.child_boyfriend_girlfriend) as child_boyfriend_girlfriend,
sum(n.child) as child,
sum(n.common_law_spouse) as common_law_spouse,
sum(n.employee) as employee,
sum(n.employer) as employer,
sum(n.friend) as friend,
sum(n.grandchild) as grandchild,
sum(n.grandparent) as grandparent,
sum(n.homosexual_relationship) as homosexual_relationship,
sum(n.in_law) as in_law,
sum(n.neighbor) as neighbor,
sum(n.other_family_member) as other_family_member,
sum(n.otherwise_known) as otherwise_known,
sum(n.parent) as parent,
sum(n.relationship_unknown) as relationship_unknown,
sum(n.sibling) as sibling,
sum(n.stepchild) as stepchild,
sum(n.spouse) as spouse,
sum(n.stepparent) as stepparent,
sum(n.stepsibling) as stepsibling,
sum(n.stranger) as stranger,
sum(n.offender) as offender,
sum(n.ex_spouse) as ex_spouse
from public.nibrs_state_denorm_victim_offender_relationship n, public.state_lk s,public.region_lk r
where s.region_code = r.region_code
group by s.region_code,r.region_name, n.offense_name, n.data_year;;
group by s.region_code,r.region_name, n.offense_name, n.data_year;

CREATE MATERIALIZED VIEW nibrs_agency_denorm_victim_offender_relationship AS
select agency_id as agency_id,