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

Use estimated data for trend charts #707

Merged
merged 15 commits into from
Apr 26, 2017

Conversation

jeremiak
Copy link
Contributor

Uses the /estimates endpoint instead of /counts so that the data displayed includes FBI estimates.

Based on #703, which should be merged first.

@jeremiak jeremiak force-pushed the jk-agency-routing-with-estimated branch from 531cc89 to 38f172a Compare April 25, 2017 15:39
@jeremiak
Copy link
Contributor Author

@brendansudol This has been rebased and should be ready for review

Jeremia Kimelman added 2 commits April 25, 2017 14:57
let { place } = appState.filters

if (!place && !placeType) {
place = nationalKey
Copy link
Contributor

@brendansudol brendansudol Apr 25, 2017

Choose a reason for hiding this comment

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

why did u replace the getPlaceInfo method in componentDidMount and render? i think that helps consolidate this place assignment logic

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Oops, I think that just got removed when I was fixing rebase conflicts. I'll look for it and take a second look

src/util/api.js Outdated
const getSummary = params => {
const { place } = params
const endpoint = `${API}/counts`
const qs = buildSummaryQueryString(params)
let endpoint
Copy link
Contributor

Choose a reason for hiding this comment

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

would use ternary here to save a few lines:

const endpoint = (place === nationalKey)
  ? `${API}/estimates/national`
  : `${API}/estimates/states/${lookupUsa(place).toUpperCase()}`

}),
)
))
const filterDataWithinYears = ({ data, since, until }) => {
Copy link
Contributor

Choose a reason for hiding this comment

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

i wonder if this function should be in '../util/summary' too and consolidated within the mungeSummaryData call to avoid multiples passes through the data

Copy link
Contributor

Choose a reason for hiding this comment

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

i think this could do the trick:

const mungeSummaryData = (crime, summaries, place, since, until) => {
  if (!summaries || !summaries[place]) return false

  const keys = Object.keys(summaries)
  return summaries[place]
    .filter(d => d.year >= since && d.year <= until)
    .map(year => {
      const data = { date: year.year }
      keys.forEach(key => {
        const source = key !== place
          ? summaries[key].find(d => d.year === data.date)
          : year
        data[key] = {
          pop: source.population,
          count: source[crime],
          rate: source[crime] / source.population * 100000,
        }
      })
      return data
    })
}

note the filter call before the map (and new since and until params)

@brendansudol
Copy link
Contributor

looks good, can review once more and then merge when final tweaks are in

Jeremia Kimelman and others added 3 commits April 25, 2017 17:56
@jeremiak
Copy link
Contributor Author

Shoot, didn't mean to merge master in. I've got to get better at the fix merge conflicts inside of github.com workflow, but in any case your feedback was received and implemented @brendansudol

@brendansudol
Copy link
Contributor

looks good!

@brendansudol brendansudol merged commit 8f45d81 into master Apr 26, 2017
@brendansudol brendansudol deleted the jk-agency-routing-with-estimated branch April 26, 2017 14:16
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants