...

Package models

import "github.com/peake100/turnup-go/models"
Overview
Index
Subdirectories

Overview ▾

Index ▾

Variables
type Analysis
    func NewAnalysis(ticker *PriceTicker) *Analysis
    func (analysis *Analysis) Chance() float64
    func (prices *Analysis) GuaranteedPrice() int
    func (prices *Analysis) MaxPrice() int
    func (prices *Analysis) MinPrice() int
    func (prices *Analysis) PriceChance(price int) float64
type HasPrices
type HasSpike
type HasSpikeChance
type HasSpikeRange
type NookPriceArray
    func (prices *NookPriceArray) ForDay(weekday time.Weekday, tod timeofday.ToD) (price int, err error)
    func (prices *NookPriceArray) ForTime(priceTime time.Time) (price int, err error)
    func (prices *NookPriceArray) SetForDay(weekday time.Weekday, tod timeofday.ToD, price int) error
    func (prices *NookPriceArray) SetForTime(priceTime time.Time, price int) error
type PatternPhase
type Patterns
    func (patterns Patterns) Get(pattern PricePattern) (*PotentialPattern, error)
type PotentialPattern
    func (prices PotentialPattern) GuaranteedPrice() int
    func (prices PotentialPattern) MaxPrice() int
    func (prices PotentialPattern) MinPrice() int
    func (prices PotentialPattern) PriceChance(price int) float64
type PotentialPricePeriod
    func (prices PotentialPricePeriod) GuaranteedPrice() int
    func (potential *PotentialPricePeriod) IsValidPrice(price int) bool
    func (prices PotentialPricePeriod) MaxPrice() int
    func (prices PotentialPricePeriod) MinPrice() int
    func (prices PotentialPricePeriod) PriceChance(price int) float64
type PotentialPricePeriods
    func (prices PotentialPricePeriods) ForDay(weekday time.Weekday, tod timeofday.ToD) (period *PotentialPricePeriod, err error)
    func (prices PotentialPricePeriods) ForTime(priceTime time.Time) (period *PotentialPricePeriod, err error)
type PotentialWeek
    func (prices PotentialWeek) GuaranteedPrice() int
    func (prices PotentialWeek) MaxPrice() int
    func (prices PotentialWeek) MinPrice() int
    func (prices PotentialWeek) PriceChance(price int) float64
type Prediction
    func (prices *Prediction) GuaranteedPrice() int
    func (prices *Prediction) MaxPrice() int
    func (prices *Prediction) MinPrice() int
    func (prices *Prediction) PriceChance(price int) float64
type Predictor
    func (predictor *Predictor) CalcHeat()
    func (predictor *Predictor) Predict() (*Prediction, error)
type PricePattern
    func PatternFromString(value string) (PricePattern, error)
    func (pattern PricePattern) BaseChance(previous PricePattern) float64
    func (pattern PricePattern) PermutationCount() int
    func (pattern PricePattern) PhaseProgression(ticker *PriceTicker) []PatternPhase
    func (pattern PricePattern) String() string
type PricePeriod
    func PricePeriodFromDay(weekday time.Weekday, tod timeofday.ToD) (PricePeriod, error)
    func PricePeriodFromTime(priceTime time.Time) (PricePeriod, error)
    func (period PricePeriod) ToD() timeofday.ToD
    func (period PricePeriod) Weekday() time.Weekday
type PriceSeries
    func (prices *PriceSeries) GuaranteedPeriods() []PricePeriod
    func (prices *PriceSeries) GuaranteedPrice() int
    func (prices *PriceSeries) MaxPeriods() []PricePeriod
    func (prices *PriceSeries) MaxPrice() int
    func (prices *PriceSeries) MinPeriods() []PricePeriod
    func (prices *PriceSeries) MinPrice() int
    func (prices *PriceSeries) PriceChance(price int) float64
type PriceTicker
    func NewTicker(purchasePrice int, previousPattern PricePattern, currentPeriod PricePeriod) *PriceTicker
type Spike
    func (spike *Spike) Has() bool
type SpikeChance
    func (spike *SpikeChance) Breakdown() *SpikeChanceBreakdown
    func (spike *SpikeChance) Chance() float64
type SpikeChanceBreakdown
    func (spikes *SpikeChanceBreakdown) ForDay(weekday time.Weekday, tod timeofday.ToD) (chance float64, err error)
    func (spikes *SpikeChanceBreakdown) ForTime(spikeTime time.Time) (chance float64, err error)
type SpikeChancesAll
    func (spikes *SpikeChancesAll) Any() HasSpikeChance
    func (spikes *SpikeChancesAll) Big() HasSpikeChance
    func (spikes *SpikeChancesAll) Small() HasSpikeChance
    func (spikes *SpikeChancesAll) SpikeRangeAll() *SpikeRangeAll
