> For the complete documentation index, see [llms.txt](https://docs.lineverge.com/automail/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://docs.lineverge.com/automail/configurations/ui-configuration/site/panels/metrics.md).

# 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 %}
