Fix storage utilization computing
This commit is contained in:
@@ -6,6 +6,7 @@ import (
|
||||
"fmt"
|
||||
"time"
|
||||
|
||||
"go-eve-pi/constants"
|
||||
"go-eve-pi/esi"
|
||||
|
||||
logger "git.site.quack-lab.dev/dave/cylogger"
|
||||
@@ -108,34 +109,37 @@ func GetStorageForCharacter(esiClient esi.ESIInterface, characterID int, accessT
|
||||
|
||||
// Analyze storage utilization
|
||||
for _, pin := range details.Pins {
|
||||
if len(pin.Contents) > 0 {
|
||||
// Calculate utilization based on contents
|
||||
totalAmount := 0
|
||||
for _, content := range pin.Contents {
|
||||
totalAmount += content.Amount
|
||||
}
|
||||
|
||||
// Determine storage type based on pin type
|
||||
storageType := "Unknown"
|
||||
switch pin.TypeID {
|
||||
case 2254, 2255, 2256: // Launch pads
|
||||
storageType = "Launch Pad"
|
||||
case 2524, 2525, 2526: // Storage facilities
|
||||
storageType = "Storage"
|
||||
}
|
||||
|
||||
// Calculate utilization percentage (assuming max capacity of 10000)
|
||||
utilization := float64(totalAmount) / 10000.0 * 100.0
|
||||
if utilization > 100.0 {
|
||||
utilization = 100.0
|
||||
}
|
||||
|
||||
storage = append(storage, StorageInfo{
|
||||
PlanetName: planetNameData.Name,
|
||||
StorageType: storageType,
|
||||
Utilization: utilization,
|
||||
})
|
||||
// Check if this pin is actually a storage facility
|
||||
_, isStorage := constants.StorageCapacities[pin.TypeID]
|
||||
if !isStorage {
|
||||
// Skip non-storage facilities (like industry facilities)
|
||||
continue
|
||||
}
|
||||
|
||||
totalVolume := 0.0
|
||||
for _, content := range pin.Contents {
|
||||
volume, exists := constants.PIProductVolumes[content.TypeID]
|
||||
if !exists {
|
||||
logger.Error("Missing product volume data for type ID %d - cannot calculate storage utilization", content.TypeID)
|
||||
return nil, fmt.Errorf("missing product volume data for type ID %d", content.TypeID)
|
||||
}
|
||||
totalVolume += float64(content.Amount) * volume
|
||||
}
|
||||
|
||||
storageType, exists := constants.PI_TYPES_MAP[pin.TypeID]
|
||||
if !exists {
|
||||
logger.Error("Unknown storage type ID %d for planet %s - this should not happen", pin.TypeID, planetNameData.Name)
|
||||
return nil, fmt.Errorf("unknown storage type ID %d", pin.TypeID)
|
||||
}
|
||||
|
||||
storageCapacity := constants.StorageCapacities[pin.TypeID]
|
||||
utilization := (totalVolume / float64(storageCapacity)) * 100.0
|
||||
|
||||
storage = append(storage, StorageInfo{
|
||||
PlanetName: planetNameData.Name,
|
||||
StorageType: storageType,
|
||||
Utilization: utilization,
|
||||
})
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user