sitecalc

package
v0.2.0 Latest Latest
Warning

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

Go to latest
Published: Nov 23, 2026 License: MIT Imports: 12 Imported by: 0 modules, 0 packages

The first number is the count of modules that contain a package that imports this one. The module count is a better indicator of popularity than the package count. A module with 100 importing packages is counted only once instead of 100 times, reflecting the fact that the choice to use the package was likely made only once, not 100 times.
A '?' means that the value hasn't been computed yet.

Documentation

Overview

Package sitecalc computes the live site quantities (spec 5.5) from the live cache: on a change of a meter value, debounced, and on a refresh tick so missing inputs remove the quantity. Results go back into the live cache; they are never stored.

Index

Constants

View Source
const (
	Debounce = 250 * time.Millisecond
	Refresh  = time.Second
)

Timing (spec 5 step 7).

Variables

This section is empty.

Functions

This section is empty.

Types

type Bus

type Bus interface {
	Subscribe(size int, policy eventbus.Overflow) *eventbus.Subscription
	Unsubscribe(s *eventbus.Subscription)
}

Bus is the part of the event bus the calculator subscribes to.

type Cache

type Cache interface {
	Get(key string) (livecache.Value, bool)
	Set(key string, v livecache.Value, interval time.Duration)
	Delete(keys ...string)
}

Cache is the part of the live cache the calculator reads and writes.

type Calculator

type Calculator struct {
	// contains filtered or unexported fields
}

Calculator is a restartable component (spec 8.2).

func New

func New(s *site.Site, cache Cache, bus Bus, clock util.Clock) (*Calculator, error)

New builds a calculator for the site s.

func (*Calculator) LastBeat

func (c *Calculator) LastBeat() time.Time

LastBeat returns the time of the last loop iteration.

func (*Calculator) Start

func (c *Calculator) Start(ctx context.Context) error

Start runs the loop until ctx ends or Stop.

func (*Calculator) State

func (c *Calculator) State() health.State

State is always Healthy: missing inputs are data, not a failure.

func (*Calculator) Stop

func (c *Calculator) Stop() error

Stop ends the loop and waits for it; idempotent.

type Getter

type Getter func(key string) (float64, bool)

Getter returns the newest value of a live key, false when it is missing.

type Result

type Result struct {
	Value  float64
	Unit   string
	Approx bool // SoC as plain mean because a battery has no capacity
}

Result is one computed live site quantity.

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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