models

package
v0.1.4 Latest Latest
Warning

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

Go to latest
Published: May 30, 2020 License: MIT Imports: 8 Imported by: 1

Documentation

Index

Constants

This section is empty.

Variables

PATTERNS is an array of the possible patterns this library might be passed in index order

PATTERNSGAME is the valid patterns in the game. Unknown is not a valid pattern, and only one we need include for practical use because of incomplete user information.

Functions

This section is empty.

Types

type Analysis

type Analysis struct {
	PriceSeries
	// Contains information about a future price series
	Future PriceSeries
	// contains filtered or unexported fields
}

Price range and the chance of the range occurring. This type is designed to be embedded into prediction, pattern, and week objects to give them a common interface for fetching price and probability information.

func NewAnalysis added in v0.1.1

func NewAnalysis(ticker *PriceTicker) *Analysis

func (*Analysis) Chance

func (analysis *Analysis) Chance() float64

The chance from 0.0-1.0 that this week / pattern / price will occur.

func (*Analysis) GuaranteedPrice added in v0.1.0

func (prices *Analysis) GuaranteedPrice() int

The highest guaranteed to happen minimum price that may occur. On PotentialPricePeriod objects, this is the *lowest possible price* for the given period, but on Week, Pattern, and Prediction object this is the minimum guaranteed price, or the highest price we can guarantee will occur this week.

func (*Analysis) MaxPrice

func (prices *Analysis) MaxPrice() int

The potential maximum price for this period / week / pattern / prediction.

func (*Analysis) MinPrice

func (prices *Analysis) MinPrice() int

The absolute minimum price that may occur.

func (*Analysis) PriceChance

func (prices *Analysis) PriceChance(price int) float64

Returns the chance of this price range resulting in this price.

type HasPrices added in v0.1.1

type HasPrices interface {
	MinPrice() int
	GuaranteedPrice() int
	MaxPrice() int
}

type HasSpike

type HasSpike interface {
	// Whether the object has the potential for a Big Spike pattern
	Has() bool
}

Interface defining a potential object that has a spike of a given type

type HasSpikeChance added in v0.0.2

type HasSpikeChance interface {
	HasSpikeRange
	Chance() float64
	Breakdown() *SpikeChanceBreakdown
}

type HasSpikeRange

type HasSpikeRange interface {
	HasSpike

	// The first price period a big hasSpikeAny could occur.
	Start() PricePeriod
	// The last price period a big hasSpikeAny could occur (inclusive).
	End() PricePeriod
}

Interface defining a potential object that has a hasSpikeAny range

type NookPriceArray

type NookPriceArray [values.PricePeriodCount]int

Holds the Nook turnip purchase prices for a week in price-period order. Adds methods for setting and fetching via time package values.

func (*NookPriceArray) ForDay

func (prices *NookPriceArray) ForDay(
	weekday time.Weekday, tod timeofday.ToD,
) (price int, err error)

Return the price for a given Weekday + time of day

func (*NookPriceArray) ForTime

func (prices *NookPriceArray) ForTime(priceTime time.Time) (price int, err error)

Return the price for a given time. The ticker does not contain any information about dates, so it is assumed that the time passed in to priceTime is for the week that the ticker describes.

func (*NookPriceArray) SetForDay

func (prices *NookPriceArray) SetForDay(
	weekday time.Weekday, tod timeofday.ToD, price int,
) error

Set the price with a Weekday / time of day for a little more ease in setting values.

func (*NookPriceArray) SetForTime

func (prices *NookPriceArray) SetForTime(priceTime time.Time, price int) error

Set a price period for a specific time. Timezone is not taken into account during this operation.

type PatternPhase

