model

package
v0.4.0 Latest Latest
Warning

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

Go to latest
Published: Nov 21, 2017 License: MIT Imports: 6 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Building

type Building struct {
	ID       bson.ObjectId   `json:"id" bson:"_id"`
	Name     string          `json:"name" bson:"name"`
	Location string          `json:"location"`
	Rooms    []Room          `json:"rooms,omitempty" bson:"-"`
	RoomIDs  []bson.ObjectId `json:"-" bson:"rooms"`
	// contains filtered or unexported fields
}

func NewBuildingModel

func NewBuildingModel(db *mgo.Database) *Building

func (*Building) Find

func (b *Building) Find() (buildings []Building, err error)

func (*Building) FindId

func (b *Building) FindId(ID bson.ObjectId) *Building

func (*Building) GetRooms

func (b *Building) GetRooms() (rooms []Room, err error)

func (*Building) Save

func (b *Building) Save() (building *Building, err error)

type Datapoint

type Datapoint struct {
	ID        bson.ObjectId `json:"id" bson:"_id"`
	SensorID  bson.ObjectId `json:"sensor_id" bson:"sensor"`
	Key       string        `json:"key" bson:"key"`
	Value     float64       `json:"value" bson:"value"`
	Timestamp int64         `json:"timestamp" bson:"timestamp"`
	DB        *mgo.Database `json:"-" bson:"-"`
}

func BulkSaveDatapoints

func BulkSaveDatapoints(db *mgo.Database, datapoints []Datapoint) (savedDatapoints []Datapoint, err error)

func DatapointModel

func DatapointModel(db *mgo.Database) *Datapoint

HubModel creates a Hub which can be used to query the db

func (*Datapoint) Find

func (d *Datapoint) Find(query interface{}) (datapoints []Datapoint, err error)

func (*Datapoint) Remove

func (d *Datapoint) Remove(ID string) error

Remove removes d from the database

func (*Datapoint) Save

func (d *Datapoint) Save() (info *mgo.ChangeInfo, err error)

Save saves d to the database

type Hub

type Hub struct {
	ID        bson.ObjectId   `json:"id" bson:"_id"`
	Name      string          `json:"name" bson:"name"`
	Serial    string          `json:"serialNumber" bson:"serial"`
	SensorIDS []bson.ObjectId `json:"-" bson:"sensors"`
	Sensors   []Sensor        `json:"sensors,omitempty" bson:"-"` // do not store directly in db
	Room      Room            `json:"room,omitempty" bson:"-"`
	// contains filtered or unexported fields
}

func HubModel

func HubModel(db *mgo.Database) *Hub

HubModel creates a Hub which can be used to query the db

func (*Hub) Find

func (h *Hub) Find() (hubs []Hub, err error)

Find finds a list of hubs

func (*Hub) FindByID

func (h *Hub) FindByID(ID string) (hub Hub, err error)

func (*Hub) GetRoom

func (h *Hub) GetRoom() (room Room, err error)

func (*Hub) GetSensors

func (h *Hub) GetSensors() (sensors []Sensor, err error)

Sensors retrieves the associated sensors from this h

func (*Hub) MarshalJSON

func (h *Hub) MarshalJSON() ([]byte, error)

func (*Hub) Remove

func (h *Hub) Remove(ID string) error

Remove removes h from the database

func (*Hub) Save

func (h *Hub) Save() (info *mgo.ChangeInfo, err error)

Save saves h to the database

func (*Hub) Status

func (h *Hub) Status() string

Status checks if hub retrieved data from sensors in the last 15 min and write the status: 'online', 'offline' or 'needs attention'

type Model

type Model struct {
	ID bson.ObjectId `json:"id" bson:"_id"`
	// contains filtered or unexported fields
}

type OccupationSensor

type OccupationSensor struct {
	InSensorDatapoints  []*Datapoint
	OutSensorDatapoints []*Datapoint
	TotalEntrances      int
	TotalExits          int
	CurrentOccupants    int
}

func (*OccupationSensor) CalculateCurrentOccupants

func (o *OccupationSensor) CalculateCurrentOccupants()

func (*OccupationSensor) CalculateEntrances

func (o *OccupationSensor) CalculateEntrances() int

func (*OccupationSensor) CalculateExits

func (o *OccupationSensor) CalculateExits() int

type Room

type Room struct {
	ID          bson.ObjectId `json:"id" bson:"_id"`
	Name        string        `json:"name" bson:"name"`
	Size        float32       `json:"size" bson:"size"`
	MaxCapacity int           `json:"maxCapacity" bson:"maxCapacity"`
	Occupation  int           `json:"occupation" bson:"occupation"`
	// Hubs        []Hub           `json:"hubs" bson:"-"`
	HubIDs     []bson.ObjectId `json:"-" bson:"hubs,omitempty"`
	BuildingID bson.ObjectId   `json:"building" bson:"building,omitempty"`

	RoomLogs    []RoomLog    `json:"logs" bson:"-"`
	RoomRosters []RoomRoster `json:"roster" bson:"-"`
	// contains filtered or unexported fields
}

func NewRoomModel

func NewRoomModel(db *mgo.Database) *Room

func (*Room) Find added in v0.3.0

func (r *Room) Find(buildingID string) (rooms []Room, err error)

func (*Room) FindId

func (r *Room) FindId(ID bson.ObjectId) (room *Room, err error)

func (*Room) Save

func (r *Room) Save() (room *Room, err error)

Save saves room to the DB

type RoomLog

type RoomLog struct {
	ID         bson.ObjectId `json:"id" bson:"_id"`
	RoomID     bson.ObjectId `json:"-" bson:"room"`
	Occupation int           `json:"occupation" bson:"occupation"`
	Timestamp  time.Time     `json:"time" bson:"timestamp"`
}

type RoomRoster added in v0.2.0

type RoomRoster struct {
	ID           bson.ObjectId `json:"id" bson:"_id"`
	RoomID       bson.ObjectId `json:"-" bson:"room"`
	PersonAmount int           `json:"amount" bson:"person_amount"`
	From         time.Time     `json:"from" bson:"from"`
	Till         time.Time     `json:"till" bson:"till"`
}

type Sensor

type Sensor struct {
	ID           bson.ObjectId `json:"id,omitempty" bson:"_id,omitempty"`
	Name         string        `json:"name,omitempty" bson:"name"`
	SensorType   string        `json:"sensorType,omitempty" bson:"sensorType"`
	Status       bool          `json:"status,omitempty" bson:"status"`
	UUID         int           `json:"UUID,omitempty" bson:"UUID"`
	Gpio_trigger int           `json:"gpio_trigger,omitempty" bson:"gpio_trigger"`
	Gpio_echo    int           `json:"gpio_echo,omitempty" bson:"gpio_echo"`
	Datapoints   []Datapoint   `json:"datapoints,omitempty" bson:"datapoints"`
	HubID        bson.ObjectId `json:"-" bson:"hub"`
	// contains filtered or unexported fields
}

type SensorJSON

type SensorJSON struct {
	Sensor
	Hub *Hub `json:"hub"`
}

SensorJSON is a wrapper to expose the relation with hub

Jump to

Keyboard shortcuts

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