models

package
v0.0.0-...-07365c2 Latest Latest
Warning

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

Go to latest
Published: Jun 27, 2021 License: Apache-2.0 Imports: 5 Imported by: 16

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Asset

type Asset struct {
	ID       string   `json:"id,omitempty"`
	SKU      string   `json:"sku,omitempty"`
	Name     string   `json:"name,omitempty"`
	Type     string   `json:"type,omitempty"`
	Info     string   `json:"info,omitempty"`
	Cost     float64  `json:"cost,omitempty"`
	Amount   int      `json:"amount,omitempty"`
	Holder   string   `json:"holder,omitempty"`
	State    string   `json:"state,omitempty" metadata:",optional"`
	Location Location `json:"location,omitempty"`
	Tags     []string `json:"tags,omitempty" metadata:",optional"`
}

Asset defines asset data models.

func (Asset) Decode

func (m Asset) Decode(b []byte) (*Asset, error)

Decode deserializes the Asset model.

func (Asset) Encode

func (m Asset) Encode() []byte

Encode serializes the Asset model.

type Device

type Device struct {
	ID       string        `json:"id"`
	IP       string        `json:"ip"`
	MAC      string        `json:"mac,omitempty" metadata:",optional"`
	Name     string        `json:"name,omitempty" metadata:",optional"`
	Hostname string        `json:"hostname"`
	Profile  string        `json:"profile,omitempty" metadata:",optional"`
	Supports Metrics       `json:"supports"`
	Holder   string        `json:"holder"`
	State    DeviceState   `json:"state,omitempty" metadata:",optional"`
	Battery  DeviceBattery `json:"battery,omitempty" metadata:",optional"`
	Location Location      `json:"location,omitempty" metadata:",optional"`
}

Device defines device data models.

func (Device) Decode

func (m Device) Decode(b []byte) (*Device, error)

Decode deserializes the Device model.

func (Device) Encode

func (m Device) Encode() []byte

Encode serializes the Device model.

func (*Device) Validate

func (m *Device) Validate() error

Validate validates the Device model.

type DeviceBattery

type DeviceBattery struct {
	Level     int  `json:"level"`
	PluggedIn bool `json:"plugged"`
}

DeviceBattery defines Device battery and power state.

type DeviceCommand

type DeviceCommand string

DeviceCommand defines Device commands enum.

const (
	// DevicePauseCmd defines DeviceCommand to "pause" Device.
	DevicePauseCmd DeviceCommand = "pause"
	// DeviceResumeCmd defines DeviceCommand to "pause" Device.
	DeviceResumeCmd DeviceCommand = "resume"
	// DevicePairingCmd defines DeviceCommand to pair Device via Bluetooth.
	DevicePairingCmd DeviceCommand = "ble_pair"
)

type DeviceCommandLogEntry

type DeviceCommandLogEntry struct {
	DeviceID  string              `json:"device_id"`
	Command   DeviceCommand       `json:"command"`
	Args      []interface{}       `json:"args"`
	Status    DeviceCommandStatus `json:"status"`
	Error     string              `json:"error"`
	Timestamp time.Time           `json:"timestamp"`
}

DeviceCommandLogEntry defines DeviceCommand execution historical log record.

func (DeviceCommandLogEntry) Decode

Decode deserializes the DeviceCommandLogEntry model.

func (DeviceCommandLogEntry) Encode

func (m DeviceCommandLogEntry) Encode() []byte

Encode serializes the DeviceCommandLogEntry model.

type DeviceCommandStatus

type DeviceCommandStatus string

DeviceCommandStatus defines DeviceCommand execution status.

const (
	// DeviceCmdCompleted defines "completed" status of DeviceCommand execution.
	DeviceCmdCompleted DeviceCommandStatus = "completed"
	// DeviceCmdProcessing defines "processing" status of DeviceCommand execution.
	DeviceCmdProcessing DeviceCommandStatus = "processing"
	// DeviceCmdFailed defines "failed" status of DeviceCommand execution.
	DeviceCmdFailed DeviceCommandStatus = "failed"
)

type DeviceState

type DeviceState string

DeviceState defines Device states enum.

var (
	// DeviceOnline defines Device "online" state.
	DeviceOnline DeviceState = "online"
	// DeviceOffline defines Device "offline" state.
	DeviceOffline DeviceState = "offline"
	// DevicePaused defines Device "paused" state.
	DevicePaused DeviceState = "paused"
)

type Location

type Location struct {
	Name      string  `json:"name"`
	Latitude  float64 `json:"latitude"`
	Longitude float64 `json:"longitude"`
}

Location defines the geospatial location data model.

func (Location) Distance

func (l Location) Distance(l2 Location) float64

Distance calculates distance between two geo points (in m).

func (Location) IsNearBy

func (l Location) IsNearBy(l2 Location, d float64) bool

IsNearBy determines whether two geo points is located within `d` distance radius (m).

type Metric

type Metric string

Metric represents tracking properties considered by the asset holder.

type MetricReadings

type MetricReadings struct {
	ID        string             `json:"id"`
	AssetID   string             `json:"asset_id"`
	DeviceID  string             `json:"device_id"`
	Location  string             `json:"location"`
	Timestamp time.Time          `json:"timestamp"`
	Values    map[Metric]float64 `json:"values"`
}

MetricReadings defines data models for readings from sensors.

func (MetricReadings) Decode

func (m MetricReadings) Decode(b []byte) (*MetricReadings, error)

Decode deserializes the MetricReadings model.

func (MetricReadings) Encode

func (m MetricReadings) Encode() []byte

Encode serializes the MetricReadings model.

type Metrics

type Metrics []Metric

Metrics represents slice of Metric properties.

type Requirement

type Requirement struct {
	MinLimit float64 `json:"min_limit"`
	MaxLimit float64 `json:"max_limit"`
}

Requirement defines per metric requirement properties limits.

type Requirements

type Requirements struct {
	ID      string          `json:"id,omitempty"`
	AssetID string          `json:"asset_id,omitempty"`
	Period  int             `json:"period,omitempty" metadata:",optional"`
	Metrics RequirementsMap `json:"metrics,omitempty"`
	FromOrg string          `json:"from_org"`
}

Requirements defines requirements data models.

func (Requirements) Decode

func (m Requirements) Decode(b []byte) (*Requirements, error)

Decode deserializes the Requirements model.

func (Requirements) Encode

func (m Requirements) Encode() []byte

Encode serializes the Requirements model.

func (*Requirements) Validate

func (m *Requirements) Validate() error

Validate validates the Requirements model.

type RequirementsMap

type RequirementsMap map[Metric]Requirement

RequirementsMap represents map with Metric key and corresponding Requirement value.

func (RequirementsMap) Metrics

func (rm RequirementsMap) Metrics() Metrics

Metrics returns all required Metrics.

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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