type PatternPhase interface {
	// The name of the phase
	Name() string

	// The predictor will set the ticker during setup to make it available for
	// calculations. The phase, in turn promises NOT to mutate the ticker.
	SetTicker(ticker *PriceTicker)

	// Returns a list of possible lengths. Should return nil if it cannot yet be
	// determined. 'lengthPass' is a counter of how many times the list of phases has
	// been passed over when computing the possible lengths. For each possible length
	// returned, a new goroutine will be spawned to compute that possibility by making
	// a copy of `phases` and calling 'set length' on this pattern.
	//
	// Should return 'nil' for “possibilities“ if possibilities cannot be computed
	// for this pass. Should panic if we are calling on a finalized phase.
	PossibleLengths(phases []PatternPhase) (possibilities []int)

	// Sets the length we want to assume for this phase. This does not need be the
	// final length, many phases go through a temp length. This method is called by
	// the predictor when setting up a series of possible phase combinations.
	SetLength(length int)

	// Returns the length set by “.SetLength()“ for other phases to inspect when
	// making calculations.
	Length() int

	// Whether the value returned by .Length() is the final length.
	IsFinal() bool

	// Returns a potential price bracket for a given day of this phase. “period“ is
	// the absolute period for the week, while “subPeriod“ is the price period
	// relative to the start of this phase, beginning at 0.
	PotentialPeriod(
		period PricePeriod, subPeriod int,
	) *PotentialPricePeriod

	// Creates a duplicate of this phase in the current state. Used for making
	// permutations.
	Duplicate() PatternPhase
}

A phase is a period of time within a price pattern that follows a single algorithm. When making predictions for a given pattern, we will iterate over a set of phases.

A phase is responsible for:

  1. Communicating a set of possible lengths.
  2. Reporting if it's length has been set in stone when the predictor is iterating over the phases to set all possible lengths.
  3. Returning the price range for a given price period within itself.
  4. Copying itself for spawning a new set of phase length possibilities.

This interface describes the methods necessary to accomplish these four goals, and is used by the predictor to map out all possible phase combinations, and get all possible price ranges for a given price period.

type Patterns

type Patterns []*PotentialPattern

Holds the potential pattern information for a prediction.

func (Patterns) Get

func (patterns Patterns) Get(pattern PricePattern) (*PotentialPattern, error)

Returns the potential pattern predictions for a given pattern. Returns nil if “pattern“ is not a valid pattern.

type PotentialPattern

type PotentialPattern struct {
	// The chance, min price and max price
	*Analysis
	Spikes *SpikeRangeAll
	// The pattern
	Pattern PricePattern
	// The potential week's price patterns
	PotentialWeeks []*PotentialWeek
}

Describes the potential prices and chance of a given price pattern.

func (PotentialPattern) GuaranteedPrice added in v0.1.0

func (prices PotentialPattern) GuaranteedPrice() int

The highest guaranteed to happen minimum price that may occur. On PotentialPricePeriod objects, this is the *lowest possible price* for the given period, but on Week, Pattern, and Prediction object this is the minimum guaranteed price, or the highest price we can guarantee will occur this week.

func (PotentialPattern) MaxPrice

func (prices PotentialPattern) MaxPrice() int

The potential maximum price for this period / week / pattern / prediction.

func (PotentialPattern) MinPrice

func (prices PotentialPattern) MinPrice() int

The absolute minimum price that may occur.

func (PotentialPattern) PriceChance

func (prices PotentialPattern) PriceChance(price int) float64

Returns the chance of this price range resulting in this price.

type PotentialPricePeriod

type PotentialPricePeriod struct {
	Spikes *SpikeHasAll

	// The price period
	PricePeriod PricePeriod

	// The pattern phase used to generate this period.
	PatternPhase PatternPhase
	// contains filtered or unexported fields
}

func (PotentialPricePeriod) GuaranteedPrice added in v0.1.0

func (prices PotentialPricePeriod) GuaranteedPrice() int

The highest guaranteed to happen minimum price that may occur. On PotentialPricePeriod objects, this is the *lowest possible price* for the given period, but on Week, Pattern, and Prediction object this is the minimum guaranteed price, or the highest price we can guarantee will occur this week.

func (*PotentialPricePeriod) IsValidPrice

func (potential *PotentialPricePeriod) IsValidPrice(price int) bool

