Skip to content

Commit 9605ea0

Browse files
Other injury/fatality counts to meet higher sums
1 parent 29da1ba commit 9605ea0

File tree

5 files changed

+39
-9
lines changed

5 files changed

+39
-9
lines changed

scss/components/_stats-counter.scss

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@
1616

1717
.count {
1818
display: inline-block;
19-
width: 25%;
19+
width: 20%;
2020
float: left;
2121
}
2222

src/components/AboutCopy.js

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -130,8 +130,9 @@ const AboutCopy = () => (
130130
</p>
131131
<p>
132132
In the NYPD motor vehicles collisions dataset, some injuries and fatalities do not have a
133-
role/vehicle ascribed to them. As a result the pedestrian/cyclist/motorist numbers in
134-
CrashMapper may not add up to the exact total injuries and fatalities in OpenData.
133+
role/vehicle ascribed to them. “Other” includes crashes in the source data that are not
134+
labeled by category (pedestrian, cyclists or motorists). In our experience they include
135+
mostly crashes where the victims are e-bike users.
135136
</p>
136137
<p>
137138
NYPD captures up to five (5) vehicles included in a crash. As long as any one of these

src/components/StatsLegend/StatsCounter.js

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
import React, { PropTypes } from 'react';
22

33
const StatsCounter = (props) => {
4-
const { cyclist, ped, driver, total, title } = props;
4+
const { cyclist, ped, driver, other, total, title } = props;
55

66
return (
77
<div className="stats-counter">
@@ -18,6 +18,10 @@ const StatsCounter = (props) => {
1818
<p>{driver.toLocaleString()}</p>
1919
<p>Motorist</p>
2020
</div>
21+
<div className="count">
22+
<p>{other.toLocaleString()}</p>
23+
<p>Unknown</p>
24+
</div>
2125
<div className="count">
2226
<p className="roboto-bold">{total.toLocaleString()}</p>
2327
<p className="roboto-bold">Total</p>
@@ -30,6 +34,7 @@ StatsCounter.defaultProps = {
3034
cyclist: 0,
3135
driver: 0,
3236
ped: 0,
37+
other: 0,
3338
total: 0,
3439
title: ''
3540
};
@@ -38,6 +43,7 @@ StatsCounter.propTypes = {
3843
cyclist: PropTypes.number,
3944
driver: PropTypes.number,
4045
ped: PropTypes.number,
46+
other: PropTypes.number,
4147
total: PropTypes.number,
4248
title: PropTypes.string
4349
};

src/components/StatsLegend/index.js

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,8 @@ class StatsLegend extends Component {
2121
motorist_killed,
2222
pedestrian_injured,
2323
pedestrian_killed,
24+
other_injured,
25+
other_killed,
2426
persons_injured,
2527
persons_killed,
2628
total_crashes,
@@ -51,13 +53,15 @@ class StatsLegend extends Component {
5153
cyclist={cyclist_killed}
5254
driver={motorist_killed}
5355
ped={pedestrian_killed}
56+
other={other_killed}
5457
total={persons_killed}
5558
/>
5659
<StatsCounter
5760
title={'Injuries'}
5861
cyclist={cyclist_injured}
5962
driver={motorist_injured}
6063
ped={pedestrian_injured}
64+
other={other_injured}
6165
total={persons_injured}
6266
/>
6367
</div>
@@ -82,6 +86,8 @@ StatsLegend.defaultProps = {
8286
motorist_killed: 0,
8387
pedestrian_injured: 0,
8488
pedestrian_killed: 0,
89+
other_injured: 0,
90+
other_killed: 0,
8591
persons_injured: 0,
8692
persons_killed: 0,
8793
total_crashes: 0,
@@ -102,6 +108,8 @@ StatsLegend.propTypes = {
102108
motorist_killed: PropTypes.number,
103109
pedestrian_injured: PropTypes.number,
104110
pedestrian_killed: PropTypes.number,
111+
other_injured: PropTypes.number,
112+
other_killed: PropTypes.number,
105113
persons_injured: PropTypes.number,
106114
persons_killed: PropTypes.number,
107115
total_crashes: PropTypes.number,

src/constants/sql_queries.js

Lines changed: 20 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -157,10 +157,19 @@ const filterByTypeWhereClause = (filterType) => {
157157
})
158158
.join('OR');
159159

160+
const typesInjuredSelected = Object.values(injury).filter(i => i).length;
161+
const typesKilledSelected = Object.values(fatality).filter(i => i).length;
162+
160163
const typesInjuredMapped = mapTypes(injury, 'injury');
161164
const typesKilledMapped = mapTypes(fatality, 'fatality');
162165

163-
if (typesInjuredMapped.length > 0 && typesKilledMapped.length > 0) {
166+
if (typesInjuredSelected === 3 && typesKilledSelected === 3) {
167+
whereClause += 'AND (number_of_persons_injured > 0 OR number_of_persons_killed > 0)';
168+
} else if (typesInjuredSelected > 0 && typesKilledSelected === 3) {
169+
whereClause += `AND (${typesInjuredMapped} OR number_of_persons_killed > 0)`;
170+
} else if (typesInjuredSelected === 3 && typesKilledSelected > 0) {
171+
whereClause += `AND (number_of_persons_injured > 0 OR ${typesKilledMapped})`;
172+
} else if (typesInjuredMapped.length > 0 && typesKilledMapped.length > 0) {
164173
whereClause += `AND (${typesInjuredMapped} OR ${typesKilledMapped})`;
165174
} else if (typesInjuredMapped.length > 0) {
166175
whereClause += `AND (${typesInjuredMapped})`;
@@ -179,6 +188,8 @@ const filterByTypeWhereClause = (filterType) => {
179188
`;
180189
}
181190

191+
console.debug(['GDA', typesInjuredSelected, typesKilledSelected, whereClause ]); //eslint-disable-line
192+
182193
return whereClause;
183194
};
184195

@@ -309,8 +320,10 @@ export const configureMapSQL = (params) => {
309320
SUM(c.number_of_motorist_killed) as motorist_killed,
310321
SUM(c.number_of_pedestrian_injured) as pedestrian_injured,
311322
SUM(c.number_of_pedestrian_killed) as pedestrian_killed,
312-
SUM(c.number_of_pedestrian_injured + c.number_of_cyclist_injured + c.number_of_motorist_injured) as persons_injured,
313-
SUM(c.number_of_pedestrian_killed + c.number_of_cyclist_killed + c.number_of_motorist_killed) as persons_killed
323+
SUM(c.number_of_persons_injured - (c.number_of_pedestrian_injured + c.number_of_cyclist_injured + c.number_of_motorist_injured)) as other_injured,
324+
SUM(c.number_of_persons_killed - (c.number_of_pedestrian_killed + c.number_of_cyclist_killed + c.number_of_motorist_killed)) as other_killed,
325+
SUM(c.number_of_persons_injured) as persons_injured,
326+
SUM(c.number_of_persons_killed) as persons_killed
314327
FROM
315328
${nyc_crashes} c
316329
${joinToGeoTableClause(geo)}
@@ -350,8 +363,10 @@ export const configureStatsSQL = (params) => {
350363
SUM(c.number_of_motorist_killed) as motorist_killed,
351364
SUM(c.number_of_pedestrian_injured) as pedestrian_injured,
352365
SUM(c.number_of_pedestrian_killed) as pedestrian_killed,
353-
SUM(c.number_of_pedestrian_injured + c.number_of_cyclist_injured + c.number_of_motorist_injured) as persons_injured,
354-
SUM(c.number_of_pedestrian_killed + c.number_of_cyclist_killed + c.number_of_motorist_killed) as persons_killed
366+
SUM(c.number_of_persons_injured - (c.number_of_pedestrian_injured + c.number_of_cyclist_injured + c.number_of_motorist_injured)) as other_injured,
367+
SUM(c.number_of_persons_killed - (c.number_of_pedestrian_killed + c.number_of_cyclist_killed + c.number_of_motorist_killed)) as other_killed,
368+
SUM(c.number_of_persons_injured) as persons_injured,
369+
SUM(c.number_of_persons_killed) as persons_killed
355370
FROM
356371
${nyc_crashes} c
357372
${joinToGeoTableClause(geo)}

0 commit comments

Comments
 (0)