Пример #1
0
 def test_possible_savings_for_practice_not_enough_months(self):
     finder = bookmark_utils.InterestingMeasureFinder(
         practice=self.practice)
     savings = finder.top_and_total_savings_in_period(10)
     self.assertEqual(savings['possible_savings'], [])
     self.assertEqual(savings['achieved_savings'], [])
     self.assertEqual(savings['possible_top_savings_total'], 0)
 def test_possible_savings_for_practice(self):
     finder = bookmark_utils.InterestingMeasureFinder(
         practice=self.practice)
     savings = finder.top_and_total_savings_in_period(3)
     self.assertEqual(savings["possible_savings"], [(self.measure, 3500)])
     self.assertEqual(savings["achieved_savings"], [])
     self.assertEqual(savings["possible_top_savings_total"], 350000)
 def test_no_hit_where_practice_best_and_low_is_bad(self):
     self.measure.low_is_good = False
     self.measure.save()
     finder = bookmark_utils.InterestingMeasureFinder(
         practice=self.low_percentile_practice)
     best_measures = finder.best_performing_in_period(3)
     self.assertFalse(best_measures)
Пример #4
0
 def test_achieved_savings(self):
     finder = bookmark_utils.InterestingMeasureFinder(
         practice=self.practice)
     savings = finder.top_and_total_savings_in_period(3)
     self.assertEqual(savings['possible_savings'], [])
     self.assertEqual(savings['achieved_savings'], [(self.measure, 1400)])
     self.assertEqual(savings['possible_top_savings_total'], 10000)
 def test_possible_savings_for_ccg(self):
     finder = bookmark_utils.InterestingMeasureFinder(
         pct=self.practice.ccg)
     savings = finder.top_and_total_savings_in_period(3)
     self.assertEqual(savings['possible_savings'], [])
     self.assertEqual(savings['achieved_savings'], [])
     self.assertEqual(savings['possible_top_savings_total'], 0)
 def test_miss_where_not_better_in_specified_number_of_months(self):
     self.measure.low_is_good = False
     self.measure.save()
     finder = bookmark_utils.InterestingMeasureFinder(
         pct=self.pct)
     worst_measures = finder.worst_performing_in_period(3)
     self.assertFalse(worst_measures)
 def test_non_ordinal_sorting(self, most_change_in_period,
                              best_performing_in_period,
                              worst_performing_in_period):
     ordinal_measure_1 = MagicMock(low_is_good=True)
     non_ordinal_measure_1 = MagicMock(low_is_good=None)
     non_ordinal_measure_2 = MagicMock(low_is_good=None)
     most_change_in_period.return_value = {
         'improvements': [(ordinal_measure_1, )],
         'declines': [(non_ordinal_measure_1, ), (non_ordinal_measure_2, )]
     }
     best_performing_in_period.return_value = [
         ordinal_measure_1, non_ordinal_measure_1
     ]
     worst_performing_in_period.return_value = [
         ordinal_measure_1, non_ordinal_measure_1
     ]
     finder = bookmark_utils.InterestingMeasureFinder(pct='foo')
     context = finder.context_for_org_email()
     self.assertEqual(context['most_changing_interesting'],
                      [(non_ordinal_measure_1, ),
                       (non_ordinal_measure_2, )])
     self.assertEqual(context['interesting'], [non_ordinal_measure_1])
     self.assertEqual(context['best'], [ordinal_measure_1])
     self.assertEqual(context['worst'], [ordinal_measure_1])
     self.assertEqual(context['most_changing']['improvements'],
                      [(ordinal_measure_1, )])
    def send_org_bookmark_email(self, org_bookmark, now_month, options):
        if org_bookmark.practice or options["practice"]:
            org = org_bookmark.practice or Practice.objects.get(
                pk=options["practice"])
        elif org_bookmark.pct or options["ccg"]:
            org = org_bookmark.pct or PCT.objects.get(pk=options["ccg"])
        elif org_bookmark.pcn or options["pcn"]:
            org = org_bookmark.pcn or PCN.objects.get(pk=options["pcn"])
        else:
            assert False
        if getattr(org, "close_date", None):
            logger.info("Skipping sending alert for closed org %s", org.pk)
            return
        stats = bookmark_utils.InterestingMeasureFinder(
            org).context_for_org_email()

        try:
            msg = bookmark_utils.make_org_email(org_bookmark,
                                                stats,
                                                tag=now_month)
            msg = EmailMessage.objects.create_from_message(msg)
            msg.send()
            logger.info("Sent org bookmark alert to %s about %s" %
                        (msg.to, org_bookmark.id))
        except bookmark_utils.BadAlertImageError as e:
            logger.exception(e)
 def test_low_change_not_returned_for_practice(self):
     finder = bookmark_utils.InterestingMeasureFinder(
         practice=self.practice_with_low_change,
         interesting_percentile_change=10)
     self.assertEqual(finder.most_change_in_period(3), {
         'improvements': [],
         'declines': []
     })
