Show median in widget on dashboard
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
12-11-2023 01:04 AM - edited 12-11-2023 01:05 AM
Hi all,
I'm trying to figure out how to show the median in a widget on a dashboard. Neither the report designer or performance analytics have any option to do this, so I would think that a scheduled script is needed. I have search the community, google etc. to find a sustainable solution, but haven't seen one yet. What I need specific is, to put the duration field from cmdb_ci_outage table into an array. By doing this, I would think that below script can help with the rest:
function median(values: number[]): number {
if (values.length === 0) {
throw new Error('Input array is empty');
}
// Sorting values, preventing original array
// from being mutated.
values = [...values].sort((a, b) => a - b);
const half = Math.floor(values.length / 2);
return (values.length % 2
? values[half]
: (values[half - 1] + values[half]) / 2
);
}
I would think that the output then can be entered into a scorecard on a manual indicator, but please let me know your thoughts, if any other solution is sustainable - I am open for suggestions.
Best regards
Anders
If my answer has helped with your question, please mark my answer as the accepted solution and give a thumbs up.
Best regards
Anders
Rising star 2024
MVP 2025
linkedIn: https://www.linkedin.com/in/andersskovbjerg/