Skip to content

Conversation

Cam-ak
Copy link

@Cam-ak Cam-ak commented Feb 17, 2025

This is my implementation of a feature designed to provide a quick, flexible method of adding metrics to the top of a model card on the dashboard overview page
simple-metrics-overview

@Cam-ak
Copy link
Author

Cam-ak commented Feb 17, 2025

I thought i would give a run down of how this feature works.

Within the 'JAZZMIN_UI_TWEAKS' dictionary the user needs to provide a customized version of the following dictionary for each metric of each model they wish:

Dictionary format details:

Key - Must be model name in lowercase 'e.g order'
Value - A list of dictionaries for all metrics the user wants for a given model (one dictionary per single metric)

Metric Dictionary Key Values

"metric" - [required] this can be one of the following values ['avg', sum', 'min', 'max', 'count' ]
"label" - [required] this it the label to be displayed on the 'simple metric' card

"method" - (optional) This is a custom method used to get some value for a special user defined metric, this method must be part of the class of the related model "e.g. 'get_total_cost' belongs to the Order class"

"icon" - (optional) Font Awsome (FA) icon title (default val: 'info' )
"colour" - (optional) background colour of the 'simple metric' card

"format-pre" - (optional) Format prefix, used to show any string before the value of the metric 'e.g. $100'
"format-post" - (optional) Format postfix, used to show any string after the value of the metric 'e.g. 100kg'

"column" - column name to search within to get metric value 'e.g. status,
"column_val" - value within defined 'column' to look for, when using the 'count' metric "e.g. look for value 'new' in the column 'status' to count all new orders"

"date_range": (optional) Used to define the date range for the metric card, if no date range if provided then all entries from db table will be used for metric
date range uses the following format, (Minus symbol is optional) : (-)[Time Val][MDYWhms]
M - months
D - days
Y - years
W - weeks
h - hours
m - minutes
s - seconds

Date Range Examples:
["-2W","today"] means a date range from "two weeks ago to today"
["1st of year","today"] means a date range from "Jan 1st to today"
["today","3D"] means a date range from "today to three days from today"

Example dictionary:

"sm_config":{"order": [
                            {   "metric":"sum",
                                "label":"Order total sum",
                                "method":"get_total_cost",
                                "icon":"clipboard-list",
                                "format-pre" : "$"
                            },
                            {   "metric":"avg",
                                "label":"Order total avg",
                                "date_range":["-2M","today"],
                                "method":"get_total_cost",
                                "icon":"clipboard-list",
                                "format-pre" : "$"
                            },
                            {
                                "metric":"count",
                                "label":"Order YTD",
                                "date_range" : ["1st of year","today"],
                                "icon":"calendar-days",
                            },
                            {
                                "metric":"count",
                                "label":"Last fortnight orders ",
                                "date_range":["-2W","today"],
                                "column":"status",
                                "column_val": "new",
                                "icon":"calendar-week",
                            },
                            {
                                "metric":"count",
                                "label":"Total 'New' orders",
                                "column":"status",
                                "column_val": "new",
                                "icon":"list-check",
                            },
                            ],
                  "product":[{
                                "metric":"count",
                                "label":"Total products",
                                "icon":"boxes-stacked",
                            },
                            {   "metric":"avg",
                                "label":"Product price avg",
                                "column":"price",
                                "icon":"box",
                                "format-pre":"$"
                            },
                            ]
                  } 

From this dictionary the 'Simple Metric' cards are built.

Feel free to ask anything else you want to know.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants