108 lines
3.5 KiB
Go
108 lines
3.5 KiB
Go
package controllers
|
|
|
|
import (
|
|
"github.com/astaxie/beego"
|
|
|
|
"git.kingpenguin.tk/chteufleur/datahouse.git/models/variables"
|
|
"git.kingpenguin.tk/chteufleur/datahouse.git/models/teleinfo"
|
|
|
|
"html/template"
|
|
"strconv"
|
|
)
|
|
|
|
//——————————————————————————————————————————————————————————————————————————————
|
|
// AddTeleinfoController
|
|
//——————————————————————————————————————————————————————————————————————————————
|
|
type AddTeleinfoController struct {
|
|
beego.Controller
|
|
}
|
|
|
|
func (c *AddTeleinfoController) Prepare() {
|
|
c.Data["version"] = variables.Version
|
|
}
|
|
|
|
func (c *AddTeleinfoController) Get() {
|
|
adresse := c.GetString(teleinfo.AdresseCompteur)
|
|
tarif := c.GetString(teleinfo.OptionTarifaire)
|
|
option := c.GetString(teleinfo.OptionBase)
|
|
hp, _ := c.GetInt(teleinfo.HeurePleinne)
|
|
hc, _ := c.GetInt(teleinfo.HeureCreuse)
|
|
|
|
teleinfo.AddData(adresse, tarif, option, int64(hp), int64(hc))
|
|
|
|
cpt := teleinfo.GetCompteurByAdresse(adresse)
|
|
if cpt == nil || cpt.Id == 0 {
|
|
teleinfo.AddCompteur(adresse)
|
|
}
|
|
c.Ctx.Output.Body([]byte(""))
|
|
}
|
|
|
|
|
|
|
|
//——————————————————————————————————————————————————————————————————————————————
|
|
// ViewTeleinfoController
|
|
//——————————————————————————————————————————————————————————————————————————————
|
|
type ViewTeleinfoController struct {
|
|
beego.Controller
|
|
}
|
|
|
|
func (c *ViewTeleinfoController) Prepare() {
|
|
c.Data["IsViewTeleinfo"] = true
|
|
c.Data["version"] = variables.Version
|
|
}
|
|
|
|
func (c *ViewTeleinfoController) Get() {
|
|
c.Data["compteurs"] = teleinfo.GetAllCompteur()
|
|
|
|
adresse := c.Ctx.Input.Param(":compteur")
|
|
cpt := teleinfo.GetCompteurByAdresse(adresse)
|
|
if cpt.Id != 0 {
|
|
c.Data["isCompteurSelected"] = true
|
|
c.Data["dataCompteur"] = teleinfo.GetLastDataForCompteur(cpt.AdresseCompteur)
|
|
c.Data["compteurAdresse"] = cpt.AdresseCompteur
|
|
desc := cpt.Description
|
|
if desc == "" {
|
|
desc = cpt.AdresseCompteur
|
|
}
|
|
c.Data["compteurDescription"] = desc
|
|
dataPower := formatDataSensorTeleInfo(teleinfo.GetAllDataForCompteur(cpt.AdresseCompteur))
|
|
c.Data["dataPower"] = template.JS(dataPower)
|
|
}
|
|
|
|
c.TplName = "teleinfo.tpl"
|
|
}
|
|
|
|
|
|
func formatDataSensorTeleInfo(values []teleinfo.TeleinfoTable) string {
|
|
ret := ""
|
|
for a := 0; a < 2; a++ {
|
|
ret += "{name : \""
|
|
if a == 0 {
|
|
ret += "Heure Pleines"
|
|
} else {
|
|
ret += "Heure Creuses"
|
|
}
|
|
ret += "\",marker : {enabled : true, radius : 3}, data : ["
|
|
for i := 0; i < len(values); i++ {
|
|
if i > 0 {
|
|
ret += ","
|
|
}
|
|
// TODO faire la dérivé de la puissance pour avoir les variations plutot que l'évolution de la puissance
|
|
horodate := strconv.FormatInt((values[i].HorodateGMT.Unix()+int64(timezoneOffset))*1000, 10)
|
|
value := ""
|
|
if a == 0 {
|
|
value = strconv.FormatInt(values[i].HeurePleinne, 10)
|
|
} else {
|
|
value = strconv.FormatInt(values[i].HeureCreuse, 10)
|
|
}
|
|
ret += "[" + horodate + "," + value + "]"
|
|
}
|
|
ret += "]}"
|
|
|
|
if a == 0 {
|
|
ret += ","
|
|
}
|
|
}
|
|
return ret
|
|
}
|