Пример #10
0
 def test_high_negative_change_returned(self):
     finder = bookmark_utils.InterestingMeasureFinder(
         self.practice_with_high_neg_change, interesting_change_window=10)
     sorted_measure = finder.most_change_against_window(1)
     measure_info = sorted_measure["declines"][0]
     self.assertEqual(measure_info["measure"].id, "cerazette")
     self.assertAlmostEqual(measure_info["from"], 21)  # start
     self.assertAlmostEqual(measure_info["to"], 7)  # end
Пример #11
0
 def test_possible_savings_low_is_good(self):
     self.measure.low_is_good = True
     self.measure.save()
     finder = bookmark_utils.InterestingMeasureFinder(self.practice)
     savings = finder.top_and_total_savings_in_period(3)
     self.assertEqual(savings["possible_savings"], [(self.measure, 3500)])
     self.assertEqual(savings["achieved_savings"], [])
     self.assertEqual(savings["possible_top_savings_total"], 350.0)
Пример #12
0
 def test_high_negative_change_returned(self):
     finder = bookmark_utils.InterestingMeasureFinder(
         practice=self.practice_with_high_neg_change,
         interesting_change_window=10)
     sorted_measure = finder.most_change_against_window(1)
     measure_info = sorted_measure['declines'][0]
     self.assertEqual(measure_info['measure'].id, 'cerazette')
     self.assertAlmostEqual(measure_info['from'], 21)  # start
     self.assertAlmostEqual(measure_info['to'], 7)  # end
Пример #13
0
 def test_high_change_declines_when_low_is_good(self):
     self.measure.low_is_good = True
     self.measure.save()
     finder = bookmark_utils.InterestingMeasureFinder(
         self.practice_with_high_change, interesting_change_window=10)
     sorted_measure = finder.most_change_against_window(1)
     measure_info = sorted_measure["declines"][0]
     self.assertEqual(measure_info["measure"].id, "cerazette")
     self.assertAlmostEqual(measure_info["from"], 7)  # start
     self.assertAlmostEqual(measure_info["to"], 21)  # end
Пример #14
0
 def test_high_negative_change_returned(self):
     finder = bookmark_utils.InterestingMeasureFinder(
         practice=self.practice_with_high_neg_change,
         interesting_percentile_change=10)
     sorted_measure = finder.most_change_in_period(3)
     measure_info = sorted_measure['declines'][0]
     self.assertEqual(measure_info[0].id, 'cerazette')
     self.assertAlmostEqual(measure_info[1], 21)  # start
     self.assertAlmostEqual(measure_info[2], 7)  # end
     self.assertAlmostEqual(measure_info[3], 0)  # residuals
Пример #15
0
 def test_high_change_declines_when_low_is_good(self):
     self.measure.low_is_good = True
     self.measure.save()
     finder = bookmark_utils.InterestingMeasureFinder(
         practice=self.practice_with_high_change,
         interesting_change_window=10)
     sorted_measure = finder.most_change_against_window(1)
     measure_info = sorted_measure['declines'][0]
     self.assertEqual(measure_info['measure'].id, 'cerazette')
     self.assertAlmostEqual(measure_info['from'], 7)  # start
     self.assertAlmostEqual(measure_info['to'], 21)  # end
                def callback():
                    stats = bookmark_utils.InterestingMeasureFinder(
                        practice=org_bookmark.practice or options['practice'],
                        pct=org_bookmark.pct
                        or options['ccg']).context_for_org_email()

                    msg = bookmark_utils.make_org_email(org_bookmark, stats)
                    msg = EmailMessage.objects.create_from_message(msg)
                    msg.send()
                    logger.info("Sent org bookmark alert to %s about %s" %
                                (msg.to, org_bookmark.id))
Пример #17
0
 def test_high_change_declines_when_low_is_good(self):
     self.measure.low_is_good = True
     self.measure.save()
     finder = bookmark_utils.InterestingMeasureFinder(
         practice=self.practice_with_high_change,
         interesting_percentile_change=10)
     sorted_measure = finder.most_change_in_period(3)
     measure_info = sorted_measure['declines'][0]
     self.assertEqual(measure_info[0].id, 'cerazette')
     self.assertAlmostEqual(measure_info[1], 7)  # start
     self.assertAlmostEqual(measure_info[2], 21)  # end
     self.assertAlmostEqual(measure_info[3], 0)  # residuals
Пример #18
0
 def test_low_change_not_returned_for_ccg(self):
     # This test will raise a warning due to all imput being
     # None. Silence it.
     import warnings
     with warnings.catch_warnings():
         warnings.simplefilter("ignore", RuntimeWarning)
         finder = bookmark_utils.InterestingMeasureFinder(
             pct=self.practice_with_low_change.ccg,
             interesting_percentile_change=10)
         self.assertEqual(finder.most_change_in_period(3), {
             'improvements': [],
             'declines': []
         })
