Nuke all storage computation

Doesn't fucking work
This commit is contained in:
2025-10-11 11:05:06 +02:00
parent 77287c6361
commit a36ce8ff78
4 changed files with 229 additions and 200 deletions

View File

@@ -6,7 +6,6 @@ import (
"fmt"
"time"
"go-eve-pi/constants"
"go-eve-pi/esi"
logger "git.site.quack-lab.dev/dave/cylogger"
@@ -28,169 +27,176 @@ type StorageInfo struct {
// GetExtractorsForCharacter retrieves extractor information for a character
func GetExtractorsForCharacter(esiClient esi.ESIInterface, characterID int, accessToken string, planetIDs []int64) ([]ExtractorInfo, error) {
logger.Info("GetExtractorsForCharacter: Starting for character ID %d", characterID)
funclog := logger.Default.WithPrefix("GetExtractorsForCharacter").WithPrefix(fmt.Sprintf("characterID=%d", characterID))
funclog.Info("Starting")
logger.Info("GetExtractorsForCharacter: Found %d planets for character %d", len(planetIDs), characterID)
funclog.Info("Found %d planets", len(planetIDs))
var extractors []ExtractorInfo
for i, planetID := range planetIDs {
logger.Info("GetExtractorsForCharacter: Processing planet %d/%d (ID: %d)", i+1, len(planetIDs), planetID)
planetlog := funclog.WithPrefix(fmt.Sprintf("planetID=%d", planetID))
planetlog.Info("Processing planet %d/%d", i+1, len(planetIDs))
// Get planet details
details, err := esiClient.GetPlanetPI(context.Background(), characterID, planetID, accessToken)
if err != nil {
logger.Warning("GetExtractorsForCharacter: Failed to fetch details for planet %d: %v", planetID, err)
planetlog.Warning("Failed to fetch details: %v", err)
continue
}
logger.Info("GetExtractorsForCharacter: Got planet details for planet %d with %d pins", planetID, len(details.Pins))
if details == nil {
planetlog.Warning("Planet details are nil")
continue
}
if details.Pins == nil {
planetlog.Warning("Planet details have no pins")
continue
}
planetlog.Info("Got planet details with %d pins", len(details.Pins))
if details != nil {
// Get planet name from universe endpoint
planetNameData, err := esiClient.GetPlanetName(context.Background(), planetID)
if err != nil {
logger.Error("GetExtractorsForCharacter: Failed to get planet name for planet ID %d: %v", planetID, err)
// Get planet name from universe endpoint
planetNameData, err := esiClient.GetPlanetName(context.Background(), planetID)
if err != nil {
planetlog.Error("Failed to get planet name: %v", err)
continue
}
planetlog.Info("Planet name: %s", planetNameData.Name)
// Count extractors and get expiry dates
extractorCount := 0
for j, pin := range details.Pins {
pinlog := planetlog.WithPrefix(fmt.Sprintf("pinID=%d", pin.PinID)).WithPrefix(fmt.Sprintf("pinTypeID=%d", pin.TypeID))
pinlog.Info("Processing pin %d/%d", j+1, len(details.Pins))
if pin.ExpiryTime == nil {
pinlog.Info("Pin %d has no expiry time", j+1)
continue
}
logger.Info("GetExtractorsForCharacter: Planet %d name: %s", planetID, planetNameData.Name)
// Count extractors and get expiry dates
extractorCount := 0
// for j, pin := range details.Pins {
// logger.Info("GetExtractorsForCharacter: Processing pin %d/%d (TypeID: %d) on planet %s", j+1, len(details.Pins), pin.TypeID, planetNameData.Name)
// if pin.ExtractorDetails != nil {
// logger.Info("GetExtractorsForCharacter: Found extractor (TypeID: %d) on planet %s", pin.TypeID, planetNameData.Name)
// extractorCount++
// expiryDate := "N/A"
// if pin.ExpiryTime != nil {
// expiryDate = *pin.ExpiryTime
// logger.Info("GetExtractorsForCharacter: Extractor expiry: %s", expiryDate)
// } else {
// logger.Info("GetExtractorsForCharacter: Extractor has no expiry time")
// }
// extractors = append(extractors, ExtractorInfo{
// PlanetName: planetNameData.Name,
// ExtractorNumber: extractorCount,
// ExpiryDate: expiryDate,
// })
// logger.Info("GetExtractorsForCharacter: Added extractor %d to results", extractorCount)
// } else {
// logger.Info("GetExtractorsForCharacter: Pin %d is not an extractor (TypeID: %d)", j+1, pin.TypeID)
// }
// }
logger.Info("GetExtractorsForCharacter: Found %d extractors on planet %s", extractorCount, planetNameData.Name)
pinlog.Info("Pin has expiry time: %s", pin.ExpiryTime.Format(time.RFC3339))
expiryDate := pin.ExpiryTime.Format(time.RFC3339)
pinlog.Info("Expiry date: %s", expiryDate)
extractors = append(extractors, ExtractorInfo{
PlanetName: planetNameData.Name,
ExtractorNumber: extractorCount,
ExpiryDate: expiryDate,
})
extractorCount++
pinlog.Info("Added extractor %d to results", extractorCount)
}
planetlog.Info("Found %d extractors", extractorCount)
}
logger.Info("GetExtractorsForCharacter: Returning %d total extractors for character %d", len(extractors), characterID)
funclog.Info("Returning %d total extractors", len(extractors))
return extractors, nil
}
// GetStorageForCharacter retrieves storage information for a character
func GetStorageForCharacter(esiClient esi.ESIInterface, characterID int, accessToken string) ([]StorageInfo, error) {
logger.Info("GetStorageForCharacter: Starting for character ID %d", characterID)
// func GetStorageForCharacter(esiClient esi.ESIInterface, characterID int, accessToken string) ([]StorageInfo, error) {
// funclog := logger.Default.WithPrefix("GetStorageForCharacter").WithPrefix(fmt.Sprintf("characterID=%d", characterID))
// funclog.Info("Starting")
// Get character planets
planets, err := esiClient.GetCharacterPlanets(context.Background(), characterID, accessToken)
if err != nil {
logger.Error("GetStorageForCharacter: Failed to get planets for character %d: %v", characterID, err)
return nil, err
}
logger.Info("GetStorageForCharacter: Found %d planets for character %d", len(planets), characterID)
// // Get character planets
// planets, err := esiClient.GetCharacterPlanets(context.Background(), characterID, accessToken)
// if err != nil {
// funclog.Error("Failed to get planets: %v", err)
// return nil, err
// }
// funclog.Info("Found %d planets", len(planets))
var storage []StorageInfo
// var storage []StorageInfo
for i, planet := range planets {
logger.Info("GetStorageForCharacter: Processing planet %d/%d (ID: %d)", i+1, len(planets), planet.PlanetID)
// for i, planet := range planets {
// planetlog := funclog.WithPrefix(fmt.Sprintf("planetID=%d", planet.PlanetID))
// planetlog.Info("Processing planet %d/%d", i+1, len(planets))
// Get planet details
details, err := esiClient.GetPlanetPI(context.Background(), characterID, planet.PlanetID, accessToken)
if err != nil {
logger.Warning("GetStorageForCharacter: Failed to fetch details for planet %d: %v", planet.PlanetID, err)
continue
}
logger.Info("GetStorageForCharacter: Got planet details for planet %d with %d pins", planet.PlanetID, len(details.Pins))
// // Get planet details
// details, err := esiClient.GetPlanetPI(context.Background(), characterID, planet.PlanetID, accessToken)
// if err != nil {
// planetlog.Warning("Failed to fetch details: %v", err)
// continue
// }
// planetlog.Info("Got planet details with %d pins", len(details.Pins))
// if details == nil {
// planetlog.Warning("Planet details are nil")
// continue
// }
if details != nil {
// Get planet name from universe endpoint
planetNameData, err := esiClient.GetPlanetName(context.Background(), planet.PlanetID)
if err != nil {
logger.Error("GetStorageForCharacter: Failed to get planet name for planet ID %d: %v", planet.PlanetID, err)
continue
}
logger.Info("GetStorageForCharacter: Planet %d name: %s", planet.PlanetID, planetNameData.Name)
// // Get planet name from universe endpoint
// planetNameData, err := esiClient.GetPlanetName(context.Background(), planet.PlanetID)
// if err != nil {
// planetlog.Error("Failed to get planet name: %v", err)
// continue
// }
// planetlog = planetlog.WithPrefix(fmt.Sprintf("planetName=%s", planetNameData.Name))
// planetlog.Info("Planet name: %s", planetNameData.Name)
// Analyze storage utilization
storageCount := 0
for j, pin := range details.Pins {
logger.Info("GetStorageForCharacter: Processing pin %d/%d (TypeID: %d) on planet %s", j+1, len(details.Pins), pin.TypeID, planetNameData.Name)
// // Analyze storage utilization
// storageCount := 0
// for j, pin := range details.Pins {
// planetlog.Info("Processing pin %d/%d (TypeID: %d) on planet %s", j+1, len(details.Pins), pin.TypeID, planetNameData.Name)
// Check if this pin is actually a storage facility
_, isStorage := constants.StorageCapacities[pin.TypeID]
if !isStorage {
logger.Info("GetStorageForCharacter: Pin %d is not a storage facility (TypeID: %d), skipping", j+1, pin.TypeID)
continue
}
logger.Info("GetStorageForCharacter: Pin %d is a storage facility (TypeID: %d)", j+1, pin.TypeID)
// // Check if this pin is actually a storage facility
// _, isStorage := constants.StorageCapacities[pin.TypeID]
// if !isStorage {
// planetlog.Info("Pin %d is not a storage facility (TypeID: %d), skipping", j+1, pin.TypeID)
// continue
// }
// planetlog.Info("Pin %d is a storage facility (TypeID: %d)", j+1, pin.TypeID)
storageType, exists := constants.PITypesMap[pin.TypeID]
if !exists {
logger.Error("GetStorageForCharacter: 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)
}
logger.Info("GetStorageForCharacter: Storage type: %s", storageType)
// storageType, exists := constants.PITypesMap[pin.TypeID]
// if !exists {
// planetlog.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)
// }
// planetlog.Info("Storage type: %s", storageType)
totalVolume := 0.0
logger.Info("GetStorageForCharacter: Processing %d contents for storage facility %s", len(pin.Contents), storageType)
for k, content := range pin.Contents {
logger.Info("GetStorageForCharacter: Processing content %d/%d (TypeID: %d, Amount: %d)", k+1, len(pin.Contents), content.TypeID, content.Amount)
// totalVolume := 0.0
// planetlog.Info("Processing %d contents for storage facility %s", len(pin.Contents), storageType)
// for k, content := range pin.Contents {
// planetlog.Info("Processing content %d/%d (TypeID: %d, Amount: %d)", k+1, len(pin.Contents), content.TypeID, content.Amount)
volume, exists := constants.PIProductVolumes[content.TypeID]
if !exists {
logger.Error("GetStorageForCharacter: 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)
}
itemVolume := float64(content.Amount) * volume
totalVolume += itemVolume
logger.Info("GetStorageForCharacter: Content TypeID %d: Amount %d, Volume %f, ItemVolume %f", content.TypeID, content.Amount, volume, itemVolume)
}
// volume, exists := constants.PIProductVolumes[content.TypeID]
// if !exists {
// planetlog.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)
// }
// itemVolume := float64(content.Amount) * volume
// totalVolume += itemVolume
// planetlog.Info("Content TypeID %d: Amount %d, Volume %f, ItemVolume %f", content.TypeID, content.Amount, volume, itemVolume)
// }
storageCapacity := constants.StorageCapacities[pin.TypeID]
utilization := (totalVolume / float64(storageCapacity)) * 100.0
logger.Info("GetStorageForCharacter: Storage calculation: %s on %s - TotalVolume: %f, Capacity: %d, Utilization: %f%%", storageType, planetNameData.Name, totalVolume, storageCapacity, utilization)
// storageCapacity := constants.StorageCapacities[pin.TypeID]
// utilization := (totalVolume / float64(storageCapacity)) * 100.0
// planetlog.Info("Storage calculation: %s on %s - TotalVolume: %f, Capacity: %d, Utilization: %f%%", storageType, planetNameData.Name, totalVolume, storageCapacity, utilization)
storage = append(storage, StorageInfo{
PlanetName: planetNameData.Name,
StorageType: storageType,
Utilization: utilization,
})
storageCount++
logger.Info("GetStorageForCharacter: Added storage facility %d to results", storageCount)
}
logger.Info("GetStorageForCharacter: Found %d storage facilities on planet %s", storageCount, planetNameData.Name)
}
}
// storage = append(storage, StorageInfo{
// PlanetName: planetNameData.Name,
// StorageType: storageType,
// Utilization: utilization,
// })
// storageCount++
// planetlog.Info("Added storage facility %d to results", storageCount)
// }
// planetlog.Info("Found %d storage facilities on planet %s", storageCount, planetNameData.Name)
// }
logger.Info("GetStorageForCharacter: Returning %d total storage facilities for character %d", len(storage), characterID)
return storage, nil
}
// funclog.Info("Returning %d total storage facilities", len(storage))
// return storage, nil
// }
// CheckStorageThresholds checks storage utilization against thresholds
func CheckStorageThresholds(storage []StorageInfo, warningThreshold, criticalThreshold float64) []StorageInfo {
var alerts []StorageInfo
// func CheckStorageThresholds(storage []StorageInfo, warningThreshold, criticalThreshold float64) []StorageInfo {
// var alerts []StorageInfo
for _, s := range storage {
if s.Utilization >= criticalThreshold {
alerts = append(alerts, s)
} else if s.Utilization >= warningThreshold {
alerts = append(alerts, s)
}
}
// for _, s := range storage {
// if s.Utilization >= criticalThreshold {
// alerts = append(alerts, s)
// } else if s.Utilization >= warningThreshold {
// alerts = append(alerts, s)
// }
// }
return alerts
}
// return alerts
// }
// CheckExtractorExpiry checks extractor expiry against thresholds
func CheckExtractorExpiry(extractors []ExtractorInfo, warningDuration, criticalDuration time.Duration) []ExtractorInfo {
@@ -202,9 +208,9 @@ func CheckExtractorExpiry(extractors []ExtractorInfo, warningDuration, criticalD
continue
}
expiryTime, err := time.Parse("2006-01-02 15:04:05", e.ExpiryDate)
expiryTime, err := time.Parse(time.RFC3339, e.ExpiryDate)
if err != nil {
logger.Warning("Failed to parse expiry date %s: %v", e.ExpiryDate, err)
logger.Warning("Failed to parse expiry date in ISO 8601 (RFC3339) format %s: %v", e.ExpiryDate, err)
continue
}
@@ -220,15 +226,15 @@ func CheckExtractorExpiry(extractors []ExtractorInfo, warningDuration, criticalD
}
// FormatStorageAlert formats a storage alert message
func FormatStorageAlert(storage StorageInfo, isCritical bool) string {
severity := "WARNING"
if isCritical {
severity = "CRITICAL"
}
// func FormatStorageAlert(storage StorageInfo, isCritical bool) string {
// severity := "WARNING"
// if isCritical {
// severity = "CRITICAL"
// }
return fmt.Sprintf("%s: %s almost full on %s (%.1f%% utilized)",
severity, storage.StorageType, storage.PlanetName, storage.Utilization)
}
// return fmt.Sprintf("%s: %s almost full on %s (%.1f%% utilized)",
// severity, storage.StorageType, storage.PlanetName, storage.Utilization)
// }
// FormatExtractorAlert formats an extractor alert message
func FormatExtractorAlert(extractor ExtractorInfo, isCritical bool) string {