'find average of varying length in a dataset
I have a service that runs every X minutes, the service is used to calculate a dataset where each element is assigned a rank based on some metrics. The ranks of these elements thus need to be used to calculate an average rank, the rank value can only be up to 100.
Now to calculate the average rank of an element over a Y period of time I would simply sum the ranks and divide the sum with the length of the array/dataset generated.
However, the length of the dataset can be different for each element (an element might not make it to the top 100 list so it will be excluded). How would I calculate the average in this case?
An example:
Suppose the service runs every 10 minutes, and we want to calculate the average for the last 60 minutes, that means the total number of services ran is 6.
element A Ranks = [2, 3, 6, 10, 5, 7]
element B Ranks = [1]
Now element B only made to the list once with a rank of 1 but couldn't make it the other 5 times, in this case, element B would be ranked 1st among all if we calculate the simple average by sum / len. I'd like to find a better average that looks at the elements' rank over time and average those accordingly.
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
| Solution | Source |
|---|
