loto

package
v2.1.0 Latest Latest
Warning

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

Go to latest
Published: Apr 14, 2026 License: GPL-3.0 Imports: 10 Imported by: 0

Documentation

Overview

Package loto provide all specificities to load data(s) for the loto game. csvconverter allow to convert csv data model into loto model. decoder allow to read and parse csv file into csv data model.

Index

Constants

View Source
const (
	NumBallInOldVersion = 7
	NumBallInDraw       = 5
)

NumBall set the expected balls in a Draw depends of the Old loto rules or the actual.

View Source
const (
	NumRankInVersion0           = 7
	NumRankInVersion1           = 7
	NumRankInVersion2           = 6
	NumRankInVersion3           = 9
	NumRankInVersion4           = 9
	NumRankInVersion4SecondDraw = 4
)

NumRank is the number rank available by lottery version.

Variables

View Source
var (
	ErrInvalidOBJInstanceConverter = errors.New("invalid csv instance to conversion")
	ErrUnknownLotteryVersion       = errors.New("invalid lottery version")
	ErrNilOBJInstance              = errors.New("obj instance can't be nil")
	ErrInvalidMetadata             = errors.New("invalid metadata to conversion into LotteryDraw")
	ErrEmptyDate                   = errors.New("date is empty")
	ErrEmptyDay                    = errors.New("day is empty")
	ErrUnknownDay                  = errors.New("day is unknown")
	ErrEmptyCurrency               = errors.New("currency is empty")
	ErrUnknownCurrency             = errors.New("currency is unknown")
)

Public error used to convert csv data type to loto model type.

View Source
var (
	ErrNilSource                = errors.New("source is nil")
	ErrInvalidSourceReader      = errors.New("invalid source reader")
	ErrInvalidDataset           = errors.New("invalid dataset")
	ErrFailedToReadFile         = errors.New("failed to read file from source")
	ErrFailedToParseCSV         = errors.New("failed to parse csv file")
	ErrFailedToCreateCSVReader  = errors.New("failed to create csv reader")
	ErrFailedToCreateCSVDecoder = errors.New("failed to create csv decoder")
	ErrFailedToDecodeCSVData    = errors.New("failed to decode csv data")

	ErrDataMissingInCSVContext = errors.New("data missing in the csv context")
	ErrDataTypeInCSVContext    = errors.New("data with an invalid type in csv context")
	ErrInvalidDatasetVersion   = errors.New("invalid dataset version to create new instance")

	ErrMissingWarningInCSVContext = errors.New("warning missing in the csv context")
	ErrInvalidWarningInCSVContext = errors.New("invalid warning in csv context")
)

Public error for decoder operations.

View Source
var Datasets = map[DatasetIdentifier]DatasetInfo{
	GrandLotoUUID:       {Type: GrandLotto, Version: LotteryV3},
	GrandLotoNoelUUID:   {Type: XmasLotto, Version: LotteryV3},
	SuperLoto199605UUID: {Type: SuperLotto, Version: LotteryV0},
	SuperLoto200810UUID: {Type: SuperLotto, Version: LotteryV2},
	SuperLoto201703UUID: {Type: SuperLotto, Version: LotteryV3},
	SuperLoto201907UUID: {Type: SuperLotto, Version: LotteryV3},
	Loto197605UUID:      {Type: NewLotto, Version: LotteryV1},
	Loto200810UUID:      {Type: NewLotto, Version: LotteryV2},
	Loto201703UUID:      {Type: NewLotto, Version: LotteryV3},
	Loto201902UUID:      {Type: NewLotto, Version: LotteryV3},
	Loto201911UUID:      {Type: NewLotto, Version: LotteryV4},
}

Datasets define a base of know history files which should be parsed.

Functions

This section is empty.

Types

type DatasetIdentifier

type DatasetIdentifier string

DatasetIdentifier is the url path for a specific history file.

const (
	GrandLotoUUID       DatasetIdentifier = "1a2b3c4d-9876-4562-b3fc-2c963f66afg6"
	GrandLotoNoelUUID   DatasetIdentifier = "1a2b3c4d-9876-4562-b3fc-2c963f66aff6"
	SuperLoto199605UUID DatasetIdentifier = "1a2b3c4d-9876-4562-b3fc-2c963f66afh6"
	SuperLoto200810UUID DatasetIdentifier = "1a2b3c4d-9876-4562-b3fc-2c963f66afi6"
	SuperLoto201703UUID DatasetIdentifier = "1a2b3c4d-9876-4562-b3fc-2c963f66afj6"
	SuperLoto201907UUID DatasetIdentifier = "1a2b3c4d-9876-4562-b3fc-2c963f66afk6"
	Loto197605UUID      DatasetIdentifier = "1a2b3c4d-9876-4562-b3fc-2c963f66afl6"
	Loto200810UUID      DatasetIdentifier = "1a2b3c4d-9876-4562-b3fc-2c963f66afm6"
	Loto201703UUID      DatasetIdentifier = "1a2b3c4d-9876-4562-b3fc-2c963f66afn6"
	Loto201902UUID      DatasetIdentifier = "1a2b3c4d-9876-4562-b3fc-2c963f66afo6"
	Loto201911UUID      DatasetIdentifier = "1a2b3c4d-9876-4562-b3fc-2c963f66afp6"
)

