package main import ( "encoding/xml" "strconv" "time" ) // FortopFormat .. type FortopFormat struct { XMLName xml.Name `xml:"Trafo-Details"` Trafo struct { TrafoNummer int `xml:"trafonummer"` Meter []Meter `xml:"meter"` } `xml:"trafo"` } // Meter contains all data from one specific meter type Meter struct { MeterID string `xml:"meter-id"` StartDate UnixTimestamp `xml:"startdate"` EndDate UnixTimestamp `xml:"enddate"` Meetwaarde []Meetwaarde `xml:"meetwaarde"` } // 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