This commit is contained in:
2019-12-06 13:36:08 +00:00
parent d3a62fe249
commit 3fd31ffb27
+103 -75
View File
@@ -5,9 +5,6 @@ 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/
@@ -18,10 +15,10 @@ type EveEyeKspace struct {
AvgSec float64 `json:"avgSec"` AvgSec float64 `json:"avgSec"`
Fid int64 `json:"fid"` Fid int64 `json:"fid"`
Gates []struct { Gates []struct {
P int64 `json:"p"` P int `json:"p"`
Q int64 `json:"q"` Q int `json:"q"`
S int64 `json:"s"` S int `json:"s"`
T int64 `json:"t"` T int `json:"t"`
} `json:"gates"` } `json:"gates"`
MapID int64 `json:"mapID"` MapID int64 `json:"mapID"`
MapName string `json:"mapName"` MapName string `json:"mapName"`
@@ -40,12 +37,12 @@ type EveEyeKspace struct {
Fid int64 `json:"fid"` Fid int64 `json:"fid"`
Fw bool `json:"fw"` Fw bool `json:"fw"`
Index int64 `json:"index"` Index int64 `json:"index"`
Links []int64 `json:"links"` Links []int `json:"links"`
Pi []int64 `json:"pi"` Pi []int64 `json:"pi"`
Rid int64 `json:"rid"` Rid int64 `json:"rid"`
Rn string `json:"rn"` Rn string `json:"rn"`
Sec float64 `json:"sec"` Sec float64 `json:"sec"`
Sid int64 `json:"sid"` Sid int `json:"sid"`
Sn string `json:"sn"` Sn string `json:"sn"`
Snode int64 `json:"snode"` Snode int64 `json:"snode"`
Sta int64 `json:"sta"` Sta int64 `json:"sta"`
@@ -60,26 +57,27 @@ type EveEyeKspace struct {
} `json:"maps"` } `json:"maps"`
} }
// EveSystemList asd // // EveSystemList asd
type EveSystemList struct { // type EveSystemList struct {
Systems []EveSystem `json:"systems"` // Systems []EveSystem `json:"systems"`
} // }
// EveSystem ss // EveSystem ss
type EveSystem struct { type EveSystem struct {
// Links []string `json:"links"` Constellation string `json:"constellation"`
Name string `json:"name"` Links []string `json:"links"`
Name string `json:"name"`
// Sec float64 `json:"sec"` // Sec float64 `json:"sec"`
Region string `json:"region"` Region string `json:"region"`
// SystemID int `json:"sid"` SystemID int `json:"sid"`
} }
// we'll record both directions here in-memory // we'll record both directions here in-memory
// then add each dest to System struct in a // then add each dest to System struct in a
type Jump struct { type Jump struct {
Type string `json:"type"` // gate, bridge Type string `json:"type"` // gate, bridge
SrcName string `json:"src"` Source string `json:"source"`
DstName string `json:"dst"` Target string `json:"target"`
} }
func main() { func main() {
@@ -95,19 +93,69 @@ func main() {
json.Unmarshal(byteValue, &OrigKspace) json.Unmarshal(byteValue, &OrigKspace)
// jsonObjJumps := gabs.New() // jsonObjJumps := gabs.New()
jsonObjSystems := gabs.New() // jsonObjSystems := gabs.New()
for _, data := range OrigKspace.Maps { List := CreateSystemList(OrigKspace)
// Region := data.MapName
FauxRegion := data.MapName
// if FauxRegion == "Delve" {
// fmt.Printf("######################## \n#### %v\n", Region) // 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 _, system := range data.Systems { // fmt.Println(jsonObjSystems.String())
err = jsonFile.Close()
if err != nil {
fmt.Printf("error closing file")
}
for _, data := range List {
fmt.Printf("[%v/%v] (%v) %v\n", data.Region, data.Name, data.Constellation, data.SystemID)
}
foo := SidToName(30004764, List)
fmt.Println(foo)
}
// SidToName returns the system name from a SystemID
func SidToName(in int, List []EveSystem) string {
// if the input number is not one of the 3000XXXX ones, we assume its a shorter one.. add 30,000,000
// This way the function will work for (EG) "30004764" or 4764
if in < 10000 {
in = in + 30000000
}
fmt.Println("in", in)
answer := ""
for _, data := range List {
if in == data.SystemID {
// fmt.Printf("%v matched to %v\n", in, data.Name)
answer = data.Name
// fmt.Printf(len(data.SystemID))
}
}
return answer
}
// CreateSystemList creates a slice of EveSystem's
func CreateSystemList(input EveEyeKspace) []EveSystem {
// FauxRegion := data.MapName
List := []EveSystem{}
for _, input := range input.Maps {
FauxRegion := input.MapName
for _, system := range input.Systems {
// TODO: learning.. this chained if sucks.. find correct pattern and learn/use it // TODO: learning.. this chained if sucks.. find correct pattern and learn/use it
// filter only for systems in the regional area of the data/map // filter only for systems in the regional area of the data/map
Region := system.Rn Region := system.Rn
if Region == FauxRegion { if Region == FauxRegion {
@@ -118,60 +166,40 @@ func main() {
// and this.. whatever it is // and this.. whatever it is
if Region != "UUA-F4" { if Region != "UUA-F4" {
SystemName := system.Sn if Region == "Delve" {
SystemID := system.Sid
Constellation := system.Cn
// SystemSec := system.Sec
// fmt.Println(SystemName)
fmt.Printf("[%v/%v]: (%v) %v -> ", Region, Constellation, SystemID, SystemName) SystemName := system.Sn
for _, link := range system.Links { SystemID := system.Sid
s := strconv.FormatInt(link, 10) Constellation := system.Cn
fmt.Printf(" %v", s) // SystemSec := system.Sec
// fmt.Println(SystemName)
// fmt.Printf("[%v/%v]: (%v) %v -> ", Region, Constellation, SystemID, SystemName)
// for _, link := range system.Links {
// // s := strconv.FormatInt(link, 10) // convert int64 into string
// // linkID := fmt.Sprint(link)
// linkName := SidToName(link, List)
// fmt.Printf(" %v", linkName)
// }
fmt.Printf("\n")
d := EveSystem{
Constellation: Constellation,
Name: SystemName,
Region: Region,
SystemID: SystemID,
}
List = append(List, d)
// jsonObjSystems.Set(SystemID, "systems", SystemName, "id")
// jsonObjSystems.Set(SystemSec, "systems", SystemName, "sec")
} }
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 _, 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")
} }
return List
} }