From 029df054c192cea1d0a9f98a8d7013078fcb722d Mon Sep 17 00:00:00 2001 From: David Stark Date: Thu, 5 Dec 2019 14:41:27 +0000 Subject: [PATCH] wip --- data/README.md | 10 ++++ data/main.go | 148 ++++++++++++++++++++++++++++++++++++------------- 2 files changed, 120 insertions(+), 38 deletions(-) create mode 100644 data/README.md diff --git a/data/README.md b/data/README.md new file mode 100644 index 0000000..54595ff --- /dev/null +++ b/data/README.md @@ -0,0 +1,10 @@ + + +Generating a struct to import these: + +See: https://github.com/ChimeraCoder/gojson + +``` +go get -v github.com/ChimeraCoder/gojson/gojson +cat foo.json | gojson +``` diff --git a/data/main.go b/data/main.go index 50db9a1..aafc6f8 100644 --- a/data/main.go +++ b/data/main.go @@ -5,80 +5,152 @@ import ( "fmt" "io/ioutil" "os" + "strconv" + + "github.com/Jeffail/gabs/v2" ) // EveEyeKspace + https://mholt.github.io/json-to-go/ // NOTE.. don't paste the whole json file in here.. just one region or else the tool won't notice gates + type EveEyeKspace struct { Maps []struct { - MapID int `json:"mapID"` - MapName string `json:"mapName"` - Scale float64 `json:"scale"` - Gates []struct { - S int `json:"s,omitempty"` - T int `json:"t,omitempty"` - P int `json:"p,omitempty"` + AvgSec float64 `json:"avgSec"` + Fid int64 `json:"fid"` + Gates []struct { + P int64 `json:"p"` + Q int64 `json:"q"` + S int64 `json:"s"` + T int64 `json:"t"` } `json:"gates"` - Fid int `json:"fid,omitempty"` - AvgSec float64 `json:"avgSec,omitempty"` - MaxSec float64 `json:"maxSec,omitempty"` - MinSec float64 `json:"minSec,omitempty"` - X float64 `json:"x,omitempty"` - Y int `json:"y,omitempty"` + MapID int64 `json:"mapID"` + MapName string `json:"mapName"` + MaxSec float64 `json:"maxSec"` + MinSec float64 `json:"minSec"` + Npc int64 `json:"npc"` + Scale float64 `json:"scale"` Systems []struct { - Sid int `json:"sid"` - Sn string `json:"sn"` - Cid int `json:"cid"` - Cn string `json:"cn"` - Rid int `json:"rid"` - Rn string `json:"rn"` - Sec float64 `json:"sec"` - D float64 `json:"d"` - Pi []int `json:"pi"` - Cel []int `json:"cel"` - Fid int `json:"fid"` - Fw bool `json:"fw"` - X float64 `json:"x"` - Y float64 `json:"y"` - Sta int `json:"sta,omitempty"` - Stasrv []int `json:"stasrv,omitempty"` + Bnode interface{} `json:"bnode"` + Cel []int64 `json:"cel"` + Cfid bool `json:"cfid"` + Cid int64 `json:"cid"` + Cn string `json:"cn"` + D float64 `json:"d"` + Ext []int64 `json:"ext"` + Fid int64 `json:"fid"` + Fw bool `json:"fw"` + Index int64 `json:"index"` + Links []int64 `json:"links"` + Pi []int64 `json:"pi"` + Rid int64 `json:"rid"` + Rn string `json:"rn"` + Sec float64 `json:"sec"` + Sid int64 `json:"sid"` + Sn string `json:"sn"` + Snode int64 `json:"snode"` + Sta int64 `json:"sta"` + Stasrv []int64 `json:"stasrv"` + Tnode string `json:"tnode"` + Vnode int64 `json:"vnode"` + X float64 `json:"x"` + Y float64 `json:"y"` } `json:"systems"` - Npc int `json:"npc,omitempty"` + X float64 `json:"x"` + Y int64 `json:"y"` } `json:"maps"` } +// EveSystemList asd +type EveSystemList struct { + Systems []EveSystem `json:"systems"` +} + +// EveSystem ss +type EveSystem struct { + // Links []string `json:"links"` + Name string `json:"name"` + // Sec float64 `json:"sec"` + Region string `json:"region"` + // SystemID int `json:"sid"` +} + +// we'll record both directions here in-memory +// then add each dest to System struct in a +type Jump struct { + Type string `json:"type"` // gate, bridge + SrcName string `json:"src"` + DstName string `json:"dst"` +} + func main() { // we're gonna read these json files and create something sensible.. jsonFile, err := os.Open("kspace.json") if err != nil { fmt.Println(err) } - defer jsonFile.Close() byteValue, _ := ioutil.ReadAll(jsonFile) var OrigKspace EveEyeKspace json.Unmarshal(byteValue, &OrigKspace) - for _, data := range OrigKspace.Maps { + // jsonObjJumps := gabs.New() + jsonObjSystems := gabs.New() + for _, data := range OrigKspace.Maps { Region := data.MapName if Region == "Delve" { - fmt.Printf("######################## \n#### %v\n", Region) + // fmt.Printf("######################## \n#### %v\n", Region) for _, system := range data.Systems { SystemName := system.Sn SystemID := system.Sid - fmt.Printf("[%v]: (%v) %v\n", Region, SystemID, SystemName) + // SystemSec := system.Sec + // fmt.Println(SystemName) + + fmt.Printf("[%v]: (%v) %v -> ", Region, SystemID, SystemName) + for _, link := range system.Links { + s := strconv.FormatInt(link, 10) + fmt.Printf(" %v", s) + } + fmt.Printf("\n") + // jsonObjSystems.Set(SystemID, "systems", SystemName, "id") + // jsonObjSystems.Set(SystemSec, "systems", SystemName, "sec") } - for _, gate := range data.Gates { - fmt.Printf("T: %v\n", gate.T) - fmt.Printf("S: %v\n", gate.S) - } + // for _, gate := range data.Gates { + // fmt.Printf("T: %v\n", gate.T) + // fmt.Printf("S: %v\n", gate.S) + // } } } + for _, data := range OrigKspace.Maps { + Region := data.MapName + if Region == "Delve" { + for _, gate := range data.Gates { + jsonObjSystems.Set(gate.S, "jumps", fmt.Sprintf("%v-%v", gate.S, gate.T), "s") + jsonObjSystems.Set(gate.T, "jumps", fmt.Sprintf("%v-%v", gate.S, gate.T), "t") + // jsonObjSystems.Set(gate.T, "jumps", "t") + // fmt.Printf("T: %v\n", gate.T) + // fmt.Printf("S: %v\n", gate.S) + } + } + } + + // for key, child := range jsonObjSystems.S("systems").ChildrenMap() { + // if key == "8RQJ-2" { + // fmt.Printf("value: %v\n", child.Data()) + // fmt.Printf("key: %v\n", key) + // } + // } + + fmt.Println(jsonObjSystems.String()) + err = jsonFile.Close() + if err != nil { + fmt.Printf("error closing file") + } + }