storage

package
v1.0.0 Latest Latest
Warning

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

Go to latest
Published: May 14, 2025 License: GPL-3.0 Imports: 15 Imported by: 0

README

storage

Persistent data storage system that manages simulation records, events, and motion data.

Notes

  • Handles creation, reading, and management of simulation data records
  • Implements efficient file-based storage with appropriate schemas
  • Provides record tracking with deterministic hashing for reproducibility
  • Supports multiple data formats including motion, events, and dynamics
  • Includes interfaces for consistent data access across the application
  • Contains error handling for storage operations
  • Uses structured file layout for organizing simulation results
  • Supports efficient querying and filtering of stored records

Documentation

Index

Constants

This section is empty.

Variables

View Source
var ErrRecordNotFound = errors.New("record not found")

ErrRecordNotFound is returned when a requested record hash does not exist.

View Source
var StorageHeaders = map[SimStorageType][]string{
	MOTION: {
		"time", "altitude", "velocity", "acceleration", "thrust",
	},
	EVENTS: {
		"time", "event_name", "motor_status", "parachute_status",
	},
	DYNAMICS: {
		"time", "position_x", "position_y", "position_z", "velocity_x", "velocity_y", "velocity_z", "acceleration_x", "acceleration_y", "acceleration_z", "orientation_x", "orientation_y", "orientation_z", "orientation_w",
	},
}

StorageHeaders is a map of columns for storage types

Functions

This section is empty.

Types

type MotorData added in v0.9.0

type MotorData struct {
	Name          string
	MaxThrust     float64
	TotalImpulse  float64
	BurnTime      float64
	AverageThrust float64
	ThrustData    []ThrustPoint
	Headers       []string   // Headers for the data columns
	Data          [][]string // Raw CSV data for motor
}

MotorData represents motor-specific simulation data

type Record

type Record struct {
	Name         string    `json:"name"`
	Hash         string    `json:"hash"`
	LastModified time.Time `json:"lastModified"` // Keep for potential compatibility, but prioritize CreationTime
	CreationTime time.Time `json:"creationTime"` // More reliable timestamp
	Path         string
	Motion       *Storage
	Events       *Storage
	Dynamics     *Storage
}

func NewRecord

func NewRecord(baseDir string, hash string, appCfg *config.Config) (*Record, error)

NewRecord creates a new simulation record with associated storage services

func (*Record) Close

func (r *Record) Close() error

Close closes all associated storage services

type RecordManager

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

RecordManager manages simulation records

func NewRecordManager

func NewRecordManager(cfg *config.Config, baseDir string, log *logf.Logger) (*RecordManager, error)

NewRecordManager creates a new RecordManager. It requires the application config, the base directory for records, and a logger.

func (*RecordManager) CreateRecord

func (rm *RecordManager) CreateRecord(cfg *config.Config) (*Record, error)

CreateRecord creates a new record with a unique hash based on the current time

func (*RecordManager) CreateRecordWithConfig added in v0.8.0

func (rm *RecordManager) CreateRecordWithConfig(configData []byte, orkData []byte) (*Record, error)

CreateRecordWithConfig creates a new record with a hash derived from configuration and OpenRocket data

func (*RecordManager) DeleteRecord

func (rm *RecordManager) DeleteRecord(hash string) error

DeleteRecord deletes a record by Hash

func (*RecordManager) GetRecord

func (rm *RecordManager) GetRecord(hash string) (*Record, error)

GetRecord retrieves an existing record by hash without creating a new one.

func (*RecordManager) GetStorageDir added in v0.7.0

func (rm *RecordManager) GetStorageDir() string

GetStorageDir returns the base directory for the record manager.

func (*RecordManager) ListRecords

func (rm *RecordManager) ListRecords() ([]*Record, error)

ListRecords lists all existing valid records in the base directory.

type SimStorageType added in v0.3.5

type SimStorageType string

SimStorageType is the type of storage service (MOTION, EVENTS, etc.)

const (
	// MOTION storage SimStorageType
	MOTION SimStorageType = "MOTION"
	// EVENTS storage SimStorageType
	EVENTS SimStorageType = "EVENTS"
	// DYNAMICS storage SimStorageType
	DYNAMICS SimStorageType = "DYNAMICS"
)

type SimulationData added in v0.9.0

type SimulationData struct {
	Motor         *MotorData                     `json:"motor" yaml:"motor"`
	MotionHeaders []string                       `json:"motion_headers,omitempty" yaml:"motion_headers,omitempty"`
	MotionData    [][]string                     `json:"motion_data,omitempty" yaml:"motion_data,omitempty"`
	EventsHeaders []string                       `json:"events_headers,omitempty" yaml:"events_headers,omitempty"`
	EventsData    [][]string                     `json:"events_data,omitempty" yaml:"events_data,omitempty"`
	ORKDoc        *openrocket.OpenrocketDocument `json:"ork_doc,omitempty" yaml:"ork_doc,omitempty"`
}

SimulationData holds overall data from a simulation run that isn't part of the static config. It's intended to be passed to functions like report generation.

type Storage

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

Storage is a service that writes csv's to disk

func NewStorage

func NewStorage(recordDir string, store SimStorageType, appCfg *config.Config) (*Storage, error)

NewStorage creates a new storage service for a specific store type within a given record directory.

func (*Storage) Close

func (s *Storage) Close() error

Close closes the storage service.

func (*Storage) FilePath added in v0.9.0

func (s *Storage) FilePath() string

FilePath returns the absolute path to the storage file.

func (*Storage) GetFilePath

func (s *Storage) GetFilePath() string

GetFilePath returns the file path of the storage service.

func (*Storage) Init

func (s *Storage) Init() error

Init ensures the header row is written if the file is new/empty. It is non-destructive if the file already appears to be initialized.

func (*Storage) ReadAll

func (s *Storage) ReadAll() ([][]string, error)

ReadAll reads all data from the storage file

func (*Storage) ReadHeadersAndData

func (s *Storage) ReadHeadersAndData() ([]string, [][]string, error)

ReadHeadersAndData reads the headers and data separately from the storage file

func (*Storage) Write

func (s *Storage) Write(data []string) error

Write writes a record to the storage service.

type StorageInterface

type StorageInterface interface {
	Init() error
	Write([]string) error
	Close() error
}

type Stores

type Stores struct {
	Motion   *Storage
	Events   *Storage
	Dynamics *Storage
}

Stores is a collection of storage services

type ThrustPoint added in v0.9.0

type ThrustPoint struct {
	Time   float64
	Thrust float64
}

ThrustPoint represents a single point on a motor thrust curve

Jump to

Keyboard shortcuts

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