def admin_stats_summary(report_schedule, run_frequency): """The domain summary, total counts of forms/chws and and breakdowns by form type and CHW""" all_data = [] global_stats = {} global_stats["name"] = "Global Total" global_stats["submissions"] = Submission.objects.count() global_stats["attachments"] = Attachment.objects.count() global_stats["form_count"] = FormDefModel.objects.count() global_stats["count"] = Metadata.objects.count() global_stats["chw_count"] = Metadata.objects.values_list('username', flat=True).distinct().count() global_stats["first_submission"] = Submission.objects.order_by("submit_time")[0].submit_time global_stats["last_submission"] = Submission.objects.order_by("-submit_time")[0].submit_time all_data.append(global_stats) for domain in Domain.objects.all(): summary = DomainSummary(domain) all_data.append(summary) body = render_to_string("hq/reports/global_stats.html", {"global_stats": all_data }) # annoying import cause of circular dependencies. from hq import reporter reporter.transport_email(body, report_schedule.recipient_user, params={"email_subject": "CommCareHQ Global Stats Report %s" %\ datetime.now().date() })
def delinquent_alert(report_schedule, run_frequency): org = report_schedule.organization transport = report_schedule.report_delivery usr = report_schedule.recipient_user threshold = 14 statdict = metastats.get_stats_for_domain(org.domain) context = get_delinquent_context_from_statdict(statdict, threshold) rendered_text = render_to_string("hq/reports/sms_delinquent_report.txt",context) if report_schedule.report_delivery == 'email': subject = "[CommCare HQ] Daily Idle Reporter Alert for " + datetime.datetime.now().strftime('%m/%d/%Y') + " " + str(threshold) + " day threshold" reporter.transport_email(rendered_text, usr, params={"email_subject":subject}) else: reporter.transport_sms(rendered_text, usr)
def _catch_all_report(report_schedule, run_frequency, domains, title): rendered_text = '' from hq import reporter # DAN HACK: everyone wants the daily reports to show the last week's worth of data # so change this if run_frequency == 'daily': run_frequency='weekly' (startdate, enddate) = reporter.get_daterange(run_frequency) for domain in domains: rendered_text += _get_catch_all_email_text(domain, startdate, enddate) if report_schedule.report_delivery == 'email': usr = report_schedule.recipient_user subject = "[CommCare HQ] %s report %s - %s :: %s" %\ (run_frequency, startdate.strftime('%m/%d/%Y'), enddate.strftime('%m/%d/%Y'), title) reporter.transport_email(rendered_text, usr, params={"startdate":startdate,"enddate":enddate,"email_subject":subject})