Skip to content
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
Original file line number Diff line number Diff line change
Expand Up @@ -5,12 +5,18 @@ select_permissions:
- role: editor
permission:
columns:
- apd_sectors
- area_eng_areas
- signal_eng_areas
- street_levels
- cr3_crash_count
- crash_count
- non_cr3_crash_count
- total_est_comp_cost
- is_hin
- is_signalized
- location_id
- council_district
- council_districts
- location_group
- location_name
filter: {}
Expand All @@ -19,12 +25,18 @@ select_permissions:
- role: readonly
permission:
columns:
- apd_sectors
- area_eng_areas
- signal_eng_areas
- street_levels
- cr3_crash_count
- crash_count
- non_cr3_crash_count
- total_est_comp_cost
- is_hin
- is_signalized
- location_id
- council_district
- council_districts
- location_group
- location_name
filter: {}
Expand All @@ -33,12 +45,18 @@ select_permissions:
- role: vz-admin
permission:
columns:
- apd_sectors
- area_eng_areas
- signal_eng_areas
- street_levels
- cr3_crash_count
- crash_count
- non_cr3_crash_count
- total_est_comp_cost
- is_hin
- is_signalized
- location_id
- council_district
- council_districts
- location_group
- location_name
filter: {}
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,57 @@
CREATE OR REPLACE VIEW locations_list_view AS WITH cr3_comp_costs AS (
SELECT
crashes_list_view.location_id,
sum(crashes_list_view.est_comp_cost_crash_based) AS cr3_comp_costs_total
FROM crashes_list_view
WHERE crashes_list_view.crash_timestamp > (now() - '5 years'::interval)
GROUP BY crashes_list_view.location_id
),

cr3_crash_counts AS (
SELECT
crashes.location_id,
count(crashes.location_id) AS crash_count
FROM crashes
WHERE
crashes.private_dr_fl = false
AND crashes.location_id IS NOT null
AND crashes.crash_timestamp > (now() - '5 years'::interval)
GROUP BY crashes.location_id
),

non_cr3_crash_counts AS (
SELECT
atd_apd_blueform.location_id,
count(atd_apd_blueform.location_id) AS crash_count,
count(atd_apd_blueform.location_id) * 10000 AS noncr3_comp_costs_total
FROM atd_apd_blueform
WHERE
atd_apd_blueform.location_id IS NOT null
AND atd_apd_blueform.is_deleted = false
AND atd_apd_blueform.case_timestamp > (now() - '5 years'::interval)
GROUP BY atd_apd_blueform.location_id
)

SELECT
locations.location_id,
locations.location_name,
locations.council_district,
locations.location_group,
coalesce(
cr3_comp_costs.cr3_comp_costs_total + non_cr3_crash_counts.noncr3_comp_costs_total,
0::bigint
) AS total_est_comp_cost,
coalesce(
cr3_crash_counts.crash_count, 0::bigint
) AS cr3_crash_count,
coalesce(
non_cr3_crash_counts.crash_count, 0::bigint
) AS non_cr3_crash_count,
coalesce(cr3_crash_counts.crash_count, 0::bigint)
+ coalesce(non_cr3_crash_counts.crash_count, 0::bigint) AS crash_count
FROM locations
LEFT JOIN cr3_crash_counts ON locations.location_id::text = cr3_crash_counts.location_id
LEFT JOIN
non_cr3_crash_counts
ON locations.location_id::text = non_cr3_crash_counts.location_id::text
LEFT JOIN cr3_comp_costs ON locations.location_id::text = cr3_comp_costs.location_id;
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
drop view locations_list_view;
create or replace view locations_list_view as
WITH cr3_comp_costs AS (
SELECT crashes_list_view.location_id,
sum(crashes_list_view.est_comp_cost_crash_based) AS cr3_comp_costs_total
FROM crashes_list_view
WHERE crashes_list_view.crash_timestamp > (now() - '5 years'::interval)
GROUP BY crashes_list_view.location_id
), cr3_crash_counts AS (
SELECT crashes.location_id,
count(crashes.location_id) AS crash_count
FROM crashes
WHERE crashes.private_dr_fl = false AND crashes.location_id IS NOT NULL AND crashes.crash_timestamp > (now() - '5 years'::interval)
GROUP BY crashes.location_id
), non_cr3_crash_counts AS (
SELECT atd_apd_blueform.location_id,
count(atd_apd_blueform.location_id) AS crash_count,
count(atd_apd_blueform.location_id) * 10000 AS noncr3_comp_costs_total
FROM atd_apd_blueform
WHERE atd_apd_blueform.location_id IS NOT NULL AND atd_apd_blueform.is_deleted = false AND atd_apd_blueform.case_timestamp > (now() - '5 years'::interval)
GROUP BY atd_apd_blueform.location_id
)
SELECT locations.location_id,
locations.location_name,
locations.council_districts,
locations.location_group,
locations.is_signalized,
locations.signal_eng_areas,
locations.area_eng_areas,
locations.street_levels,
locations.apd_sectors,
locations.is_hin,
COALESCE(cr3_comp_costs.cr3_comp_costs_total + non_cr3_crash_counts.noncr3_comp_costs_total, 0::bigint) AS total_est_comp_cost,
COALESCE(cr3_crash_counts.crash_count, 0::bigint) AS cr3_crash_count,
COALESCE(non_cr3_crash_counts.crash_count, 0::bigint) AS non_cr3_crash_count,
COALESCE(cr3_crash_counts.crash_count, 0::bigint) + COALESCE(non_cr3_crash_counts.crash_count, 0::bigint) AS crash_count
FROM locations
LEFT JOIN cr3_crash_counts ON locations.location_id::text = cr3_crash_counts.location_id
LEFT JOIN non_cr3_crash_counts ON locations.location_id::text = non_cr3_crash_counts.location_id::text
LEFT JOIN cr3_comp_costs ON locations.location_id::text = cr3_comp_costs.location_id;
8 changes: 7 additions & 1 deletion database/views/locations_list_view.sql
Copy link
Member

