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

Add Enterprise SMS Report #35437

Merged
merged 11 commits into from
Dec 4, 2024
Merged

Add Enterprise SMS Report #35437

merged 11 commits into from
Dec 4, 2024

Conversation

mjriley
Copy link
Contributor

@mjriley mjriley commented Nov 25, 2024

Product Description

Adds a new Enterprise SMS Report, including associated tile and API.

Technical Summary

Associated ticket: https://dimagi.atlassian.net/browse/SAAS-16131

At the moment, the new API is implemented using the old population logic, as the new iterator logic was only written for Elasticsearch queries and didn't take into account how to generate summary statistics. The intent is to eventually use the new iterator logic, but more work will need to be done to determine how best to support the SMS queries with that framework

Feature Flag

We mentioned we would prefer to do an iterative approach to these new tiles, so this is ready for release without a feature flag

Safety Assurance

Safety story

Tested locally -- generated the report, accessed the API through the browser, and accessed it through PowerBI. Verified that UI worked as expected.

Automated test coverage

None at the moment. As it stands, the code to be tested is the EnterpriseSMSReport code, but I'd like to eventually move the logic out of there into a query class and test against that.

QA Plan

TBD

Rollback instructions

  • This PR can be reverted after deploy with no further considerations

Labels & Review

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

@mjriley mjriley added the product/admin Change affects admin pages only visible to super users / staff label Nov 25, 2024
Copy link
Contributor

@jingcheng16 jingcheng16 left a comment

Choose a reason for hiding this comment

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

Reviewed partial of the PR with @biyeun



class EnterpriseSMSReport(EnterpriseReport):
title = gettext_lazy('SMS Sent')
Copy link
Contributor

Choose a reason for hiding this comment

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

Change the title to align with the design doc

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Addressed in fc4fccd

def __init__(self, account, couch_user, start_date=None, end_date=None, num_days=30):
super().__init__(account, couch_user)

if not end_date:
Copy link
Contributor

Choose a reason for hiding this comment

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

Can you make it as a util function so other tiles can reuse it?

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 believe I did this in the iterators PR, which is still in review. Re-adding it here would cause conflicts, so I'm going to wait until that PR is merged for this functionality

@property
def headers(self):
headers = super().headers
headers = [_('Project Space Name'), _('# Sent'), _('# Received'), _('# Errors')]
Copy link
Contributor

Choose a reason for hiding this comment

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

Simplify the header to be Project Space

Copy link
Contributor Author

Choose a reason for hiding this comment

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

.annotate(error_count=error_subquery)
.values_list('domain', 'sent_count', 'received_count', 'error_count')
)
num_sent = sum([result['direction_count'] for result in results if result['direction'] == OUTGOING])
Copy link
Contributor

Choose a reason for hiding this comment

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

Should we only include sms that is succesfully sent and received? If we don't charge them, then we should not include errored sms in num_sent and num_received

Copy link
Contributor

Choose a reason for hiding this comment

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

total_for_domain should also align with the number in report, when people sum up num_sent for all domains

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Addressed in 1adcaf3

REPORT_SLUG = EnterpriseReport.SMS

def get_report_task(self, request):
start_date = request.GET.get('startdate', None)
Copy link
Contributor

Choose a reason for hiding this comment

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

util function for it?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

@jingcheng16
Copy link
Contributor

@mjriley Can review again once the conflicts with master are resolved. Btw, do you plan to put it through QA?

@mjriley mjriley merged commit 4561106 into master Dec 4, 2024
13 checks passed
@mjriley mjriley deleted the mjr/sms-usage-tile branch December 4, 2024 20:19
Copy link

sentry-io bot commented Dec 7, 2024

Suspect Issues

This pull request was deployed and Sentry observed the following issues:

  • ‼️ TypeError: '<=' not supported between instances of 'datetime.datetime' and 'str' /a/{domain}/enterprise/dashboard/{slug}/total/ View Issue

Did you find this useful? React with a 👍 or 👎

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
product/admin Change affects admin pages only visible to super users / staff
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants