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

New dashboard #4330

Open
wants to merge 28 commits into
base: develop
Choose a base branch
from
Open

New dashboard #4330

wants to merge 28 commits into from

Conversation

srugano
Copy link
Contributor

@srugano srugano commented Oct 15, 2024

Copy link

codecov bot commented Oct 15, 2024

Codecov Report

Attention: Patch coverage is 77.72021% with 43 lines in your changes missing coverage. Please review.

Project coverage is 55.05%. Comparing base (6ef7a33) to head (1a824d1).

Files with missing lines Patch % Lines
src/hct_mis_api/apps/dashboard/celery_tasks.py 53.12% 15 Missing ⚠️
src/hct_mis_api/apps/dashboard/views.py 75.00% 15 Missing ⚠️
src/hct_mis_api/apps/dashboard/services.py 80.00% 11 Missing ⚠️
src/hct_mis_api/config/settings.py 88.88% 1 Missing ⚠️
src/hct_mis_api/middlewares/xframe.py 90.90% 1 Missing ⚠️

❗ There is a different number of reports uploaded between BASE (6ef7a33) and HEAD (1a824d1). Click for more details.

HEAD has 2 uploads less than BASE
Flag BASE (6ef7a33) HEAD (1a824d1)
unittests 2 0
Additional details and impacted files
@@             Coverage Diff              @@
##           develop    #4330       +/-   ##
============================================
- Coverage    77.59%   55.05%   -22.55%     
============================================
  Files          944      950        +6     
  Lines        44624    44620        -4     
============================================
- Hits         34628    24564    -10064     
- Misses        9996    20056    +10060     
Flag Coverage Δ
e2e 55.05% <77.72%> (+7.44%) ⬆️
unittests ?

Flags with carried forward coverage won't be shown. Click here to find out more.

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

@srugano srugano marked this pull request as ready for review October 22, 2024 01:06
@mmaciekk mmaciekk added frontend Changes in FE code backend Changes in BE code labels Oct 30, 2024
@domdinicola
Copy link
Collaborator

@srugano regenerate lock

@domdinicola
Copy link
Collaborator

@srugano regenerate pdm

@srugano srugano requested a review from mmaciekk November 3, 2024 05:53
}

const url = householdDataUrl;
console.log(url);
Copy link
Contributor

Choose a reason for hiding this comment

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

remove console.log

).value();

const totalSuccessfulUSD = successfulPaymentsGroupUSD.sum;
console.log(totalSuccessfulUSD);
Copy link
Contributor

Choose a reason for hiding this comment

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

remove console.log

(p, v) => p - (v.children_count || 0),
() => 0
).value();
console.log( successfulPaymentsCountUSD.sum, totalPaymentsCount, pendingPaymentsGroupUSD.count);
Copy link
Contributor

Choose a reason for hiding this comment

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

remove console log

assert "0" in pageCountryDashboard.getTotalNumberOfFeedback().text
assert "USD 0.00" in pageCountryDashboard.getTotalAmountTransferred().text
pageCountryDashboard.switch_to_dashboard_iframe()
# assert pageCountryDashboard.get_total_amount_paid().text == "", "Expected total amount paid to be empty."
Copy link
Contributor

Choose a reason for hiding this comment

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

Why are these tests commented out?

from typing import List, Optional

from django.http import HttpRequest, HttpResponse
from django.utils.deprecation import MiddlewareMixin
Copy link
Contributor

Choose a reason for hiding this comment

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

@johniak, @MarekBiczysko Please check if this middleware is correct. I needed to overwrite the default django setting in order to display dashboard page in an iframe

pyproject.toml Outdated
@@ -98,6 +98,7 @@ dev = [
"pytest<8.0.0,>=7.4.4",
"pytest-django<5.0.0,>=4.5.2",
"pytest-echo<2.0.0,>=1.7.1",
"pytest-mock<4.0.0,>=3.6.0",
Copy link
Member

Choose a reason for hiding this comment

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

What is the reason for this library? Is it needed?

Copy link
Contributor Author

@srugano srugano Nov 4, 2024

Choose a reason for hiding this comment

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

That's the way I was able to test tasks running in exceptions.

"""
Test that generate_dash_report_task refreshes data for the given business area.
"""
mock_refresh_data = mocker.patch.object(DashboardDataCache, "refresh_data")
Copy link
Member

Choose a reason for hiding this comment

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

This is the wrong way to call patch.object. You are not patching an object here

mock_household_objects.using.return_value.filter.return_value = mock_households
mock_serializer.return_value.data = {"id": 1, "name": "test"}

with patch.object(DashboardDataCache, "store_data") as mock_store_data:
Copy link
Member

Choose a reason for hiding this comment

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

this can be done with monkeypatch and it is more correct in this case

assert "0" in pageCountryDashboard.getTotalNumberOfGrievances().text
assert "0" in pageCountryDashboard.getTotalNumberOfFeedback().text
assert "USD 0.00" in pageCountryDashboard.getTotalAmountTransferred().text
pageCountryDashboard.switch_to_dashboard_iframe()
Copy link
Member

Choose a reason for hiding this comment

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

what are these commented out lines?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

still updating the figures

tests/unit/apps/dashboard/test_services.py Show resolved Hide resolved
@patch.object(DashboardDataCache, "refresh_data")
@patch("hct_mis_api.apps.core.models.BusinessArea.objects")
def test_update_dashboard_figures(
mock_business_area_objects: MagicMock, mock_refresh_data: MagicMock, afghanistan: BusinessArea
Copy link
Member

Choose a reason for hiding this comment

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

where are these fixtures ?

Comment on lines 40 to 49
@classmethod
def refresh_data(cls, business_area_slug: str) -> Dict[str, Any]:
"""
Generate and store updated data for a given business area.
"""
households = Household.objects.using("read_only").filter(business_area__slug=business_area_slug)
serialized_data = DashboardHouseholdSerializer(households, many=True).data

cls.store_data(business_area_slug, serialized_data)
return serialized_data
Copy link
Contributor

Choose a reason for hiding this comment

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

If I understand correctly we cache ALL households/payments data for the whole BA and then do the statistics calculations in the browser. This is huge amount of data for some business areas, wouldn't be easier to precalculate statistics on server side and cache only the final results?

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 have tested with 500000 payments over 3 years and it can handle. I have precalculated some totals

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
backend Changes in BE code frontend Changes in FE code
Projects
None yet
Development

Successfully merging this pull request may close these issues.

5 participants