Returns “true“ if “price“ falls within the price range of this potential period. Used by the predictor to remove phase permutations that do not match the current price values of a user.

func (PotentialPricePeriod) MaxPrice

func (prices PotentialPricePeriod) MaxPrice() int

The potential maximum price for this period / week / pattern / prediction.

func (PotentialPricePeriod) MinPrice

func (prices PotentialPricePeriod) MinPrice() int

The absolute minimum price that may occur.

func (PotentialPricePeriod) PriceChance

func (prices PotentialPricePeriod) PriceChance(price int) float64

Returns the chance of this price range resulting in this price.

type PotentialPricePeriods

type PotentialPricePeriods []*PotentialPricePeriod

This will be implemented as a slice as we will not always hit all 12 price periods when evaluating if a potential week needs to be thrown out

func (PotentialPricePeriods) ForDay

func (prices PotentialPricePeriods) ForDay(
	weekday time.Weekday, tod timeofday.ToD,
) (period *PotentialPricePeriod, err error)

Return the potential price period for a given Weekday + time of day

func (PotentialPricePeriods) ForTime

func (prices PotentialPricePeriods) ForTime(
	priceTime time.Time,
) (period *PotentialPricePeriod, err error)

Return the potential price period for a given time. The ticker does not contain any information about dates, so it is assumed that the time passed in to priceTime is for the week that the ticker describes.

type PotentialWeek

type PotentialWeek struct {
	// Holds chance and price information
	*Analysis

	// Details about if and when a price spike could occur for this week.
	Spikes *SpikeRangeAll

	// Holds the details of the potential price periods.
	Prices PotentialPricePeriods
}

func (PotentialWeek) GuaranteedPrice added in v0.1.0

func (prices PotentialWeek) GuaranteedPrice() int

The highest guaranteed to happen minimum price that may occur. On PotentialPricePeriod objects, this is the *lowest possible price* for the given period, but on Week, Pattern, and Prediction object this is the minimum guaranteed price, or the highest price we can guarantee will occur this week.

func (PotentialWeek) MaxPrice

func (prices PotentialWeek) MaxPrice() int

The potential maximum price for this period / week / pattern / prediction.

func (PotentialWeek) MinPrice

func (prices PotentialWeek) MinPrice() int

The absolute minimum price that may occur.

func (PotentialWeek) PriceChance

func (prices PotentialWeek) PriceChance(price int) float64

Returns the chance of this price range resulting in this price.

type Prediction

type Prediction struct {
	PriceSeries
	Heat     int
	Future   PriceSeries
	Spikes   *SpikeChancesAll
	Patterns Patterns
}

func (*Prediction) GuaranteedPrice added in v0.1.0

func (prices *Prediction) GuaranteedPrice() int

The highest guaranteed to happen minimum price that may occur. On PotentialPricePeriod objects, this is the *lowest possible price* for the given period, but on Week, Pattern, and Prediction object this is the minimum guaranteed price, or the highest price we can guarantee will occur this week.

func (*Prediction) MaxPrice

func (prices *Prediction) MaxPrice() int

The potential maximum price for this period / week / pattern / prediction.

func (*Prediction) MinPrice

func (prices *Prediction) MinPrice() int

The absolute minimum price that may occur.

func (*Prediction) PriceChance

func (prices *Prediction) PriceChance(price int) float64

Returns the chance of this price range resulting in this price.

type Predictor

type Predictor struct {
	// The price ticker to use for this prediction
	Ticker *PriceTicker
	// contains filtered or unexported fields
}

func (*Predictor) CalcHeat added in v0.1.3

func (predictor *Predictor) CalcHeat()

Calculate the investment heat for this island.

func (*Predictor) Predict

func (predictor *Predictor) Predict() (*Prediction, error)

type PricePattern

type PricePattern int

Price Pattern Enum value

