stats

package
v0.2.0 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Sep 15, 2026 License: Apache-2.0 Imports: 5 Imported by: 0

Documentation

Overview

Package stats aggregates folded resource histories into the per-window activity the project summary reports: per resource type, how many resources began or ended their life inside the window, and how many minutes they ran within it. It folds through internal/core/timeline, so the summary counts the same intervals every other consumer of a history counts.

The package does no I/O. Loading the histories is the caller's job, which keeps the arithmetic answerable without a database.

The normative specification is roadmap/02-phase-2-reporting-dashboards.md, WP 2.1.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Activity

type Activity struct {
	ResourceType string
	// Created and Deleted count the resources of the type whose life began or
	// ended inside the window.
	Created int
	Deleted int
	// TotalMinutes is the time every resource of the type ran within the window,
	// truncated to whole minutes.
	TotalMinutes int64
}

Activity is what one resource type did inside a window.

func Summarize

func Summarize(histories []History, projectID string, from, to, now time.Time) []Activity

Summarize folds each history and aggregates the results per resource type over the half-open window [from, to), for the project projectID names. A create or a delete counts when the folded timestamp falls inside the window. An interval contributes the seconds it overlaps the window, whatever state the resource was in: what a state is worth is a rating question, and rating is Phase 3. An interval still open ends at now, so a window reaching into the future bills no time that has not been served yet.

The histories are whole ones, and projectID is what says which part of each belongs to this summary. A resource that changed hands accrues its seconds here only over the intervals it carried this project through: the transfer closes the interval the resource ran under the old owner and opens one under the new, so a resource is billed to one project at a time rather than to both for the rest of its life. What a project created and deleted is read off its own events instead, because a transfer moves a resource rather than its birth.

A resource type gets a row once one of the project's histories of it folds into a life or an interval, even when the window holds nothing of it. A history the project has no event in folds into nothing and gets no row.

The result is sorted by resource type and is never nil.

type History

type History struct {
	ResourceType string
	Events       []event.Stored
}

History is one resource's stored events together with the type of resource they describe. Each resource folds on its own, so a caller passes one History per resource rather than one merged event slice.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL