model

package
v0.0.0-...-c83d288 Latest Latest
Warning

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

Go to latest
Published: Jun 11, 2018 License: MIT Imports: 24 Imported by: 12

Documentation

Overview

Package model encapsulates the persistence layer and higher level functionality in a MOTKI application.

This package is responsible for retrieving data from third-party sources, storing it, manipulating it, etc. Most data is stored in the application's database and all remote calls are throttled. Types are normalized in this package to provide a uniform interface as well as augmentation of the raw data.

Using This Package

This package is meant for use by both the client and server portions of the MOTKI protocol. All Manager types, however, cannot be used by the client as they require a direct database connection.

Generally, this package should be used over the evedb, eveapi, and evemarketer packages.

Index

Constants

View Source
const (
	OrderStateOpen      OrderState = "open"
	OrderStateExpired              = "expired"
	OrderStateCancelled            = "cancelled"
)

Variables

View Source
var (
	ErrUserExists   = errors.New("user already exists")
	ErrMissingField = errors.New("missing field")
)
View Source
var ErrCorpNotRegistered = errors.New("ceo or director is not registered for the given corporation")

Functions

func APIScopesForRole

func APIScopesForRole(r Role) []string

Types

type Alliance

type Alliance struct {
	AllianceID  int       `json:"alliance_id"`
	Name        string    `json:"name"`
	DateFounded time.Time `json:"date_founded"`
	Ticker      string    `json:"ticker"`
}

type Asset

type Asset struct {
	ItemID       int    `json:"item_id"`
	LocationID   int    `json:"location_id"`
	LocationType string `json:"location_type"`
	LocationFlag string `json:"location_flag"`
	TypeID       int    `json:"type_id"`
	Quantity     int    `json:"quantity"`
	Singleton    bool   `json:"singleton"`
	// contains filtered or unexported fields
}

type AssetManager

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

func (*AssetManager) GetAssetSystem

func (m *AssetManager) GetAssetSystem(a *Asset) (*evedb.System, error)

func (*AssetManager) GetCorporationAsset

func (m *AssetManager) GetCorporationAsset(ctx context.Context, corpID int, itemID int) (res *Asset, err error)

func (*AssetManager) GetCorporationAssets

func (m *AssetManager) GetCorporationAssets(ctx context.Context, corpID int) (res []*Asset, err error)

func (*AssetManager) GetCorporationAssetsByTypeAndLocationID

func (m *AssetManager) GetCorporationAssetsByTypeAndLocationID(ctx context.Context, corpID, typeID, locationID int) (res []*Asset, err error)

GetCorporationAssetsByTypeAndLocationID queries the database to find any assets with the given type and location.

This method will not fetch assets from the API.

type Authorization

type Authorization struct {
	UserID        int           `json:"user_id"`
	CharacterID   int           `json:"character_id"`
	CorporationID int           `json:"corporation_id"`
	Role          Role          `json:"role"`
	Token         *oauth2.Token `json:"token"`
	// contains filtered or unexported fields
}

func (*Authorization) Context

func (a *Authorization) Context() context.Context

type Blueprint

type Blueprint struct {
	ItemID             int           `json:"item_id"`
	LocationID         int           `json:"location_id"`
	LocationFlag       string        `json:"location_flag"`
	TypeID             int           `json:"type_id"`
	TimeEfficiency     int           `json:"time_efficiency"`
	MaterialEfficiency int           `json:"material_efficiency"`
	Kind               BlueprintKind `json:"kind"`
	Quantity           int           `json:"quantity"`

	// -1 = infinite runs (a BPO)
	Runs int `json:"runs"`
}

type BlueprintKind

type BlueprintKind string
var (
	BlueprintOriginal BlueprintKind = "bpo"
	BlueprintCopy     BlueprintKind = "bpc"
)

type BlueprintManager

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

func (*BlueprintManager) GetCorporationBlueprints

func (m *BlueprintManager) GetCorporationBlueprints(ctx context.Context, corpID int) (jobs []*Blueprint, err error)

type Character

type Character struct {
	CharacterID   int       `json:"character_id"`
	Name          string    `json:"name"`
	BloodlineID   int       `json:"bloodline_id"`
	RaceID        int       `json:"race_id"`
	AncestryID    int       `json:"ancestry_id"`
	CorporationID int       `json:"corporation_id"`
	AllianceID    int       `json:"alliance_id"`
	BirthDate     time.Time `json:"birth_date"`
	Description   string    `json:"description"`
}

type CharacterManager

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

func (*CharacterManager) GetCharacter

