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

NIBRS view for Region #1341

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: 0 additions & 1 deletion src/actions/summarized.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
import { SUMMARIZED_FAILED, SUMMARIZED_FETCHING, SUMMARIZED_RECEIVED } from './constants'
import api from '../util/api'
// import { calculateRates, reshapeData } from '../util/summarized'

export const failedSummarized = error => ({
type: SUMMARIZED_FAILED,
Expand Down
10 changes: 7 additions & 3 deletions src/containers/NibrsContainer.js
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,7 @@ class NibrsContainer extends React.Component {
)
}
});
content.push(<div className={`col col-12 sm-col-6 mb2 px1 ${cls}`}><div className='p2 sm-p3 bg-white black'> <h2 className='mt0 mb2 pb1 fs-18 sm-fs-22 sans-serif blue border-bottom border-blue-light'> {category}</h2> {cards}</div></div>)
content.push(<div className={`col col-12 sm-col-6 mb2 px1 ${cls}`}><div className='p2 sm-p3 bg-white black'> <h2 className='mt0 mb2 pb1 fs-18 sm-fs-22 sans-serif blue border-bottom border-blue-light'> {category}</h2> {cards}</div></div>)
});

return content
Expand Down Expand Up @@ -92,9 +92,13 @@ class NibrsContainer extends React.Component {
) {
return null
}

const placeDisplay = isAgency ? agency.display : lookupUsa(place).display
const nibrsFirstYear = this.initialNibrsYear(place, placeType, since)
let nibrsFirstYear
if (placeType === 'region') {
nibrsFirstYear = since
} else {
nibrsFirstYear = this.initialNibrsYear(place, placeType, since)
}
const { data, error } = nibrsCounts

const isReady = nibrsCounts.loaded
Expand Down
2 changes: 2 additions & 0 deletions src/util/api.js
Original file line number Diff line number Diff line change
Expand Up @@ -186,6 +186,8 @@ const fetchNibrsCounts = ({ dim, pageType, place, placeType, type, placeId }) =>
? 'national'
: placeType === 'agency'
? `agency/${place}`
: placeType === 'region'
? `regions/${place}`
: `states/${placeId}`

const field = dimensionEndpoints[dim] || dim
Expand Down
4 changes: 3 additions & 1 deletion src/util/participation.js
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,9 @@ export const shouldFetchSummaries = (filters, region, states) =>
isValidCrime(filters.pageType) && validateFilter(filters, region.regions, states.states)

export const shouldFetchNibrs = ({ pageType, place, placeType }) => {
if (noNibrs.includes(pageType) || placeType === 'region' || pageType === 'violent-crime' || pageType === 'property-crime') return false
if (noNibrs.includes(pageType) || pageType === 'violent-crime' || pageType === 'property-crime') return false

if (placeType === 'region') return true;

const placeNorm = placeType === 'agency' ? oriToState(place) : place
const coverage = lookup(placeNorm)
Expand Down
3 changes: 2 additions & 1 deletion src/util/summary.js
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,7 @@ export const calculateRates = (summaries, placeType) => {
const summaryObject = Object()
do {
const yrData = getYearData(summaries, place, minYr)

if (yrData.length > 0) {
const offensesObject = Object()
const offenses = Object.keys(yrData[0]).filter(
Expand All @@ -60,8 +61,8 @@ export const calculateRates = (summaries, placeType) => {
offensesObject.year = minYr;
offensesObject.population = population
withRegionRates.push(offensesObject)
minYr += 1;
}
minYr += 1;
} while (minYr <= MAX_YEAR)
summaryObject[place] = withRegionRates;
return summaryObject;
Expand Down
4 changes: 4 additions & 0 deletions src/util/usa.js
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,10 @@ const data = [
{ id: 'wv', slug: 'west-virginia', placeType: 'state' },
{ id: 'wi', slug: 'wisconsin', placeType: 'state' },
{ id: 'wy', slug: 'wyoming', placeType: 'state' },
{ id: 'west', slug: 'west', placeType: 'region' },
{ id: 'south', slug: 'south', placeType: 'region' },
{ id: 'northeast', slug: 'northeast', placeType: 'region' },
{ id: 'midwest', slug: 'midwest', placeType: 'region' },
].map(d => ({
...d,
display: d.display || startCase(d.slug),
Expand Down