Utils

package
v0.0.0-...-4997d78 Latest Latest
Warning

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

Go to latest
Published: May 31, 2021 License: MIT Imports: 11 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var Cache = make(map[string]CacheType)
View Source
var NameAdjustments = map[string]string{}

A list of incorrect -> correct name mappings, use this as last resort to fix incorrect/inconsistent names

Functions

func ConvertDate

func ConvertDate(date string) string

func FixName

func FixName(c string) string

func ForecastHandler

func ForecastHandler(w http.ResponseWriter, r *http.Request)

func IndexHandler

func IndexHandler(w http.ResponseWriter, r *http.Request)

func LoadIndex

func LoadIndex(I *Index) (modtime time.Time, err error)

func LoadRaces

func LoadRaces(dst string, R *Races) (modtime time.Time, err error)

func LoadSummary

func LoadSummary(dst string, S *Summary) (modtime time.Time, err error)

func LoadURL

func LoadURL(url string, f func(io.Reader) (interface{}, error)) (val interface{}, err error)

func MapHandler

func MapHandler(w http.ResponseWriter, r *http.Request)

func RacesHandler

func RacesHandler(w http.ResponseWriter, r *http.Request)

func SummaryHandler

func SummaryHandler(w http.ResponseWriter, r *http.Request)

func ValueHandler

func ValueHandler(w http.ResponseWriter, r *http.Request, name string, loadValue func(map[string]string) (interface{}, time.Time, error), writeValue func(http.ResponseWriter, interface{}, map[string]string))

func WriteForecastScript

func WriteForecastScript(w http.ResponseWriter)

func WriteHtmlFooter

func WriteHtmlFooter(w http.ResponseWriter)

func WriteHtmlHeader

func WriteHtmlHeader(w http.ResponseWriter, name string, refresh, plot, maps bool)

func WriteHtmlLines

func WriteHtmlLines(w http.ResponseWriter, text []string)

func WriteHtmlScript

func WriteHtmlScript(w http.ResponseWriter, script string)

func WriteMapScript

func WriteMapScript(w http.ResponseWriter)

Types

type CacheType

type CacheType struct {
	Value    interface{}
	ModTime  time.Time
	LastLoad time.Time
}

type CandidateForecast

type CandidateForecast struct {
	Candidate          string  `json:"candidate"`
	ConcentrationParam float64 `json:"concentration_param"` // Dirichlet distribution params
	Odds               float64 `json:"odds"`
}

type CombinedUpdater

type CombinedUpdater []UpdaterDst

func (CombinedUpdater) Update

func (U CombinedUpdater) Update(dst string) (Summary, error)

type DateRace

type DateRace struct {
	Name string
	Date string
	Race string
}

type Forecast

type Forecast []CandidateForecast

func (Forecast) Equal

func (F Forecast) Equal(F2 Forecast) bool

func (Forecast) GetText

func (F Forecast) GetText(thresh float64) []string

func (Forecast) SetOdds

func (F Forecast) SetOdds(sims uint64)

func (Forecast) Sort

func (F Forecast) Sort()

type Index

type Index []DateRace

func (Index) GetText

func (I Index) GetText() []string

type MultiUpdater

type MultiUpdater []UpdaterDst

func (MultiUpdater) Update

func (U MultiUpdater) Update(dst string) error

type Race

type Race struct {
	Name string `json:"name"`
	Race string `json:"race"`
}

type Races

type Races []Race

func (Races) GetText

func (R Races) GetText(date string, other bool) []string

type RegionCandidate

type RegionCandidate struct {
	Candidate string `json:"candidate"`
	Votes     uint64 `json:"votes"`
}

type RegionVote

type RegionVote struct {
	Candidates      []RegionCandidate `json:"candidates"`
	TotalVotes      uint64            `json:"total_votes"`
	PortionComplete float64           `json:"portion_complete"`
}

type RegionVotePriority

type RegionVotePriority struct {
	RegionVote
	Priority map[string]int
}

func (RegionVotePriority) Len

func (S RegionVotePriority) Len() int

func (RegionVotePriority) Less

func (S RegionVotePriority) Less(i, j int) bool

func (RegionVotePriority) Swap

func (S RegionVotePriority) Swap(i, j int)

type Summary

type Summary struct {
	SummaryDefaults `json:",inline"`
	SummaryVote     `json:",inline"`
	Regions         map[string]SummaryRegion `json:"regions,omitempty"`
	Forecast        Forecast                 `json:"forecast,omitempty"`
	ForecastWeight  float64                  `json:"forecast_weight"`
}

func CombineSummaries

func CombineSummaries(Defaults SummaryDefaults, Ss ...Summary) Summary

func (Summary) Equal

func (A Summary) Equal(B Summary) bool

func (Summary) GetText

func (S Summary) GetText(date, race string) []string

func (Summary) SaveToFile

func (S Summary) SaveToFile(dst string) error

func (Summary) Sort

func (S Summary) Sort()

type SummaryCandidate

type SummaryCandidate struct {
	Candidate   string `json:"candidate"`
	Votes       uint64 `json:"votes"`
	PartyLetter string `json:"party_letter"`
	Winner      bool   `json:"winner"`
}

type SummaryDefaults

type SummaryDefaults struct {
	Name               string            `json:"name"`
	PrefixText         []string          `json:"prefix_text"`
	SuffixText         []string          `json:"suffix_text"`
	VotePortionThresh  float64           `json:"vote_portion_thresh"`
	MapPortionThresh   float64           `json:"map_portion_thresh"`
	OddsThresh         float64           `json:"odds_thresh"`
	GraphPortionThresh float64           `json:"graph_portion_thresh"`
	GraphOddsThresh    float64           `json:"graph_odds_thresh"`
	Colors             map[string]string `json:"colors"`
	Priority           map[string]int    `json:"priority"`
	OtherRaces         Races             `json:"other_races,omitempty"`
	ShowDate           bool              `json:"show_date"`
	ShowMap            bool              `json:"show_map"`
}

type SummaryRegion

type SummaryRegion struct {
	RegionVote `json:",inline"`
	Name       string `json:"name"`
	Exclude    bool   `json:"exclude"`
}

type SummaryVote

type SummaryVote struct {
	Candidates      []SummaryCandidate `json:"candidates"`
	TotalVotes      uint64             `json:"total_votes"`
	PortionComplete float64            `json:"portion_complete"`
}

type SummaryVotePriority

type SummaryVotePriority struct {
	SummaryVote
	Priority map[string]int
}

func (SummaryVotePriority) Len

func (S SummaryVotePriority) Len() int

func (SummaryVotePriority) Less

func (S SummaryVotePriority) Less(i, j int) bool

func (SummaryVotePriority) Swap

func (S SummaryVotePriority) Swap(i, j int)

type Updater

type Updater interface {
	Update(dst string) (Summary, error)
}

type UpdaterDst

type UpdaterDst struct {
	U   Updater
	Dst string
}

Jump to

Keyboard shortcuts

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