Skip to content

skybrush_log_analyzer.analysis

skybrush_log_analyzer.analysis.compact(analysis)

Returns the compact view of an analysis API response.

Keeps the note, the status counts, and the test results with their name, status, title and messages. Test results and status counts are ordered by severity. Drops internal IDs and null fields.

Source code in skybrush_log_analyzer/analysis.py
def compact(analysis: dict[str, Any]) -> dict[str, Any]:
    """
    Returns the compact view of an analysis API response.

    Keeps the note, the status counts, and the test results with their name,
    status, title and messages. Test results and status counts are ordered by
    severity. Drops internal IDs and null fields.
    """
    tests = [
        _test_view(result)
        for result in sorted(
            analysis.get("test_results") or [],
            key=lambda result: _STATUS_RANK.get(result.get("status"), len(_STATUS_RANK)),
        )
    ]
    view = {
        "note_title": analysis.get("note_title"),
        "note_description": analysis.get("note_description"),
        "status_counts": _status_counts(tests),
        "test_results": tests,
    }
    return _without_none_fields(view)

skybrush_log_analyzer.analysis.select_tests(analysis, test_names)

Returns the analysis with only the results of the given tests kept.

Source code in skybrush_log_analyzer/analysis.py
def select_tests(analysis: dict[str, Any], test_names: list[str]) -> dict[str, Any]:
    """Returns the analysis with only the results of the given tests kept."""
    selected = set(test_names)
    return {
        **analysis,
        "test_results": [
            result for result in analysis.get("test_results") or [] if result.get("test_name") in selected
        ],
    }

skybrush_log_analyzer.analysis.drop_pass_messages(analysis)

Returns the analysis with the messages of passing test results omitted.

Source code in skybrush_log_analyzer/analysis.py
def drop_pass_messages(analysis: dict[str, Any]) -> dict[str, Any]:
    """Returns the analysis with the messages of passing test results omitted."""
    return {
        **analysis,
        "test_results": [
            {key: value for key, value in result.items() if key != "messages"}
            if result.get("status") == "PASS"
            else result
            for result in analysis.get("test_results") or []
        ],
    }