-
Notifications
You must be signed in to change notification settings - Fork 3
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
Conversation
Pull Request Test Coverage Report for Build 338364154
💛 - Coveralls |
There was a problem hiding this 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!
There was a problem hiding this 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 }) { |
There was a problem hiding this comment.
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]}${ |
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
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 }) { |
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
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.
There was a problem hiding this 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) { |
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
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.
There was a problem hiding this 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"} |
There was a problem hiding this comment.
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( |
There was a problem hiding this comment.
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
There was a problem hiding this comment.
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!
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.
@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
Related issues
Checklists
Development
These boxes should be checked by the submitter prior to merging:
Code review
These boxes should be checked by reviewers prior to merging: