1 // Copyright (C) The Arvados Authors. All rights reserved.
3 // SPDX-License-Identifier: AGPL-3.0
11 // NormalizePriceHistory de-duplicates and sorts instance prices, most
13 func NormalizePriceHistory(prices []InstancePrice) []InstancePrice {
14 // copy provided slice instead of modifying it in place
15 prices = append([]InstancePrice(nil), prices...)
16 // sort by timestamp, newest first
17 sort.Slice(prices, func(i, j int) bool {
18 return prices[i].StartTime.After(prices[j].StartTime)
20 // remove duplicate data points, keeping the oldest
21 for i := 0; i < len(prices)-1; i++ {
22 if prices[i].StartTime == prices[i+1].StartTime || prices[i].Price == prices[i+1].Price {
23 prices = append(prices[:i], prices[i+1:]...)