func (m *CharacterManager) GetCharacter(characterID int) (*Character, error)

type CorpManager

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

func (*CorpManager) FetchCorporationDetail

func (m *CorpManager) FetchCorporationDetail(ctx context.Context) (*CorporationDetail, error)

func (*CorpManager) GetAlliance

func (m *CorpManager) GetAlliance(allianceID int) (*Alliance, error)

func (*CorpManager) GetCorporation

func (m *CorpManager) GetCorporation(corporationID int) (*Corporation, error)

func (*CorpManager) GetCorporationAuthorization

func (m *CorpManager) GetCorporationAuthorization(corpID int) (*Authorization, error)

func (*CorpManager) GetCorporationConfig

func (m *CorpManager) GetCorporationConfig(corpID int) (*CorporationConfig, error)

func (*CorpManager) GetCorporationDetail

func (m *CorpManager) GetCorporationDetail(corpID int) (*CorporationDetail, error)

func (*CorpManager) GetCorporationsOptedIn

func (m *CorpManager) GetCorporationsOptedIn() ([]int, error)

func (*CorpManager) SaveCorporationConfig

func (m *CorpManager) SaveCorporationConfig(corpID int, detail *CorporationConfig) error

type Corporation

type Corporation struct {
	CorporationID int       `json:"corporation_id"`
	Name          string    `json:"name"`
	AllianceID    int       `json:"alliance_id"`
	CreationDate  time.Time `json:"creation_date"`
	Description   string    `json:"description"`
	Ticker        string    `json:"ticker"`
}

type CorporationConfig

type CorporationConfig struct {
	OptIn     bool      `json:"opt_in"`
	OptInBy   int       `json:"opt_in_by"`
	OptInDate time.Time `json:"opt_in_date"`

	CreatedBy int       `json:"created_by"`
	CreatedAt time.Time `json:"created_at"`
}

type CorporationDetail

type CorporationDetail struct {
	CorporationID int    `json:"corporation_id"`
	CEOID         int    `json:"ceoid"`
	CEOName       string `json:"ceo_name"`
	StationID     int    `json:"station_id"`
	StationName   string `json:"station_name"`
	FactionID     int    `json:"faction_id"`
	MemberCount   int    `json:"member_count"`
	Shares        int    `json:"shares"`

	Wallets Divisions `json:"wallets"`
	Hangars Divisions `json:"hangars"`
}

type CorporationStructure

type CorporationStructure struct {
	Structure
	ProfileID   int64     `json:"profile_id"`
	Services    []string  `json:"services"`
	FuelExpires time.Time `json:"fuel_expires"`
	StateStart  time.Time `json:"state_start"`
	StateEnd    time.Time `json:"state_end"`
	UnanchorsAt time.Time `json:"unanchors_at"`
	State       string    `json:"state"`

	CurrReinforceWindow ReinforceWindow `json:"curr_reinforce_window"`
	NextReinforceWindow ReinforceWindow `json:"next_reinforce_window"`
}

A CorporationStructure contains additional, sensitive information about a citadel.

type Divisions

type Divisions map[string]string

Divisions is a map of division key to division name.

func (Divisions) GetName

func (d Divisions) GetName(idx int) (string, bool)

func (*Divisions) Scan

func (d *Divisions) Scan(src interface{}) error

func (Divisions) Value

func (d Divisions) Value() (driver.Value, error)

type IndustryJob

type IndustryJob struct {
	JobID                int             `json:"job_id"`
	InstallerID          int             `json:"installer_id"`
	FacilityID           int             `json:"facility_id"`
	LocationID           int             `json:"location_id"`
	ActivityID           int             `json:"activity_id"`
	BlueprintID          int             `json:"blueprint_id"`
	BlueprintTypeID      int             `json:"blueprint_type_id"`
	BlueprintLocationID  int             `json:"blueprint_location_id"`
	OutputLocationID     int             `json:"output_location_id"`
	ProductTypeID        int             `json:"product_type_id"`
	Runs                 int             `json:"runs"`
	Cost                 decimal.Decimal `json:"cost"`
	LicensedRuns         int             `json:"licensed_runs"`
	Probability          decimal.Decimal `json:"probability"`
	Status               string          `json:"status"`
	StartDate            time.Time       `json:"start_date"`
	EndDate              time.Time       `json:"end_date"`
	PauseDate            time.Time       `json:"pause_date"`
	CompletedDate        time.Time       `json:"completed_date"`
	CompletedCharacterID int             `json:"completed_character_id"`
	SuccessfulRuns       int             `json:"successful_runs"`
}

