weather

package
v0.0.0-...-88057de Latest Latest
Warning

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

Go to latest
Published: Apr 26, 2024 License: Apache-2.0 Imports: 11 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func ResetCache

func ResetCache()

Types

type Client

type Client interface {
	GetTotalRain(since time.Duration) (float32, error)
	GetAverageHighTemperature(since time.Duration) (float32, error)
}

Client is an interface defining the possible methods used to interact with the weather client APIs

func NewClient

func NewClient(c *Config, storageCallback func(map[string]interface{}) error) (client Client, err error)

NewClient will use the config to create and return the correct type of weather client. If no type is provided, this will return a nil client rather than an error since Weather client is not required

type Config

type Config struct {
	ID      babyapi.ID             `json:"id" yaml:"id"`
	Type    string                 `json:"type" yaml:"type"`
	Options map[string]interface{} `json:"options" yaml:"options"`
}

Config is used to identify and configure a client type

func (*Config) Bind

func (wc *Config) Bind(r *http.Request) error

func (*Config) EndDated

func (*Config) EndDated() bool

EndDated allows this to satisfy an interface even though the resources does not have end-dates

func (*Config) GetID

func (wc *Config) GetID() string

func (*Config) Patch

func (wc *Config) Patch(newConfig *Config) *babyapi.ErrResponse

Patch allows modifying an existing Config with fields from a new one

func (*Config) Render

func (wc *Config) Render(_ http.ResponseWriter, _ *http.Request) error

func (*Config) SetEndDate

func (*Config) SetEndDate(_ time.Time)

type Control

type Control struct {
	Rain         *ScaleControl        `json:"rain_control,omitempty"`
	SoilMoisture *SoilMoistureControl `json:"moisture_control,omitempty"`
	Temperature  *ScaleControl        `json:"temperature_control,omitempty"`
}

Control defines certain parameters and behaviors to influence watering patterns based off weather data

func (*Control) Patch

func (wc *Control) Patch(new *Control)

Patch allows modifying the struct in-place with values from a different instance

type MockClient

type MockClient struct {
	mock.Mock
}

MockClient is an autogenerated mock type for the Client type

func NewMockClient

func NewMockClient(t interface {
	mock.TestingT
	Cleanup(func())
}) *MockClient

NewMockClient creates a new instance of MockClient. It also registers a testing interface on the mock and a cleanup function to assert the mocks expectations. The first argument is typically a *testing.T value.

func (*MockClient) GetAverageHighTemperature

func (_m *MockClient) GetAverageHighTemperature(since time.Duration) (float32, error)

GetAverageHighTemperature provides a mock function with given fields: since

func (*MockClient) GetTotalRain

func (_m *MockClient) GetTotalRain(since time.Duration) (float32, error)

GetTotalRain provides a mock function with given fields: since

type ScaleControl

type ScaleControl struct {
	BaselineValue *float32 `json:"baseline_value"`
	Factor        *float32 `json:"factor"`
	Range         *float32 `json:"range"`
	ClientID      xid.ID   `json:"client_id"`
}

ScaleControl is a generic struct that enables scaling BaselineValue is the value that scaling starts at Range is the most extreme value that scaling will go to (used as max/min) Factor is the maximum amount that this will scale by. This must be between 0 and 1, where 0 is no scaling and 1 scale by the full proportion of the range When a measured value is equal to or greater than the BaselineValue, factor is used to scale up the current value based on the proportion of the difference between current value and BaselineValue to the Range

For example: BaselineValue: 90, Factor: 0.5, Range: 30, WaterDuration: 30m

  • Input 100 degrees: (100 - 90)/30 * 0.5 + 1 = 1.1666666667 => water 35m
  • Input 120 degrees: (120 - 90)/30 * 0.5 + 1 = 1.5, max scaling
  • Input 130 degrees: (130 - 90)/30 * 0.5 + 1 = 1.6666666667 => greater than factor of 0.5, so we cut off at 1.5 and water 45m
  • Input 80 degrees: ( 80 - 90)/30 * 0.5 + 1 = 0.8333333333 => water 25m
  • Input 60 degrees: ( 60 - 90)/30 * 0.5 + 1 = 0.5 => water 15m
  • Input 50 degrees: ( 50 - 90)/30 * 0.5 + 1 = 0.3333333333 => less than factor of 0.5, so we round up to 0.5

Basically, a Factor of 0.5 means that if watering is set at 30m, I want to water at most 45 min and at least 15 min This way, the control doesn't need to know anything about the durations and can just return a multiplier that makes this happen

func (*ScaleControl) InvertedScaleDownOnly

func (sc *ScaleControl) InvertedScaleDownOnly(actualValue float32) float32

InvertedScaleDownOnly calculates and returns the multiplier based on the input value, but is inverted so higher input values cause scaling < 1. Also it will only scale in this direction

func (*ScaleControl) Patch

func (sc *ScaleControl) Patch(new *ScaleControl)

Patch allows modifying the struct in-place with values from a different instance

func (*ScaleControl) Scale

func (sc *ScaleControl) Scale(actualValue float32) float32

Scale calculates and returns the multiplier based on the input value

type SoilMoistureControl

type SoilMoistureControl struct {
	MinimumMoisture *int `json:"minimum_moisture,omitempty"`
}

SoilMoistureControl defines parameters for delaying watering based on soil moisture data. This will skip watering if the soil moisture is below the minimum soil moisture value is currently hard-coded as the average value over the last 15 minutes

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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