+// timeText describes the time per call and how many calls ran at once. A call
+// runs from its date for its seconds.
+func timeText(records []usageRecord) string {
+ type event struct {
+ at time.Time
+ delta int
+ }
+
+ var events []event
+ seconds := make([]float64, 0, len(records))
+ total := 0.0
+ for _, record := range records {
+ start, err := time.Parse(time.RFC3339Nano, record.Date)
+ if err != nil {
+ continue
+ }
+
+ length := time.Duration(record.Seconds * float64(time.Second))
+ events = append(events, event{
+ at: start,
+ delta: 1,
+ }, event{
+ at: start.Add(length),
+ delta: -1,
+ })
+ seconds = append(seconds, record.Seconds)
+ total += record.Seconds
+ }
+
+ if len(events) == 0 {
+ return "time: no dated calls"
+ }
+
+ slices.SortFunc(events, func(a, b event) int {
+ return cmp.Or(a.at.Compare(b.at), cmp.Compare(a.delta, b.delta))
+ })
+
+ running, most := 0, 0
+ for _, e := range events {
+ running += e.delta
+ most = max(most, running)
+ }
+
+ wall := events[len(events)-1].at.Sub(events[0].at).Seconds()
+ slices.Sort(seconds)
+
+ return fmt.Sprintf("time: %.0f s in all, %.1f calls per minute, %.1f s per call (median %.1f, max %.1f), calls at once: at most %d, %.1f on average", wall, 60*float64(len(seconds))/max(wall, 1e-9), total/float64(len(seconds)), seconds[len(seconds)/2], seconds[len(seconds)-1], most, total/max(wall, 1e-9))
+}
+