57 lines
1.2 KiB
Go
57 lines
1.2 KiB
Go
|
package main
|
||
|
|
||
|
import (
|
||
|
"encoding/xml"
|
||
|
"strconv"
|
||
|
"time"
|
||
|
)
|
||
|
|
||
|
// FortopFormat ..
|
||
|
type FortopFormat struct {
|
||
|
XMLName xml.Name `xml:"Trafo-Details"`
|
||
|
Trafo struct {
|
||
|
TrafoNummer int `xml:"trafonummer"`
|
||
|
Meter struct {
|
||
|
MeterID int `xml:"meter-id"`
|
||
|
StartDate UnixTimestamp `xml:"startdate"`
|
||
|
EndDate int `xml:"enddate"`
|
||
|
Meetwaarde []Meetwaarde `xml:"meetwaarde"`
|
||
|
} `xml:"meter"`
|
||
|
} `xml:"trafo"`
|
||
|
}
|
||
|
|
||
|
// Meetwaarde contains the data that is not pointless garbage
|
||
|
type Meetwaarde struct {
|
||
|
Naam string `xml:"naam"`
|
||
|
Range []Range `xml:"range"`
|
||
|
}
|
||
|
|
||
|
// Range is a single set of data
|
||
|
type Range struct {
|
||
|
Date UnixTimestamp `xml:"date"`
|
||
|
Value float64 `xml:"value"`
|
||
|
}
|
||
|
|
||
|
// UnixTimestamp is a time.Time that can parse unix timestamps
|
||
|
type UnixTimestamp time.Time
|
||
|
|
||
|
// UnmarshalText implements encoding.TextUnmarshaler
|
||
|
func (t *UnixTimestamp) UnmarshalText(b []byte) error {
|
||
|
i, err := strconv.ParseInt(string(b), 10, 64)
|
||
|
if err != nil {
|
||
|
return err
|
||
|
}
|
||
|
*t = UnixTimestamp(time.Unix(i, 0))
|
||
|
return nil
|
||
|
}
|
||
|
|
||
|
func (t UnixTimestamp) String() string {
|
||
|
return time.Time(t).Format(`2006-01-02 15:04`)
|
||
|
}
|
||
|
|
||
|
// Sets are multiple sets of date
|
||
|
type Sets map[time.Time]Set
|
||
|
|
||
|
// Set is a set of data
|
||
|
type Set map[string]float64
|