Skip to content

Commit

Permalink
[Justice Counts] Remove published datapoints endpoint (Recidiviz/reci…
Browse files Browse the repository at this point in the history
…diviz-data#17026)

## Description of the change

Remove no-longer-used `published_datapoints` endpoint.

NOTE: must merge Recidiviz/justice-counts#189
before this

## Type of change

> All pull requests must have at least one of the following labels
applied (otherwise the PR will fail):

| Label | Description |
|-----------------------------
|-----------------------------------------------------------------------------------------------------------
|
| Type: Bug | non-breaking change that fixes an issue |
| Type: Feature | non-breaking change that adds functionality |
| Type: Breaking Change | fix or feature that would cause existing
functionality to not work as expected |
| Type: Non-breaking refactor | change addresses some tech debt item or
prepares for a later change, but does not change functionality |
| Type: Configuration Change | adjusts configuration to achieve some end
related to functionality, development, performance, or security |
| Type: Dependency Upgrade | upgrades a project dependency - these
changes are not included in release notes |

## Related issues

Closes #XXXX

## Checklists

### Development

**This box MUST be checked by the submitter prior to merging**:
- [x] **Double- and triple-checked that there is no Personally
Identifiable Information (PII) being mistakenly added in this pull
request**

These boxes should be checked by the submitter prior to merging:
- [ ] Tests have been written to cover the code changed/added as part of
this pull request

### 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

GitOrigin-RevId: 525dab46c78b745f59df4c19d2cb9fac7e00162b
  • Loading branch information
terryttsai authored and Helper Bot committed Dec 20, 2022
1 parent 4c6c26a commit 9400399
Show file tree
Hide file tree
Showing 2 changed files with 1 addition and 128 deletions.
10 changes: 1 addition & 9 deletions recidiviz/justice_counts/control_panel/routes/api.py
Original file line number Diff line number Diff line change
Expand Up @@ -698,7 +698,7 @@ def allowed_file(filename: Optional[str] = None) -> bool:

### Dashboards ###

def get_agency_datapoints(agency_id: str, published_only: bool = False) -> Response:
def get_agency_datapoints(agency_id: str) -> Response:
permissions = g.user_context.permissions if "user_context" in g else []
if agency_id is None:
# If no agency_id is specified, pick one of the agencies
Expand All @@ -719,7 +719,6 @@ def get_agency_datapoints(agency_id: str, published_only: bool = False) -> Respo
# we are only fetching reports here to get the list of report
# ids in an agency, so no need to fetch datapoints here
include_datapoints=False,
published_only=published_only,
)
report_id_to_status = {report.id: report.status for report in reports}
report_id_to_frequency = {
Expand Down Expand Up @@ -783,13 +782,6 @@ def get_datapoints_by_agency_id(agency_id: str) -> Response:
except Exception as e:
raise _get_error(error=e) from e

@api_blueprint.route("agencies/<agency_id>/published_datapoints", methods=["GET"])
def get_published_datapoints_by_agency_id(agency_id: str) -> Response:
try:
return get_agency_datapoints(agency_id=agency_id, published_only=True)
except Exception as e:
raise _get_error(error=e) from e

@api_blueprint.route("/agencies/<agency_id>/published_data", methods=["GET"])
def get_agency_published_data(agency_id: str) -> Response:
try:
Expand Down
119 changes: 0 additions & 119 deletions recidiviz/tests/justice_counts/control_panel/server_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -1750,125 +1750,6 @@ def test_get_datapoints_by_agency_id(self) -> None:
},
)

def test_get_published_datapoints_by_agency_id(self) -> None:
user_A = self.test_schema_objects.test_user_A
report1 = self.test_schema_objects.test_report_monthly
report2 = self.test_schema_objects.test_report_monthly
report2.status = schema.ReportStatus.PUBLISHED
report2.date_range_start = datetime.date.fromisoformat("2022-07-01")
report2.date_range_end = datetime.date.fromisoformat("2022-08-01")
self.session.add_all([report1, report2, user_A])