type IndustryManager

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

func (*IndustryManager) GetCorporationIndustryJobs

func (m *IndustryManager) GetCorporationIndustryJobs(ctx context.Context, corpID int) (jobs []*IndustryJob, err error)

type InventoryItem

type InventoryItem struct {
	TypeID        int       `json:"type_id"`
	LocationID    int       `json:"location_id"`
	MinimumLevel  int       `json:"minimum_level"`
	CurrentLevel  int       `json:"current_level"`
	CorporationID int       `json:"corporation_id"`
	FetchedAt     time.Time `json:"fetched_at"`
}

type InventoryManager

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

func (*InventoryManager) GetCorporationInventory

func (m *InventoryManager) GetCorporationInventory(ctx context.Context, corpID int) (items []*InventoryItem, err error)

func (*InventoryManager) NewInventoryItem

func (m *InventoryManager) NewInventoryItem(ctx context.Context, corpID, typeID, locationID int) (*InventoryItem, error)

func (*InventoryManager) SaveInventoryItem

func (m *InventoryManager) SaveInventoryItem(ctx context.Context, item *InventoryItem) error

type Location

type Location struct {
	// The original LocationID this location represents.
	LocationID int `json:"location_id"`

	// The solar system this location is found in.
	System *evedb.System `json:"system"`

	// The constellation this location is found in.
	Constellation *evedb.Constellation `json:"constellation"`

	// The region this location is found in.
	Region *evedb.Region `json:"region"`

	// The NPC station at this location. May be nil.
	Station *evedb.Station `json:"station"`

	// The player-owned structure at this location. May be nil.
	Structure *Structure `json:"structure"`
	// contains filtered or unexported fields
}

Location describes a station, structure, or solar system in the EVE universe.

This is a basic abstraction over the loosely defined "location ID" found in various API responses. A Location may represent an NPC station, a player-owned Citadel, or simply a solar system.

Any Location will contain, at a minimum, System, Constellation, and Region info. Station and Structure may be nil if the location is only as specific as a solar system. Otherwise, Station OR Structure will be populated, but never both.

func (Location) IsCitadel

func (l Location) IsCitadel() bool

IsCitadel returns true if the location is a player-controlled citadel.

Use this method to determine if a location represents a player-controlled structure.

func (Location) IsStation

func (l Location) IsStation() bool

IsStation returns true if the location is a NPC station.

Use this method to determine if a location represents a NPC station.

func (Location) IsSystem

func (l Location) IsSystem() bool

IsSystem returns true if the location does not contain station or citadel information.

Use this method to determine if a location is neither a station nor structure. In other words, this method returns true if the location is strictly just a solar system.

func (Location) ParentID

func (l Location) ParentID() int

ParentID returns the LocationID, StructureID, or SystemID that this location exists in.

func (Location) String

func (l Location) String() string

type LocationManager

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

func (*LocationManager) GetLocation

func (m *LocationManager) GetLocation(ctx context.Context, locationID int) (*Location, error)

GetLocation attempts to resolve the given location.

func (*LocationManager) QueryLocations

func (m *LocationManager) QueryLocations(ctx context.Context, query string) ([]*Location, error)

type MailManager

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

func (*MailManager) AddToMailingList

func (m *MailManager) AddToMailingList(key string, rec MailingListSubscriber) error

func (*MailManager) GetMailingList

func (m *MailManager) GetMailingList(key string) ([]*MailingListSubscriber, error)

type MailingListSubscriber

type MailingListSubscriber struct {
	Name  string `json:"name"`
	Email string `json:"email"`
}

type Manager

A Manager handles loading and saving of data.

Most data is stored in the configured database and only fetched from external sites when necessary.

func NewManager

func NewManager(pool *db.ConnPool, evedb *evedb.EveDB, api *eveapi.EveAPI, ec *evemarketer.EveMarketer) *Manager

NewManager creates a new Manager, ready for use.

func (*Manager) UpdateCorporationDataFunc

func (m *Manager) UpdateCorporationDataFunc(logger log.Logger) func() error

UpdateCorporationData fetches updated data for all opted-in corporations.

The function returned by this method is intended to be invoke in regular intervals.

type MarketManager

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

func (*MarketManager) GetCorporationOrder

func (m *MarketManager) GetCorporationOrder(ctx context.Context, corpID, orderID int) (*MarketOrder, error)

func (*MarketManager) GetCorporationOrders

func (m *MarketManager) GetCorporationOrders(ctx context.Context, corpID int) (orders []*MarketOrder, err error)

