예제 #1
0
def test_statistics_without_resolution_unresolved(
    statistics, correct_result_statistics
):
    result = calculate_statistics(
        statistics, ["Comments", "Attachments", "Time to Resolve"]
    )

    assert result == correct_result_statistics
예제 #2
0
def test_statistics_with_resolution_unresolved_piece(
    statistics_2, correct_result_statistics
):
    result = calculate_statistics(
        statistics_2, ["Comments", "Attachments", "Time to Resolve"]
    )

    corr_result = correct_result_statistics.copy()
    corr_result["Time to Resolve"]["minimum"] = "1"

    assert result == corr_result
예제 #3
0
def test_statistics_with_resolution_unresolved_all(
    statistics_3, correct_result_statistics
):
    result = calculate_statistics(
        statistics_3, ["Comments", "Attachments", "Time to Resolve"]
    )

    corr_result = correct_result_statistics.copy()
    corr_result["Time to Resolve"] = {
        "minimum": "0",
        "maximum": "0",
        "mean": "0",
        "std": "0",
    }
    assert result == corr_result
예제 #4
0
def test_statistics_error(statistics, correct_result_statistics):
    statistics.iloc[0] = "None"
    result = calculate_statistics(
        statistics, ["Comments", "Attachments", "Time to Resolve"]
    )

    corr_result = correct_result_statistics.copy()
    for key in corr_result:
        corr_result[key] = {
            "minimum": "0",
            "maximum": "0",
            "mean": "0",
            "std": "0",
        }

    assert result == corr_result
예제 #5
0
    def get(self, request):
        cache = redis_conn.get(
            f"user:{request.user.id}:analysis_and_training:filters"
        )
        filters = loads(cache) if cache else None

        fields = get_issues_fields(request.user.id)
        issues = get_issues_dataframe(fields=fields, filters=filters)

        if issues.empty:
            return Response({})

        statistics = calculate_statistics(
            issues,
            ["Comments", "Attachments", "Time to Resolve"],
        )
        context = {"statistics": statistics}

        return Response(context)
예제 #6
0
    def get(self, request):

        cache = redis_conn.get(f"analysis_and_training:{request.user.id}")
        if cache:
            return Response(loads(cache))
        fields = get_issues_fields(request.user)
        issues = get_issues(fields=fields)
        if not issues:
            # TODO: FE shows progress bar when data is empty
            return Response({})

        issues = pd.DataFrame.from_records(issues)
        freq_terms = calculate_frequently_terms(issues)
        statistics = calculate_statistics(
            df=issues, series=["Comments", "Attachments", "Time to Resolve"])
        defect_submission = calculate_defect_submission(df=issues,
                                                        period="Month")
        significant_terms = get_significant_terms(issues)
        filters = get_filters(request.user, issues=issues)

        context = {
            "records_count": {
                "total": len(issues),
                "filtered": len(issues)
            },
            "frequently_terms": freq_terms,
            "statistics": statistics,
            "submission_chart": defect_submission,
            "significant_terms": significant_terms,
            "filters": filters,
        }
        redis_conn.set(
            name=f"analysis_and_training:{request.user.id}",
            value=dumps(context),
            ex=60 * 30,
        )

        return Response(context)
예제 #7
0
    def post(self, request):
        fields = get_issues_fields(request.user)

        filters = get_filters(
            request.user,
            issues=pd.DataFrame.from_records(get_issues(fields=fields)),
        )

        if request.data.get("action") == "apply":
            new_filters = request.data.get("filters")
            if new_filters:
                for new_filter in new_filters:
                    for filter_ in filters:
                        if new_filter["name"] == filter_["name"]:
                            filter_.update({
                                "current_value":
                                new_filter["current_value"],
                                "filtration_type":
                                new_filter["filtration_type"],
                                "exact_match":
                                new_filter["exact_match"],
                            })
                issues = get_issues(filters=filters, fields=fields)
            else:
                issues = get_issues(fields=fields)
        else:
            issues = get_issues(fields=fields)

        if len(issues) == 0:
            context = {
                "records_count": {
                    "total": get_issue_count(),
                    "filtered": 0
                },
                "frequently_terms": [],
                "statistics": {},
                "submission_chart": {},
                "significant_terms": {},
                "filters": filters,
            }
            redis_conn.set(f"analysis_and_training:{request.user.id}",
                           dumps(context))
            return Response({})

        issues = pd.DataFrame.from_records(issues)
        freq_terms = calculate_frequently_terms(issues)
        statistics = calculate_statistics(
            df=issues, series=["Comments", "Attachments", "Time to Resolve"])
        submission_chart = calculate_defect_submission(df=issues,
                                                       period="Month")
        significant_terms = get_significant_terms(
            issues, get_training_settings(request.user))

        context = {
            "records_count": {
                "total": get_issue_count(),
                "filtered": len(issues),
            },
            "frequently_terms": freq_terms,
            "statistics": statistics,
            "submission_chart": submission_chart,
            "significant_terms": significant_terms,
            "filters": filters,
        }
        redis_conn.set(f"analysis_and_training:{request.user.id}",
                       dumps(context))

        return Response(context)
예제 #8
0
def test_statistics_result(statistics):
    result = calculate_statistics(statistics, ["Comments", "Attachments"])

    assert result == CORRECT_RESULT