report_metric = self.test_schema_objects.reported_residents_metric
ReportInterface.add_or_update_metric(
session=self.session,
report=report1,
report_metric=report_metric,
user_account=user_A,
)
ReportInterface.add_or_update_metric(
session=self.session,
report=report2,
report_metric=report_metric,
user_account=user_A,
)
self.session.commit()

with self.app.test_request_context():
g.user_context = UserContext(
auth0_user_id=user_A.auth0_user_id, agency_ids=[report1.source_id]
)
response = self.client.get(
f"/api/agencies/{report1.source_id}/published_datapoints"
)

self.assertEqual(response.status_code, 200)
agency_datapoints = self.session.query(Datapoint).all()
response_json = assert_type(response.json, dict)
response_json_datapoints = assert_type(response_json["datapoints"], list)
print("response_json_datapoints", response_json_datapoints)
self.assertEqual(len(agency_datapoints), len(response_json_datapoints))

response_json_datapoint = assert_type(response_json_datapoints[0], dict)
self.assertEqual(response_json_datapoint["dimension_display_name"], None)
self.assertEqual(response_json_datapoint["disaggregation_display_name"], None)
self.assertEqual(
response_json_datapoint["end_date"], "Mon, 01 Aug 2022 00:00:00 GMT"
)
self.assertEqual(
response_json_datapoint["frequency"], ReportingFrequency.MONTHLY.value
)
self.assertEqual(response_json_datapoint["is_published"], True)
self.assertEqual(
response_json_datapoint["metric_definition_key"],
"LAW_ENFORCEMENT_RESIDENTS",
)
self.assertEqual(
response_json_datapoint["metric_display_name"], "Jurisdiction Residents"
)
self.assertEqual(
response_json_datapoint["start_date"], "Fri, 01 Jul 2022 00:00:00 GMT"
)
self.assertEqual(response_json_datapoint["value"], 5000)

response_json_dimensions = response_json[
"dimension_names_by_metric_and_disaggregation"
]

self.assertEqual(
response_json_dimensions,
{
"LAW_ENFORCEMENT_ARRESTS": {
"Gender": ["Male", "Female", "Other", "Non-Binary", "Unknown"],
"Offense Type": ["Person", "Property", "Drug", "Other", "Unknown"],
"Race / Ethnicity": [
"American Indian / Alaskan Native / Hispanic",
"Asian / Hispanic",
"Black / Hispanic",
"More than one race / Hispanic",
"Native Hawaiian / Pacific Islander / Hispanic",
"White / Hispanic",
"Other / Hispanic",
"Unknown / Hispanic",
"American Indian / Alaskan Native / Not Hispanic",
"Asian / Not Hispanic",
"Black / Not Hispanic",
"More than one race / Not Hispanic",
"Native Hawaiian / Pacific Islander / Not Hispanic",
"White / Not Hispanic",
"Other / Not Hispanic",
"Unknown / Not Hispanic",
"American Indian / Alaskan Native / Unknown Ethnicity",
"Asian / Unknown Ethnicity",
"Black / Unknown Ethnicity",
"More than one race / Unknown Ethnicity",
"Native Hawaiian / Pacific Islander / Unknown Ethnicity",
"White / Unknown Ethnicity",
"Other / Unknown Ethnicity",
"Unknown / Unknown Ethnicity",
],
},
"LAW_ENFORCEMENT_BUDGET": {},
"LAW_ENFORCEMENT_CALLS_FOR_SERVICE": {
"Call Type": ["Emergency", "Non-emergency", "Unknown"]
},
"LAW_ENFORCEMENT_COMPLAINTS_SUSTAINED": {},
"LAW_ENFORCEMENT_REPORTED_CRIME": {
"Offense Type": ["Person", "Property", "Drug", "Other", "Unknown"]
},
"LAW_ENFORCEMENT_TOTAL_STAFF": {},
"LAW_ENFORCEMENT_USE_OF_FORCE_INCIDENTS": {
"Force Type": [
"Physical",
"Restraint",
"Verbal",
"Weapon",
"Unknown",
]
},
},
)

def test_session(self) -> None:
# Add data
name = "Agency Alpha"
Expand Down

0 comments on commit 9400399

Please sign in to comment.