database

package
v0.0.0-...-992f2a4 Latest Latest
Warning

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

Go to latest
Published: Dec 1, 2022 License: GPL-3.0 Imports: 6 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var (
	MemoryBucket      = []byte("memory")
	DeviceBucket      = []byte("device")
	DeviceGraphBucket = []byte("deviceGraph")
	TimeTableBucket   = []byte("timeChain")
)

Functions

func GetUniqueHash

func GetUniqueHash(deviceId, integration string) string

GetUniqueHash will return the unique hash created from the deviceid and integration

Types

type Database

type Database struct {
	Connection *bolt.DB
}
var MartianData Database

func (*Database) DeleteGraphValue

func (d *Database) DeleteGraphValue(graphToDelete DeviceGraph) (updated bool, err error)

DeleteGraphValue will remove the graph provided

func (*Database) GetAllAutomatedGraphs

func (d *Database) GetAllAutomatedGraphs() (automatedGraphs []DeviceGraph)

GetAllAutomatedGraphs will return all of the automated graphs

func (*Database) GetAllAutomatedTimeTables

func (d *Database) GetAllAutomatedTimeTables() []TimeTable

GetAllTimeTables will return all of the timetables

func (*Database) GetAllDeviceGraphs

func (d *Database) GetAllDeviceGraphs() (graphs []DeviceGraph)

GetAllDeviceGraphss

func (*Database) GetAllDevices

func (d *Database) GetAllDevices() (devices []Device)

GetAllDevices

func (*Database) GetAllGraphs

func (d *Database) GetAllGraphs() (graphs []UniqueHashGraphs)

GetAllDeviceGraphss

func (*Database) GetAllTimeTables

func (d *Database) GetAllTimeTables() []TimeTable

GetAllTimeTables will return all of the timetables

func (*Database) GetAutomatedGraphs

func (d *Database) GetAutomatedGraphs(uniqueId, integration, status string) (graphResults []DeviceGraph)

GetAutomatedGraphs will return all of the graphs that are automated for the provided uniqueid and integration

func (*Database) GetAutomatedTimeTableEntry

func (d *Database) GetAutomatedTimeTableEntry(timeBlock string) []Device

GetTimeTableEntry will return the devices that are available for that time

func (*Database) GetDevice

func (d *Database) GetDevice(uniqueId, integration string) (device Device)

GetDevice will return the device row for the provided uniqueId and integration

func (*Database) GetDeviceByHash

func (d *Database) GetDeviceByHash(uniqueHash string) (device Device)

GetDeviceByHash will return the device row for the provided uniqueId and integration

func (*Database) GetDeviceGraphValues

func (d *Database) GetDeviceGraphValues(fromUniqueHash string) (deviceGraphs UniqueHashGraphs, err error)

GetDeviceGraphValues

func (*Database) GetDeviceValues

func (d *Database) GetDeviceValues(uniqueHash string) (device Device, err error)

GetDeviceValues

func (*Database) GetGraphByRelationship

func (d *Database) GetGraphByRelationship(firstId, firstIntegration, firstStatus, lastId, lastIntegration, lastStatus string) (graph DeviceGraph, err error)

GetGraphByRelationship gets the graph by the first and last pieces provided

func (*Database) GetGraphs

func (d *Database) GetGraphs(uniqueId, integration string) (graphResults []DeviceGraph)

GetGraphs will return all of the graphs for the provided uniqueid and integration

func (*Database) GetMemoryData

func (d *Database) GetMemoryData() (bool, []byte)

GetMemoryData will grab the memory data from the database

returns a boolean on if the value exists along with the value

func (*Database) GetTimeTableValues

func (d *Database) GetTimeTableValues(timeBlock string) (times TimeTable, err error)

GetTimeTableValues

func (*Database) ImproveEnergyEfficiency

func (d *Database) ImproveEnergyEfficiency(amount int) bool

ImproveEnergyEfficiencyDaily will decrease the time that devices are on by a minute per day

func (*Database) PutDeviceGraphValues

func (d *Database) PutDeviceGraphValues(graphs UniqueHashGraphs) (err error)

