Exemple #1
0
def command(cycle):
    data = Cycle.objects.filter(title=cycle)
    for cycle in data:
        report = FreeFormReport(None, cycle.title).build_form_db(cycle)
        run_checks(report)
        persist_scores(report)
    export_results()
def perform_checks():
    cycle = "Sep - Oct 2015"
    data = Cycle.objects.filter(title=cycle)
    for cycle in data:
        report = FreeFormReport(None, cycle.title).build_form_db(cycle)
        run_checks(report)
        persist_scores(report)

    checks = [
        {'combination': F1, 'test': STABLE_PATIENT_VOLUMES, 'cycle': cycle, YES: 793, NO: 405, NOT_REPORTING: 632},
        {'combination': DEFAULT, 'test': NNRTI_NEW_PAED, 'cycle': cycle, YES: 681, NO: 644, NOT_REPORTING: 509},
        {'combination': DEFAULT, 'test': NNRTI_NEW_ADULTS, 'cycle': cycle, YES: 799, NO: 573, NOT_REPORTING: 462},
        {'combination': DEFAULT, 'test': NNRTI_CURRENT_PAED, 'cycle': cycle, YES: 548, NO: 780, NOT_REPORTING: 506},
        {'combination': DEFAULT, 'test': NNRTI_CURRENT_ADULTS, 'cycle': cycle, YES: 937, NO: 439, NOT_REPORTING: 458},
    ]
    for check in checks:
        if check.get('combination') == DEFAULT:
            yes_condition = {DEFAULT: YES}
            no_condition = {DEFAULT: NO}
            not_reporting_condition = {(DEFAULT): NOT_REPORTING}
        else:
            yes_condition = {check.get('combination'): YES}
            no_condition = {check.get('combination'): NO}
            not_reporting_condition = {check.get('combination'): NOT_REPORTING}
        for key, condition in {YES: yes_condition, NO: no_condition, NOT_REPORTING: not_reporting_condition}.items():
            test_description = "%s %s" % (check['test'], key)
            filter_key = "%s__icontains" % check.get('test')
            filter_by = {filter_key: make_cond(condition)}
            count = Score.objects.filter(cycle=check['cycle'], **filter_by).count()
            expected = check[key]
            actual = count
            if expected == actual:
                print colored(test_description + " Passed", "green")
            else:
                tolerance = 10
                diff = abs(float(expected) - float(actual))
                c = "yellow" if diff <= tolerance else "red"
                print colored(test_description + " Failed", c), colored("Got %s instead of %s " % (actual, expected), c), colored("diff: %s" % diff, "blue")
        print "\n"
def perform_checks():
    cycle = "Sep - Oct 2015"
    data = Cycle.objects.filter(title=cycle)
    for cycle in data:
        report = FreeFormReport(None, cycle.title).build_form_db(cycle)
        run_checks(report)
        persist_scores(report)

    checks = [
        {
            'combination': F1,
            'test': STABLE_PATIENT_VOLUMES,
            'cycle': cycle,
            YES: 793,
            NO: 405,
            NOT_REPORTING: 632
        },
        {
            'combination': DEFAULT,
            'test': NNRTI_NEW_PAED,
            'cycle': cycle,
            YES: 681,
            NO: 644,
            NOT_REPORTING: 509
        },
        {
            'combination': DEFAULT,
            'test': NNRTI_NEW_ADULTS,
            'cycle': cycle,
            YES: 799,
            NO: 573,
            NOT_REPORTING: 462
        },
        {
            'combination': DEFAULT,
            'test': NNRTI_CURRENT_PAED,
            'cycle': cycle,
            YES: 548,
            NO: 780,
            NOT_REPORTING: 506
        },
        {
            'combination': DEFAULT,
            'test': NNRTI_CURRENT_ADULTS,
            'cycle': cycle,
            YES: 937,
            NO: 439,
            NOT_REPORTING: 458
        },
    ]
    for check in checks:
        if check.get('combination') == DEFAULT:
            yes_condition = {DEFAULT: YES}
            no_condition = {DEFAULT: NO}
            not_reporting_condition = {(DEFAULT): NOT_REPORTING}
        else:
            yes_condition = {check.get('combination'): YES}
            no_condition = {check.get('combination'): NO}
            not_reporting_condition = {check.get('combination'): NOT_REPORTING}
        for key, condition in {
                YES: yes_condition,
                NO: no_condition,
                NOT_REPORTING: not_reporting_condition
        }.items():
            test_description = "%s %s" % (check['test'], key)
            filter_key = "%s__icontains" % check.get('test')
            filter_by = {filter_key: make_cond(condition)}
            count = Score.objects.filter(cycle=check['cycle'],
                                         **filter_by).count()
            expected = check[key]
            actual = count
            if expected == actual:
                print colored(test_description + " Passed", "green")
            else:
                tolerance = 10
                diff = abs(float(expected) - float(actual))
                c = "yellow" if diff <= tolerance else "red"
                print colored(test_description + " Failed", c), colored(
                    "Got %s instead of %s " % (actual, expected),
                    c), colored("diff: %s" % diff, "blue")
        print "\n"