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

Make the Dashboard page compatible with the new data model #1493

Merged
Merged
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
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,7 @@ select
cimv.micromobility_sus_serious_injry_count as micromobility_serious_injury_count,
cimv.other_fatality_count as other_death_count,
cimv.other_sus_serious_injry_count as other_serious_injury_count,
cimv.years_of_life_lost,
to_char(
crashes.crash_timestamp, 'YYYY-MM-DD"T"HH24:MI:SS'
) as crash_timestamp,
Expand Down
Original file line number Diff line number Diff line change
@@ -1,3 +1,145 @@
table:
name: socrata_export_crashes_view
schema: public
select_permissions:
- role: editor
permission:
columns:
- bicycle_death_count
- bicycle_serious_injury_count
- death_cnt
- law_enf_fatality_count
- micromobility_death_count
- micromobility_serious_injury_count
- motorcycle_death_count
- motorcycle_serious_injury_count
- motor_vehicle_death_count
- motor_vehicle_serious_injury_count
- nonincap_injry_cnt
- non_injry_cnt
- other_death_count
- other_serious_injury_count
- pedestrian_death_count
- pedestrian_serious_injury_count
- poss_injry_cnt
- sus_serious_injry_cnt
- tot_injry_cnt
- unkn_injry_cnt
- years_of_life_lost
- crash_fatal_fl
- onsys_fl
- private_dr_fl
- road_constr_zone_fl
- crash_id
- crash_sev_id
- crash_speed_limit
- id
- latitude
- longitude
- address_primary
- address_secondary
- case_id
- crash_timestamp
- crash_timestamp_ct
- point
- rpt_block_num
- rpt_street_name
- rpt_street_sfx
- units_involved
filter: {}
allow_aggregations: true
comment: ""
- role: readonly
permission:
columns:
- bicycle_death_count
- bicycle_serious_injury_count
- death_cnt
- law_enf_fatality_count
- micromobility_death_count
- micromobility_serious_injury_count
- motorcycle_death_count
- motorcycle_serious_injury_count
- motor_vehicle_death_count
- motor_vehicle_serious_injury_count
- nonincap_injry_cnt
- non_injry_cnt
- other_death_count
- other_serious_injury_count
- pedestrian_death_count
- pedestrian_serious_injury_count
- poss_injry_cnt
- sus_serious_injry_cnt
- tot_injry_cnt
- unkn_injry_cnt
- years_of_life_lost
- crash_fatal_fl
- onsys_fl
- private_dr_fl
- road_constr_zone_fl
- crash_id
- crash_sev_id
- crash_speed_limit
- id
- latitude
- longitude
- address_primary
- address_secondary
- case_id
- crash_timestamp
- crash_timestamp_ct
- point
- rpt_block_num
- rpt_street_name
- rpt_street_sfx
- units_involved
filter: {}
allow_aggregations: true
comment: ""
- role: vz-admin
permission:
columns:
- bicycle_death_count
- bicycle_serious_injury_count
- death_cnt
- law_enf_fatality_count
- micromobility_death_count
- micromobility_serious_injury_count
- motorcycle_death_count
- motorcycle_serious_injury_count
- motor_vehicle_death_count
- motor_vehicle_serious_injury_count
- nonincap_injry_cnt
- non_injry_cnt
- other_death_count
- other_serious_injury_count
- pedestrian_death_count
- pedestrian_serious_injury_count
- poss_injry_cnt
- sus_serious_injry_cnt
- tot_injry_cnt
- unkn_injry_cnt
- years_of_life_lost
- crash_fatal_fl
- onsys_fl
- private_dr_fl
- road_constr_zone_fl
- crash_id
- crash_sev_id
- crash_speed_limit
- id
- latitude
- longitude
- address_primary
- address_secondary
- case_id
- crash_timestamp
- crash_timestamp_ct
- point
- rpt_block_num
- rpt_street_name
- rpt_street_sfx
- units_involved
filter: {}
allow_aggregations: true
comment: ""
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,7 @@ select
cimv.micromobility_sus_serious_injry_count as micromobility_serious_injury_count,
cimv.other_fatality_count as other_death_count,
cimv.other_sus_serious_injry_count as other_serious_injury_count,
cimv.years_of_life_lost,
to_char(
crashes.crash_timestamp, 'YYYY-MM-DD"T"HH24:MI:SS'
) as crash_timestamp,
Expand Down
80 changes: 5 additions & 75 deletions atd-vze/src/queries/dashboard.js
Original file line number Diff line number Diff line change
@@ -1,92 +1,22 @@
import { gql } from "apollo-boost";

