Exemple #1
0
def compare_ucr_dbs(domain,
                    report_config_id,
                    filter_values,
                    sort_column=None,
                    sort_order=None,
                    params=None):
    if report_config_id not in settings.UCR_COMPARISONS:
        return

    control_report, unused = get_report_config(report_config_id, domain)
    candidate_report = None

    new_report_config_id = settings.UCR_COMPARISONS.get(report_config_id)
    if new_report_config_id is not None:
        # a report is configured to be compared against
        candidate_report, unused = get_report_config(new_report_config_id,
                                                     domain)
        _compare_ucr_reports(domain, control_report, candidate_report,
                             filter_values, sort_column, sort_order, params)
    else:
        # no report is configured. Assume we should try mirrored engine_ids
        # report_config.config is a DataSourceConfiguration
        for engine_id in control_report.config.mirrored_engine_ids:
            _compare_ucr_reports(domain,
                                 control_report,
                                 control_report,
                                 filter_values,
                                 sort_column,
                                 sort_order,
                                 params,
                                 candidate_engine_id=engine_id)
Exemple #2
0
def compare_ucr_dbs(domain,
                    report_config_id,
                    filter_values,
                    sort_column=None,
                    sort_order=None,
                    params=None):
    from corehq.apps.userreports.laboratory.experiment import UCRExperiment

    new_report_config_id = settings.UCR_COMPARISONS.get(report_config_id)
    if new_report_config_id is None:
        return

    def _run_report(spec):
        data_source = ConfigurableReportDataSource.from_spec(
            spec, include_prefilters=True)
        data_source.set_filter_values(filter_values)
        if sort_column:
            data_source.set_order_by([
                (data_source.top_level_columns[int(sort_column)].column_id,
                 sort_order.upper())
            ])

        if params:
            datatables_params = DatatablesParams.from_request_dict(params)
            start = datatables_params.start
            limit = datatables_params.count
        else:
            start, limit = None, None
        page = list(data_source.get_data(start=start, limit=limit))
        total_records = data_source.get_total_records()
        json_response = {
            'aaData': page,
            "iTotalRecords": total_records,
        }
        total_row = data_source.get_total_row(
        ) if data_source.has_total_row else None
        if total_row is not None:
            json_response["total_row"] = total_row
        return json_response

    old_spec, unused = get_report_config(report_config_id, domain)
    new_spec, unused = get_report_config(new_report_config_id, domain)
    experiment_context = {
        "domain": domain,
        "report_config_id": report_config_id,
        "new_report_config_id": new_report_config_id,
        "filter_values": filter_values,
    }
    experiment = UCRExperiment(name="UCR DB Experiment",
                               context=experiment_context)
    with experiment.control() as c:
        c.record(_run_report(old_spec))

    with experiment.candidate() as c:
        c.record(_run_report(new_spec))

    objects = experiment.run()
    return objects
Exemple #3
0
def compare_ucr_dbs(domain, report_config_id, filter_values, sort_column=None, sort_order=None, params=None):
    from corehq.apps.userreports.laboratory.experiment import UCRExperiment

    new_report_config_id = settings.UCR_COMPARISONS.get(report_config_id)
    if new_report_config_id is None:
        return

    def _run_report(spec):
        data_source = ConfigurableReportDataSource.from_spec(spec, include_prefilters=True)
        data_source.set_filter_values(filter_values)
        if sort_column:
            data_source.set_order_by(
                [(data_source.top_level_columns[int(sort_column)].column_id, sort_order.upper())]
            )

        if params:
            datatables_params = DatatablesParams.from_request_dict(params)
            start = datatables_params.start
            limit = datatables_params.count
        else:
            start, limit = None, None
        page = list(data_source.get_data(start=start, limit=limit))
        total_records = data_source.get_total_records()
        json_response = {
            'aaData': page,
            "iTotalRecords": total_records,
        }
        total_row = data_source.get_total_row() if data_source.has_total_row else None
        if total_row is not None:
            json_response["total_row"] = total_row
        return json_response

    old_spec, unused = get_report_config(report_config_id, domain)
    new_spec, unused = get_report_config(new_report_config_id, domain)
    experiment_context = {
        "domain": domain,
        "report_config_id": report_config_id,
        "new_report_config_id": new_report_config_id,
        "filter_values": filter_values,
    }
    experiment = UCRExperiment(name="UCR DB Experiment", context=experiment_context)
    with experiment.control() as c:
        c.record(_run_report(old_spec))

    with experiment.candidate() as c:
        c.record(_run_report(new_spec))

    objects = experiment.run()
    return objects
Exemple #4
0
 def _get_report_and_data_source(report_id, domain):
     report = get_report_config(report_id, domain)[0]
     data_source = ReportFactory.from_spec(report, include_prefilters=True)
     if report.soft_rollout > 0 and data_source.config.backend_id == UCR_LABORATORY_BACKEND:
         if random.random() < report.soft_rollout:
             data_source.override_backend_id(UCR_ES_BACKEND)
     return report, data_source
Exemple #5
0
def has_location_filter(view_fn, *args, **kwargs):
    """check that the report has at least one location choice provider filter
    """
    report, _ = get_report_config(config_id=kwargs.get('subreport_slug'),
                                  domain=kwargs.get('domain'))
    return any(filter_.choice_provider.
               location_safe if hasattr(filter_, 'choice_provider') else False
               for filter_ in report.ui_filters)
