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"
"io/ioutil"
"os"
"strconv"
"github.com/Jeffail/gabs/v2"
)
// EveEyeKspace + https://mholt.github.io/json-to-go/
@@ -18,10 +15,10 @@ type EveEyeKspace struct {
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"`
P int `json:"p"`
Q int `json:"q"`
S int `json:"s"`
T int `json:"t"`
} `json:"gates"`
MapID int64 `json:"mapID"`
MapName string `json:"mapName"`
@@ -40,12 +37,12 @@ type EveEyeKspace struct {
Fid int64 `json:"fid"`
Fw bool `json:"fw"`
Index int64 `json:"index"`
Links []int64 `json:"links"`
Links []int `json:"links"`
Pi []int64 `json:"pi"`
Rid int64 `json:"rid"`
Rn string `json:"rn"`
Sec float64 `json:"sec"`
Sid int64 `json:"sid"`
Sid int `json:"sid"`
Sn string `json:"sn"`
Snode int64 `json:"snode"`
Sta int64 `json:"sta"`
@@ -60,26 +57,27 @@ type EveEyeKspace struct {
} `json:"maps"`
}
// EveSystemList asd
type EveSystemList struct {
Systems []EveSystem `json:"systems"`
}
// // EveSystemList asd
// type EveSystemList struct {
// Systems []EveSystem `json:"systems"`
// }
// EveSystem ss
type EveSystem struct {
// Links []string `json:"links"`
Name string `json:"name"`
Constellation string `json:"constellation"`
Links []string `json:"links"`
Name string `json:"name"`
// Sec float64 `json:"sec"`
Region string `json:"region"`
// SystemID int `json:"sid"`
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"`
Type string `json:"type"` // gate, bridge
Source string `json:"source"`
Target string `json:"target"`
}
func main() {
@@ -95,19 +93,69 @@ func main() {
json.Unmarshal(byteValue, &OrigKspace)
// jsonObjJumps := gabs.New()
jsonObjSystems := gabs.New()
// jsonObjSystems := gabs.New()
for _, data := range OrigKspace.Maps {
// Region := data.MapName
FauxRegion := data.MapName
// if FauxRegion == "Delve" {
List := CreateSystemList(OrigKspace)
// 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
// filter only for systems in the regional area of the data/map
Region := system.Rn
if Region == FauxRegion {
@@ -118,60 +166,40 @@ func main() {
// and this.. whatever it is
if Region != "UUA-F4" {
SystemName := system.Sn
SystemID := system.Sid
Constellation := system.Cn
// SystemSec := system.Sec
// fmt.Println(SystemName)
if Region == "Delve" {
fmt.Printf("[%v/%v]: (%v) %v -> ", Region, Constellation, SystemID, SystemName)
for _, link := range system.Links {
s := strconv.FormatInt(link, 10)
fmt.Printf(" %v", s)
SystemName := system.Sn
SystemID := system.Sid
Constellation := system.Cn
// 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
}