2019-05-17 09:11:07 +03:00
|
|
|
package travelnetparser
|
|
|
|
|
|
|
|
import (
|
|
|
|
"errors"
|
|
|
|
"fmt"
|
|
|
|
"mapserver/luaparser"
|
2023-01-20 20:04:27 +03:00
|
|
|
"os"
|
2019-05-17 09:11:07 +03:00
|
|
|
)
|
|
|
|
|
|
|
|
type GenericPos struct {
|
|
|
|
X int `json:"x"`
|
|
|
|
Y int `json:"y"`
|
|
|
|
Z int `json:"z"`
|
|
|
|
}
|
|
|
|
|
|
|
|
type Travelnet struct {
|
|
|
|
Timestamp int64 `json:"timestamp"`
|
|
|
|
Pos *GenericPos `json:"pos"`
|
|
|
|
}
|
|
|
|
|
|
|
|
func ParseFile(filename string) (map[string]map[string]map[string]*Travelnet, error) {
|
2023-01-20 20:04:27 +03:00
|
|
|
content, err := os.ReadFile(filename)
|
2019-05-17 09:11:07 +03:00
|
|
|
if err != nil {
|
|
|
|
return nil, err
|
|
|
|
}
|
|
|
|
|
|
|
|
return Parse(content)
|
|
|
|
}
|
|
|
|
|
|
|
|
// owner -> network -> name ->Travelnet-Data
|
|
|
|
func Parse(data []byte) (map[string]map[string]map[string]*Travelnet, error) {
|
|
|
|
p := luaparser.New()
|
|
|
|
travelnets := make(map[string]map[string]map[string]*Travelnet)
|
|
|
|
|
|
|
|
ownermap, err := p.ParseMap(string(data[:]))
|
|
|
|
|
|
|
|
if err != nil {
|
|
|
|
return nil, err
|
|
|
|
}
|
|
|
|
|
|
|
|
for owner, rawnetworkmap := range ownermap {
|
|
|
|
fmt.Println(owner)
|
|
|
|
|
|
|
|
networkmap, ok := rawnetworkmap.(map[string]interface{})
|
|
|
|
if !ok {
|
|
|
|
return nil, errors.New("networkmap parsing failed")
|
|
|
|
}
|
|
|
|
|
|
|
|
for network, rawstationmap := range networkmap {
|
|
|
|
fmt.Println("+", network)
|
|
|
|
|
|
|
|
stationmap, ok := rawstationmap.(map[string]interface{})
|
|
|
|
if !ok {
|
|
|
|
return nil, errors.New("stationmap parsing failed")
|
|
|
|
}
|
|
|
|
|
|
|
|
for station, rawentries := range stationmap {
|
|
|
|
fmt.Println("++", station)
|
|
|
|
|
|
|
|
entries, ok := rawentries.(map[string]interface{})
|
|
|
|
if !ok {
|
|
|
|
return nil, errors.New("entries parsing failed")
|
|
|
|
}
|
|
|
|
|
|
|
|
for entry := range entries {
|
|
|
|
fmt.Println("+++", entry)
|
|
|
|
//TODO:
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return travelnets, nil
|
|
|
|
}
|