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

Network manager funnel performance #391

Open
wants to merge 15 commits into
base: main
Choose a base branch
from

Conversation

hemant10yadav
Copy link
Contributor

@hemant10yadav hemant10yadav commented Sep 16, 2024

@hemant10yadav hemant10yadav changed the title Hy/network manager funnel performance Network manager funnel performance Sep 16, 2024
Base automatically changed from hy/invite-program to hy/managed-opportunity-creation September 18, 2024 06:54
Base automatically changed from hy/managed-opportunity-creation to main September 18, 2024 06:54
@hemant10yadav hemant10yadav self-assigned this Sep 18, 2024
@hemant10yadav hemant10yadav marked this pull request as draft September 30, 2024 03:00
@hemant10yadav hemant10yadav marked this pull request as ready for review September 30, 2024 08:15
Copy link
Collaborator

@calellowitz calellowitz left a comment

Choose a reason for hiding this comment

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

generally looks good. a few questions and one small nit

commcare_connect/program/helpers.py Outdated Show resolved Hide resolved
)
.exclude(status__in=[VisitValidationStatus.over_limit, VisitValidationStatus.trial])
.order_by("visit_date")
.values("visit_date")[:1]
Copy link
Collaborator

Choose a reason for hiding this comment

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

nit: You can use .first() here instead of the slice

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I tried .first() but subquery here expects a queryset.

commcare_connect/program/helpers.py Outdated Show resolved Hide resolved
from commcare_connect.program.models import ManagedOpportunity, Program


def calculate_safe_percentage(numerator, denominator):
Copy link
Member

Choose a reason for hiding this comment

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

It's not worth for this to be a function, may be a private function inside the caller would be better

Copy link
Contributor Author

@hemant10yadav hemant10yadav Oct 15, 2024

Choose a reason for hiding this comment

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

I have used this function in PR-402 too.

assert annotated_opp.percentage_conversion == 60.0

def test_empty_scenario(self):
opps = get_annotated_managed_opportunity(self.program)
Copy link
Member

Choose a reason for hiding this comment

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

You could consider using parametrize, to combine some of the tests like below (not tested). Allows to be more DRY and concise.

    @pytest.mark.parametrize(
        "visit_statuses, passing_assessments, expected_invited, expected_passing, expected_delivery, expected_conversion",
        [
            ([VisitValidationStatus.pending, VisitValidationStatus.pending, VisitValidationStatus.trial], 
             [True, True, True], 5, 5, 3, 60.0),  # Basic scenario
            ([], [], 0, 0, 0, 0.0),  # Empty scenario
            ([VisitValidationStatus.pending] * 3, [True] * 3, 1, 1, 1, 100.0),  # Multiple visits scenario
            ([VisitValidationStatus.over_limit, VisitValidationStatus.trial], 
             [True, True], 2, 2, 0, 0.0),  # Excluded statuses
            ([VisitValidationStatus.pending, VisitValidationStatus.pending], 
             [False, True], 2, 1, 2, 100.0),  # Failed assessments
        ]
    )
    def test_scenarios(self, visit_statuses, passing_assessments, expected_invited, expected_passing, expected_delivery, expected_conversion):
        for i, visit_status in enumerate(visit_statuses):
            self.create_user_with_access(visit_status=visit_status, passed_assessment=passing_assessments[i])

        opps = get_annotated_managed_opportunity(self.program)
        assert len(opps) == 1
        annotated_opp = opps[0]
        assert annotated_opp.workers_invited == expected_invited
        assert annotated_opp.workers_passing_assessment == expected_passing
        assert annotated_opp.workers_starting_delivery == expected_delivery
        assert annotated_opp.percentage_conversion == expected_conversion

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Added f87aa02

Copy link
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.

LGTM. Thanks 🙌🏽

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