func (*MarketManager) GetMarketPrice

func (m *MarketManager) GetMarketPrice(typeID int) (*MarketPrice, error)

func (*MarketManager) GetMarketPrices

func (m *MarketManager) GetMarketPrices(typeID int, typeIDs ...int) ([]*MarketPrice, error)

func (*MarketManager) GetMarketStat

func (m *MarketManager) GetMarketStat(typeID int, typeIDs ...int) ([]*MarketStat, error)

GetMarketStat gets market information for the given types.

Multiple typeIDs may be specified, but the method signature requires at least the first is given.

func (*MarketManager) GetMarketStatRegion

func (m *MarketManager) GetMarketStatRegion(regionID int, typeID int, typeIDs ...int) ([]*MarketStat, error)

GetMarketStatRegion gets market information for the given region and types.

Multiple typeIDs may be specified, but the method signature requires at least the first is given.

func (*MarketManager) GetMarketStatSystem

func (m *MarketManager) GetMarketStatSystem(systemID int, typeID int, typeIDs ...int) ([]*MarketStat, error)

GetMarketStatSystem gets market information for the given system and types.

Multiple typeIDs may be specified, but the method signature requires at least the first is given.

type MarketOrder

type MarketOrder struct {
	OrderID      int             `json:"order_id"`
	CharID       int             `json:"char_id"`
	LocationID   int             `json:"location_id"`
	TypeID       int             `json:"type_id"`
	VolEntered   int             `json:"vol_entered"`
	VolRemaining int             `json:"vol_remaining"`
	MinVolume    int             `json:"min_volume"`
	OrderState   OrderState      `json:"order_state"`
	Range        string          `json:"range"`
	AccountKey   int             `json:"account_key"`
	Duration     int             `json:"duration"`
	Escrow       decimal.Decimal `json:"escrow"`
	Price        decimal.Decimal `json:"price"`
	Bid          bool            `json:"bid"`
	Issued       time.Time       `json:"issued"`
}

type MarketPrice

type MarketPrice struct {
	TypeID int             `json:"type_id"`
	Avg    decimal.Decimal `json:"avg"`
	Base   decimal.Decimal `json:"base"`
}

A MarketPrice is a universal average price for a given item.

type MarketStat

type MarketStat struct {
	Kind        evemarketer.StatKind `json:"kind"`
	TypeID      int                  `json:"type_id"`
	Volume      int                  `json:"volume"`
	WAvg        decimal.Decimal      `json:"w_avg"`
	Avg         decimal.Decimal      `json:"avg"`
	Variance    decimal.Decimal      `json:"variance"`
	StdDev      decimal.Decimal      `json:"std_dev"`
	Median      decimal.Decimal      `json:"median"`
	FivePercent decimal.Decimal      `json:"five_percent"`
	Max         decimal.Decimal      `json:"max"`
	Min         decimal.Decimal      `json:"min"`
	Timestamp   time.Time            `json:"timestamp"`
}

MarketStat is region-specific price information for the given type.

func (MarketStat) View

func (m MarketStat) View() StatView

type OrderState

type OrderState string

One of: open, expired, cancelled

func (*OrderState) Scan

func (r *OrderState) Scan(src interface{}) error

func (OrderState) Value

func (r OrderState) Value() (driver.Value, error)

type Product

type Product struct {
	ProductID          int             `json:"product_id"`
	TypeID             int             `json:"type_id"`
	Materials          []*Product      `json:"materials"`
	Quantity           int             `json:"quantity"`
	MarketPrice        decimal.Decimal `json:"market_price"`
	MarketRegionID     int             `json:"market_region_id"`
	MaterialEfficiency decimal.Decimal `json:"material_efficiency"`
	BatchSize          int             `json:"batch_size"`
	Kind               ProductKind     `json:"kind"`

	ParentID      int `json:"parent_id"`
	CorporationID int `json:"corporation_id"`
}

Product represents one part of a production chain.

func (Product) Clone

func (p Product) Clone() *Product

Clone copies the Product and all materials, omitting the ProductIDs.

func (Product) Cost

func (p Product) Cost() decimal.Decimal

Cost returns the total cost for one single unit of the completed parent product.

type ProductKind

type ProductKind string

ProductKind describes the way a product is acquired.

const (
	ProductBuy   ProductKind = "buy"
	ProductBuild ProductKind = "build"
)

type ProductManager

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

func (*ProductManager) GetAllProducts

func (m *ProductManager) GetAllProducts(corpID int) ([]*Product, error)

