storage

package
v0.4.2 Latest Latest
Warning

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

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

README

internal/storage

Responsibility

  • Manages the storage of simulation data.
  • Provides functions for creating, reading, and listing simulation records.
  • Handles the creation of data files and metadata files.

Scope

  • Record creation and management.
  • Data file and metadata file handling.
  • Storage service initialization.

Test Suite Overview

  • Tests should cover record creation, data file handling, and metadata file handling.

Decisions & Potential Gotchas

  • Storage format should be well-defined and documented.
  • Metadata file handling may need to be optimized for performance.
  • Error handling should be robust.

Documentation

Index

Constants

This section is empty.

Variables

View Source
var StorageHeaders = map[SimStorageType][]string{
	MOTION: {
		"time", "altitude", "velocity", "acceleration", "thrust",
	},
	EVENTS: {
		"time", "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 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) (*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(baseDir string) (*RecordManager, error)

func (*RecordManager) CreateRecord

func (rm *RecordManager) CreateRecord() (*Record, error)

CreateRecord creates a new record with a unique hash

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) 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 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) (*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) 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.

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

Jump to

Keyboard shortcuts

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