velodrome/transform/plugins/bundle.go
func (b BundledStates) Percentile(t time.Time, percentile int) time.Duration {
	if percentile > 100 || percentile <= 0 {
		panic(fmt.Errorf("percentile %d is out of scope", percentile))
	}

	ages := []time.Duration{}
	for _, age := range b.ages(t) {
		ages = append(ages, age)
	}

	if len(ages) == 0 {
		return 0
	}

	sort.Sort(ByDuration(ages))

	index := int(math.Ceil(float64(percentile)*float64(len(ages))/100) - 1)
	if index >= len(ages) {
		panic(fmt.Errorf("Index is out of range: %d/%d", index, len(ages)))
	}
	return ages[index]
}
func (b BundledStates) Percentile(t time.Time, percentile int) time.Duration {
	if percentile > 100 || percentile <= 0 {
		panic(fmt.Errorf("percentile %d is out of scope", percentile))
	}

	ages := []time.Duration{}
	for _, age := range b.ages(t) {
		ages = append(ages, age)
	}

	if len(ages) == 0 {
		return 0
	}

	sort.Sort(ByDuration(ages))

	index := int(math.Ceil(float64(percentile)*float64(len(ages))/100) - 1)
	if index >= len(ages) {
		panic(fmt.Errorf("Index is out of range: %d/%d", index, len(ages)))
	}
	return ages[index]
}
// Percentile returns given percentile for age of all active states at time t