eve

package
v0.1.13 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Aug 30, 2026 License: MIT Imports: 6 Imported by: 0

Documentation

Overview

Package eve holds the static-data lookups that every killmail touches.

A killmail arrives from ESI as a bag of numeric IDs. Turning it into a row means resolving each of those against the SDE — the ship's group, the group's category, the system's region, a module's meta level — and doing so tens of times per kill. Going to Postgres for each would make the parser latency-bound on data that changes once a fortnight, so the whole working set is loaded once and read from memory afterwards.

The set is small: ~53 k types, ~8.5 k systems, ~11 k dogma values, and a few thousand rows besides. Under 20 MB resident.

Index

Constants

View Source
const (
	AttrRigSize    int32 = 1547
	AttrMetaLevel  int32 = 633
	AttrHeatDamage int32 = 1211
)
View Source
const FallbackPrice = 0.01

FallbackPrice is the value of a type with no market history at or before the kill date.

Variables

View Source
var DogmaAttributes = []int32{1547, 633, 1211}

DogmaAttributes are the only attributes any killmail computation reads.

1547 rigSize    — the ship-size exponent behind base points
 633 metaLevel  — module quality, weighting the danger factor
1211 heatDamage — marks a module as active-fittable, i.e. dangerous

Loading all ~14 M rows of type_dogma_attributes to reach 11 k of them would be absurd, so the preload filters. A lookup for any other attribute reports absent, which is correct here and would be a bug if this list ever grows without the callers being revisited.

Functions

func Slugify

func Slugify(s string) string

Slugify renders a market group name as a URL segment.

Matches the TypeScript implementation exactly, including replacing `&` with "and" before stripping punctuation — so "Ammunition & Charges" becomes "ammunition-and-charges" rather than "ammunition-charges". The paths are user-visible URLs, so a difference here is a broken link.

Types

type Cache

type Cache struct {
	// contains filtered or unexported fields
}

Cache is an immutable snapshot of the static data.

Nothing writes to it after Load returns, so it needs no locking and can be shared across every goroutine in the process. Picking up a new SDE build means calling Load again and swapping the pointer — deliberately not an in-place refresh, which would reintroduce the locking this design exists to avoid.

func Load

func Load(ctx context.Context, pool *pgxpool.Pool) (*Cache, error)

Load reads every lookup table into memory.

The queries run in sequence rather than concurrently: each is a bulk scan where transfer dominates and round trips do not, and serialising them keeps one connection busy instead of occupying most of a pool sized for a pooler.

func NewCache

func NewCache(d CacheData) *Cache

NewCache builds a cache from data already in hand. The maps are adopted, not copied — the caller must not retain a reference and mutate them, which would break the no-locking guarantee.

func (*Cache) CategoryOfType

func (c *Cache) CategoryOfType(typeID int32) int32

CategoryOfType resolves a type straight to its category, which is the question most callers actually have. It reads inv_types.category_id — already denormalised by the SDE importer — rather than hopping through the group.

func (*Cache) Constellation

func (c *Cache) Constellation(id int32) (Constellation, bool)

Constellation looks up a constellation.

func (*Cache) CountsByName

func (c *Cache) CountsByName() map[string]int

CountsByName reports how many rows of each table are held, which is what makes an empty or half-loaded cache visible before it silently produces killmails full of nulls.

func (*Cache) CustomPrice

func (c *Cache) CustomPrice(typeID int32) (float64, bool)

CustomPrice returns the hand-maintained or generated price for a type, which overrides the market for hulls that never trade.

func (*Cache) Dogma

func (c *Cache) Dogma(typeID, attrID int32) (float64, bool)

Dogma looks up one attribute of one type. Only the attributes in DogmaAttributes are held; anything else always reports absent.

func (*Cache) Group

func (c *Cache) Group(id int32) (Group, bool)

Group looks up an inventory group.

func (*Cache) Region

func (c *Cache) Region(id int32) (Region, bool)

Region looks up a region.

func (*Cache) System

func (c *Cache) System(id int32) (System, bool)

System looks up a solar system.

func (*Cache) Type

func (c *Cache) Type(id int32) (Type, bool)

Type looks up an inventory type.

type CacheData

type CacheData struct {
	Types          map[int32]Type
	Groups         map[int32]Group
	Systems        map[int32]System
	Regions        map[int32]Region
	Constellations map[int32]Constellation
	Dogma          map[DogmaKey]float64
	CustomPrices   map[int32]float64
}