0 = "FLUCTUATING"
1 = "BIG SPIKE"
2 = "DECREASING"
3 = "SMALL SPIKE"
4 = "UNKNOWN"
const (
	FLUCTUATING PricePattern = 0
	BIGSPIKE    PricePattern = 1
	DECREASING  PricePattern = 2
	SMALLSPIKE  PricePattern = 3
	UNKNOWN     PricePattern = 4
)

func PatternFromString

func PatternFromString(value string) (PricePattern, error)

Returns a pattern from a string: The following values are valid. The four names are:

  1. Fluctuating
  2. Big Spikes
  3. Decreasing
  4. Small Spikes
  5. Unknown

Incoming values are upper-cased, and spaces are removed before evaluating; all of the following would be handled without error for Big Spikes:

  • BIGSPIKE
  • bigspike
  • BIG SPIKE
  • Big Spikes
  • big spike
  • etc.

func (PricePattern) BaseChance

func (pattern PricePattern) BaseChance(previous PricePattern) float64

Returns a the chance of this pattern occurring based on the pattern from last week

func (PricePattern) PermutationCount

func (pattern PricePattern) PermutationCount() int

The total possible phase combinations for this pattern. Can be used to determine actual chance of this pattern once possibilities have been removed by a ticker.

func (PricePattern) PhaseProgression

func (pattern PricePattern) PhaseProgression(ticker *PriceTicker) []PatternPhase

Returns a new set of phase definitions that can be used to calculate the possible price values for a week.

func (PricePattern) String

func (pattern PricePattern) String() string

type PricePeriod

type PricePeriod int

func PricePeriodFromDay

func PricePeriodFromDay(weekday time.Weekday, tod timeofday.ToD) (PricePeriod, error)

Get the price period for a given weekday and time of day (AM / PM).

func PricePeriodFromTime

func PricePeriodFromTime(priceTime time.Time) (PricePeriod, error)

Get the price period that would occur on a real-world time. Timezone information is ignored -- all times are treated as naive.

func (PricePeriod) ToD

func (period PricePeriod) ToD() timeofday.ToD

The time of day (AM / PM) this price occurs on.

func (PricePeriod) Weekday

func (period PricePeriod) Weekday() time.Weekday

The weekday this price period occurs on. Sunday = 0.

type PriceSeries added in v0.0.1

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

Information about the min and max prices over the 12 price periods of the week.

func (*PriceSeries) GuaranteedPeriods added in v0.1.0

func (prices *PriceSeries) GuaranteedPeriods() []PricePeriod

The PricePeriods that this minimum guaranteed price might occur. On PotentialWeeks, this will always be a single value, but on PotentialPatterns and Predictions, every possible day the minimum guaranteed price *might* occur is used.

func (*PriceSeries) GuaranteedPrice added in v0.1.0

func (prices *PriceSeries) GuaranteedPrice() int

The highest guaranteed to happen minimum price that may occur. On PotentialPricePeriod objects, this is the *lowest possible price* for the given period, but on Week, Pattern, and Prediction object this is the minimum guaranteed price, or the highest price we can guarantee will occur this week.

func (*PriceSeries) MaxPeriods added in v0.0.1

func (prices *PriceSeries) MaxPeriods() []PricePeriod

The PricePeriods that this maximum potential price might occur. On PotentialWeeks, this will always be a single value, but on PotentialPatterns and Predictions, every possible day the maximum potential price *might* occur is used.

func (*PriceSeries) MaxPrice added in v0.0.1

func (prices *PriceSeries) MaxPrice() int

The potential maximum price for this period / week / pattern / prediction.

func (*PriceSeries) MinPeriods added in v0.0.1

func (prices *PriceSeries) MinPeriods() []PricePeriod

The price periods that the absolute minimum price might occur

func (*PriceSeries) MinPrice added in v0.0.1

func (prices *PriceSeries) MinPrice() int

The absolute minimum price that may occur.

func (*PriceSeries) PriceChance added in v0.0.1

func (prices *PriceSeries) PriceChance(price int) float64

Returns the chance of this price range resulting in this price.

type PriceTicker

