rw

package
v0.1.1 Latest Latest
Warning

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

Go to latest
Published: Aug 16, 2023 License: MIT Imports: 16 Imported by: 0

Documentation

Index

Constants

View Source
const (
	CSVExt       string = ".csv"
	CSVDelimiter rune   = ','
	CSVComment   rune   = '#'
)
View Source
const (
	// XXX: but can also have no extension?
	DATExt string = ".dat"
)

Variables

View Source
var (
	ErrBadReader = fmt.Errorf(
		"bad input type, available types are: %q",
		common.MapKeys(Readers))
	ErrBadReaderOutOf = fmt.Errorf(
		"bad input type, available types are: %q",
		common.MapKeys(ReadersFromFn))
)
View Source
var (
	// Archive is the global in-memory store for archives.
	// It is (intended to be used as) a singleton, hence, any change
	// persists throughout the program run time.
	// WARNING: technically not a singleton because it's not in a separate
	// package, so anyone in 'rw' can instantiate a raw archive.
	Archive *archive
)
View Source
var (
	ErrBadOutput = fmt.Errorf(
		"bad output type, available types are: %q",
		common.MapKeys(Writers))
)
View Source
var (
	ErrMultipleEmpty = errors.New("multple: no inputs defined")
)
View Source
var (
	// RAM is the global in-memory store for dataframe.DataFrames.
	// It is (intended to be used as) a singleton, hence, any change
	// persists throughout the program run time.
	// WARNING: technically not a singleton because it's not in a separate
	// package, so anyone in 'rw' can instantiate a raw ram.
	RAM *ram
)
View Source
var Readers = map[string]ReaderFactory{
	"csv":         func(n *yaml.Node) (Reader, error) { return NewCsv(n) },
	"dat":         func(n *yaml.Node) (Reader, error) { return NewDat(n) },
	"time-series": func(n *yaml.Node) (Reader, error) { return NewTimeSeries(n) },
	"ram":         func(n *yaml.Node) (Reader, error) { return NewRam(n) },
	"multiple":    func(n *yaml.Node) (Reader, error) { return NewMultiple(n) },
	"archive":     func(n *yaml.Node) (Reader, error) { return NewArchive(n) },
}
View Source
var ReadersFromFn = map[string]ReaderOutOfFactory{
	"csv":         func(n *yaml.Node) (ReaderFromFn, error) { return NewCsv(n) },
	"dat":         func(n *yaml.Node) (ReaderFromFn, error) { return NewDat(n) },
	"time-series": func(n *yaml.Node) (ReaderFromFn, error) { return NewTimeSeries(n) },
}
View Source
var Writers = map[string]WriterFactory{
	"csv": func(n *yaml.Node) (Writer, error) { return NewCsv(n) },
	"ram": func(n *yaml.Node) (Writer, error) { return NewRam(n) },
}

Functions

func DecodeRuneOrDefault

func DecodeRuneOrDefault(s string, dflt rune) rune

DecodeRuneOrDefault tries to decode a rune from a string and returns the decoded rune on success or dflt if the decoding fails.

func NewArchive

func NewArchive(n *yaml.Node) (*archive, error)

NewArchive initializes Archive, if it has not been initialized, and marshals the run time config into it.

func NewCsv

func NewCsv(n *yaml.Node) (*csv, error)

func NewDat

func NewDat(n *yaml.Node) (*dat, error)

func NewMultiple

func NewMultiple(n *yaml.Node) (*multiple, error)

func NewRam

func NewRam(n *yaml.Node) (*ram, error)

NewRam initializes RAM, if it has not been initialized, and marshals the run time config into it.

func NewTimeSeries

func NewTimeSeries(n *yaml.Node) (*timeSeries, error)

func OutDir

func OutDir(path string) error

OutDir is a function which takes a file path and, if necessary, recursively creates all directories necessary for the path to be valid.

func Read

func Read(config *Config) (*dataframe.DataFrame, error)

Read reads a dataframe.DataFrame using the specification from the config.

func ReadFromFn

func ReadFromFn(fn ReaderFunc, config *Config) (*dataframe.DataFrame, error)

ReadFromFn reads a dataframe.DataFrame from a ReaderFromFn supplied with fn using the specification from the config.

func SetExt

func SetExt(path, ext string) string

SetExt sets the file name extension of path to ext and returns the new path.

func SetNames

func SetNames(df *dataframe.DataFrame, names []string) (*dataframe.DataFrame, error)

func Write

func Write(df *dataframe.DataFrame, configs []Config) error

Write executes all Writers as defined in the config An error is returned if any of the Writers return an error.

Types

type Config

type Config struct {
	// Type is the input type name.
	Type string `yaml:"type"`
	// Fields is a list of field names.
	// If defined, these names are used for the field names
	// of read dataframe.DataFrame.
	Fields []string `yaml:"fields"`
	// TypeSpec is the input type specification.
	TypeSpec yaml.Node `yaml:"type_spec"`
}

type Reader

type Reader interface {
	Read() (*dataframe.DataFrame, error)
}

type ReaderFactory

type ReaderFactory func(*yaml.Node) (Reader, error)

type ReaderFromFn

type ReaderFromFn interface {
	ReadFromFn(ReaderFunc) (*dataframe.DataFrame, error)
}

type ReaderFunc

type ReaderFunc func(string) (io.ReadCloser, error)

type ReaderOutOfFactory

type ReaderOutOfFactory func(*yaml.Node) (ReaderFromFn, error)

type Writer

type Writer interface {
	Write(*dataframe.DataFrame) error
}

type WriterFactory

type WriterFactory func(*yaml.Node) (Writer, error)

Jump to

Keyboard shortcuts

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