This commit is contained in:
2019-12-05 14:41:27 +00:00
parent 9984f0d2ea
commit 029df054c1
2 changed files with 120 additions and 38 deletions
+10
View File
@@ -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
```
+110 -38
View File
@@ -5,80 +5,152 @@ import (
"fmt" "fmt"
"io/ioutil" "io/ioutil"
"os" "os"
"strconv"
"github.com/Jeffail/gabs/v2"
) )
// EveEyeKspace + https://mholt.github.io/json-to-go/ // 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 // NOTE.. don't paste the whole json file in here.. just one region or else the tool won't notice gates
type EveEyeKspace struct { type EveEyeKspace struct {
Maps []struct { Maps []struct {
MapID int `json:"mapID"` AvgSec float64 `json:"avgSec"`
MapName string `json:"mapName"` Fid int64 `json:"fid"`
Scale float64 `json:"scale"` Gates []struct {
Gates []struct { P int64 `json:"p"`
S int `json:"s,omitempty"` Q int64 `json:"q"`
T int `json:"t,omitempty"` S int64 `json:"s"`
P int `json:"p,omitempty"` T int64 `json:"t"`
} `json:"gates"` } `json:"gates"`
Fid int `json:"fid,omitempty"` MapID int64 `json:"mapID"`
AvgSec float64 `json:"avgSec,omitempty"` MapName string `json:"mapName"`
MaxSec float64 `json:"maxSec,omitempty"` MaxSec float64 `json:"maxSec"`
MinSec float64 `json:"minSec,omitempty"` MinSec float64 `json:"minSec"`
X float64 `json:"x,omitempty"` Npc int64 `json:"npc"`
Y int `json:"y,omitempty"` Scale float64 `json:"scale"`
Systems []struct { Systems []struct {
Sid int `json:"sid"` Bnode interface{} `json:"bnode"`
Sn string `json:"sn"` Cel []int64 `json:"cel"`
Cid int `json:"cid"` Cfid bool `json:"cfid"`
Cn string `json:"cn"` Cid int64 `json:"cid"`
Rid int `json:"rid"` Cn string `json:"cn"`
Rn string `json:"rn"` D float64 `json:"d"`
Sec float64 `json:"sec"` Ext []int64 `json:"ext"`
D float64 `json:"d"` Fid int64 `json:"fid"`
Pi []int `json:"pi"` Fw bool `json:"fw"`
Cel []int `json:"cel"` Index int64 `json:"index"`
Fid int `json:"fid"` Links []int64 `json:"links"`
Fw bool `json:"fw"` Pi []int64 `json:"pi"`
X float64 `json:"x"` Rid int64 `json:"rid"`
Y float64 `json:"y"` Rn string `json:"rn"`
Sta int `json:"sta,omitempty"` Sec float64 `json:"sec"`
Stasrv []int `json:"stasrv,omitempty"` 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"` } `json:"systems"`
Npc int `json:"npc,omitempty"` X float64 `json:"x"`
Y int64 `json:"y"`
} `json:"maps"` } `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() { func main() {
// we're gonna read these json files and create something sensible.. // we're gonna read these json files and create something sensible..
jsonFile, err := os.Open("kspace.json") jsonFile, err := os.Open("kspace.json")
if err != nil { if err != nil {
fmt.Println(err) fmt.Println(err)
} }
defer jsonFile.Close()
byteValue, _ := ioutil.ReadAll(jsonFile) byteValue, _ := ioutil.ReadAll(jsonFile)
var OrigKspace EveEyeKspace var OrigKspace EveEyeKspace
json.Unmarshal(byteValue, &OrigKspace) json.Unmarshal(byteValue, &OrigKspace)
for _, data := range OrigKspace.Maps { // jsonObjJumps := gabs.New()
jsonObjSystems := gabs.New()
for _, data := range OrigKspace.Maps {
Region := data.MapName Region := data.MapName
if Region == "Delve" { if Region == "Delve" {
fmt.Printf("######################## \n#### %v\n", Region) // fmt.Printf("######################## \n#### %v\n", Region)
for _, system := range data.Systems { for _, system := range data.Systems {
SystemName := system.Sn SystemName := system.Sn
SystemID := system.Sid 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 { // for _, gate := range data.Gates {
fmt.Printf("T: %v\n", gate.T) // fmt.Printf("T: %v\n", gate.T)
fmt.Printf("S: %v\n", gate.S) // 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")
}
} }