gear

package
v0.0.2 Latest Latest
Warning

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

Go to latest
Published: Jul 29, 2021 License: Unlicense Imports: 10 Imported by: 0

Documentation

Index

Constants

View Source
const (
	// ConversionFactorKGtoLBS is the weight of 1 KG in LBS
	ConversionFactorKGtoLBS float64 = 2.20462262185
)

Variables

View Source
var (
	// MensBarKG represents a standard men's 20 KG barbell
	MensBarKG = Bar{
		Weight: 20.0,
		Unit:   KG,
	}
	// MensBarLBS represents a standard men's 45 LBS barbell
	MensBarLBS = Bar{
		Weight: 45.0,
		Unit:   LBS,
	}
	// WomensBarKG represents a standard women's 15 KG barbell
	WomensBarKG = Bar{
		Weight: 15.0,
		Unit:   KG,
	}
	// WomensBarLBS represents a standard women's 35 LBS barbell
	WomensBarLBS = Bar{
		Weight: 35.0,
		Unit:   LBS,
	}
)
View Source
var (
	// DefaultGear is a map of default Gear structs
	DefaultGear = map[Unit]Gear{
		LBS: {
			Bar:    MensBarLBS,
			Plates: DefaultPlatesLBS,
			Unit:   LBS,
		},
		KG: {
			Bar:    MensBarKG,
			Plates: DefaultPlatesKG,
			Unit:   KG,
		},
	}
)
View Source
var DefaultPlatesKG = Plates{
	Weights: DefaultWeightsKB,
	Unit:    KG,
}

DefaultPlatesKG is the default set of plates in KB

View Source
var DefaultPlatesLBS = Plates{
	Weights: DefaultWeightsLBS,
	Unit:    LBS,
}

DefaultPlatesLBS is the default set of plates in LBS

View Source
var DefaultWeightsKB = []float64{
	1.25,
	2.5,
	5,
	10,
	15,
	20,
}

DefaultWeightsKB is the default set of weights in KB

View Source
var DefaultWeightsLBS = []float64{
	2.5,
	5,
	10,
	25,
	35,
	45,
}

DefaultWeightsLBS is the default set of weights in LBS

View Source
var (
	// ErrInputLessThanBar is an error message used to warn that a Rounding call requests
	// a value that is less than the weight of the empty bar, itself.
	ErrInputLessThanBar = errors.New("input weight is less than the minimum weight of the bar")
)
View Source
var (
	// ErrInvalidUnit error are for any uint that is not represented by KG or LBS
	ErrInvalidUnit = errors.New("invalid unit")
)
View Source
var (
	// ErrNoPlatesFound is the basic error for not finding plates.
	ErrNoPlatesFound = errors.New("no plates found")
)

Functions

func ConvertFromTo

func ConvertFromTo(w float64, from Unit, to Unit) (float64, error)

ConvertFromTo takes a float64 and a from and to unit and converts the float into the requested unit. For instance if you wanted to convert 55 lbs to kg, Convert(55.0, LBS, KG) would return 24.9476, nil.

func FormFields

func FormFields() (r template.HTML, err error)

FormFields returns an html snippet for choosing lifting gear for the submit form

func Recommend

func Recommend(weight float64, plates []float64) ([]float64, error)

Recommend takes a weight and a set of plates and returns a sorted recommendation of plates for one side of the bar

func ToValues

func ToValues(g Gear) (url.Values, error)

ToValues takes a Gear and returns properly formatted url.Values to be used in a get URL.

Types

type Bar

type Bar struct {
	Weight float64 `json:"weight"`
	Unit   Unit    `json:"unit"`
}

Bar contains the weight and units of a Barbell

func (Bar) ConvertTo

func (b Bar) ConvertTo(u Unit) (float64, error)

ConvertTo takes a Unit and returns the converted weight or an error. If the bar is already in requested unit, it simply returns the weight.

func (Bar) String

func (b Bar) String() string

String prints the human readable string format of the bar data structure

type Gear

type Gear struct {
	Bar    Bar    `json:"bar"`
	Plates Plates `json:"plates"`
	Unit   Unit   `json:"unit"`
}

Gear is a struct that represents the weight inputs for the Bar, Plates, and desired unites for the Gear to be measured in. Gear is primary used to calculate possible weight totals from a requested weight amount, and is meant to be used to convert a lift from a calculated percentage into the greatest possible incremental weight with the equipment provided.

func FromValues

func FromValues(vals url.Values) (g Gear, err error)

FromValues takes a set of values in `url.Values` format and returns gear and an error.

func (Gear) Min

func (g Gear) Min() (float64, error)

Min returns the minimum amount allowed for rounding. This is based on the bar weight converted to the Gear Units.

func (Gear) Recommend

func (g Gear) Recommend(weight float64) ([]float64, error)

Recommend takes

func (Gear) Round

func (g Gear) Round(weight float64) (float64, error)

Round takes a float64 number and returns the rounded total based on the bar and incremental plate weights, converted to the gear units. If the bar and incremental plates are in KG but the Gear units are LBS, the float64 will be returned in gear units of LBS.

func (Gear) String

func (g Gear) String() string

String outputs the string format for Gear.

func (Gear) Valid

func (g Gear) Valid() bool

Valid checks that all units used in Gear.Unit, gear.Plates.Unit, and gear.Bar.Unit, are valid all must be valid for a true response

type Plates

type Plates struct {
	Weights []float64 `json:"weights"`
	Unit    Unit      `json:"unit"`
}

Plates are are a set of plates and its corresponding unit.

func (*Plates) Add

func (p *Plates) Add(plate float64)

Add takes a plate and adds it to the set of weights.

func (Plates) Min

func (p Plates) Min() (float64, error)

Min gets the smallest increment of plate in the Weights slice.

func (*Plates) Remove

func (p *Plates) Remove(plate float64)

Remove takes a plate and removes it from the set of weights.

func (Plates) Round

func (p Plates) Round(weight float64) (float64, error)

Round takes a weight and uses its increment for rounding and doubles the increment to match the smallest increment per side of the bar. It returns the closest number below or even to the weight that is divisible by the doubled increment

func (Plates) String

func (p Plates) String() string

func (*Plates) Tidy

func (p *Plates) Tidy()

Tidy cleans up the plates by removing duplicates and sorting them

type Unit

type Unit uint

Unit is used to enumerate units for weights

const (
	// KG represents the metric unit Kilograms
	KG Unit = iota
	// LBS represents the imperial unit for pounds
	LBS
)

func UnitFromString

func UnitFromString(s string) (Unit, error)

UnitFromString takes a string and returns a unit or error

func (Unit) MarshalJSON

func (u Unit) MarshalJSON() ([]byte, error)

MarshalJSON is used for human readable json.

func (Unit) String

func (u Unit) String() string

String prints the human readable value from the enum

func (*Unit) UnmarshalJSON

func (u *Unit) UnmarshalJSON(b []byte) error

UnmarshalJSON is used to convert human readable json to a Unit type

func (Unit) Valid

func (u Unit) Valid() bool

Valid checks that a Unit is either KG or LBS and returns a boolean

Jump to

Keyboard shortcuts

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