Exemple #6
0
def has_location_filter(view_fn, *args, **kwargs):
    """check that the report has at least one location choice provider filter
    """
    report, _ = get_report_config(config_id=kwargs.get('subreport_slug'), domain=kwargs.get('domain'))
    return any(
        filter_.choice_provider.location_safe
        if hasattr(filter_, 'choice_provider') else False
        for filter_ in report.ui_filters
    )
Exemple #7
0
def has_location_filter(view_fn, *args, **kwargs):
    """check that the report has at least one location based filter or
    location choice provider filter
    """
    report, _ = get_report_config(config_id=kwargs.get('subreport_slug'),
                                  domain=kwargs.get('domain'))
    return any(
        getattr(getattr(filter_, 'choice_provider', None), 'location_safe',
                False) or getattr(filter_, 'location_filter', False)
        for filter_ in report.ui_filters)
Exemple #8
0
def has_location_filter(view_fn, *args, **kwargs):
    """check that the report has at least one location based filter or
    location choice provider filter
    """
    report, _ = get_report_config(config_id=kwargs.get('subreport_slug'), domain=kwargs.get('domain'))
    return any(
        getattr(getattr(filter_, 'choice_provider', None), 'location_safe', False) or
        getattr(filter_, 'location_filter', False)
        for filter_ in report.ui_filters
    )
Exemple #9
0
def report_has_location_filter(config_id, domain):
    """check that the report has at least one location based filter or
    location choice provider filter
    """
    if not (config_id and domain):
        return False
    report, _ = get_report_config(config_id=config_id, domain=domain)
    return any(
        getattr(getattr(filter_, 'choice_provider', None), 'location_safe',
                False) or getattr(filter_, 'location_filter', False)
        for filter_ in report.ui_filters)
Exemple #10
0
def compare_ucr_dbs(domain, report_config_id, filter_values, sort_column=None, sort_order=None, params=None):
    if report_config_id not in settings.UCR_COMPARISONS:
        return

    control_report, unused = get_report_config(report_config_id, domain)
    candidate_report = None

    new_report_config_id = settings.UCR_COMPARISONS.get(report_config_id)
    if new_report_config_id is not None:
        # a report is configured to be compared against
        candidate_report, unused = get_report_config(new_report_config_id, domain)
        _compare_ucr_reports(
            domain, control_report, candidate_report, filter_values, sort_column, sort_order, params)
    else:
        # no report is configured. Assume we should try mirrored engine_ids
        # report_config.config is a DataSourceConfiguration
        for engine_id in control_report.config.mirrored_engine_ids:
            _compare_ucr_reports(
                domain, control_report, control_report, filter_values, sort_column,
                sort_order, params, candidate_engine_id=engine_id)
Exemple #11
0
def compare_ucr_dbs(domain,
                    report_config_id,
                    filter_values,
                    sort_column=None,
                    sort_order=None,
                    params=None):
    from corehq.apps.userreports.laboratory.experiment import UCRExperiment

    def _run_report(backend_to_use):
        data_source = ReportFactory.from_spec(spec,
                                              include_prefilters=True,
                                              backend=backend_to_use)
        data_source.set_filter_values(filter_values)
        if sort_column:
            data_source.set_order_by([
                (data_source.top_level_columns[int(sort_column)].column_id,
                 sort_order.upper())
            ])

        if params:
            datatables_params = DatatablesParams.from_request_dict(params)
            start = datatables_params.start
            limit = datatables_params.count
        else:
            start, limit = None, None
        page = list(data_source.get_data(start=start, limit=limit))
        total_records = data_source.get_total_records()
        json_response = {
            'aaData': page,
            "iTotalRecords": total_records,
        }
        total_row = data_source.get_total_row(
        ) if data_source.has_total_row else None
        if total_row is not None:
            json_response["total_row"] = total_row
        return json_response

    spec, is_static = get_report_config(report_config_id, domain)
    experiment_context = {
        "domain": domain,
        "report_config_id": report_config_id,
        "filter_values": filter_values,
    }
    experiment = UCRExperiment(name="UCR DB Experiment",
                               context=experiment_context)
    with experiment.control() as c:
        c.record(_run_report(UCR_SQL_BACKEND))

    with experiment.candidate() as c:
        c.record(_run_report(UCR_ES_BACKEND))

    objects = experiment.run()
    return objects
Exemple #12
0
def _get_report_and_data_source(report_id, domain):
    report = get_report_config(report_id, domain)[0]
    data_source = ConfigurableReportDataSource.from_spec(
        report, include_prefilters=True)
    return report, data_source
Exemple #13
0
def get_report_config_or_404(config_id, domain):
    try:
        return get_report_config(config_id, domain)
    except ReportConfigurationNotFoundError:
        raise Http404
Exemple #14
0
 def _get_report_and_data_source(report_id, domain):
     report = get_report_config(report_id, domain)[0]
     data_source = ConfigurableReportDataSource.from_spec(report, include_prefilters=True)
     return report, data_source
 def _get_report_and_data_source(report_id, domain):
     report = get_report_config(report_id, domain)[0]
     data_source = ReportFactory.from_spec(report)
     return report, data_source
Exemple #16
0
 def _get_report_and_data_source(report_id, domain):
     report = get_report_config(report_id, domain)[0]
     data_source = ReportFactory.from_spec(report, include_prefilters=True)
     return report, data_source
Exemple #17
0
def get_report_config_or_404(config_id, domain):
    try:
        return get_report_config(config_id, domain)
    except ReportConfigurationNotFoundError:
        raise Http404
Exemple #18
0
 def _get_report_and_data_source(report_id, domain):
     report = get_report_config(report_id, domain)[0]
     data_source = ReportFactory.from_spec(report, include_prefilters=True)
     return report, data_source