Documentation
¶
Overview ¶
Package predictor provides functionalities for loading predictions based on saved data.
Index ¶
- type Controller
- type DayType
- type HolidayChecker
- type HourlyStats
- type Prediction
- type Predictor
- func (p *Predictor) AddEvent(event databaser.Event)
- func (p *Predictor) AddEvents(events []databaser.Event)
- func (p *Predictor) GetTypicalLoad(t time.Time) float64
- func (p *Predictor) Predict(hoursAhead uint8) Prediction
- func (p *Predictor) PredictRange(maxHours uint8) []Prediction
- func (p *Predictor) String() string
- type RussianHolidayChecker
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type Controller ¶
type Controller struct {
Hours uint8
// contains filtered or unexported fields
}
Controller manages the predictor and handles incoming events.
func Run ¶
func Run(ctx context.Context, db *databaser.DB, eventCh <-chan databaser.Event, cfg *config.Config) (*Controller, error)
Run initializes and returns a new Controller with the predictor and event channel.
func (*Controller) LoadEvents ¶
LoadEvents loads historical events from the database into the predictor.
func (*Controller) PredictLoad ¶
func (c *Controller) PredictLoad(hours uint8) []databaser.Event
PredictLoad generates load predictions for the configured number of hours.
func (*Controller) Run ¶
func (c *Controller) Run(ctx context.Context) <-chan struct{}
Run starts the controller to listen for events and process them.
type HolidayChecker ¶
HolidayChecker checks if a given date is a holiday and retrieves the holiday title.
type HourlyStats ¶
type HourlyStats struct {
LastUpdate time.Time // last update time
WeightedSum float64 // Sum(load × weight)
TotalWeight float64 // Sum(weight)
Count uint64 // total events counted
}
HourlyStats is a storage for hourly statistics.
type Prediction ¶
type Prediction struct {
TargetTime time.Time
Hour int
Load float64
Confidence float64 // prediction confidence [0.0..1.0]
IsHoliday bool
}
Prediction represents a load prediction for a specific hour.
type Predictor ¶
type Predictor struct {
// contains filtered or unexported fields
}
Predictor holds the statistics and provides methods to update and retrieve predictions.
func New ¶
func New(holidayChecker HolidayChecker) *Predictor
New creates a new Predictor instance with the provided HolidayChecker.
func (*Predictor) AddEvents ¶ added in v1.0.0
AddEvents adds multiple events to the predictor and updates the statistics.
func (*Predictor) GetTypicalLoad ¶ added in v0.0.14
GetTypicalLoad returns the typical load for the given time based on historical data.
func (*Predictor) Predict ¶
func (p *Predictor) Predict(hoursAhead uint8) Prediction
Predict returns a load prediction for the specified number of hours ahead.
func (*Predictor) PredictRange ¶
func (p *Predictor) PredictRange(maxHours uint8) []Prediction
PredictRange returns load predictions for the next maxHours hours.
type RussianHolidayChecker ¶
type RussianHolidayChecker struct {
// contains filtered or unexported fields
}
RussianHolidayChecker implements HolidayChecker for Russian holidays.
func NewRussianHolidayChecker ¶
func NewRussianHolidayChecker(ctx context.Context, db *databaser.DB, location *time.Location) (*RussianHolidayChecker, error)
NewRussianHolidayChecker creates a new RussianHolidayChecker with holidays loaded from the database.
func (*RussianHolidayChecker) HolidayTitle ¶
func (c *RussianHolidayChecker) HolidayTitle(t time.Time) string
HolidayTitle returns the title of the holiday for the given date.