mj

package module
v0.0.0-...-7b4344e Latest Latest
Warning

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

Go to latest
Published: Oct 3, 2023 License: MIT Imports: 11 Imported by: 0

README

mahjonggstats

Go Report Card PkgGoDev

Go program to display statistics from Gnome mahjongg.

Software architecture

This project uses a Model-View-Controller approach. Here are the types associated with each:

Model
  • History
  • HistoryLine
  • LevelHistory
View
  • View
Controller
  • Controller

The mainline is cmd/mahjonggstats.go.

References

Documentation

Index

Constants

View Source
const DEFAULT_FILENAME = ".local/share/gnome-mahjongg/history"

DEFAULT_FILENAME is the history file name in the user home directory

Variables

This section is empty.

Functions

func DateString

func DateString(t time.Time) string

DateString returns the time as a date-only string in yyyy-mm-dd format

func FormatTime

func FormatTime(seconds int) string

FormatTime creates a string with hh:mm:ss from the specified number of seconds

Types

type Controller

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

Controller contains the view and command line arguments.

func NewController

func NewController(view *View, args map[string]any) Controller

NewController creates a new Controller object using the specified view and command line arguments.

func (Controller) Run

func (c Controller) Run()

Run runs the application

type History

type History struct {
	// The history line record array
	Records []HistoryLine

	// A map of level names to LevelHistory objects
	Levels map[string]LevelHistory
}

History is a collection of HistoryLine records for this user from the gnome mahjongg history file.

func NewHistory

func NewHistory(loaders ...Loader) History

NewHistory creates a new History containing all user history records.

func (History) EarliestDate

func (h History) EarliestDate() time.Time

EarliestDate returns the date of the earliest record in the history. Panics if there is no history.

func (History) LatestDate

func (h History) LatestDate() time.Time

LatestDate returns the date of the latest record in the history. Panics if there is no history.

func (History) LevelNames

func (h History) LevelNames() []string

LevelNames returns the list of all distinct level names in this history. The list is sorted in ascending order of the mean game time of each level.

func (History) Load

func (h History) Load() []HistoryLine

Loads all history records.

This method can be patched with a mock object that provides hard-coded data (see unit tests).

type HistoryLine

type HistoryLine struct {
	GameDateTime time.Time
	LevelName    string
	Seconds      int
}

HistoryLine is a single record in mahjongg history. There is a file named "history" in ~/.local/share/gnome-mahjongg which contains a line for each completed game. This line contains:

  1. A date and time stamp in the format yyyy-mm-ddTHH:MM:SS-9999
  2. The name of the level (e.g., "easy", "overpass", etc.)
  3. The number of seconds it took to complete the game.

For example:

2023-01-04T22:12:03-0500 easy 209
2023-01-04T22:15:04-0500 easy 169
2023-01-04T22:20:38-0500 overpass 269
2023-01-06T14:31:35-0500 overpass 453
2023-01-06T16:36:48-0500 tictactoe 228
2023-01-06T16:42:17-0500 confounding 252
2023-01-06T17:01:03-0500 overpass 299
2023-01-06T17:07:52-0500 ziggurat 285
2023-01-06T17:13:49-0500 confounding 288

func NewHistoryLine

func NewHistoryLine(line string) (HistoryLine, error)

NewHistoryLine creates a new HistoryLine structure from a line in the mahjongg history file

func (HistoryLine) String

func (hl HistoryLine) String() string

String returns a string representation of the type

func (HistoryLine) TimeDate

func (hl HistoryLine) TimeDate() string

TimeDate returns the number of seconds found in this record in the format hh:mm:ss (MM/DD/YYYY)

type LevelHistory

type LevelHistory struct {
	LevelName string
	Records   []HistoryLine
}

LevelHistory is a list of history lines for a particular level.

func NewLevelHistory

func NewLevelHistory(levelName string, records []HistoryLine) LevelHistory

NewLevelHistory creates a new LevelHistory object with the specified name and history line records.

func (LevelHistory) Confidence

func (lh LevelHistory) Confidence() (float64, float64)

Confidence returns the low and high estimates of the time values for all records at a 95% confidence level.

func (LevelHistory) Count

func (lh LevelHistory) Count() int

Count returns the number of history lines in this level

func (LevelHistory) Mean

func (lh LevelHistory) Mean() float64

Mean returns the mean of the time values for all records.

func (LevelHistory) StandardDeviation

func (lh LevelHistory) StandardDeviation() float64

StandardDeviation returns the standard deviation of the time values for all records.

type Loader

type Loader interface {
	Load() []HistoryLine
}

Loader specifies the method(s) that a history line loader must implement. The History type implements the interface, and so do any mock objects used for testing.

type View

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

View presents the history on standard output.

func NewView

func NewView(model *History, args map[string]any) (View, error)

NewView creates a new View with the specified history model.

func (View) ShowAllLevels

func (v View) ShowAllLevels()

ShowAllLevels displays the history for each level.

func (View) ShowHeading

func (v View) ShowHeading()

ShowHeading displays the number of games between the earliest and latest date.

func (View) ShowLevelNames

func (v View) ShowLevelNames()

ShowLevelNames displays the level names.

func (View) ShowSummary

func (v View) ShowSummary()

ShowSummary displays a summary of average times for each level.

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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