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

Add demographic breakdown to recidivism chart #238

Merged
merged 29 commits into from
Oct 30, 2020

Conversation

macfarlandian
Copy link
Collaborator

@macfarlandian macfarlandian commented Oct 28, 2020

Description of the change

When a single cohort is selected, enables the standard demographic breakdown as seen in the rest of the site. When this happens the chart displays one line per demographic group; when multiple cohorts are selected, this control is disabled and the view reverts to the total for that cohort.

Screen Shot 2020-10-28 at 12 03 42 PM

@jjdressel11 please let me know if these fixture files do not match how you'd like the real exports to look! (The values in them, FYI, are completely random, though I tried to make curves resemble the exponential decay we have observed in real data)

Type of change

  • Bug fix (non-breaking change that fixes an issue)
  • New feature (non-breaking change that adds functionality)
  • Breaking change (fix or feature that would cause existing functionality to not work as expected)
  • Configuration change (adjusts configuration to achieve some end related to functionality, development, performance, or security)

Related issues

Closes #233

Checklists

Development

These boxes should be checked by the submitter prior to merging:

  • Manual testing against realistic data has been performed locally

Code review

These boxes should be checked by reviewers prior to merging:

  • This pull request has a descriptive title and information useful to a reviewer
  • This pull request has been moved out of a Draft state, has no "Work In Progress" label, and has assigned reviewers
  • Potential security implications or infrastructural changes have been considered, if relevant

@coveralls
Copy link

coveralls commented Oct 28, 2020

Pull Request Test Coverage Report for Build 338364154

  • 29 of 41 (70.73%) changed or added relevant lines in 5 files are covered.
  • 1 unchanged line in 1 file lost coverage.
  • Overall coverage increased (+9.2%) to 25.408%

Changes Missing Coverage Covered Lines Changed/Added Lines %
public-dashboard-client/src/testUtils.js 10 11 90.91%
public-dashboard-client/src/viz-recidivism-rates/VizRecidivismRates.js 13 14 92.86%
public-dashboard-client/src/page-sentencing/PageSentencing.js 0 5 0.0%
public-dashboard-client/src/viz-recidivism-rates/RecidivismRatesChart.js 5 10 50.0%
Files with Coverage Reduction New Missed Lines %
public-dashboard-client/src/page-sentencing/PageSentencing.js 1 0%
Totals Coverage Status
Change from base Build 338343730: 9.2%
Covered Lines: 393
Relevant Lines: 1492

💛 - Coveralls

Copy link
Member

@jessex jessex left a comment

Choose a reason for hiding this comment

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

Looks and functions great, @macfarlandian!

@jessex jessex mentioned this pull request Oct 28, 2020
8 tasks
Copy link

@jovergaag jovergaag left a comment

Choose a reason for hiding this comment

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

Suggestion for a place to add a test, plus a few missing copyright disclaimers. This is AWESOME!

@@ -3,9 +3,14 @@ import PropTypes from "prop-types";
import Dropdown from "./Dropdown";
import { DIMENSIONS_LIST } from "../constants";

