maintenance

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: 20 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 maintenance holds the CLI jobs that run with the server stopped: the shared lock next to the database, dumps, backups, backfill, import and data correction (spec 13).

Index

Constants

View Source
const (
	LevelDaily   = "daily"
	LevelMonthly = "monthly"
	LevelYearly  = "yearly"
	LevelTotal   = "total"
)

Period levels of a solis database; the register key of a series is "<base>_<level>" (pv_energy_daily, pv_energy_monthly, ...).

Variables

View Source
var ErrLocked = errors.New("maintenance: database is in use (server running?)")

ErrLocked means another process (normally the running server) holds the lock.

View Source
var ErrNotSolis = errors.New("maintenance: not a solis database (no daily_values table)")

ErrNotSolis means the source database has no solis daily_values table.

View Source
var ErrSolisMap = errors.New("maintenance: invalid import map")

ErrSolisMap marks an invalid import map; the message lists every problem.

Functions

func Dump

func Dump(ctx context.Context, job DumpJob, opts DumpOptions, w io.Writer) error

Dump records opts.Count polls of a device and writes them as a profile.Fixture. Failed polls are recorded with their error. MAC addresses are removed.

func LockPath

func LockPath(dbPath string) string

LockPath returns the lock file of a database path.

Types

type DumpJob

type DumpJob struct {
	Source  SampleSource
	Profile *profile.Profile
	Clock   util.Clock
	Log     zerolog.Logger
}

DumpJob bundles the dependencies of a dump.

type DumpOptions

type DumpOptions struct {
	Count    int
	Interval time.Duration
}

DumpOptions controls a dump.

type ImportJob

type ImportJob struct {
	Source   SolisSource
	Target   storage.ImportStore
	Map      *SolisMap
	Series   map[string]storage.SeriesDef // from SolisMap.Resolve
	Location *time.Location
	Clock    util.Clock
	Name     string // recorded as import source (file name of the solis database)
}

ImportJob bundles the dependencies of import-solis (spec 7.8).

type ImportReport

type ImportReport struct {
	Cutoff     string // first day not imported
	Series     []SeriesReport
	Unmapped   []string // solis keys with daily values that the map does not name
	Status     int      // imported status changes
	StatusKeys []string // solis status keys that the map does not name
	Mismatches []PeriodMismatch
}

ImportReport is the summary printed by import-solis.

func ImportSolis

func ImportSolis(ctx context.Context, job ImportJob) (*ImportReport, error)

ImportSolis imports a solis database (spec 7.8): each daily value becomes one bucket in the last slot of its local day (estimated|imported), the difference between a solis total and its daily sum becomes carry, and the status log becomes status_event. Days from today or from the first day pvmon already stored on are skipped.

type Lock

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

Lock is a held flock on <db>.lock.

func AcquireExclusive

func AcquireExclusive(dbPath string) (*Lock, error)

AcquireExclusive takes the lock of a "stopped" job; it fails with ErrLocked while the server or another job holds the lock.

func AcquireShared

func AcquireShared(dbPath string) (*Lock, error)

AcquireShared takes the server's shared lock; jobs then cannot take the exclusive one.

func (*Lock) Release

func (l *Lock) Release() error

Release unlocks and closes the lock file.

type PeriodMismatch

type PeriodMismatch struct {
	Key, Level, Period string
	Stored, Daily      float64
	Days               int // solis days of the period
}

PeriodMismatch is a solis month or year whose stored value is not its daily sum (cutover offsets, purged days); pvmon only has the daily values (spec 7.8).

type SampleSource

type SampleSource interface {
	FetchAll(ctx context.Context) (profile.Sample, error)
}

SampleSource reads raw polls of one device (collector.Fetcher).

type SeriesReport

type SeriesReport struct {
	Key      string // solis key without level suffix
	Target   string // <meter>/<channel>
	Days     int    // imported days
	KWh      float64
	Later    int // days on or after the cutoff, left to pvmon's own data
	Negative int // negative daily values, not imported
	CarryKWh float64
	// TotalBelow is set when the solis total is lower than its daily sum (no carry).
	TotalBelow bool
}

SeriesReport is the import result of one solis energy series.

type SolisDB

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

SolisDB reads the tables of a solis database (schema v3, read-only).

func NewSolisDB

func NewSolisDB(ctx context.Context, db *sql.DB) (*SolisDB, error)

NewSolisDB checks that db is a solis database.

func (*SolisDB) Status

func (s *SolisDB) Status(ctx context.Context) ([]SolisStatus, error)

Status implements SolisSource.

func (*SolisDB) Values

func (s *SolisDB) Values(ctx context.Context, level string) ([]SolisValue, error)

Values implements SolisSource.

type SolisMap

type SolisMap struct {
	Energy map[string]string `yaml:"energy"`
	Status struct {
		Device    string            `yaml:"device"`
		Registers map[string]string `yaml:"registers"`
	} `yaml:"status"`
}

SolisMap assigns solis series to the new site (spec 7.8). Energy maps a solis key without level suffix (pv_energy) to "<meter>/<channel>"; Status maps solis status keys to the status registers of one device's profile.

func ParseSolisMap

func ParseSolisMap(data []byte) (*SolisMap, error)

ParseSolisMap decodes a map file; unknown fields fail.

func (*SolisMap) Resolve

func (m *SolisMap) Resolve(s *site.Site) (map[string]storage.SeriesDef, error)

Resolve checks the map against the site and returns the target series per solis key. Every problem is reported, not only the first.

type SolisSource

type SolisSource interface {
	// Values returns all values of a level, ordered by key and period.
	Values(ctx context.Context, level string) ([]SolisValue, error)
	// Status returns the status log in time order; unparsable timestamps fail.
	Status(ctx context.Context) ([]SolisStatus, error)
}

SolisSource reads a solis database.

type SolisStatus

type SolisStatus struct {
	Key  string
	At   time.Time
	Code int64
}

SolisStatus is one row of the solis status log.

type SolisValue

type SolisValue struct {
	Base   string
	Period string
	KWh    float64
}

SolisValue is one stored solis value: Base is the key without its level suffix, Period the day (2006-01-02), month (2006-01) or year (2006); empty for totals.

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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