51 lines
832 B
Go
51 lines
832 B
Go
package controllers
|
|
|
|
import (
|
|
"github.com/astaxie/beego"
|
|
|
|
"datahouse/models/sensor"
|
|
"datahouse/models/temperature"
|
|
|
|
"strconv"
|
|
)
|
|
|
|
type SensorPrint struct {
|
|
Name string
|
|
Value string
|
|
Unit string
|
|
Horodate string
|
|
}
|
|
|
|
type MainController struct {
|
|
beego.Controller
|
|
}
|
|
|
|
func (c *MainController) Get() {
|
|
c.Data["sensors"] = getLastTemps()
|
|
c.TplNames = "index.tpl"
|
|
}
|
|
|
|
|
|
func getLastTemps() ([]SensorPrint) {
|
|
sensors := sensor.GetAllSensor()
|
|
var values []SensorPrint
|
|
for _, s := range sensors {
|
|
sens := new(SensorPrint)
|
|
|
|
sens.Name = s.Description
|
|
if sens.Name == "" {
|
|
sens.Name = s.SensorMAC
|
|
}
|
|
|
|
t := temperature.GetLastTempForSensor(s.Id)
|
|
sens.Value = strconv.FormatInt(t.Value, 10)
|
|
sens.Unit = "°C"
|
|
|
|
sens.Horodate = t.HorodateGMT.Format("04h05")
|
|
|
|
values = append(values, *sens)
|
|
}
|
|
|
|
return values
|
|
}
|