# Metrics

Below is an example configuration of a panel using the **Metrics** module:

```python
{
    "width": 12,
    "height": 180,
    "full_row": True,
    "url_name": "frame_empty_frame",
    "url_action_name": "metrics_survey",
    "content": {
        "view": custom_views.MonitorMetrics,
        "view_params": {
            "model": custom_models.Monitor,
            "group_by": ["survey", "surveygroup__name"],
            "aggregations": [
                {
                    "function": "Count",
                    "value": "id",
                },  # annotation
            ],
        },
    },
},
```

The view\_params are:

* model the model this table is based on
* group\_by and order\_by determine how the data is organized.
* aggregations specify how to summarize the data (e.g., counting records).

The custom\_views can be defined as followed:

```python
class MonitorMetrics(module_views.Kpi):
    def set_context(self, request):
        datasets = []
        surveys = []
        surveygroup__names = []

        queryset = self.get_queryset()
        if queryset:
            for item in queryset:
                if item["survey"]:
                    surveys.append(item["survey"])
                if item["surveygroup__name"]:
                    surveygroup__names.append(item["surveygroup__name"])

        datasets.append(
            {
                "width": 6,
                "value": "Surveys",
                "label": ", ".join(sorted(set(surveys))),
            }
        )
        datasets.append(
            {
                "width": 6,
                "value": "Survey Groups",
                "label": ", ".join(sorted(set(surveygroup__names))),
            }
        )
        self.context = {"metrics_new": datasets}
```

This custom\_views can generate the card with the surveys and survey group.

{% hint style="info" %}
**Formatting**\
You can use formatting functions from str\_utils for nicer visuals.
{% endhint %}


---

# Agent Instructions: Querying This Documentation

If you need additional information that is not directly available in this page, you can query the documentation dynamically by asking a question.

Perform an HTTP GET request on the current page URL with the `ask` query parameter:

```
GET https://docs.lineverge.com/automail/configurations/ui-configuration/site/panels/metrics.md?ask=<question>
```

The question should be specific, self-contained, and written in natural language.
The response will contain a direct answer to the question and relevant excerpts and sources from the documentation.

Use this mechanism when the answer is not explicitly present in the current page, you need clarification or additional context, or you want to retrieve related documentation sections.