GetAllProducts returns all production chains associated with the given corporation.

func (*ProductManager) GetProduct

func (m *ProductManager) GetProduct(corpID int, productID int) (*Product, error)

GetProduct returns a production chain for the given corporation and root product.

func (*ProductManager) NewProduct

func (m *ProductManager) NewProduct(corpID int, typeID int) (*Product, error)

NewProduct creates a new production chain for the given corporation and type.

func (*ProductManager) SaveProduct

func (m *ProductManager) SaveProduct(product *Product) error

SaveProduct saves the given production chain in the database.

This function automatically handles both inserting and updating.

func (*ProductManager) UpdateProductMarketPrices

func (m *ProductManager) UpdateProductMarketPrices(ctx context.Context, product *Product, regionID int) error

UpdateProductMarketPrices fetches the latest market data for the production chain in the specified region.

This method updates the Product's regionID. To avoid this behavior, pass the current regionID in.

err := m.UpdateProductMarketPrices(prod, prod.RegionID)

func (*ProductManager) UpdateProductMarketPricesRecursive

func (m *ProductManager) UpdateProductMarketPricesRecursive(product *Product, regionID int) error

type ReinforceHour

type ReinforceHour int

func (ReinforceHour) String

func (h ReinforceHour) String() string

type ReinforceWindow

type ReinforceWindow struct {
	Weekday     time.Weekday  `json:"weekday"`
	Hour        ReinforceHour `json:"hour"`
	EffectiveAt time.Time     `json:"effective_at"`
}

func (*ReinforceWindow) Scan

func (h *ReinforceWindow) Scan(src interface{}) error

func (ReinforceWindow) String

func (h ReinforceWindow) String() string

func (ReinforceWindow) Value

func (h ReinforceWindow) Value() (driver.Value, error)

type Role

type Role int
const (
	RoleAnon Role = iota
	RoleUser
	RoleMember
	RoleLogistics
	RoleDirector
	RoleAdmin
)

func (*Role) Scan

func (r *Role) Scan(src interface{}) error

func (Role) Value

func (r Role) Value() (driver.Value, error)

type StatView

type StatView struct {
	Kind        string    `json:"kind"`
	TypeID      int       `json:"type_id"`
	Volume      int       `json:"volume"`
	WAvg        float64   `json:"w_avg"`
	Avg         float64   `json:"avg"`
	Variance    float64   `json:"variance"`
	StdDev      float64   `json:"std_dev"`
	Median      float64   `json:"median"`
	FivePercent float64   `json:"five_percent"`
	Max         float64   `json:"max"`
	Min         float64   `json:"min"`
	Timestamp   time.Time `json:"timestamp"`
	// contains filtered or unexported fields
}

type Structure

type Structure struct {
	StructureID int64  `json:"structure_id"`
	Name        string `json:"name"`
	SystemID    int64  `json:"system_id"`
	TypeID      int64  `json:"type_id"`
}

A Structure is a player-owned citadel.

type StructureManager

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

func (*StructureManager) GetCorporationStructures

func (m *StructureManager) GetCorporationStructures(ctx context.Context, corpID int) ([]*CorporationStructure, error)

func (*StructureManager) GetStructure

func (m *StructureManager) GetStructure(ctx context.Context, structureID int) (*Structure, error)

type User

type User struct {
	UserID int    `json:"user_id"`
	Name   string `json:"name"`
	Email  string `json:"email"`
}

type UserManager

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

func (*UserManager) AuthenticateUser

func (m *UserManager) AuthenticateUser(name, password string) (*User, string, error)

func (*UserManager) CreateUserVerificationHash

func (m *UserManager) CreateUserVerificationHash(user *User) ([]byte, error)

func (*UserManager) GetAuthorization

func (m *UserManager) GetAuthorization(user *User, role Role) (*Authorization, error)

func (*UserManager) GetUserBySessionKey

func (m *UserManager) GetUserBySessionKey(key string) (*User, error)

func (*UserManager) NewUser

func (m *UserManager) NewUser(name, email, password string) (*User, error)

func (*UserManager) RemoveAuthorization

func (m *UserManager) RemoveAuthorization(user *User, role Role) error

func (*UserManager) SaveAuthorization

func (m *UserManager) SaveAuthorization(u *User, r Role, characterID int, tok *oauth2.Token) error

func (*UserManager) VerifyUserEmail

func (m *UserManager) VerifyUserEmail(email string, hash []byte) (bool, error)

Jump to

Keyboard shortcuts

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