UUIDs for the different lotto history datasets from the FDJ API. Used in the URL to fetch the source.

func DatasetIdentifiers

func DatasetIdentifiers() []DatasetIdentifier

DatasetIdentifiers return all history files identifiers.

type DatasetInfo

type DatasetInfo struct {
	Type    LottoType
	Version LotteryVersion
}

DatasetInfo define a type and version to target the rules to used for decode a csv history file.

type Decoder

type Decoder interface {
	// Decode the CSV file configured during the call to NewDecoder / NewDecoderWithDataset.
	Decode() ([]*LotteryDraw, error)
	// UnusedFields return slice of header which are not used by LotteryDraw.Metadata.Identifier.
	UnusedFields() map[string][]string
}

Decoder is a factory to decode a csv file. Create a new Decoder with the NewDecoder function or NewDecoderWithDataset if you want target custom csv file.

func NewDecoder

func NewDecoder(src *source.Source) (Decoder, error)

NewDecoder decode the source parameter. It automatically get the associated dataset info to know the type and version used to decode data. If you decode a custom csv file, prefer calling the NewDecoderWithDataset function to provide the appropriate DatasetInfo.

func NewDecoderWithDataset

func NewDecoderWithDataset(src *source.Source, dataset DatasetInfo) (Decoder, error)

NewDecoderWithDataset take the source parameter and try to decode it with the DatasetInfo.

type Draw

type Draw struct {
	NumBalls     int32
	Balls        []int32
	LuckyBall    int32
	HasLuckyBall bool
	NumRanks     int32
	WinStats     map[WinRank]WinStat
}

Draw is the result for a draw section in a LotteryDraw.

type LotteryDraw

type LotteryDraw struct {
	Metadata      Metadata
	FirstDraw     Draw
	SecondDraw    Draw
	WinningCode   WinningCode
	HasSecondDraw bool
	JokerPlus     string
	JokerV1       string
	HasJokerV1    bool
}

LotteryDraw represents a lotto draw.

func CSVConverter

func CSVConverter(lottoType LottoType, version LotteryVersion, csvOBJ any) (*LotteryDraw, error)

CSVConverter to LotteryDraw model.

type LotteryVersion

type LotteryVersion string

LotteryVersion setup the configuration for the LotteryDraw. Depends on the LotteryVersion some elements exist or not (ex: second draw).

const (
	LotteryV0 LotteryVersion = "v0"
	LotteryV1 LotteryVersion = "v1"
	LotteryV2 LotteryVersion = "v2"
	LotteryV3 LotteryVersion = "v3"
	LotteryV4 LotteryVersion = "v4"
)

Lottery version supported value.

type LottoType

type LottoType string

LottoType allow to make a diff between classic lotto (new-lotto), grand lotto, super lotto and xmas lotto.

const (
	// SuperLotto is a super lotto event.
	SuperLotto LottoType = "super-lotto"
	// GrandLotto is a big lotto event.
	GrandLotto LottoType = "grand-lotto"
	// XmasLotto is a christmas lotto event.
	XmasLotto LottoType = "xmas-lotto"
	// NewLotto is a common type for the lotto. It define a basic game.
	NewLotto LottoType = "new-lotto"
)

type Metadata

type Metadata struct {
	FDJID          string
	Date           time.Time
	ForclosureDate time.Time
	Version        LotteryVersion
	Type           LottoType
	Day            model.Day
	Currency       model.Currency
	TirageOrder    int32
	IsOldType      bool
}

Metadata represents the metadata of a LotteryDraw.

type WinRank

type WinRank int8

WinRank type set the gain position.

const (
	Rank1 WinRank = 1
	Rank2 WinRank = 2
	Rank3 WinRank = 3
	Rank4 WinRank = 4
	Rank5 WinRank = 5
	Rank6 WinRank = 6
	Rank7 WinRank = 7
	Rank8 WinRank = 8
	Rank9 WinRank = 9
)

Rank is the different positions to gain something. example with the new lotto.WinRank1: one ball + lucky ball. Rank1: 5 balls with lucky ball. Rank2: 5 balls without lucky ball. Rank3: 4 balls with lucky ball. Rank4: 4 balls without lucky ball. Rank5: 3 balls with lucky ball. Rank6: 3 balls without lucky ball. Rank7: 2 balls with lucky ball. Rank8: 2 balls without lucky ball. Rank9: 1 or 0 balls with lucky ball.

type WinStat

type WinStat struct {
	Rate   float64
	Number int32
}

WinStat give the rate and number winner by rank.

type WinningCode

type WinningCode struct {
	Codes    []string
	Price    float64
	NumCodes int
}

WinningCode is a result for the winning codes for each LotteryDraw.

Directories

Path Synopsis
Package csv describe all formats available for the FDJ's lotto history.
Package csv describe all formats available for the FDJ's lotto history.

Jump to

Keyboard shortcuts

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