// These queries are derived from the ETL that populates our Socrata data sets
// This query is derived from the view that populates our Socrata dataset
// so that the VZV and VZE widget totals match up
// See https://github.com/cityofaustin/atd-vz-data/blob/master/atd-etl/app/process/socrata_queries.py
export const GET_CRASHES_YTD = gql`
query GetCrashesYTD($yearStart: date, $yearEnd: date) {
fatalities: atd_txdot_crashes_aggregate(
where: {
crash_date: { _lt: $yearEnd, _gte: $yearStart }
private_dr_fl: { _eq: "N" }
_and: [
{ crash_date: { _is_null: false } }
{ crash_time: { _is_null: false } }
]
_or: [
{ in_austin_full_purpose: { _eq: true } }
{ _and: [{ city_id: { _eq: 22 } }, { position: { _is_null: true } }] }
]
}
query GetCrashesYTD($yearStart: String!) {
socrata_export_crashes_view_aggregate(
where: { crash_timestamp: { _gte: $yearStart } }
) {
aggregate {
sum {
atd_fatality_count
death_cnt
}
}
}
seriousInjuriesAndTotal: atd_txdot_crashes_aggregate(
where: {
crash_date: { _lt: $yearEnd, _gte: $yearStart }
private_dr_fl: { _eq: "N" }
_and: [
{ crash_date: { _is_null: false } }
{ crash_time: { _is_null: false } }
]
_or: [
{ in_austin_full_purpose: { _eq: true } }
{ _and: [{ city_id: { _eq: 22 } }, { position: { _is_null: true } }] }
]
}
) {
aggregate {
sum {
sus_serious_injry_cnt
}
}
}
primaryPersonFatalities: atd_txdot_primaryperson_aggregate(
where: {
crash: { private_dr_fl: { _eq: "N" } }
_and: {
prsn_injry_sev_id: { _eq: 4 }
crash: { crash_date: { _lt: $yearEnd, _gte: $yearStart } }
_or: [
{ crash: { in_austin_full_purpose: { _eq: true } } }
{
_and: [
{ crash: { city_id: { _eq: 22 } } }
{ crash: { position: { _is_null: true } } }
]
}
]
}
}
) {
aggregate {
sum {
years_of_life_lost
}
}
}
personFatalities: atd_txdot_person_aggregate(
where: {
crash: { private_dr_fl: { _eq: "N" } }
_and: {
prsn_injry_sev_id: { _eq: 4 }
crash: { crash_date: { _lt: $yearEnd, _gte: $yearStart } }
_or: [
{ crash: { in_austin_full_purpose: { _eq: true } } }
{
_and: [
{ crash: { city_id: { _eq: 22 } } }
{ crash: { position: { _is_null: true } } }
]
}
]
}
}
) {
aggregate {
sum {
years_of_life_lost
Expand Down
16 changes: 16 additions & 0 deletions atd-vze/src/queries/tempRecords.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
import { gql } from "apollo-boost";

export const GET_TEMP_RECORDS = gql`
query getTempRecords {
crashes(
where: { is_temp_record: { _eq: true } }
order_by: { record_locator: desc }
) {
record_locator
case_id
crash_timestamp
updated_by
updated_at
}
}
`;
19 changes: 15 additions & 4 deletions atd-vze/src/views/Tools/CreateCrashRecord.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import React, { useState, useReducer } from "react";
import { Link } from "react-router-dom";
import { useQuery } from "@apollo/react-hooks";

import {
Alert,
Expand All @@ -23,6 +24,7 @@ import { gql } from "apollo-boost";
import "./CreateCrashRecord.css";
import UnitsForm from "./UnitsForm";
import CreateCrashRecordTable from "./CreateCrashRecordTable";
import { GET_TEMP_RECORDS } from "../../queries/tempRecords";
import { useAuth0 } from "../../auth/authContext";

// Builds an array of units objects with nested arrays of person objects within them
Expand Down Expand Up @@ -71,6 +73,10 @@ function buildNestedObjects(unitFormState, userEmail) {
}

const CreateCrashRecord = ({ client }) => {
const { loading, error, data, refetch } = useQuery(GET_TEMP_RECORDS, {
fetchPolicy: "no-cache",
});

const { user } = useAuth0();

const userEmail = user.email;
Expand Down Expand Up @@ -196,6 +202,7 @@ const CreateCrashRecord = ({ client }) => {
.then(res => {
// Re-route to the crash details page for the new temp record on successful creation
setSuccessfulNewRecordId(res.data.insert_crashes_cris.returning[0].id);
refetch();
})
.catch(error => {
setFeedback({ title: "Error", message: String(error) });
Expand Down Expand Up @@ -347,13 +354,13 @@ const CreateCrashRecord = ({ client }) => {
fade={false}
>
{/*eslint-disable-next-line*/}
<i className="fa fa-check-circle" /> Successfsully
created crash{" "}
<i className="fa fa-check-circle" /> Successfully created
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

lil typo 😄

crash{" "}
<Link
to={`/crashes/T${successfulNewRecordId}`}
className="alert-link"
>
#{successfulNewRecordId}
#T{successfulNewRecordId}
</Link>
</Alert>
<Alert
Expand All @@ -374,7 +381,11 @@ const CreateCrashRecord = ({ client }) => {
</Row>
<Row>
<Col>
<CreateCrashRecordTable />
<CreateCrashRecordTable
crashesData={data.crashes}
loading={loading}
error={error}
/>
</Col>
</Row>
</>
Expand Down
Loading