PutDeviceGraphValues

func (*Database) PutDeviceValues

func (d *Database) PutDeviceValues(device Device) (err error)

PutDeviceValues

func (*Database) PutTimeTableValues

func (d *Database) PutTimeTableValues(timeTable string, timeEntries TimeTable) (err error)

PutTimeTableValues

func (*Database) RecreateGraphBucket

func (d *Database) RecreateGraphBucket() error

func (*Database) RecreateTimeBucket

func (d *Database) RecreateTimeBucket() error

func (*Database) ResetDeviceGraph

func (d *Database) ResetDeviceGraph() bool

ResetDeviceGraph will delete all unautomated entries

func (*Database) RetrieveDataFromDeviceGraphByWeight

func (d *Database) RetrieveDataFromDeviceGraphByWeight(weightAmount int) (graphResults []DeviceGraph)

RetrieveDataFromDeviceGraph grabs data from the device graph above the specified weight amount

func (*Database) SetDevice

func (d *Database) SetDevice(data Device) (inserted bool)

SetDevice will set the device in the database, will return a false if it was unable to insert or device already exists

func (*Database) SetGraph

func (d *Database) SetGraph(graphData DeviceGraph) bool

SetGraph Will set the graph for the first time

func (*Database) StoreMemoryData

func (d *Database) StoreMemoryData(jsonBrain interface{}) bool

StoreMemoryData will store the memory data in the bolt database

returns a boolean on storage success

func (*Database) UpdateEfficiencyTime

func (d *Database) UpdateEfficiencyTime(uniquehash string, updateBy int) bool

UpdateEfficiencyTime will update the efficiency time in the device table for the provided hash by provided amount

func (*Database) UpdateGraphTableWithAutomated

func (d *Database) UpdateGraphTableWithAutomated(graphData DeviceGraph) bool

UpdateGraphTableWithAutomated will set entries as automated

func (*Database) UpdateGraphWeight

func (d *Database) UpdateGraphWeight(graphData DeviceGraph, amount int) bool

UpdateGraphWeight will update the weight on the graph entry

func (*Database) UpdateWeightsForTimeTable

func (d *Database) UpdateWeightsForTimeTable(timeTable string, timeDevices []Device) bool

UpdateWeightsForTimeTable will update the weights for all of the devices currently active

type Device

type Device struct {
	DeviceId                string `json:"deviceId"`
	UniqueHash              string `json:"uniqueHash"`
	Name                    string `json:"name,omitempty"`
	Label                   string `json:"label,omitempty"`
	Type                    string `json:"type,omitempty"`
	Integration             string `json:"integration,omitempty"`
	EnergyEfficiencyMinutes int    `json:"energyEfficiencyMinutes,omitempty"`
}

type DeviceGraph

type DeviceGraph struct {
	FromUniqueHash string `json:"fromUniqueHash"`
	FromStatus     string `json:"fromStatus"`
	ToUniqueHash   string `json:"toUniqueHash"`
	ToStatus       string `json:"toStatus"`
	Weight         int    `json:"weight"`
	Automated      bool   `json:"automated"`
	TimeAutomated  bool   `json:"timeAutomated"`
}

func AssembleDeviceGraph

func AssembleDeviceGraph(fromId, fromIntegration, fromStatus, toId, toIntegration, toStatus string) (deviceGraph DeviceGraph, sameDevice bool)

AssembleDeviceGraph will create the graph sructure required to insert into table, will return a boolean on if the device_graph has the same device in the from->to positions

type TimeBlocks

type TimeBlocks struct {
	UniqueHash string `json:"uniqueHash"`
	Weight     int    `json:"weight"`
	Automated  bool   `json:"automated"`
	TimeKey    string `json:"timeKey"`
}

type TimeTable

type TimeTable struct {
	Times []TimeBlocks `json:"timeBlocks"`
}

type UniqueHashGraphs

type UniqueHashGraphs struct {
	Graphs []DeviceGraph `json:"graphs"`
}

Jump to

Keyboard shortcuts

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