From 22a76ff8ecbc212ff0b3abc7fd56f0968e00e142 Mon Sep 17 00:00:00 2001 From: PhatPhuckDave Date: Sun, 25 Jan 2026 01:20:41 +0100 Subject: [PATCH] Return ids with analytics --- analytics.go | 3 +++ analytics_queries.go | 15 +++++++++------ 2 files changed, 12 insertions(+), 6 deletions(-) diff --git a/analytics.go b/analytics.go index c4b9eb0..a08e4cc 100644 --- a/analytics.go +++ b/analytics.go @@ -65,6 +65,7 @@ type TimeAggregationByMonth struct { // Location aggregation results type LocationAggregationBySystem struct { + SolarSystemID int32 `json:"solar_system_id"` SolarSystemName string `json:"solar_system_name"` RegionName string `json:"region_name"` Security float32 `json:"security"` @@ -95,6 +96,7 @@ type LocationAggregationBySecurity struct { // Ship aggregation results type ShipAggregationByVictimShip struct { + ShipTypeID int32 `json:"victim_ship_type_id"` ShipTypeName string `json:"victim_ship_type_name"` ShipGroupName string `json:"victim_ship_group_name"` ShipCategoryName string `json:"victim_ship_category_name"` @@ -166,6 +168,7 @@ type ModuleAggregationBySlotType struct { } type ModuleAggregationByModule struct { + ItemTypeID int32 `json:"item_type_id"` ItemTypeName string `json:"item_type_name"` ItemGroupName string `json:"item_group_name"` ItemCategoryName string `json:"item_category_name"` diff --git a/analytics_queries.go b/analytics_queries.go index 4944466..158fe65 100644 --- a/analytics_queries.go +++ b/analytics_queries.go @@ -159,6 +159,7 @@ func (db *DBWrapper) QueryLocationBySystem(ctx context.Context, filters Analytic query := fmt.Sprintf(` SELECT + solar_system_id, solar_system_name, region_name, security, @@ -167,7 +168,7 @@ func (db *DBWrapper) QueryLocationBySystem(ctx context.Context, filters Analytic count(DISTINCT victim_ship_type_name) as ship_variety FROM zkill.killmails %s - GROUP BY solar_system_name, region_name, security + GROUP BY solar_system_id, solar_system_name, region_name, security ORDER BY kill_count DESC `, whereClause) @@ -181,7 +182,7 @@ func (db *DBWrapper) QueryLocationBySystem(ctx context.Context, filters Analytic var results []LocationAggregationBySystem for rows.Next() { var r LocationAggregationBySystem - if err := rows.Scan(&r.SolarSystemName, &r.RegionName, &r.Security, &r.KillCount, &r.UniqueVictims, &r.ShipVariety); err != nil { + if err := rows.Scan(&r.SolarSystemID, &r.SolarSystemName, &r.RegionName, &r.Security, &r.KillCount, &r.UniqueVictims, &r.ShipVariety); err != nil { return nil, fmt.Errorf("failed to scan row: %w", err) } results = append(results, r) @@ -301,6 +302,7 @@ func (db *DBWrapper) QueryShipByVictim(ctx context.Context, filters AnalyticsFil query := fmt.Sprintf(` SELECT + victim_ship_type_id, victim_ship_type_name, victim_ship_group_name, victim_ship_category_name, @@ -308,7 +310,7 @@ func (db *DBWrapper) QueryShipByVictim(ctx context.Context, filters AnalyticsFil count(DISTINCT victim_character_id) as unique_pilots_killed FROM zkill.killmails %s - GROUP BY victim_ship_type_name, victim_ship_group_name, victim_ship_category_name + GROUP BY victim_ship_type_id, victim_ship_type_name, victim_ship_group_name, victim_ship_category_name ORDER BY kill_count DESC `, whereClause) @@ -322,7 +324,7 @@ func (db *DBWrapper) QueryShipByVictim(ctx context.Context, filters AnalyticsFil var results []ShipAggregationByVictimShip for rows.Next() { var r ShipAggregationByVictimShip - if err := rows.Scan(&r.ShipTypeName, &r.ShipGroupName, &r.ShipCategoryName, &r.KillCount, &r.UniquePilots); err != nil { + if err := rows.Scan(&r.ShipTypeID, &r.ShipTypeName, &r.ShipGroupName, &r.ShipCategoryName, &r.KillCount, &r.UniquePilots); err != nil { return nil, fmt.Errorf("failed to scan row: %w", err) } results = append(results, r) @@ -663,6 +665,7 @@ func (db *DBWrapper) QueryModuleByModule(ctx context.Context, filters AnalyticsF args := append(killmailArgs, slotArgs...) query := fmt.Sprintf(` SELECT + item_type_id, item_type_name, item_group_name, item_category_name, @@ -671,7 +674,7 @@ func (db *DBWrapper) QueryModuleByModule(ctx context.Context, filters AnalyticsF FROM zkill.killmail_items WHERE killmail_id IN %s %s - GROUP BY item_type_name, item_group_name, item_category_name + GROUP BY item_type_id, item_type_name, item_group_name, item_category_name ORDER BY times_fitted DESC `, killmailSubquery, slotTypeFilter) @@ -685,7 +688,7 @@ func (db *DBWrapper) QueryModuleByModule(ctx context.Context, filters AnalyticsF var results []ModuleAggregationByModule for rows.Next() { var r ModuleAggregationByModule - if err := rows.Scan(&r.ItemTypeName, &r.ItemGroupName, &r.ItemCategoryName, &r.TimesFitted, &r.ShipsWithModule); err != nil { + if err := rows.Scan(&r.ItemTypeID, &r.ItemTypeName, &r.ItemGroupName, &r.ItemCategoryName, &r.TimesFitted, &r.ShipsWithModule); err != nil { return nil, fmt.Errorf("failed to scan row: %w", err) } results = append(results, r)