feat(SystemStatistics): add system jumps and kills statistics with toggle functionality

This commit is contained in:
2025-09-14 22:37:00 +02:00
parent 41f7d3157f
commit 8575155f4b
9 changed files with 354 additions and 0 deletions

View File

@@ -95,6 +95,19 @@ type esiCharacterLocationResponse struct {
StructureID int64 `json:"structure_id"`
}
// ESI Statistics data structures
type SystemJumps struct {
SystemID int64 `json:"system_id"`
ShipJumps int64 `json:"ship_jumps"`
}
type SystemKills struct {
SystemID int64 `json:"system_id"`
ShipKills int64 `json:"ship_kills"`
PodKills int64 `json:"pod_kills"`
NpcKills int64 `json:"npc_kills"`
}
func NewESISSO(clientID string, redirectURI string, scopes []string) *ESISSO {
s := &ESISSO{
clientID: clientID,
@@ -177,6 +190,72 @@ func (s *ESISSO) GetCharacterLocations(ctx context.Context) ([]CharacterLocation
return out, nil
}
// GetSystemJumps fetches system jump statistics from ESI
func (s *ESISSO) GetSystemJumps(ctx context.Context) ([]SystemJumps, error) {
fmt.Printf("🚀 ESI API REQUEST: Fetching system jumps data from https://esi.evetech.net/v2/universe/system_jumps\n")
client := &http.Client{Timeout: 10 * time.Second}
req, err := http.NewRequestWithContext(ctx, http.MethodGet, esiBase+"/v2/universe/system_jumps", nil)
if err != nil {
return nil, err
}
req.Header.Set("Accept", "application/json")
req.Header.Set("X-Compatibility-Date", "2025-08-26")
req.Header.Set("X-Tenant", "tranquility")
resp, err := client.Do(req)
if err != nil {
return nil, err
}
defer resp.Body.Close()
if resp.StatusCode != http.StatusOK {
return nil, fmt.Errorf("ESI API returned status %d", resp.StatusCode)
}
var jumps []SystemJumps
if err := json.NewDecoder(resp.Body).Decode(&jumps); err != nil {
return nil, err
}
fmt.Printf("✅ ESI API SUCCESS: Fetched %d system jumps entries\n", len(jumps))
return jumps, nil
}
// GetSystemKills fetches system kill statistics from ESI
func (s *ESISSO) GetSystemKills(ctx context.Context) ([]SystemKills, error) {
fmt.Printf("⚔️ ESI API REQUEST: Fetching system kills data from https://esi.evetech.net/v2/universe/system_kills\n")
client := &http.Client{Timeout: 10 * time.Second}
req, err := http.NewRequestWithContext(ctx, http.MethodGet, esiBase+"/v2/universe/system_kills", nil)
if err != nil {
return nil, err
}
req.Header.Set("Accept", "application/json")
req.Header.Set("X-Compatibility-Date", "2025-08-26")
req.Header.Set("X-Tenant", "tranquility")
resp, err := client.Do(req)
if err != nil {
return nil, err
}
defer resp.Body.Close()
if resp.StatusCode != http.StatusOK {
return nil, fmt.Errorf("ESI API returned status %d", resp.StatusCode)
}
var kills []SystemKills
if err := json.NewDecoder(resp.Body).Decode(&kills); err != nil {
return nil, err
}
fmt.Printf("✅ ESI API SUCCESS: Fetched %d system kills entries\n", len(kills))
return kills, nil
}
func (s *ESISSO) saveToken() {
if s.db == nil || s.characterID == 0 {
return