Exemple #1
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 #2
0
def _compare_ucr_reports(domain,
                         control_report,
                         candidate_report,
                         filter_values,
                         sort_column,
                         sort_order,
                         params,
                         candidate_engine_id=None):
    from corehq.apps.userreports.laboratory.experiment import UCRExperiment

    def _run_report(spec, engine_id=None):
        data_source = ConfigurableReportDataSource.from_spec(
            spec, include_prefilters=True)
        if engine_id:
            data_source.data_source.override_engine_id(engine_id)
        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

    experiment_context = {
        "domain": domain,
        "report_config_id": control_report._id,
        "new_report_config_id": candidate_report._id,
        "filter_values": filter_values,
    }
    experiment = UCRExperiment(name="UCR DB Experiment",
                               context=experiment_context)
    with experiment.control() as c:
        c.record(_run_report(control_report))

    with experiment.candidate() as c:
        c.record(_run_report(candidate_report, candidate_engine_id))

    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

    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 #4
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 #5
0
def _compare_ucr_reports(domain, control_report, candidate_report, filter_values, sort_column, sort_order, params,
                         candidate_engine_id=None):
    from corehq.apps.userreports.laboratory.experiment import UCRExperiment

    def _run_report(spec, engine_id=None):
        data_source = ConfigurableReportDataSource.from_spec(spec, include_prefilters=True)
        if engine_id:
            data_source.override_engine_id(engine_id)
        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

    experiment_context = {
        "domain": domain,
        "report_config_id": control_report._id,
        "new_report_config_id": candidate_report._id,
        "filter_values": filter_values,
    }
    experiment = UCRExperiment(name="UCR DB Experiment", context=experiment_context)
    with experiment.control() as c:
        c.record(_run_report(control_report))

    with experiment.candidate() as c:
        c.record(_run_report(candidate_report, candidate_engine_id))

    objects = experiment.run()
    return objects