Add more data about frequency
All checks were successful
continuous-integration/drone/push Build is passing

This commit is contained in:
nemunaire 2022-12-04 11:20:32 +01:00
parent bf1512cf0a
commit 0ec424c224
2 changed files with 51 additions and 12 deletions

View File

@ -12,6 +12,19 @@ import (
const SwissGridAPI = "https://www.swissgrid.ch/bin/services/apicache?path=/content/swissgrid/fr/home/operation/grid-data/current-data/jcr:content/parsys/livedatawidget_10292"
var (
LastFreqPlan = 50.0
GridTz *time.Location
)
func init() {
var err error
GridTz, err = time.LoadLocation("Europe/Zurich")
if err != nil {
panic(err)
}
}
type SwissGridItem struct {
Id string `json:"id"`
Label string `json:"label"`
@ -67,30 +80,53 @@ func FetchFrequency() (*SwissGridData, error) {
}
func WriteFrequency(writer TICWriter, freq *SwissGridData) error {
points := map[string]Point{}
horodate := time.Now()
for _, i := range freq.Data.Table {
if i.Id == "FreqAct" {
if i.Id == "FreqPlan" {
f, err := strconv.ParseFloat(strings.Fields(i.Value)[0], 64)
if err != nil {
return err
}
point := Point{
if LastFreqPlan != f {
points["FREQPLAN"] = Point{
Data: []byte(fmt.Sprintf("%.0f", f*1000)),
}
LastFreqPlan = f
}
} else if i.Id == "FreqAct" {
f, err := strconv.ParseFloat(strings.Fields(i.Value)[0], 64)
if err != nil {
return err
}
points["FREQ"] = Point{
Data: []byte(fmt.Sprintf("%.0f", f*1000)),
}
err = writer.AddPoints(
map[string]Point{
"FREQ": point,
},
time.Now(),
)
} else if i.Id == "GridTimeDev" {
f, err := strconv.ParseFloat(strings.Fields(i.Value)[0], 64)
if err != nil {
log.Println("Unable to write frequency point:", err)
return err
}
break
points["GRIDTIMEDEV"] = Point{
Data: []byte(fmt.Sprintf("%.0f", f*1000)),
}
} else if i.Id == "SampleTimestamp" {
var err error
horodate, err = time.ParseInLocation("02.01.2006 15:04:05", i.Value, GridTz)
if err != nil {
return err
}
}
}
err := writer.AddPoints(points, horodate)
if err != nil {
log.Println("Unable to write frequency point:", err)
}
return nil
}

View File

@ -51,7 +51,10 @@ var (
}
MeasurementUnits = map[string]string{
"FREQ": "mHz",
"FREQ": "mHz",
"FREQPLAN": "mHz",
"GRIDTIMEDEV": "ms",
"EAST": "Wh",
"EASF01": "Wh",
"EASF02": "Wh",