Files
zkill-susser/types.go
2026-01-06 18:11:14 +01:00

155 lines
3.7 KiB
Go

package main
import "time"
type Killmail struct {
Attackers []Attacker `json:"attackers"`
KillmailID int64 `json:"killmail_id"`
KillmailTime time.Time `json:"killmail_time"`
SolarSystemID int64 `json:"solar_system_id"`
Victim Victim `json:"victim"`
KillmailHash string `json:"killmail_hash"`
HTTPLastModified time.Time `json:"http_last_modified"`
}
type Attacker struct {
AllianceID int64 `json:"alliance_id"`
CharacterID int64 `json:"character_id"`
CorporationID int64 `json:"corporation_id"`
DamageDone int64 `json:"damage_done"`
FinalBlow bool `json:"final_blow"`
SecurityStatus float64 `json:"security_status"`
ShipTypeID int64 `json:"ship_type_id"`
WeaponTypeID int64 `json:"weapon_type_id"`
}
type Victim struct {
AllianceID int64 `json:"alliance_id"`
CharacterID int64 `json:"character_id"`
CorporationID int64 `json:"corporation_id"`
DamageTaken int64 `json:"damage_taken"`
Items []Item `json:"items"`
Position Position `json:"position"`
ShipTypeID int64 `json:"ship_type_id"`
}
type Item struct {
Flag int64 `json:"flag"`
ItemTypeID int64 `json:"item_type_id"`
QuantityDestroyed *int64 `json:"quantity_destroyed,omitempty"`
Singleton int64 `json:"singleton"`
QuantityDropped *int64 `json:"quantity_dropped,omitempty"`
}
type Position struct {
X float64 `json:"x"`
Y float64 `json:"y"`
Z float64 `json:"z"`
}
// region Clickhouse killmails
// FlatKillmail - Main analytical table
// Denormalized for fast aggregations
type FlatKillmail struct {
// Core killmail data
KillmailID int64
KillmailTime time.Time
SolarSystemID int64
KillmailHash string
// Victim data (flattened)
VictimShipTypeID int64
VictimCharacterID int64
VictimCorporationID int64
VictimAllianceID int64
VictimDamageTaken int64
// Victim position
VictimPosX float64
VictimPosY float64
VictimPosZ float64
// Attacker summary stats
AttackerCount uint16
TotalDamageDone int64
FinalBlowShipType int64
Attackers []Attacker
Items []Item
}
// FlatModule - Separate table optimized for module co-occurrence queries
type FlatModule struct {
KillmailID int64
ItemTypeID int64
Slot ModuleSlot
}
// Helper functions
func boolToUint8(b bool) uint8 {
if b {
return 1
}
return 0
}
func derefInt64(ptr *int64) int64 {
if ptr == nil {
return 0
}
return *ptr
}
type ModuleSlot string
var (
ModuleSlotLow ModuleSlot = "Low"
ModuleSlotMid ModuleSlot = "Mid"
ModuleSlotHigh ModuleSlot = "High"
ModuleSlotRig ModuleSlot = "Rig"
ModuleSlotSubsystem ModuleSlot = "Subsystem"
ModuleSlotDrone ModuleSlot = "Drone"
ModuleSlotOther ModuleSlot = "Other"
)
// region Other various types
type QueryParams struct {
Ship int64
Systems []int64
Modules []int64
Groups []int64
KillmailLimit int
}
type ModuleStatsData struct {
KillmailIDs []int64
}
// CacheEntry stores both statistics (JSON) and images (blobs) in unified cache
// For 404s, we store a special marker: []byte{0xFF, 0xFE, 0xFD} (NOT_FOUND_MARKER)
type CacheEntry struct {
Key string `gorm:"primaryKey"`
Data []byte `gorm:"type:BLOB;not null"`
CreatedAt time.Time `gorm:"not null;index"`
}
var notFoundMarker = []byte{0xFF, 0xFE, 0xFD} // Special marker for cached 404s
func (CacheEntry) TableName() string {
return "cache_entries"
}
type FitStatistics struct {
TotalKillmails int64
ShipBreakdown map[int64]int64
SystemBreakdown map[int64]int64
HighSlotModules map[int32]int64
MidSlotModules map[int32]int64
LowSlotModules map[int32]int64
Rigs map[int32]int64
Drones map[int32]int64
KillmailIDs []int64
}