storage

package
v0.3.2 Latest Latest
Warning

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

Go to latest
Published: Feb 21, 2026 License: MIT Imports: 9 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Data

type Data struct {
	Version   int                  `json:"version"`
	UpdatedAt time.Time            `json:"updated_at"`
	TaskStats map[string]*TaskData `json:"task_stats"`
}

Data represents the persisted data structure.

type Loadable

type Loadable interface {
	Load(r io.Reader) error
}

Loadable is an interface for objects that can be loaded.

type ModelInfo

type ModelInfo struct {
	Exists    bool      `json:"exists"`
	Path      string    `json:"path"`
	Size      int64     `json:"size,omitempty"`
	UpdatedAt time.Time `json:"updated_at,omitempty"`
}

ModelInfo returns information about the saved model.

type ModelStorage

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

ModelStorage handles persistence of prediction models.

func NewModelStorage

func NewModelStorage(s *Storage) *ModelStorage

NewModelStorage creates a new ModelStorage.

func (*ModelStorage) DeleteModel

func (ms *ModelStorage) DeleteModel() error

DeleteModel deletes the saved model file.

func (*ModelStorage) GetModelInfo

func (ms *ModelStorage) GetModelInfo() ModelInfo

GetModelInfo returns information about the saved model.

func (*ModelStorage) LoadModel

func (ms *ModelStorage) LoadModel(model Loadable) error

LoadModel loads a model from disk.

func (*ModelStorage) ModelExists

func (ms *ModelStorage) ModelExists() bool

ModelExists returns whether a saved model exists.

func (*ModelStorage) SaveModel

func (ms *ModelStorage) SaveModel(model Saveable) error

SaveModel saves a model to disk.

type Saveable

type Saveable interface {
	Save(w io.Writer) error
}

Saveable is an interface for objects that can be saved.

type Storage

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

Storage handles persistence of learning data.

func New

func New(dataDir string, flushInterval time.Duration, logger *slog.Logger) *Storage

New creates a new Storage instance.

func (*Storage) GetAllTaskStats

func (s *Storage) GetAllTaskStats() map[string]*TaskData

GetAllTaskStats returns statistics for all tasks.

func (*Storage) GetTaskStats

func (s *Storage) GetTaskStats(task string) *TaskData

GetTaskStats returns statistics for a specific task.

func (*Storage) IsDirty

func (s *Storage) IsDirty() bool

IsDirty returns whether data has unsaved changes.

func (*Storage) Load

func (s *Storage) Load() error

Load loads data from disk. If file doesn't exist, returns empty data.

func (*Storage) MarkDirty

func (s *Storage) MarkDirty()

MarkDirty marks data as needing to be saved.

func (*Storage) Save

func (s *Storage) Save() error

Save saves data to disk.

func (*Storage) Start

func (s *Storage) Start(ctx context.Context)

Start starts the periodic flush goroutine.

func (*Storage) Stop

func (s *Storage) Stop() error

Stop stops the periodic flush and saves final state. Multiple calls to Stop are safe and idempotent.

func (*Storage) TaskCount

func (s *Storage) TaskCount() int

TaskCount returns the number of tracked tasks.

func (*Storage) UpdateTaskStats

func (s *Storage) UpdateTaskStats(task string, count int64, cpuDelta, memDelta, gpuDelta, vramDelta float64)

UpdateTaskStats updates statistics for a task.

type TaskData

type TaskData struct {
	Task         string  `json:"task"`
	Count        int64   `json:"count"`
	AvgCPUDelta  float64 `json:"avg_cpu_delta"`
	AvgMemDelta  float64 `json:"avg_mem_delta"`
	AvgGPUDelta  float64 `json:"avg_gpu_delta,omitempty"`
	AvgVRAMDelta float64 `json:"avg_vram_delta,omitempty"`
}

TaskData represents persisted statistics for a task type.

Jump to

Keyboard shortcuts

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