Пример #19
0
def preview_bookmark(request, practice=None, pct=None, url=None, name=None):
    user = User(email='*****@*****.**')
    user.profile = Profile()
    if pct or practice:
        context = bookmark_utils.InterestingMeasureFinder(
            practice=practice, pct=pct).context_for_org_email()
        bookmark = OrgBookmark(practice=practice, pct=pct, user=user)
        msg = bookmark_utils.make_org_email(bookmark, context)
    else:
        bookmark = SearchBookmark(url=url, user=user, name=name)
        msg = bookmark_utils.make_search_email(bookmark)
    html = msg.alternatives[0][0]
    images = msg.attachments
    return HttpResponse(_convert_images_to_data_uris(html, images))
Пример #20
0
 def send_org_bookmark_email(self, org_bookmark, now_month, options):
     stats = bookmark_utils.InterestingMeasureFinder(
         practice=org_bookmark.practice or options['practice'],
         pct=org_bookmark.pct or options['ccg']
     ).context_for_org_email()
     try:
         msg = bookmark_utils.make_org_email(org_bookmark, stats, tag=now_month)
         msg = EmailMessage.objects.create_from_message(msg)
         msg.send()
         logger.info(
             "Sent org bookmark alert to %s about %s" % (
                 msg.to, org_bookmark.id))
     except bookmark_utils.BadAlertImageError as e:
         logger.exception(e)
Пример #21
0
 def test_non_ordinal_sorting(
     self,
     most_change_against_window,
     best_performing_in_period,
     worst_performing_in_period,
 ):
     ordinal_measure_1 = MagicMock(low_is_good=True)
     non_ordinal_measure_1 = MagicMock(low_is_good=None)
     non_ordinal_measure_2 = MagicMock(low_is_good=None)
     most_change_against_window.return_value = {
         "improvements": [
             {
                 "measure": ordinal_measure_1
             },
             {
                 "measure": non_ordinal_measure_2
             },
         ],
         "declines": [{
             "measure": non_ordinal_measure_1
         }],
     }
     best_performing_in_period.return_value = [
         ordinal_measure_1,
         non_ordinal_measure_2,
     ]
     worst_performing_in_period.return_value = [
         ordinal_measure_1,
         non_ordinal_measure_1,
     ]
     finder = bookmark_utils.InterestingMeasureFinder(
         PCT.objects.create(code="000"))
     context = finder.context_for_org_email()
     self.assertCountEqual(
         context["most_changing_interesting"],
         [{
             "measure": non_ordinal_measure_1
         }, {
             "measure": non_ordinal_measure_2
         }],
     )
     self.assertCountEqual(context["interesting"],
                           [non_ordinal_measure_1, non_ordinal_measure_2])
     self.assertEqual(context["best"], [ordinal_measure_1])
     self.assertEqual(context["worst"], [ordinal_measure_1])
     self.assertEqual(context["most_changing"]["improvements"],
                      [{
                          "measure": ordinal_measure_1
                      }])
Пример #22
0
    def handle(self, *args, **options):
        self.validate_options(**options)
        for org_bookmark in self.get_org_bookmarks(**options):
            stats = bookmark_utils.InterestingMeasureFinder(
                practice=org_bookmark.practice or options['practice'],
                pct=org_bookmark.pct or options['ccg']).context_for_org_email()

            msg = bookmark_utils.make_org_email(
                org_bookmark, stats)
            msg.send()
            logger.info("Sent message to user %s about bookmark %s" % (
                msg.recipients(), org_bookmark.id))
        for search_bookmark in self.get_search_bookmarks(**options):
            recipient_id = search_bookmark.user.id
            msg = bookmark_utils.make_search_email(
                search_bookmark)
            msg.send()
            logger.info("Sent message to user %s about bookmark %s" % (
                recipient_id, search_bookmark.id))
Пример #23
0
 def test_hit_where_practice_best_in_specified_number_of_months(self):
     finder = bookmark_utils.InterestingMeasureFinder(
         practice=self.low_percentile_practice)
     best_measures = finder.best_performing_in_period(3)
     self.assertIn(self.measure, best_measures)
Пример #24
0
 def test_miss_where_not_worst_in_specified_number_of_months(self):
     MeasureValue.objects.all().delete()
     finder = bookmark_utils.InterestingMeasureFinder(pct=self.pct)
     worst_measures = finder.worst_performing_in_period(3)
     self.assertFalse(worst_measures)
Пример #25
0
 def test_miss_where_not_enough_global_data(self):
     finder = bookmark_utils.InterestingMeasureFinder(pct=self.pct)
     worst_measures = finder.worst_performing_in_period(6)
     self.assertFalse(worst_measures)
Пример #26
0
 def test_hit_where_ccg_worst_in_specified_number_of_months(self):
     finder = bookmark_utils.InterestingMeasureFinder(pct=self.pct)
     worst_measures = finder.worst_performing_in_period(3)
     self.assertIn(self.measure, worst_measures)
     self.assertNotIn(self.exotic_measure, worst_measures)