Have you tried to replicate it manually? Send you values to a list, sort the list, find your number, get the rank (index of number +1), repeat until the next index does not equal your number, divide total of ranks by total occurrences of your number.