type PriceTicker struct {
	// The previous week's price pattern
	PreviousPattern PricePattern

	// The purchase price on sunday for this week
	PurchasePrice int

	// The current price period. We need to support not knowing what the current
	// price is if we are charting data for someone else's island, but need to give
	// accurate future price ranges, so we will need to explicitly know from the
	// user what price period the island is currently in.
	CurrentPeriod PricePeriod

	// There are 12 buy-price periods in a week, we are going to store the 12 buy prices
	// in a 12-int array. A price of 'zero' will stand for 'not available'
	//
	// Because PricePeriod is an extension of int, we can access the array with
	// PricePeriod objects.
	Prices NookPriceArray
}

func NewTicker

func NewTicker(
	purchasePrice int,
	previousPattern PricePattern,
	currentPeriod PricePeriod,
) *PriceTicker

type Spike added in v0.0.2

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

Implementation of HasSpike

func (*Spike) Has added in v0.0.2

func (spike *Spike) Has() bool

Whether the object has the potential for a Big Spike pattern

type SpikeChance added in v0.0.2

type SpikeChance struct {
	SpikeRange
	// contains filtered or unexported fields
}

func (*SpikeChance) Breakdown added in v0.0.2

func (spike *SpikeChance) Breakdown() *SpikeChanceBreakdown

func (*SpikeChance) Chance added in v0.0.2

func (spike *SpikeChance) Chance() float64

type SpikeChanceBreakdown

type SpikeChanceBreakdown [values.PricePeriodCount]float64

func (*SpikeChanceBreakdown) ForDay

func (spikes *SpikeChanceBreakdown) ForDay(
	weekday time.Weekday, tod timeofday.ToD,
) (chance float64, err error)

Return the spike chance for a given Weekday + time of day

func (*SpikeChanceBreakdown) ForTime

func (spikes *SpikeChanceBreakdown) ForTime(
	spikeTime time.Time,
) (chance float64, err error)

Return the spike chance for a given time. The ticker does not contain any information about dates, so it is assumed that the time passed in to spikeTime is for the week that the density describes.

type SpikeChancesAll added in v0.0.2

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

A probability heat-map of when a price spike might occur.

func (*SpikeChancesAll) Any added in v0.0.2

func (spikes *SpikeChancesAll) Any() HasSpikeChance

func (*SpikeChancesAll) Big added in v0.0.2

func (spikes *SpikeChancesAll) Big() HasSpikeChance

func (*SpikeChancesAll) Small added in v0.0.2

func (spikes *SpikeChancesAll) Small() HasSpikeChance

func (*SpikeChancesAll) SpikeRangeAll added in v0.0.2

func (spikes *SpikeChancesAll) SpikeRangeAll() *SpikeRangeAll

Converts from HasSpikeChancesAll to HasSpikeRangesAll

type SpikeHasAll added in v0.0.2

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

func (*SpikeHasAll) Any added in v0.0.2

func (spikes *SpikeHasAll) Any() HasSpike

func (*SpikeHasAll) Big added in v0.0.2

func (spikes *SpikeHasAll) Big() HasSpike

func (*SpikeHasAll) Small added in v0.0.2

func (spikes *SpikeHasAll) Small() HasSpike

type SpikeRange

type SpikeRange struct {
	Spike
	// contains filtered or unexported fields
}

Implementation of HasSpikeRange

func (*SpikeRange) End added in v0.0.2

func (spike *SpikeRange) End() PricePeriod

The last price period any spike pattern could occur.

func (*SpikeRange) Start added in v0.0.2

func (spike *SpikeRange) Start() PricePeriod

The first price period any spike pattern could occur.

type SpikeRangeAll added in v0.0.2

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

func (*SpikeRangeAll) Any added in v0.0.2

func (spike *SpikeRangeAll) Any() HasSpikeRange

func (*SpikeRangeAll) Big added in v0.0.2

func (spike *SpikeRangeAll) Big() HasSpikeRange

func (*SpikeRangeAll) Small added in v0.0.2

func (spike *SpikeRangeAll) Small() HasSpikeRange

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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