Choose a reason for hiding this comment

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

so nice having this diff to review!

Original file line number Diff line number Diff line change
Expand Up @@ -37,8 +37,14 @@ non_cr3_crash_counts AS (
SELECT
locations.location_id,
locations.location_name,
locations.council_district,
locations.council_districts,
locations.location_group,
locations.is_signalized,
locations.signal_eng_areas,
locations.area_eng_areas,
locations.street_levels,
locations.apd_sectors,
locations.is_hin,
coalesce(
cr3_comp_costs.cr3_comp_costs_total + non_cr3_crash_counts.noncr3_comp_costs_total,
0::bigint
Expand Down
4 changes: 3 additions & 1 deletion database/views/materialized/location_crashes_view.sql
Original file line number Diff line number Diff line change
@@ -1,10 +1,11 @@
-- Most recent migration: database/migrations/default/1767430748998_crash_address_display_trigger/up.sql
-- Most recent migration: database/migrations/default/1771445809119_update_location_crashes_view/up.sql

DROP MATERIALIZED VIEW IF EXISTS location_crashes_view;

CREATE MATERIALIZED VIEW location_crashes_view AS SELECT
crashes.record_locator,
crashes.cris_crash_id,
crashes.id AS crash_pk,
'CR3'::text AS type,
crashes.location_id,
crashes.case_id,
Expand Down Expand Up @@ -87,6 +88,7 @@ UNION ALL
SELECT
null::text AS record_locator,
aab.form_id AS cris_crash_id,
null::integer AS crash_pk,
'NON-CR3'::text AS type,
aab.location_id,
aab.case_id::text AS case_id,
Expand Down
45 changes: 44 additions & 1 deletion editor/configs/locationColumns.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,10 @@
import { ColDataCardDef } from "@/types/types";
import { Location } from "@/types/locations";
import { formatArrayToString, formatDollars } from "@/utils/formatters";
import {
formatArrayToString,
formatDollars,
formatYesNoString,
} from "@/utils/formatters";

export const locationColumns = {
location_id: {
Expand All @@ -25,4 +29,43 @@ export const locationColumns = {
label: "ASMP Street level(s)",
valueFormatter: formatArrayToString,
},
apd_sectors: {
path: "apd_sectors",
label: "APD sector(s)",
sortable: false,
defaultHidden: false,
valueFormatter: formatArrayToString,
},
area_eng_areas: {
path: "area_eng_areas",
label: "Area engineer",
sortable: false,
valueFormatter: formatArrayToString,
},
signal_eng_areas: {
path: "signal_eng_areas",
label: "Signal engineer",
sortable: false,
valueFormatter: formatArrayToString,
},
council_districts: {
path: "council_districts",
label: "Council district(s)",
sortable: false,
valueFormatter: formatArrayToString,
},
is_hin: {
path: "is_hin",
label: "High injury network",
sortable: true,
defaultHidden: false,
valueFormatter: formatYesNoString,
},
is_signalized: {
path: "is_signalized",
label: "Signalized",
sortable: true,
defaultHidden: false,
valueFormatter: formatYesNoString,
},
} satisfies Record<string, ColDataCardDef<Location>>;
7 changes: 6 additions & 1 deletion editor/configs/locationDataCard.ts
Original file line number Diff line number Diff line change
@@ -1,9 +1,14 @@
import { locationColumns } from "./locationColumns";

export const locationCardColumns = [
locationColumns.location_id,
locationColumns.cr3_crash_count,
locationColumns.non_cr3_crash_count,
locationColumns.total_est_comp_cost,
locationColumns.street_level,
locationColumns.area_eng_areas,
locationColumns.signal_eng_areas,
locationColumns.is_signalized,
locationColumns.council_districts,
locationColumns.is_hin,
locationColumns.apd_sectors
];
14 changes: 14 additions & 0 deletions editor/configs/locationsListViewColumns.tsx
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import Link from "next/link";
import { ColDataCardDef } from "@/types/types";
import { LocationsListRow } from "@/types/locationsList";
import { locationColumns } from "@/configs/locationColumns";

export const locationsListViewColumns: ColDataCardDef<LocationsListRow>[] = [
{
Expand All @@ -17,6 +18,12 @@ export const locationsListViewColumns: ColDataCardDef<LocationsListRow>[] = [
path: "location_name",
label: "Location",
sortable: true,
style: {
maxWidth: "30rem",
overflow: "hidden",
textOverflow: "ellipsis",
whiteSpace: "nowrap",
Copy link
Member Author

Choose a reason for hiding this comment

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

This puts a cap on our extremely long location names

Image

},
},
{
path: "cr3_crash_count",
Expand All @@ -28,4 +35,11 @@ export const locationsListViewColumns: ColDataCardDef<LocationsListRow>[] = [
label: "Non-CR3 crashes",
sortable: true,
},
locationColumns.area_eng_areas,
locationColumns.signal_eng_areas,
locationColumns.is_signalized,
locationColumns.council_districts,
{ ...locationColumns.street_level, defaultHidden: true },
{ ...locationColumns.apd_sectors, defaultHidden: true },
{ ...locationColumns.is_hin, defaultHidden: true },
];
Loading