From 295d564951525612be44b8c4862ede6a5bf6b1c9 Mon Sep 17 00:00:00 2001
From: chteufleur
Date: Fri, 16 Dec 2016 20:21:17 +0100
Subject: [PATCH] Modification of teleinfo to match base option.
---
controllers/teleinfo.go | 52 ++++++++--------------
models/teleinfo/teleinfo.go | 82 +++++++++++++++++++----------------
models/variables/variables.go | 2 +-
views/teleinfo.tpl | 9 ++--
4 files changed, 66 insertions(+), 79 deletions(-)
diff --git a/controllers/teleinfo.go b/controllers/teleinfo.go
index e23a9ca..9e60f5a 100644
--- a/controllers/teleinfo.go
+++ b/controllers/teleinfo.go
@@ -3,8 +3,8 @@ package controllers
import (
"github.com/astaxie/beego"
+ "git.kingpenguin.tk/chteufleur/datahouse.git/models/teleinfo"
"git.kingpenguin.tk/chteufleur/datahouse.git/models/variables"
- "git.kingpenguin.tk/chteufleur/datahouse.git/models/teleinfo"
"html/template"
"strconv"
@@ -22,13 +22,15 @@ func (c *AddTeleinfoController) Prepare() {
}
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)
+ adresse := c.GetString(teleinfo.AdresseCompteur)
+ tarif := c.GetString(teleinfo.OptionTarifaire)
+ option, _ := c.GetInt(teleinfo.OptionBase)
+ isousc, _ := c.GetInt(teleinfo.IntensiteSouscrite)
+ iinst, _ := c.GetInt(teleinfo.IntensiteInstantanne)
+ imax, _ := c.GetInt(teleinfo.IntensiteMax)
+ papp, _ := c.GetInt(teleinfo.PuissanceApparente)
- teleinfo.AddData(adresse, tarif, option, int64(hp), int64(hc))
+ teleinfo.AddData(adresse, tarif, int64(option), int64(isousc), int64(iinst), int64(imax), int64(papp))
cpt := teleinfo.GetCompteurByAdresse(adresse)
if cpt == nil || cpt.Id == 0 {
@@ -37,8 +39,6 @@ func (c *AddTeleinfoController) Get() {
c.Ctx.Output.Body([]byte(""))
}
-
-
//——————————————————————————————————————————————————————————————————————————————
// ViewTeleinfoController
//——————————————————————————————————————————————————————————————————————————————
@@ -72,36 +72,18 @@ func (c *ViewTeleinfoController) Get() {
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 += "{name : \"Puissance apparente (VA)\",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 := strconv.FormatInt(values[i].PuissanceApparente, 10)
+ ret += "[" + horodate + "," + value + "]"
}
+ ret += "]}"
return ret
}
diff --git a/models/teleinfo/teleinfo.go b/models/teleinfo/teleinfo.go
index c7d7d1c..3dc3d09 100644
--- a/models/teleinfo/teleinfo.go
+++ b/models/teleinfo/teleinfo.go
@@ -8,20 +8,22 @@ import (
"git.kingpenguin.tk/chteufleur/datahouse.git/models/utils"
"git.kingpenguin.tk/chteufleur/datahouse.git/models/variables"
- "time"
+ "time"
)
const (
- AdresseCompteur = "ADCO"
- OptionTarifaire = "OPTARIF"
- OptionBase = "BASE" // Wh
- HeurePleinne = "HCHP" // Wh
- HeureCreuse = "HCHC" // Wh
+ AdresseCompteur = "ADCO"
+ OptionTarifaire = "OPTARIF"
+ OptionBase = "BASE" // Wh
+ IntensiteSouscrite = "ISOUSC" // A
+ IntensiteInstantanne = "IINST" // A
+ IntensiteMax = "IMAX" // A
+ PuissanceApparente = "PAPP" // VA
)
var (
_, timezoneOffset = time.Now().Zone()
- log = logs.NewLogger(10000)
+ log = logs.NewLogger(10000)
optionTarifaireTranslate = make(map[string]string)
)
@@ -36,34 +38,35 @@ func init() {
optionTarifaireTranslate["EJP."] = "EJP"
}
-
-
//——————————————————————————————————————————————————————————————————————————————
// TeleinfoTable
//——————————————————————————————————————————————————————————————————————————————
type TeleinfoTable struct {
- Id int64
- HorodateGMT time.Time `orm:"auto_now;type(datetime)"`
- AdresseCompteur string
- OptionTarifaire string
- OptionBase string
- HeurePleinne int64
- HeureCreuse int64
+ Id int64
+ HorodateGMT time.Time `orm:"auto_now;type(datetime)"`
+ AdresseCompteur string
+ OptionTarifaire string
+ OptionBase int64
+ IntensiteSouscrite int64
+ IntensiteInstantanne int64
+ IntensiteMax int64
+ PuissanceApparente int64
}
-
-func AddData(adresse, tarif, option string, hp, hc int64) {
- log.Info("Add teleinfo {adresse: %s, tarif: %s, option: %s, hp: %d, hc: %d}", adresse, tarif, option, hp, hc)
+func AddData(adresse, tarif string, base, isousc, iinst, imax, papp int64) {
+ log.Info("Add teleinfo {adresse: %s, tarif: %s, base: %s Wh, isousc: %d A, iinst: %d A, imax: %d A, ppap: %d VA}", adresse, tarif, base, isousc, iinst, imax, papp)
o := orm.NewOrm()
o.Using(database.Alias)
- ti := new(TeleinfoTable)
- ti.AdresseCompteur = adresse
- ti.OptionTarifaire = tarif
- ti.OptionBase = option
- ti.HeurePleinne = hp
- ti.HeureCreuse = hc
- o.Insert(ti)
+ ti := new(TeleinfoTable)
+ ti.AdresseCompteur = adresse
+ ti.OptionTarifaire = tarif
+ ti.OptionBase = base
+ ti.IntensiteSouscrite = isousc
+ ti.IntensiteInstantanne = iinst
+ ti.IntensiteMax = imax
+ ti.PuissanceApparente = papp
+ o.Insert(ti)
}
func GetAllDataForCompteur(adresseCompteur string) []TeleinfoTable {
@@ -81,10 +84,13 @@ func GetAllDataForCompteur(adresseCompteur string) []TeleinfoTable {
d.AdresseCompteur = utils.GetString(m, "AdresseCompteur")
d.OptionTarifaire = optionTarifaireTranslate[utils.GetString(m, "OptionTarifaire")]
- d.OptionBase = utils.GetString(m, "OptionBase")
+ d.OptionBase = utils.GetInt(m, "OptionBase")
- d.HeurePleinne = utils.GetInt(m, "HeurePleinne")
- d.HeureCreuse = utils.GetInt(m, "HeureCreuse")
+ d.IntensiteSouscrite = utils.GetInt(m, "IntensiteSouscrite")
+ d.IntensiteInstantanne = utils.GetInt(m, "IntensiteInstantanne")
+ d.IntensiteMax = utils.GetInt(m, "IntensiteMax")
+
+ d.PuissanceApparente = utils.GetInt(m, "PuissanceApparente")
dataArray = append(dataArray, *d)
}
@@ -106,10 +112,13 @@ func GetLastDataForCompteur(adresseCompteur string) *TeleinfoTable {
data.AdresseCompteur = utils.GetString(m, "AdresseCompteur")
data.OptionTarifaire = optionTarifaireTranslate[utils.GetString(m, "OptionTarifaire")]
- data.OptionBase = utils.GetString(m, "OptionBase")
+ data.OptionBase = utils.GetInt(m, "OptionBase")
- data.HeurePleinne = utils.GetInt(m, "HeurePleinne")
- data.HeureCreuse = utils.GetInt(m, "HeureCreuse")
+ data.IntensiteSouscrite = utils.GetInt(m, "IntensiteSouscrite")
+ data.IntensiteInstantanne = utils.GetInt(m, "IntensiteInstantanne")
+ data.IntensiteMax = utils.GetInt(m, "IntensiteMax")
+
+ data.PuissanceApparente = utils.GetInt(m, "PuissanceApparente")
}
}
return data
@@ -121,15 +130,13 @@ func DeleteDataCompteur(adresseCompteur string) {
o.Delete(&TeleinfoTable{AdresseCompteur: adresseCompteur})
}
-
-
//——————————————————————————————————————————————————————————————————————————————
// CompteurTeleinfoTable
//——————————————————————————————————————————————————————————————————————————————
type CompteurTeleinfoTable struct {
- Id int64
- AdresseCompteur string
- Description string
+ Id int64
+ AdresseCompteur string
+ Description string
}
func GetCompteurByAdresse(adresse string) *CompteurTeleinfoTable {
@@ -190,7 +197,6 @@ func GetSensor(id int64) *CompteurTeleinfoTable {
o := orm.NewOrm()
o.Using(database.Alias)
-
var ret = new(CompteurTeleinfoTable)
var maps []orm.Params
_, err := o.QueryTable(new(CompteurTeleinfoTable)).Filter("Id", id).Values(&maps)
diff --git a/models/variables/variables.go b/models/variables/variables.go
index 46588ca..b9d8e27 100644
--- a/models/variables/variables.go
+++ b/models/variables/variables.go
@@ -1,7 +1,7 @@
package variables
const (
- Version = "0.1.2"
+ Version = "0.1.4"
SessionName = "Session_Data_House"
diff --git a/views/teleinfo.tpl b/views/teleinfo.tpl
index 1caf0db..0f6ea67 100644
--- a/views/teleinfo.tpl
+++ b/views/teleinfo.tpl
@@ -138,11 +138,10 @@
{{.compteurDescription}}
- N° Compteur: {{.dataCompteur.AdresseCompteur}}
- Option tarifaire: {{.dataCompteur.OptionTarifaire}}
- Option base: {{.dataCompteur.OptionBase}}
- Heure pleine: {{.dataCompteur.HeurePleinne}} Wh
- Heure creuse: {{.dataCompteur.HeureCreuse}} Wh
+ N° Compteur : {{.dataCompteur.AdresseCompteur}}
+ Option tarifaire : {{.dataCompteur.OptionTarifaire}}
+ Option base : {{.dataCompteur.OptionBase}} Wh
+ Intensité souscrite : {{.dataCompteur.IntensiteSouscrite}} A