predictor

package
v0.0.21 Latest Latest
Warning

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

Go to latest
Published: Dec 6, 2025 License: MIT Imports: 9 Imported by: ? 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 predictor provides functionalities for loading predictions based on saved data.

Index

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

func (c *Controller) LoadEvents(ctx context.Context, db *databaser.DB) error

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 DayType

type DayType uint8

DayType defines the type of day.

const (
	Monday DayType = iota
	Tuesday
	Wednesday
	Thursday
	Friday
	Saturday
	Sunday
	Holiday // predefined holiday
)

Day type constants representing days of the week and holidays.

type HolidayChecker

type HolidayChecker interface {
	IsHoliday(t time.Time) bool
	HolidayTitle(t time.Time) string
}

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) AddEvent

func (p *Predictor) AddEvent(event databaser.Event)

AddEvent adds a new event to the predictor and updates the statistics.

func (*Predictor) GetTypicalLoad added in v0.0.14

func (p *Predictor) GetTypicalLoad(t time.Time) float64

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.

func (*Predictor) String

func (p *Predictor) String() string

String implements the Stringer interface for Predictor. It returns statistics for all day types and 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.

func (*RussianHolidayChecker) IsHoliday

func (c *RussianHolidayChecker) IsHoliday(t time.Time) bool

IsHoliday checks if the given date is a holiday.

Jump to

Keyboard shortcuts

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