export default function DimensionControl({ onChange }) {
export default function DimensionControl({ onChange, ...passThruProps }) {

Choose a reason for hiding this comment

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

I've just noticed that this file and a few others that you've touched here do not have the Copyright disclaimer at the top.

@@ -136,7 +137,10 @@ export default function RecidivismRatesChart({ data, highlightedCohort }) {
}}
renderKey={(d) =>
// if it has a label, it's a line; if not, it's a point
d.label || `${d.releaseCohort}-${d.followupYears}`
d.label ||
`${d.releaseCohort}-${d[DIMENSION_DATA_KEYS.race]}${

Choose a reason for hiding this comment

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

I finally figured out what you mean by lines and points. They are the lines and points passed into the XYFrame.
Maybe it would be more clear to add a label to each point on line 62 when they are created? Or in prepareChartData. That may be a little more clear how the points are going to be labeled and avoid this confusion. Just a thought.

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

yes great suggestion!

* Otherwise (i.e., a single cohort and some dimensional breakdown is selected),
* will return one data series per demographic subgroup.
*/
function prepareChartData({ data, dimension, selectedCohorts }) {

Choose a reason for hiding this comment

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

This might be a nice place to add a test. There are a few branches of logic so a couple of tests to show the chart data at the end of each branch might be helpful.

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

I did add some tests here but I have mixed feelings about them. Exporting and testing this function itself felt like too much of a low-level implementation detail, since it's so specific to the Semiotic API. Testing the rendered output is also not super obvious since it's mainly just, like, drawing a bunch of lines? I settled on testing the label text that Semiotic renders, since it should reflect the data input in the same way that the chart marks do, but it's still pretty idiosyncratic ... e.g. if we swapped in a different library that produced an equivalent-looking chart I have low confidence that these tests would still pass, since chart labeling is still not a well established web standard.

Also I had to do something kind of funky to get the data fixture into the test environment? I actually think it's kind of a fun solution honestly but it is definitely quick-and-dirty.

Copy link

@jovergaag jovergaag left a comment

Choose a reason for hiding this comment

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

Awesome. Just one comment about the fixture data. 🌞

@@ -20,3 +44,26 @@ export { customRender as render };

// provide original render method as a fallback if needed
export { render as renderUnwrapped };

// retrieve a data fixture from spotlight-api
export function getDataFixture(filename) {

Choose a reason for hiding this comment

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

Oh thats interesting. Is this fixture data manually generated or part of the nightly build and randomized? Just want to keep our eye on when/how this fixture data will become out of sync with live data and what that might mean for the tests.

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

we have just been manually generating them when a new file is added to the API. I think it mostly doesn't matter if the values drift a bit, but if the shape drifts and causes tests to fail then that's a good signal that we need to update our fixtures anyway?

The one exception to this I can think of is the time-series metrics (population, supervision success rates), which have some baked-in assumptions about the data being relative to the current date. There is already a test for some of that functionality (a utility function that handles missing data) that mocks the system date to create different test conditions, so probably we would just have to do some more of that if we wanted to use those fixtures for something.

Copy link
Contributor

@jjdressel11 jjdressel11 left a comment

Choose a reason for hiding this comment

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

Besides moving this to the Prison page, this looks great!

{"state_code": "US_DEMO", "release_cohort": "2017", "followup_years": "1", "recidivism_rate": "0.28022799575391744", "recidivated_releases": "83", "releases": "297"}
{"state_code": "US_DEMO", "release_cohort": "2017", "followup_years": "2", "recidivism_rate": "0.3273667202949975", "recidivated_releases": "97", "releases": "297"}
{"state_code": "US_DEMO", "release_cohort": "2018", "followup_years": "1", "recidivism_rate": "0.14163508588973228", "recidivated_releases": "45", "releases": "322"}
{"state_code": "US_DEMO", "gender": "ALL", "age_bucket": "ALL", "race_or_ethnicity": "ALL", "releases": 441, "release_cohort": "2009", "followup_years": "1", "recidivism_rate": "0.15472315694153785", "recidivated_releases": "68"}
Copy link
Contributor

Choose a reason for hiding this comment

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

My backend support query produces a file with this name and with these fields!

const [highlightedCohort, setHighlightedCohort] = useState();
const [recidivismDimension, setRecidivismDimension] = useState(
Copy link
Contributor

Choose a reason for hiding this comment

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

Agreed offline that these charts should be on the Prison page instaed

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

yes I am going to deal with that in a separate PR. Thanks for catching it!

Base automatically changed from ian/233-recidivism-filters to master October 30, 2020 20:48
@macfarlandian macfarlandian merged commit 739a0aa into master Oct 30, 2020
@macfarlandian macfarlandian deleted the ian/233-recidivism-demographics branch October 30, 2020 21:09
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.

Add filter control and demographic breakdown to Recidivism chart
5 participants