Added planetery constellation and region info, added new caches methods to ease the development

This commit is contained in:
Thomas Schwery 2017-02-17 09:57:01 +01:00
parent ce7d4e1504
commit 3d9c09785d

129
main.go
View file

@ -338,11 +338,12 @@ func printCharacterPlanets(swaggerclient *ESI.App, m *Character) {
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,
solarSystemInfo.SolarSystemName,
solarSystemInfo.ConstellationName,
solarSystemInfo.RegionName,
*planet.PlanetType,
*planet.UpgradeLevel, *planet.NumPins,
*planet.UpgradeLevel,
time.Time(*planet.LastUpdate).Format(defaultDateFormat),
)
@ -375,7 +376,7 @@ func printCharacterPlanets(swaggerclient *ESI.App, m *Character) {
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,
*pin.ExtractorDetails.CycleTime,
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)
fmt.Printf(" ✔ Factory ????? cycle, ?????\n")
} else {
fmt.Printf(" ✔ Factory % 4ds cycle, %s\n",
fmt.Printf(" ✔ Factory % 5ds cycle, %s\n",
schematicInfo.CycleTime,
schematicInfo.SchematicName,
)
@ -407,7 +408,7 @@ func getUniverseNames(swaggerclient *ESI.App, itemIds *[]int32) map[int32]string
itemMissingNames := make(map[int32]string)
for _, itemID := range *itemIds {
itemName := getCachedData(fmt.Sprintf("%d.name", itemID))
itemName := getCachedDataSub(itemID, "name")
if itemName != "" {
itemNames[itemID] = itemName
} else {
@ -433,7 +434,7 @@ func getUniverseNames(swaggerclient *ESI.App, itemIds *[]int32) map[int32]string
itemName := searchResult.Name
itemID := searchResult.ID
putCacheData(fmt.Sprintf("%d.name", *itemID), *itemName)
putCacheDataSub(*itemID, "name", *itemName)
itemNames[*itemID] = *itemName
}
@ -450,8 +451,8 @@ type planetInformation struct {
func getPlanetInformation(swaggerclient *ESI.App, planetID int32) planetInformation {
planetName := getCachedData(fmt.Sprintf("%d.name", planetID))
planetType := getCachedData(fmt.Sprintf("%d.type", planetID))
planetName := getCachedDataSub(planetID, "name")
planetType := getCachedDataIntSub(planetID, "type")
if planetName == "" {
pcallParams := ESIUniverse.NewGetUniversePlanetsPlanetIDParams()
@ -465,49 +466,82 @@ func getPlanetInformation(swaggerclient *ESI.App, planetID int32) planetInformat
planetInfo.PlanetName = *planetESIInfo.Name
planetInfo.PlanetTypeID = *planetESIInfo.TypeID
putCacheData(fmt.Sprintf("%d.name", planetID), planetInfo.PlanetName)
putCacheData(fmt.Sprintf("%d.type", planetID), fmt.Sprintf("%d.name", planetInfo.PlanetTypeID))
putCacheDataSub(planetID, "name", planetInfo.PlanetName)
putCacheDataIntSub(planetID, "type", planetInfo.PlanetTypeID)
return planetInfo
}
pPlanetType, _ := strconv.ParseInt(planetType, 10, 32)
var planetInfo planetInformation
planetInfo.PlanetName = planetName
planetInfo.PlanetTypeID = int32(pPlanetType)
planetInfo.PlanetTypeID = planetType
return planetInfo
}
// SolarSystemInfo - Structure to store and cache the Solar System information from ESI
type SolarSystemInfo struct {
SolarSystemName string
type solarSystemInfo struct {
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.WithSystemID(solarSystemID)
sesiresponse, _ := swaggerclient.Universe.GetUniverseSystemsSystemID(scallParams)
solarSystemESIInfo := sesiresponse.Payload
var solarSystemInfo SolarSystemInfo
solarSystemInfo.SolarSystemName = *solarSystemESIInfo.Name
var ssInfo solarSystemInfo
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
solarSystemInfo.SolarSystemName = systemName
return solarSystemInfo
var ssInfo 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
@ -518,8 +552,8 @@ type SchematicInfo struct {
func getSchematicsInformation(swaggerclient *ESI.App, schematicID int32) (*SchematicInfo, error) {
schematicName := getCachedData(fmt.Sprintf("%d.name", schematicID))
schematicCycle := getCachedData(fmt.Sprintf("%d.cycle", schematicID))
schematicName := getCachedDataSub(schematicID, "name")
schematicCycle := getCachedDataIntSub(schematicID, "cycle")
if schematicName == "" {
scallParams := ESIPlanetaryInteraction.NewGetUniverseSchematicsSchematicIDParams()
@ -536,16 +570,16 @@ func getSchematicsInformation(swaggerclient *ESI.App, schematicID int32) (*Schem
schematicInfo.CycleTime = *schematicsESIInfo.CycleTime
schematicInfo.SchematicName = *schematicsESIInfo.SchematicName
putCacheData(fmt.Sprintf("%d.name", schematicID), schematicInfo.SchematicName)
putCacheData(fmt.Sprintf("%d.cycle", schematicID), fmt.Sprintf("%d", schematicInfo.CycleTime))
putCacheDataSub(schematicID, "name", schematicInfo.SchematicName)
putCacheDataIntSub(schematicID, "cycle", schematicInfo.CycleTime)
return &schematicInfo, nil
}
var schematicInfo SchematicInfo
pCycleTime, _ := strconv.ParseInt(schematicCycle, 10, 32)
schematicInfo.CycleTime = int32(pCycleTime)
schematicInfo.CycleTime = schematicCycle
schematicInfo.SchematicName = schematicName
return &schematicInfo, nil
}
@ -616,6 +650,25 @@ func handleAuthenticationCallback(w http.ResponseWriter, r *http.Request) {
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 {
db, err := sql.Open("sqlite3", *cacheDBPath)
if err != nil {
@ -645,6 +698,14 @@ func getCachedData(key string) string {
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) {
db, err := sql.Open("sqlite3", *cacheDBPath)
if err != nil {