util

package
v0.0.0-...-d8ac9bd Latest Latest
Warning

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

Go to latest
Published: May 18, 2024 License: Apache-2.0 Imports: 14 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func AppendString

func AppendString(b []byte, s string) []byte

func AppendTime

func AppendTime(b []byte, t time.Time) []byte

func AppendValue

func AppendValue(b []byte, v value.Value) []byte

func AssertLength

func AssertLength(s int, b []byte) error

func BaseName

func BaseName(fileName string) (string, string)

BaseName splits the filename and file type from a path. if the file does not contain a '.' then this returns file,""

func FloatDefault

func FloatDefault(a *float64, b float64) float64

func In

func In(s string, p ...string) bool

In returns true if s is one of the strings in p. This is a case-insensitive test.

func Itoa

func Itoa(i int, p int) string

func Match

func Match(s, pat string) bool

Match tests s against pattern pat.

If p starts and ends with '*' then this means contains the text between them.

If p starts with '*' only then means match the end of the pattern

If p ends with '*' only then means match the start of the pattern

A '|' allows for multiple patterns

A pattern of "" means always match

func PadToLength

func PadToLength(b []byte, l int) ([]byte, error)

func ReadString

func ReadString(b []byte) (string, []byte)

func ReadTime

func ReadTime(b []byte) (time.Time, error)

func ReadValue

func ReadValue(b []byte) (value.Value, error)

func Sprintf

func Sprintf(f string, args ...interface{}) string

Sprintf is similar to fmt.Sprintf except it is customised for handling our own data types.

It's primarily used by weatherbot with it's output formatting.

The format comprises the following:

%% % character

%d integer or floating point with 0 decimal places

%e The unit for Value's, "" otherwise

%f floating point

%.1f floating point 1 decimal place

%.2f floating point 2 decimal place

%.3f floating point 3 decimal place

%s String value

%t Trend, show ↓ → or ↑ depending on the trend value

%T Integer value in unix seconds - returns as "Jan 02 15:04:05 MST"

%u Unit value with unit suffix

%v interface value

%W Wind direction

func StringDefault

func StringDefault(a, b string) string

func ToFloat64

func ToFloat64(v interface{}) (float64, bool)

func ToString

func ToString(v interface{}) string

func WindCompassDirection

func WindCompassDirection(d float64) string

Types

type DataSource

type DataSource interface {
	// Size of the DataSource
	Size() int
	// Get a specific entry in the DataSource
	Get(int) (time.Time, value.Value)
	// Period returns the Period of the entries within the DataSource
	Period() time2.Period
	// GetYRange returns the Range of values in the DataSource
	GetYRange() *value.Range
	// GetUnit returns the Unit of the values in the DataSource
	GetUnit() *value.Unit
	// ForEach calls a function for each entry in the DataSource
	ForEach(func(int, time.Time, value.Value))
}

DataSource represents a collection of values to be plotted

func LimitedPseudoDataSource

func LimitedPseudoDataSource(c value.Calculator, period time2.Period, unit *value.Unit, stepSize time.Duration, min, max value.Value, t value.Time) (DataSource, error)

LimitedPseudoDataSource is more optimal than PseudoDataSource as it doesn't have to precalculate the results as the min/max Value's are provided, so calculations are made on the fly.

func PseudoDataSource

func PseudoDataSource(c value.Calculator, period time2.Period, unit *value.Unit, stepSize time.Duration, t value.Time) (DataSource, error)

PseudoDataSource returns a DataSource based on the output of a calculator

func SliceDataSource

func SliceDataSource(s []Entry, period time2.Period, unit *value.Unit) (DataSource, error)

SliceDataSource returns a DataSource over a slice of Entry's

type Entry

type Entry struct {
	Time  time.Time
	Value value.Value
}

type StringMap

type StringMap map[string]string

func NewStringMap

func NewStringMap() StringMap

func (*StringMap) Add

func (a *StringMap) Add(k, v string) bool

func (*StringMap) Contains

func (a *StringMap) Contains(k string) bool

func (*StringMap) ForEach

func (a *StringMap) ForEach(f func(string, string) error) error

func (*StringMap) Get

func (a *StringMap) Get(k string) string

func (*StringMap) IsEmpty

func (a *StringMap) IsEmpty() bool

func (*StringMap) Keys

func (a *StringMap) Keys() []string

func (*StringMap) Size

func (a *StringMap) Size() int

type StringSet

type StringSet map[string]interface{}

func NewStringSet

func NewStringSet() StringSet

func (*StringSet) Add

func (a *StringSet) Add(s string) bool

func (*StringSet) AddAll

func (a *StringSet) AddAll(s ...string)

func (*StringSet) Contains

func (a *StringSet) Contains(s string) bool

func (*StringSet) Entries

func (a *StringSet) Entries() []string

func (*StringSet) ForEach

func (a *StringSet) ForEach(f func(string) error) error

func (*StringSet) IsEmpty

func (a *StringSet) IsEmpty() bool

func (*StringSet) MarshalJSON

func (a *StringSet) MarshalJSON() ([]byte, error)

func (*StringSet) Size

func (a *StringSet) Size() int

func (*StringSet) UnmarshalJSON

func (a *StringSet) UnmarshalJSON(data []byte) error

Directories

Path Synopsis
mq

Jump to

Keyboard shortcuts

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