Added planetery constellation and region info, added new caches methods to ease the development
This commit is contained in:
parent
ce7d4e1504
commit
3d9c09785d
1 changed files with 95 additions and 34 deletions
129
main.go
129
main.go
|
@ -338,11 +338,12 @@ func printCharacterPlanets(swaggerclient *ESI.App, m *Character) {
|
||||||
|
|
||||||
planetName := getPlanetInformation(swaggerclient, *planet.PlanetID)
|
planetName := getPlanetInformation(swaggerclient, *planet.PlanetID)
|
||||||
|
|
||||||
fmt.Printf("Planet %s, %s - %s, level %d with %d structures - Updated %s\n",
|
fmt.Printf("Planet %s, %s, %s - Type %s, Lvl %d - Updated %s\n",
|
||||||
planetName.PlanetName,
|
planetName.PlanetName,
|
||||||
solarSystemInfo.SolarSystemName,
|
solarSystemInfo.ConstellationName,
|
||||||
|
solarSystemInfo.RegionName,
|
||||||
*planet.PlanetType,
|
*planet.PlanetType,
|
||||||
*planet.UpgradeLevel, *planet.NumPins,
|
*planet.UpgradeLevel,
|
||||||
time.Time(*planet.LastUpdate).Format(defaultDateFormat),
|
time.Time(*planet.LastUpdate).Format(defaultDateFormat),
|
||||||
)
|
)
|
||||||
|
|
||||||
|
@ -375,7 +376,7 @@ func printCharacterPlanets(swaggerclient *ESI.App, m *Character) {
|
||||||
duration = time.Time(pin.ExpiryTime).Sub(now)
|
duration = time.Time(pin.ExpiryTime).Sub(now)
|
||||||
}
|
}
|
||||||
|
|
||||||
fmt.Printf(" %s Extractor % 4ds cycle, %s, %d per cycle, %s %s (%s)\n",
|
fmt.Printf(" %s Extractor % 5ds cycle, %s, %d per cycle, %s %s (%s)\n",
|
||||||
status,
|
status,
|
||||||
*pin.ExtractorDetails.CycleTime,
|
*pin.ExtractorDetails.CycleTime,
|
||||||
pinNames[*pin.ExtractorDetails.ProductTypeID],
|
pinNames[*pin.ExtractorDetails.ProductTypeID],
|
||||||
|
@ -392,7 +393,7 @@ func printCharacterPlanets(swaggerclient *ESI.App, m *Character) {
|
||||||
log.Printf("Error on getSchematicsInformation: %T, %s\n", serr, serr)
|
log.Printf("Error on getSchematicsInformation: %T, %s\n", serr, serr)
|
||||||
fmt.Printf(" ✔ Factory ????? cycle, ?????\n")
|
fmt.Printf(" ✔ Factory ????? cycle, ?????\n")
|
||||||
} else {
|
} else {
|
||||||
fmt.Printf(" ✔ Factory % 4ds cycle, %s\n",
|
fmt.Printf(" ✔ Factory % 5ds cycle, %s\n",
|
||||||
schematicInfo.CycleTime,
|
schematicInfo.CycleTime,
|
||||||
schematicInfo.SchematicName,
|
schematicInfo.SchematicName,
|
||||||
)
|
)
|
||||||
|
@ -407,7 +408,7 @@ func getUniverseNames(swaggerclient *ESI.App, itemIds *[]int32) map[int32]string
|
||||||
itemMissingNames := make(map[int32]string)
|
itemMissingNames := make(map[int32]string)
|
||||||
|
|
||||||
for _, itemID := range *itemIds {
|
for _, itemID := range *itemIds {
|
||||||
itemName := getCachedData(fmt.Sprintf("%d.name", itemID))
|
itemName := getCachedDataSub(itemID, "name")
|
||||||
if itemName != "" {
|
if itemName != "" {
|
||||||
itemNames[itemID] = itemName
|
itemNames[itemID] = itemName
|
||||||
} else {
|
} else {
|
||||||
|
@ -433,7 +434,7 @@ func getUniverseNames(swaggerclient *ESI.App, itemIds *[]int32) map[int32]string
|
||||||
itemName := searchResult.Name
|
itemName := searchResult.Name
|
||||||
itemID := searchResult.ID
|
itemID := searchResult.ID
|
||||||
|
|
||||||
putCacheData(fmt.Sprintf("%d.name", *itemID), *itemName)
|
putCacheDataSub(*itemID, "name", *itemName)
|
||||||
|
|
||||||
itemNames[*itemID] = *itemName
|
itemNames[*itemID] = *itemName
|
||||||
}
|
}
|
||||||
|
@ -450,8 +451,8 @@ type planetInformation struct {
|
||||||
|
|
||||||
func getPlanetInformation(swaggerclient *ESI.App, planetID int32) planetInformation {
|
func getPlanetInformation(swaggerclient *ESI.App, planetID int32) planetInformation {
|
||||||
|
|
||||||
planetName := getCachedData(fmt.Sprintf("%d.name", planetID))
|
planetName := getCachedDataSub(planetID, "name")
|
||||||
planetType := getCachedData(fmt.Sprintf("%d.type", planetID))
|
planetType := getCachedDataIntSub(planetID, "type")
|
||||||
|
|
||||||
if planetName == "" {
|
if planetName == "" {
|
||||||
pcallParams := ESIUniverse.NewGetUniversePlanetsPlanetIDParams()
|
pcallParams := ESIUniverse.NewGetUniversePlanetsPlanetIDParams()
|
||||||
|
@ -465,49 +466,82 @@ func getPlanetInformation(swaggerclient *ESI.App, planetID int32) planetInformat
|
||||||
planetInfo.PlanetName = *planetESIInfo.Name
|
planetInfo.PlanetName = *planetESIInfo.Name
|
||||||
planetInfo.PlanetTypeID = *planetESIInfo.TypeID
|
planetInfo.PlanetTypeID = *planetESIInfo.TypeID
|
||||||
|
|
||||||
putCacheData(fmt.Sprintf("%d.name", planetID), planetInfo.PlanetName)
|
putCacheDataSub(planetID, "name", planetInfo.PlanetName)
|
||||||
putCacheData(fmt.Sprintf("%d.type", planetID), fmt.Sprintf("%d.name", planetInfo.PlanetTypeID))
|
putCacheDataIntSub(planetID, "type", planetInfo.PlanetTypeID)
|
||||||
|
|
||||||
return planetInfo
|
return planetInfo
|
||||||
}
|
}
|
||||||
|
|
||||||
pPlanetType, _ := strconv.ParseInt(planetType, 10, 32)
|
|
||||||
|
|
||||||
var planetInfo planetInformation
|
var planetInfo planetInformation
|
||||||
planetInfo.PlanetName = planetName
|
planetInfo.PlanetName = planetName
|
||||||
planetInfo.PlanetTypeID = int32(pPlanetType)
|
planetInfo.PlanetTypeID = planetType
|
||||||
|
|
||||||
return planetInfo
|
return planetInfo
|
||||||
}
|
}
|
||||||
|
|
||||||
// SolarSystemInfo - Structure to store and cache the Solar System information from ESI
|
type solarSystemInfo struct {
|
||||||
type SolarSystemInfo struct {
|
SolarSystemName string
|
||||||
SolarSystemName string
|
ConstellationID int32
|
||||||
|
ConstellationName string
|
||||||
|
RegionID int32
|
||||||
|
RegionName string
|
||||||
}
|
}
|
||||||
|
|
||||||
func getSolarSystemInformation(swaggerclient *ESI.App, solarSystemID int32) SolarSystemInfo {
|
func getSolarSystemInformation(swaggerclient *ESI.App, solarSystemID int32) solarSystemInfo {
|
||||||
|
|
||||||
systemName := getCachedData(fmt.Sprintf("%d.name", solarSystemID))
|
systemName := getCachedDataSub(solarSystemID, "name")
|
||||||
|
systemConstellationID := getCachedDataIntSub(solarSystemID, "constellation")
|
||||||
|
constellationName := getCachedDataSub(systemConstellationID, "name")
|
||||||
|
constellationRegionID := getCachedDataIntSub(systemConstellationID, "region")
|
||||||
|
regionName := getCachedDataSub(constellationRegionID, "name")
|
||||||
|
|
||||||
if systemName == "" {
|
if systemName == "" || constellationName == "" || regionName == "" {
|
||||||
scallParams := ESIUniverse.NewGetUniverseSystemsSystemIDParams()
|
scallParams := ESIUniverse.NewGetUniverseSystemsSystemIDParams()
|
||||||
scallParams.WithSystemID(solarSystemID)
|
scallParams.WithSystemID(solarSystemID)
|
||||||
|
|
||||||
sesiresponse, _ := swaggerclient.Universe.GetUniverseSystemsSystemID(scallParams)
|
sesiresponse, _ := swaggerclient.Universe.GetUniverseSystemsSystemID(scallParams)
|
||||||
|
|
||||||
solarSystemESIInfo := sesiresponse.Payload
|
solarSystemESIInfo := sesiresponse.Payload
|
||||||
|
|
||||||
var solarSystemInfo SolarSystemInfo
|
var ssInfo solarSystemInfo
|
||||||
solarSystemInfo.SolarSystemName = *solarSystemESIInfo.Name
|
ssInfo.SolarSystemName = *solarSystemESIInfo.Name
|
||||||
|
ssInfo.ConstellationID = *solarSystemESIInfo.ConstellationID
|
||||||
|
|
||||||
putCacheData(fmt.Sprintf("%d.name", solarSystemID), solarSystemInfo.SolarSystemName)
|
ccallParams := ESIUniverse.NewGetUniverseConstellationsConstellationIDParams()
|
||||||
|
ccallParams.WithConstellationID(ssInfo.ConstellationID)
|
||||||
|
|
||||||
return solarSystemInfo
|
cesiresponse, _ := swaggerclient.Universe.GetUniverseConstellationsConstellationID(ccallParams)
|
||||||
|
constellationESIInfo := cesiresponse.Payload
|
||||||
|
|
||||||
|
ssInfo.ConstellationName = *constellationESIInfo.Name
|
||||||
|
ssInfo.RegionID = *constellationESIInfo.RegionID
|
||||||
|
|
||||||
|
rcallParams := ESIUniverse.NewGetUniverseRegionsRegionIDParams()
|
||||||
|
rcallParams.WithRegionID(ssInfo.RegionID)
|
||||||
|
|
||||||
|
resiresponse, _ := swaggerclient.Universe.GetUniverseRegionsRegionID(rcallParams)
|
||||||
|
regionESIInfo := resiresponse.Payload
|
||||||
|
|
||||||
|
ssInfo.RegionName = *regionESIInfo.Name
|
||||||
|
|
||||||
|
putCacheDataSub(solarSystemID, "name", ssInfo.SolarSystemName)
|
||||||
|
putCacheDataIntSub(solarSystemID, "constellation", ssInfo.ConstellationID)
|
||||||
|
|
||||||
|
putCacheDataSub(ssInfo.ConstellationID, "name", ssInfo.ConstellationName)
|
||||||
|
putCacheDataIntSub(ssInfo.ConstellationID, "region", ssInfo.RegionID)
|
||||||
|
|
||||||
|
putCacheDataSub(ssInfo.RegionID, "name", ssInfo.RegionName)
|
||||||
|
|
||||||
|
return ssInfo
|
||||||
}
|
}
|
||||||
|
|
||||||
var solarSystemInfo SolarSystemInfo
|
var ssInfo solarSystemInfo
|
||||||
solarSystemInfo.SolarSystemName = systemName
|
|
||||||
return solarSystemInfo
|
ssInfo.SolarSystemName = systemName
|
||||||
|
ssInfo.ConstellationID = systemConstellationID
|
||||||
|
ssInfo.ConstellationName = constellationName
|
||||||
|
ssInfo.RegionID = constellationRegionID
|
||||||
|
ssInfo.RegionName = regionName
|
||||||
|
return ssInfo
|
||||||
}
|
}
|
||||||
|
|
||||||
// SchematicInfo - Structure to store and cache the schematics information from ESI
|
// SchematicInfo - Structure to store and cache the schematics information from ESI
|
||||||
|
@ -518,8 +552,8 @@ type SchematicInfo struct {
|
||||||
|
|
||||||
func getSchematicsInformation(swaggerclient *ESI.App, schematicID int32) (*SchematicInfo, error) {
|
func getSchematicsInformation(swaggerclient *ESI.App, schematicID int32) (*SchematicInfo, error) {
|
||||||
|
|
||||||
schematicName := getCachedData(fmt.Sprintf("%d.name", schematicID))
|
schematicName := getCachedDataSub(schematicID, "name")
|
||||||
schematicCycle := getCachedData(fmt.Sprintf("%d.cycle", schematicID))
|
schematicCycle := getCachedDataIntSub(schematicID, "cycle")
|
||||||
|
|
||||||
if schematicName == "" {
|
if schematicName == "" {
|
||||||
scallParams := ESIPlanetaryInteraction.NewGetUniverseSchematicsSchematicIDParams()
|
scallParams := ESIPlanetaryInteraction.NewGetUniverseSchematicsSchematicIDParams()
|
||||||
|
@ -536,16 +570,16 @@ func getSchematicsInformation(swaggerclient *ESI.App, schematicID int32) (*Schem
|
||||||
schematicInfo.CycleTime = *schematicsESIInfo.CycleTime
|
schematicInfo.CycleTime = *schematicsESIInfo.CycleTime
|
||||||
schematicInfo.SchematicName = *schematicsESIInfo.SchematicName
|
schematicInfo.SchematicName = *schematicsESIInfo.SchematicName
|
||||||
|
|
||||||
putCacheData(fmt.Sprintf("%d.name", schematicID), schematicInfo.SchematicName)
|
putCacheDataSub(schematicID, "name", schematicInfo.SchematicName)
|
||||||
putCacheData(fmt.Sprintf("%d.cycle", schematicID), fmt.Sprintf("%d", schematicInfo.CycleTime))
|
putCacheDataIntSub(schematicID, "cycle", schematicInfo.CycleTime)
|
||||||
|
|
||||||
return &schematicInfo, nil
|
return &schematicInfo, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
var schematicInfo SchematicInfo
|
var schematicInfo SchematicInfo
|
||||||
pCycleTime, _ := strconv.ParseInt(schematicCycle, 10, 32)
|
schematicInfo.CycleTime = schematicCycle
|
||||||
schematicInfo.CycleTime = int32(pCycleTime)
|
|
||||||
schematicInfo.SchematicName = schematicName
|
schematicInfo.SchematicName = schematicName
|
||||||
|
|
||||||
return &schematicInfo, nil
|
return &schematicInfo, nil
|
||||||
|
|
||||||
}
|
}
|
||||||
|
@ -616,6 +650,25 @@ func handleAuthenticationCallback(w http.ResponseWriter, r *http.Request) {
|
||||||
messages <- token
|
messages <- token
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func getCachedDataIntSub(key int32, subkey string) int32 {
|
||||||
|
return getCachedDataInt(fmt.Sprintf("%d.%s", key, subkey))
|
||||||
|
}
|
||||||
|
|
||||||
|
func getCachedDataSub(key int32, subkey string) string {
|
||||||
|
return getCachedData(fmt.Sprintf("%d.%s", key, subkey))
|
||||||
|
}
|
||||||
|
|
||||||
|
func getCachedDataInt(key string) int32 {
|
||||||
|
strVal := getCachedData(key)
|
||||||
|
|
||||||
|
intVal, convErr := strconv.ParseInt(strVal, 10, 32)
|
||||||
|
if convErr != nil {
|
||||||
|
return -1
|
||||||
|
}
|
||||||
|
|
||||||
|
return int32(intVal)
|
||||||
|
}
|
||||||
|
|
||||||
func getCachedData(key string) string {
|
func getCachedData(key string) string {
|
||||||
db, err := sql.Open("sqlite3", *cacheDBPath)
|
db, err := sql.Open("sqlite3", *cacheDBPath)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
|
@ -645,6 +698,14 @@ func getCachedData(key string) string {
|
||||||
return response
|
return response
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func putCacheDataIntSub(key int32, subkey string, value int32) {
|
||||||
|
putCacheDataSub(key, subkey, fmt.Sprintf("%d", value))
|
||||||
|
}
|
||||||
|
|
||||||
|
func putCacheDataSub(key int32, subkey string, value string) {
|
||||||
|
putCacheData(fmt.Sprintf("%d.%s", key, subkey), value)
|
||||||
|
}
|
||||||
|
|
||||||
func putCacheData(key string, value string) {
|
func putCacheData(key string, value string) {
|
||||||
db, err := sql.Open("sqlite3", *cacheDBPath)
|
db, err := sql.Open("sqlite3", *cacheDBPath)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
|
|
Reference in a new issue