tsmongo

package
v0.0.0-...-13156d4 Latest Latest
Warning

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

Go to latest
Published: Oct 2, 2018 License: MIT Imports: 5 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var ErrInvalidFanStatus = fmt.Errorf("Invalid status")

ErrInvalidFanStatus represent invalid fan status.

Functions

This section is empty.

Types

type BedroomService

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

BedroomService allows the user to update and get information about the bedroom state.

func NewBedroomService

func NewBedroomService(s *Session) *BedroomService

NewBedroomService creates a new BedroomService, which allows to interact with the bedroom field of the timeseries.

func (*BedroomService) FetchState

func (b *BedroomService) FetchState(start time.Time, finish time.Time) ([]BedroomState, error)

FetchState returns the bedroom state updates in the considered period.

func (*BedroomService) UpdateTemperature

func (b *BedroomService) UpdateTemperature(t time.Time, temp float64) error

UpdateTemperature changes bedroom temperature at the specified time, updating the database.

type BedroomState

type BedroomState struct {
	Timestamp   time.Time `json:"timestamp,omitempty"`
	Temperature float64   `json:"temp,omitempty"`
}

BedroomState state stores the bedroom state (e.g. temperature, humidity) at a certain moment.

type FanService

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

FanService allows the user to update and get information about the bedroom fan.

func NewFanService

func NewFanService(s *Session) *FanService

NewFanService creates a new BedroomService, which allows to interact with the fan field of the timeseries.

func (FanService) FetchState

func (f FanService) FetchState(start time.Time, finish time.Time) ([]FanState, error)

FetchState returns the fan status updates in the considered period. Important to n

func (FanService) LastState

func (f FanService) LastState() (FanState, error)

LastState returns the last fan status.

func (FanService) UpdateStatus

func (f FanService) UpdateStatus(t time.Time, s FanStatus) error

UpdateStatus changes the fan status at specified time, updating the database.

type FanState

type FanState struct {
	Timestamp time.Time `json:"timestamp,omitempty"`
	Status    FanStatus `json:"status,omitempty"`
}

FanState stores the state of the fan at a certain moment.

type FanStatus

type FanStatus int

FanStatus represents the speed/power of the bedroom fan.

const (
	FanOff       FanStatus = 0
	FanLowSpeed  FanStatus = 1
	FanHighSpeed FanStatus = 2
)

Enumerates the three possibilites for the fan speed.

type ForecastService

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

ForecastService allows the user to update and get information about the weather forecast.

func NewForecastService

func NewForecastService(s *Session) *ForecastService

NewForecastService creates a new ForecastService, which allows to interact with the forecast field of the timeseries.

func (*ForecastService) Fetch

func (wf *ForecastService) Fetch(start time.Time, finish time.Time) ([]weather.State, error)

Fetch fetches a time range of weather forecast samples.

func (*ForecastService) Update

func (wf *ForecastService) Update(states ...weather.State) error

Update updates the database with the new information about the weather forecast. This call assumes the weather.State.Timestamp is a future timestamp, so it overrides whichever information is associated to it (it should be none).

type Prediction

type Prediction struct {
	Timestamp   time.Time `bson:"-"`
	TempFanOff  float64   `bson:"fan_off,omitempty"`
	TempFanLow  float64   `bson:"fan_low,omitempty"`
	TempFanHigh float64   `bson:"fan_high,omitempty"`
}

Prediction represents a prediction of a bedroom temperature at a certain time in any of the following states: fan off, low or high.

type PredictionService

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

PredictionService allows users to store or fetch predictions.

func NewPredictionService

func NewPredictionService(s *Session) *PredictionService

NewPredictionService creates a new PredictionService, which allows to interact with the predictions field of the timeseries.

func (*PredictionService) Update

func (p *PredictionService) Update(ps ...Prediction) error

Update stores the passed-in predictions. The call overrides any previously stored predictions.

type Session

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

Session represents a connection to a mongo timeseries collection.

func Dial

func Dial(uri string) (*Session, error)

Dial sets up a connection to the specified timeseries database specified by the passed-in URI.

func NewSession

func NewSession(s *mgo.Session, dbName string) *Session

NewSession creates a new Session instance, which allows the communication to the underlying timeseries mongo database;

func (*Session) Close

func (s *Session) Close()

Close release resources associated with this connection.

func (*Session) Copy

func (s *Session) Copy() *Session

Copy works just like New, but preserves the database and any authentication information from the original session.

func (*Session) Last

func (s *Session) Last(field string) (TSRecord, error)

Last returns the last element in the timeseries, if any.

func (*Session) Query

func (s *Session) Query(field string, start time.Time, finish time.Time) ([]TSRecord, error)

Query fetches all records from timeseries mongo with the specified range.

func (*Session) Upsert

func (s *Session) Upsert(field string, val ...TSRecord) error

Upsert inserts the given data into the timeseries database overriding the data if necessary. If more than one values are passed, it performs a bulk-upsert.

type TSRecord

type TSRecord struct {
	Timestamp time.Time   `bson:"timestamp_hour,omitempty"`
	Value     interface{} `bson:"value,omitempty"`
}

TSRecord represents a value to be added to timeseries database.

type WeatherService

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

WeatherService allows the user to update and get information about the weather.

func NewWeatherService

func NewWeatherService(s *Session) *WeatherService

NewWeatherService creates a new WeatherService, which allows to interact with the weather field of the timeseries.

func (*WeatherService) Fetch

func (w *WeatherService) Fetch(start time.Time, finish time.Time) ([]weather.State, error)

Fetch fetches a time range of weather temperatures (which do not include forecasts).

func (*WeatherService) Update

func (w *WeatherService) Update(s weather.State) error

Update updates the StatusDB with the new information about the current weather.

Jump to

Keyboard shortcuts

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