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

adding db view for neighborhood specific summary #30

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
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
1 change: 1 addition & 0 deletions setup/install.sh
Original file line number Diff line number Diff line change
Expand Up @@ -16,3 +16,4 @@ psql -U $NOLA311_DB_USER -d $NOLA311_DB_NAME -h $NOLA311_DB_HOST -p $NOLA311_DB_
psql -U $NOLA311_DB_USER -d $NOLA311_DB_NAME -h $NOLA311_DB_HOST -p $NOLA311_DB_PORT -f views/closed_tickets_stats.sql -q
psql -U $NOLA311_DB_USER -d $NOLA311_DB_NAME -h $NOLA311_DB_HOST -p $NOLA311_DB_PORT -f views/call_records_for_review.sql -q
psql -U $NOLA311_DB_USER -d $NOLA311_DB_NAME -h $NOLA311_DB_HOST -p $NOLA311_DB_PORT -f views/call_records_with_call_for_details.sql -q
psql -U $NOLA311_DB_USER -d $NOLA311_DB_NAME -h $NOLA311_DB_HOST -p $NOLA311_DB_PORT -f views/open_tickets_neighborhood_summary.sql -q
37 changes: 37 additions & 0 deletions views/open_tickets_neighborhood_summary.sql
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
set search_path to 'nola311';

drop view if exists nola311.open_tickets_neighborhood_summary;
create view nola311.open_tickets_neighborhood_summary as (
with
open_tickets as (
select
neighborhood_district,
issue_type,
extract(year from ticket_created_date_time) as year_created,
extract(month from ticket_created_date_time) as month_created,
justify_interval(age(ticket_created_date_time)) as time_open
from nola311.calls
where ticket_status = 'Open'
),
ticket_stats as (
select
neighborhood_district,
issue_type,
year_created,
month_created,
count(*) as number_open
from open_tickets
group by neighborhood_district, issue_type, year_created, month_created
)
select
issue_type,
neighborhood_district,
count(*) as num_issues
from ticket_stats
group by neighborhood_district, issue_type
);

comment on view nola311.open_tickets_neighborhood_summary is 'A summary of the total number of open tickets by issue type for each neighborhood';

grant all on nola311.open_tickets_neighborhood_summary to nola311;