Documentation
¶
Overview ¶
Package report is the pure energy report model (spec 12): complete days of the site quantities go in, sums, ratios, sections, patterns and key figures (with an optional comparison period) come out. No I/O, no clock, no logging; renderers (JSON, CSV, PDF) only format what Build returns.
Every ratio is computed from the summed energy of a period, never as an average of daily ratios. A day counts for a section only with a complete value of every series the section needs; other days are reported as missing, never as 0 kWh.
Index ¶
- Constants
- Variables
- func MeterKey(kind, id string) string
- func ParseDay(s string) (time.Time, error)
- type Bucket
- type Category
- type CompareInput
- type CompareMode
- type Comparison
- type Day
- type DaySlots
- type DayValue
- type Direction
- type Energy
- type Figure
- type FigureKind
- type Granularity
- type Input
- type Layout
- type Loadpoints
- type Meter
- type MeterEnergy
- type MeterQuality
- type Patterns
- type Profile
- type Range
- type Report
- type Section
- type Slot
- type SolarParts
- type Split
- type Summary
Constants ¶
const ( KeyPV = "pv" KeyConsumption = "consumption" KeyImport = "import" KeyExport = "export" KeyCharge = "charge" KeyDischarge = "discharge" )
Keys of Day.Values and Slot.Values (Wh). Per-meter keys come from MeterKey.
const KeyLoadpoint = "lp"
KeyLoadpoint is the kind of a loadpoint's energy key.
const LowImportBelow = 500
LowImportBelow (Wh) is the daily grid import below which a day counts as a day with almost no grid import: inverters and meters draw a few hundred Wh even on days the house runs on solar and battery alone, so a threshold of zero would never match.
const (
// MaxRangeDays caps a report at about ten years (spec 12).
MaxRangeDays = 3660
)
const ( // MinBalanceDays is the shortest period (complete days) with a battery quotient and a // balance difference: the battery level at the start and end is not stored, so over a // few days it dominates both values (spec 12). MinBalanceDays = 28 )
const SlotsPerDay = 96
SlotsPerDay is the number of 15-minute slots of a day without DST change.
Variables ¶
var ErrInvalidRange = errors.New("invalid report parameters")
ErrInvalidRange: bad from/to, granularity or comparison parameters (400).
Functions ¶
Types ¶
type Bucket ¶
type Bucket struct {
// Key is YYYY-MM-DD, YYYY-MM or YYYY.
Key string
// From and To are the bucket's days inside the range.
From, To time.Time
// Partial is true when the range cuts the bucket (a month or year not fully inside).
Partial bool
Summary Summary
}
Bucket is one group of days (a day, month or year) of the range.
type CompareInput ¶
type CompareInput struct {
Mode CompareMode
Range Range
Days []Day
}
CompareInput is the comparison period and its days.
type CompareMode ¶
type CompareMode int
CompareMode selects the comparison period.
const ( // CompareNone disables the comparison. CompareNone CompareMode = iota // ComparePrevious compares with the period directly before. ComparePrevious // CompareLastYear compares with the same dates one year earlier. CompareLastYear )
func ParseCompare ¶
func ParseCompare(s string) (CompareMode, error)
ParseCompare parses "previous", "last_year" or "none"; "" is the default last_year (seasons make the previous period a poor comparison for most ranges).
type Comparison ¶
type Comparison struct {
Mode CompareMode
Range Range
Summary Summary
// Matched is true when the periods cannot be compared as wholes (missing days or a
// different length): the figures then compare only the days both periods have.
Matched bool
MatchedDays int
}
Comparison is the comparison period.
type Day ¶
type Day struct {
// Date is the local calendar day as midnight UTC (calendar math without DST).
Date time.Time
// Values holds the series that are complete on this day (Wh); a missing key means
// incomplete or no data.
Values map[string]float64
// Slots are the time-resolved sums of the day; nil when a bucket has a gap, so the
// estimates fall back to the daily balance.
Slots *DaySlots
}
Day is one local calendar day.
type DaySlots ¶
type DaySlots struct {
// GridCharge = Σ min(charge, import): battery charge that came from the grid.
// Discharge = Σ battery discharge.
GridCharge, Discharge float64
// Solar and SolarConsumption are what the PV estimates of each loadpoint and of
// the consumption are made of.
Solar map[string]SolarParts
SolarConsumption SolarParts
// Profile is the consumption per slot of day (Wh, a repeated DST hour adds up),
// Count the number of buckets per slot.
Profile [SlotsPerDay]float64
Count [SlotsPerDay]int
// Peak is the highest 15-minute mean consumption (W) at PeakAt.
Peak float64
PeakAt time.Time
}
DaySlots are the time-resolved sums of one day (spec 12, time-resolved estimates).
func EstimateDay ¶
EstimateDay sums the slots of one day; nil without slots or when any slot has a gap. loadpoints are the loadpoint IDs.
type Energy ¶
type Energy struct {
PV, Consumption, Import, Export, Charge, Discharge float64
}
Energy holds the site quantities of one day or a sum of days (Wh).
type Figure ¶
type Figure struct {
// ID names the figure (renderers map it to a label).
ID string
Kind FigureKind
Better Direction
// Value is the range's value over all its complete days; nil = no data.
Value *float64
// Compared and Base are the two values the change is computed from: the range's and
// the comparison period's. With Comparison.Matched both cover only the matched days
// (so Compared can differ from Value); otherwise Compared equals Value and Base is
// the whole comparison period. Nil without a comparison or without data.
Compared, Base *float64
// Change = Compared - Base: Wh, or a fraction for ratios (x100 = percentage points).
Change *float64
// ChangePct is Change / base for energy figures (a fraction); nil when base is 0.
ChangePct *float64
}
Figure is one key figure of the report.
type FigureKind ¶
type FigureKind int
FigureKind says how a key figure is measured and compared.
const ( // KindEnergy is Wh; changes in Wh and percent. KindEnergy FigureKind = iota // KindRatio is a share 0..1; changes in percentage points (as a fraction). KindRatio )
func (FigureKind) String ¶
func (k FigureKind) String() string
String returns the API name of k: energy or ratio.
type Granularity ¶
type Granularity int
Granularity is how buckets group the days of a range.
const ( // ByDay is one bucket per day. ByDay Granularity = iota // ByMonth is one bucket per calendar month. ByMonth // ByYear is one bucket per calendar year. ByYear )
func AutoGranularity ¶
func AutoGranularity(r Range) Granularity
AutoGranularity groups up to ~2 months by day, up to 2 years by month, longer by year.
func ParseGranularity ¶
func ParseGranularity(s string, r Range) (Granularity, error)
ParseGranularity parses "day", "month" or "year"; "" picks AutoGranularity(r).
type Input ¶
type Input struct {
Range Range
Granularity Granularity
Layout Layout
// Days of the range (others are ignored), any order.
Days []Day
// Compare is the comparison period; nil = no comparison.
Compare *CompareInput
// TodayExcluded says the requested range ended today and was cut to end yesterday.
TodayExcluded bool
// Quality lists the meters' data quality in the range.
Quality []MeterQuality
}
Input is everything Build needs.
type Layout ¶
type Layout struct {
// PV are the top-level PV meters; empty = no PV.
PV []Meter
// Batteries are the batteries; empty = no battery section.
Batteries []Meter
// Loadpoints are the consumers directly under the site.
Loadpoints []Meter
}
Layout is the part of the site that decides which sections exist (spec 12).
func (Layout) HasBattery ¶
HasBattery reports whether the site has a battery.
type Loadpoints ¶
type Loadpoints struct {
Section
Categories []Category
// House = consumption − loadpoints over the same days (Wh); nil without such days.
// It can be negative when meters disagree.
House *float64
// HouseSolar ≈ PV-covered part of House, within 0..House; the share is nil when
// House is not positive.
HouseSolar float64
}
Loadpoints is the loadpoint section.
type Meter ¶
type Meter struct {
ID, Label, Category string
// KWp is the peak power of a PV meter (0 = unknown).
KWp float64
}
Meter is a meter a section reports on.
type MeterEnergy ¶
type MeterEnergy struct {
Meter
// In / Out (Wh): battery charged / discharged, PV yield in Out, loadpoint in In.
In, Out float64
// Share of the section total (PV); Solar ≈ PV-covered energy and SolarShare
// (loadpoints); Ratio = Out / In (battery, from MinBalanceDays); SpecificYield =
// kWh/kWp (PV with kwp).
MeterEnergy is the energy of one meter over the days its section counts.
type MeterQuality ¶
type MeterQuality struct {
ID, Label string
// MissingDays have no complete value; EstimatedDays contain estimated buckets.
MissingDays, EstimatedDays int
}
MeterQuality is the data quality of one meter in the range (spec 12, data quality).
type Patterns ¶
type Patterns struct {
// Extremes; nil without complete days. Ties go to the earliest day.
BestPV, LowestPV, MaxConsumption, MaxImport *DayValue // values in Wh
// WeekdayConsumption / WeekendConsumption are the average consumption per complete
// Monday-Friday / Saturday-Sunday; nil without such days.
WeekdayConsumption, WeekendConsumption *float64
WeekdayDays, WeekendDays int
// LowImportDays imported less than LowImportBelow from the grid.
LowImportDays int
}
Patterns are day-level observations of the complete days of the range.
type Profile ¶
type Profile struct {
Mean [SlotsPerDay]*float64
Peak *float64
PeakAt time.Time
}
Profile is the load profile: mean consumption per slot of day (W, nil without data) and the highest 15-minute mean.
type Range ¶
Range is an inclusive range of calendar days, each as midnight UTC.
func ParseRange ¶
ParseRange parses from/to (YYYY-MM-DD, inclusive) and checks from <= to <= today and the maximum length. today is the caller's local day (server TZ).
type Report ¶
type Report struct {
Range Range
Granularity Granularity
Layout Layout
// Summary covers the days with every core series.
Summary Summary
Patterns Patterns
// Buckets group the range by Granularity, oldest first, empty ones included.
Buckets []Bucket
// Sections; nil when the site has nothing to show (spec 12 table).
PVSources *Section
Batteries *Section
Loadpoints *Loadpoints
Profile Profile
// Comparison is nil without a comparison period.
Comparison *Comparison
Figures []Figure
// MissingDays are the days without every core series (at most maxListedDays).
MissingDays []time.Time
Quality []MeterQuality
// TodayExcluded is true when the requested range ended today and the report ends
// yesterday.
TodayExcluded bool
}
Report is the computed report.
type Section ¶
type Section struct {
CompleteDays int
Meters []MeterEnergy
}
Section is a list of meters over the days with every series of the section.
type Slot ¶
Slot is one 15-minute bucket of the site (Wh per key); Gap marks a missing or incomplete value of any needed series.
type SolarParts ¶ added in v0.4.0
type SolarParts struct {
// NotImported = Σ energy × share not taken from the grid directly; Battery =
// Σ energy × share taken from the battery, a part of NotImported.
NotImported, Battery float64
}
SolarParts are the slot sums of one consumer for its PV estimate. The PV-covered energy depends on how much of the battery output was bought from the grid, which is known only for the whole range.
type Split ¶
type Split struct {
Solar, Battery, Grid float64
Split divides one energy amount into three parts (Wh) with their shares (0..1). Sources: Grid = imported, Battery = discharged minus the grid charge (bought energy counts once, as grid), Solar = the rest; they add up to the consumption. PV split: Solar = used directly, Battery = charged from PV, Grid = exported.
type Summary ¶
type Summary struct {
// Days is the number of calendar days, CompleteDays those with every core series.
Days, CompleteDays int
Total Energy
// PerDay is Total / CompleteDays; nil without complete days.
PerDay *Energy
// SelfSufficiency = (consumption − import) / consumption; SelfConsumption =
// (PV − export) / PV; 0..1, nil without a denominator.
SelfSufficiency, SelfConsumption *float64
// GridCharge ≈ battery charge from the grid (time-resolved, spec 12).
GridCharge float64
// Sources: where the consumption came from; PVSplit: where the PV went (≈).
Sources, PVSplit Split
// BalanceDiff = energy in − energy out (Wh), BalanceDiffShare = BalanceDiff / in.
// Nil below MinBalanceDays complete days.
BatteryRatio, BalanceDiff, BalanceDiffShare *float64
// FallbackDays had a gap, so their estimates come from the daily balance.
FallbackDays int
}
Summary is the evaluation of the complete days of one period.
Source Files
¶
Directories
¶
| Path | Synopsis |
|---|---|
|
Package csv writes a report's buckets as CSV: one row per day, month or year with the site quantities and the derived columns (this app's estimates end in _est_kwh).
|
Package csv writes a report's buckets as CSV: one row per day, month or year with the site quantities and the derived columns (this app's estimates end in _est_kwh). |
|
Package pdf renders a report as an A4 PDF (spec 12): a summary page with key figures, energy charts and where the energy came from and went, the sections the site has (battery, PV sources, loadpoints, load profile), patterns, comparison and data quality, a compact table and a last page on how the report is calculated.
|
Package pdf renders a report as an A4 PDF (spec 12): a summary page with key figures, energy charts and where the energy came from and went, the sections the site has (battery, PV sources, loadpoints, load profile), patterns, comparison and data quality, a compact table and a last page on how the report is calculated. |