Skip to content

Cs/ccct 2283 coverage area calculation update#1138

Open
Charl1996 wants to merge 3 commits intomainfrom
cs/CCCT-2283-coverage-area-calculation-update
Open

Cs/ccct 2283 coverage area calculation update#1138
Charl1996 wants to merge 3 commits intomainfrom
cs/CCCT-2283-coverage-area-calculation-update

Conversation

@Charl1996
Copy link
Copy Markdown
Contributor

@Charl1996 Charl1996 commented Apr 22, 2026

Product Description

When a work area is excluded from a microplanning opportunity, it is now consistently treated as non-existent across all coverage calculations and exports:

  • The work area group's building count no longer includes buildings from
    excluded work areas.
  • The CSV download omits excluded work areas entirely.
  • The expected_visit_count on an excluded work area is set to zero at
    the time of exclusion.

Technical Summary

Link to ticket here

This is a release path 3 feature — Experiments & early stage iterations of
product area

Three related gaps were closed to make excluded work areas invisible to
coverage-area calculations:

  • WorkAreaGroup.building_count (models.py): The cached_property now
    filters out WorkAreaStatus.EXCLUDED work areas before summing
    building_count, so group-level totals reflect only active areas.
  • download_work_areas view (views.py): The base queryset for the CSV
    export now excludes work areas with EXCLUDED status before passing to
    WorkAreaMapFilterSet, so excluded areas never appear in downloads.
  • exclude_work_areas view (views.py): When a work area is excluded,
    expected_visit_count is set to 0 and included in update_fields,
    ensuring the visit target is zeroed out at exclusion time.

Safety Assurance

Safety story

Changes are isolated to read paths (queryset filtering, property aggregation)
and a single extra field write during the existing exclusion flow. No
migrations are required. Excluded work areas already had their
work_area_group nulled out; this PR extends that same cleanup logic to
expected_visit_count and to the two remaining read surfaces. Existing
excluded records will have their expected_visit_count corrected the next
time they are excluded (no backfill needed for historical data since this is
an early-stage feature).

Automated test coverage

  • TestWorkAreaGroupBuildingCount (tests/test_models.py) — three
    cases: sums non-excluded areas, ignores excluded areas, returns zero when all
    excluded.
  • TestDownloadWorkAreas.test_excludes_excluded_work_areas
    (tests/test_views.py) — verifies excluded work areas are absent from the
    CSV download.
  • TestExcludeWorkAreas (tests/test_views.py) — extended with an
    assertion that expected_visit_count == 0 after exclusion.

QA Plan

N.A

Labels & Review

  • The set of people pinged as reviewers is appropriate for the level of
    risk of the change

@Charl1996 Charl1996 marked this pull request as ready for review April 22, 2026 13:44
Comment thread commcare_connect/microplanning/models.py
@Charl1996 Charl1996 force-pushed the cs/CCCT-2283-coverage-area-calculation-update branch from 0e22125 to 8665c2c Compare April 22, 2026 15:40
Copy link
Copy Markdown
Contributor

@pxwxnvermx pxwxnvermx left a comment

Choose a reason for hiding this comment

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

Couple of questions regarding clustering.

  1. Do the excluded work areas still remain a part of the work area group that was assigned to them during clustering?
  2. Can a work area be excluded before the clustering is run? If yes, should that work area be excluded from the clustering?

@Charl1996 Charl1996 force-pushed the cs/CCCT-2283-coverage-area-calculation-update branch from f5e99f6 to 8665c2c Compare April 23, 2026 09:10
@Charl1996
Copy link
Copy Markdown
Contributor Author

@pxwxnvermx

Do the excluded work areas still remain a part of the work area group that was assigned to them during clustering?

I think so? Let me confirm.

Can a work area be excluded before the clustering is run? If yes, should that work area be excluded from the clustering?

Not as far as I'm aware, but I'll check as well.

@Charl1996
Copy link
Copy Markdown
Contributor Author

@pxwxnvermx

Can a work area be excluded before the clustering is run? If yes, should that work area be excluded from the clustering?

See 9460268

Do the excluded work areas still remain a part of the work area group that was assigned to them during clustering?

Confirmed for now it will be.

Comment on lines +174 to +175
slug="excluded-area",
ward="ward-1",
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Minor nit: Since these values aren't being tested anywhere these fields can safely be removed as they get given defaults by the factory.

@mkangia mkangia mentioned this pull request May 1, 2026
9 tasks
Base automatically changed from ze/exclude-work-areas to main May 6, 2026 13:41
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.

4 participants