type SpikeHasAll
    func (spikes *SpikeHasAll) Any() HasSpike
    func (spikes *SpikeHasAll) Big() HasSpike
    func (spikes *SpikeHasAll) Small() HasSpike
type SpikeRange
    func (spike *SpikeRange) End() PricePeriod
    func (spike *SpikeRange) Start() PricePeriod
type SpikeRangeAll
    func (spike *SpikeRangeAll) Any() HasSpikeRange
    func (spike *SpikeRangeAll) Big() HasSpikeRange
    func (spike *SpikeRangeAll) Small() HasSpikeRange

Package files

analysis.go analysisPrices.go pattern.go period.go phase.go phaseAutoCalc.go phaseAutoCalcPeriodGen.go phaseAutoCore.go phasesBigSpike.go phasesDecreasing.go phasesFluctuating.go phasesSmallSpike.go potentialPattern.go potentialPeriod.go potentialWeek.go prediction.go predictionSpikeInfo.go predictor.go predictorCalcChances.go predictorHeat.go predictorPattern.go predictorWeek.go spikeInfo.go ticker.go tickerPrices.go utils.go

Variables

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

var PATTERNS = [5]PricePattern{FLUCTUATING, BIGSPIKE, DECREASING, SMALLSPIKE, UNKNOWN}

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.

var PATTERNSGAME = [4]PricePattern{FLUCTUATING, BIGSPIKE, DECREASING, SMALLSPIKE}

type Analysis

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.

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

func NewAnalysis

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

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

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

type HasSpike

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

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

type HasSpikeChance

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

type HasSpikeRange

Interface defining a potential object that has a hasSpikeAny range

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
}

type NookPriceArray

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

type NookPriceArray [values.PricePeriodCount]int

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

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 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
}

type Patterns

Holds the potential pattern information for a prediction.

type Patterns []*PotentialPattern

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

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

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
}

func (PotentialPattern) GuaranteedPrice

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

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

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

type PotentialPricePeriods []*PotentialPricePeriod

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

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

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

func (predictor *Predictor) CalcHeat()

Calculate the investment heat for this island.

func (*Predictor) Predict

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

type PricePattern

Price Pattern Enum value

0 = "FLUCTUATING"
1 = "BIG SPIKE"
2 = "DECREASING"
3 = "SMALL SPIKE"
4 = "UNKNOWN"
type PricePattern int
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

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

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

func (*PriceSeries) GuaranteedPeriods

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

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

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

func (prices *PriceSeries) MaxPrice() int

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

func (*PriceSeries) MinPeriods

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

The price periods that the absolute minimum price might occur

func (*PriceSeries) MinPrice

func (prices *PriceSeries) MinPrice() int

The absolute minimum price that may occur.

func (*PriceSeries) PriceChance

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

Implementation of HasSpike

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

func (*Spike) Has

func (spike *Spike) Has() bool

Whether the object has the potential for a Big Spike pattern

type SpikeChance

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

func (*SpikeChance) Breakdown

func (spike *SpikeChance) Breakdown() *SpikeChanceBreakdown

func (*SpikeChance) Chance

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

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

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

func (*SpikeChancesAll) Any

func (spikes *SpikeChancesAll) Any() HasSpikeChance

func (*SpikeChancesAll) Big

func (spikes *SpikeChancesAll) Big() HasSpikeChance

func (*SpikeChancesAll) Small

func (spikes *SpikeChancesAll) Small() HasSpikeChance

func (*SpikeChancesAll) SpikeRangeAll

func (spikes *SpikeChancesAll) SpikeRangeAll() *SpikeRangeAll

Converts from HasSpikeChancesAll to HasSpikeRangesAll

type SpikeHasAll

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

func (*SpikeHasAll) Any

func (spikes *SpikeHasAll) Any() HasSpike

func (*SpikeHasAll) Big

func (spikes *SpikeHasAll) Big() HasSpike

func (*SpikeHasAll) Small

func (spikes *SpikeHasAll) Small() HasSpike

type SpikeRange

Implementation of HasSpikeRange

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

func (*SpikeRange) End

func (spike *SpikeRange) End() PricePeriod

The last price period any spike pattern could occur.

func (*SpikeRange) Start

func (spike *SpikeRange) Start() PricePeriod

The first price period any spike pattern could occur.

type SpikeRangeAll

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

func (*SpikeRangeAll) Any

func (spike *SpikeRangeAll) Any() HasSpikeRange

func (*SpikeRangeAll) Big

func (spike *SpikeRangeAll) Big() HasSpikeRange

func (*SpikeRangeAll) Small

func (spike *SpikeRangeAll) Small() HasSpikeRange

Subdirectories

Name Synopsis
..
patterns
timeofday