CacheData is the raw contents of a Cache. Load fills one from Postgres; NewCache accepts one directly, which is what tests and fixtures use.

type Constellation

type Constellation struct {
	Name     string
	RegionID int32
}

Constellation is the subset of constellations the killmail path reads.

type Day

type Day struct {
	// contains filtered or unexported fields
}

Day is the resolved price of every requested type on one date.

func (*Day) Of

func (d *Day) Of(typeID int32) float64

Of returns the price of a type, applying the full order of precedence.

A type that was not passed to On resolves to the floor rather than reaching for the database, so a missed type shows up as a wrong value in a diff rather than as an unexplained query in a hot loop.

type DogmaKey

type DogmaKey struct {
	TypeID      int32
	AttributeID int32
}

DogmaKey identifies one attribute of one type.

type Group

type Group struct {
	CategoryID int32
	Name       string
}

Group is the subset of inv_groups the killmail path reads.

type MarketPaths

type MarketPaths map[int32]string

MarketPaths maps a market group id to its slug path.

func LoadMarketPaths

func LoadMarketPaths(ctx context.Context, pool *pgxpool.Pool) (MarketPaths, error)

LoadMarketPaths materialises the path for every market group.

func (MarketPaths) Path

func (m MarketPaths) Path(marketGroupID int32) string

Path returns the market path for a group, or "" when there is none.

An empty string rather than a sentinel because the caller writes it into a nullable JSON field, where absent and empty mean the same thing.

func (MarketPaths) PathForType

func (m MarketPaths) PathForType(c *Cache, typeID int32) string

PathForType resolves a type id's market path through its group.

type Prices

type Prices struct {
	// contains filtered or unexported fields
}

Prices resolves market values for a given day.

Killmails are valued a whole mail at a time — one ship plus everything fitted and in the hold — so the lookup is built around a batch: collect every type on the mail, resolve them in one query, then value from memory. Fetching each type separately would turn a 200-item Rorqual loss into 200 round trips.

func NewPrices

func NewPrices(pool *pgxpool.Pool, cache *Cache) *Prices

NewPrices builds a price resolver over a loaded cache.

func (*Prices) On

func (p *Prices) On(ctx context.Context, date string, typeIDs []int32) (*Day, error)

On resolves the market price of each type as of date (YYYY-MM-DD).

Types settled by a custom price or a group rule are not queried — those answers do not depend on the date, so asking the market about them would be wasted work.

func (*Prices) Seed

func (p *Prices) Seed(date string, market map[int32]float64)

Seed installs a day's prices directly, without a database.

It exists so a price snapshot can come from somewhere other than Postgres — a test fixture, or a warm start from a file. After it returns, On() for that date is answered entirely from memory and a type absent from the snapshot resolves to the floor rather than triggering a query, exactly as it would after Snapshot.

func (*Prices) Snapshot

func (p *Prices) Snapshot(ctx context.Context, date string) (int, error)

Snapshot resolves every type's price as of date in a single query.

It exists for the archive importers, which parse a whole day of killmails at once. Asking per killmail would be twenty thousand queries for a day that has exactly one answer per type; asking once up front is one. After it returns, On() for that date is answered entirely from memory, including for types that have never traded.

type Region

type Region struct {
	Name string
}

Region is the subset of regions the killmail path reads.

type System

type System struct {
	ConstellationID int32
	RegionID        int32
	Name            string

	// Security is stored as a plain float because the column has no NULLs:
	// every one of the 8,490 systems carries a value, and 0.0 is a real
	// security rating rather than a stand-in for "unknown".
	Security float64
}

System is the subset of solar_systems the killmail path reads.

type Type

type Type struct {
	GroupID    int32
	CategoryID int32
	Name       string

	// VariationParentTypeID is the T1 root of a meta/variant family. The
	// fittings extractor collapses T2, faction and storyline variants onto it
	// so one doctrine does not read as a dozen. Zero for types with no parent.
	VariationParentTypeID int32

	// MetaGroupID distinguishes deadspace (5) and officer (6) modules, which
	// is what makes a fit worth announcing.
	MetaGroupID int32

	// MarketGroupID resolves to a `/market/a/b/c` path when a killlist row is
	// published live, so it links the same way a REST-fetched row does.
	MarketGroupID int32
}

Type is the subset of inv_types the killmail path reads.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL