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
- Variables
- func Dump(ctx context.Context, job DumpJob, opts DumpOptions, w io.Writer) error
- func LockPath(dbPath string) string
- type DumpJob
- type DumpOptions
- type ImportJob
- type ImportReport
- type Lock
- type PeriodMismatch
- type SampleSource
- type SeriesReport
- type SolisDB
- type SolisMap
- type SolisSource
- type SolisStatus
- type SolisValue
Constants ¶
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 ¶
var ErrLocked = errors.New("maintenance: database is in use (server running?)")
ErrLocked means another process (normally the running server) holds the lock.
var ErrNotSolis = errors.New("maintenance: not a solis database (no daily_values table)")
ErrNotSolis means the source database has no solis daily_values table.
var ErrSolisMap = errors.New("maintenance: invalid import map")
ErrSolisMap marks an invalid import map; the message lists every problem.
Functions ¶
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 ¶
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 ¶
AcquireExclusive takes the lock of a "stopped" job; it fails with ErrLocked while the server or another job holds the lock.
func AcquireShared ¶
AcquireShared takes the server's shared lock; jobs then cannot take the exclusive one.
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 ¶
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 ¶
NewSolisDB checks that db is a solis database.
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 ¶
ParseSolisMap decodes a map file; unknown fields fail.
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 ¶
SolisStatus is one row of the solis status log.
type SolisValue ¶
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.