// Standings returns the current Driver Standings for the Championship.
Standings returns the current Driver Standings for the Championship.
// Standings returns the current Driver Standings for the Championship .
func (c *ChampionshipClass) Standings(events []*ChampionshipEvent) []*ChampionshipStanding {
	var out []*ChampionshipStanding
	entrants := make(map[string]*ChampionshipStanding)
	if len(events) > 0 {
		for _, entrant := range c.Entrants {
			if entrants[entrant.GUID] == nil {
				entrants[entrant.GUID] = &ChampionshipStanding{
					Entrant: entrant,
				}
			}
		}
	}
	for _, event := range events {
		qualifying, qualifyingOK := event.Sessions[SessionTypeQualifying]
		if qualifyingOK && qualifying.Results != nil {
			for pos, driver := range c.ResultsForClass(qualifying.Results.Result) {
				if pos != 0 {
					continue
				}
				if _, ok := entrants[driver.DriverGUID]; ok {
					entrants[driver.DriverGUID].Points += float64(c.Points.PolePosition)
				}
			}
		}
		race, raceOK := event.Sessions[SessionTypeRace]
		if raceOK && race.Results != nil {
			fastestLap := race.Results.FastestLap()
			for pos, driver := range c.ResultsForClass(race.Results.Result) {
				if driver.TotalTime <= 0 {
					continue
				}
				if _, ok := entrants[driver.DriverGUID]; ok {
					entrants[driver.DriverGUID].Points += c.PointForPos(pos)
					if fastestLap.DriverGUID == driver.DriverGUID {
						entrants[driver.DriverGUID].Points += float64(c.Points.BestLap)
					}
				}
			}
		}
		race2, race2OK := event.Sessions[SessionTypeSecondRace]
		if race2OK && race2.Results != nil {
			fastestLap := race2.Results.FastestLap()
			for pos, driver := range c.ResultsForClass(race2.Results.Result) {
				if driver.TotalTime <= 0 {
					continue
				}
				if _, ok := entrants[driver.DriverGUID]; ok {
					entrants[driver.DriverGUID].Points += c.PointForPos(pos) * c.Points.SecondRaceMultiplier
					if fastestLap.DriverGUID == driver.DriverGUID {
						entrants[driver.DriverGUID].Points += float64(c.Points.BestLap) * c.Points.SecondRaceMultiplier
					}
				}
			}
		}
	}
	for _, entrant := range entrants {
		if entrant.Entrant.Name == "" {
			continue
		}
		out = append(out, entrant)
	}
	sort.Slice(out, func(i, j int) bool {
		if out[i].Points == out[j].Points {
			return out[i].Entrant.Name < out[j].Entrant.Name
		}
		return out[i].Points > out[j].Points
	})
	return out
}
func ( c * ChampionshipClass ) Standings ( events [ ] * ChampionshipEvent ) [ ] * ChampionshipStanding { var out [ ] * ChampionshipStanding entrants := make ( map [ string ] * ChampionshipStanding ) if len ( events ) > 0 { for _ , entrant := range c . Entrants { if entrants [ entrant . GUID ] == nil { entrants [ entrant . GUID ] = & ChampionshipStanding { Entrant : entrant , } } } } for _ , event := range events { qualifying , qualifyingOK := event . Sessions [ SessionTypeQualifying ] if qualifyingOK && qualifying . Results != nil { for pos , driver := range c . ResultsForClass ( qualifying . Results . Result ) { if pos != 0 { continue } if _ , ok := entrants [ driver . DriverGUID ] ; ok { entrants [ driver . DriverGUID ] . Points += float64 ( c . Points . PolePosition ) } } } race , raceOK := event . Sessions [ SessionTypeRace ] if raceOK && race . Results != nil { fastestLap := race . Results . FastestLap ( ) for pos , driver := range c . ResultsForClass ( race . Results . Result ) { if driver . TotalTime <= 0 { continue } if _ , ok := entrants [ driver . DriverGUID ] ; ok { entrants [ driver . DriverGUID ] . Points += c . PointForPos ( pos ) if fastestLap . DriverGUID == driver . DriverGUID { entrants [ driver . DriverGUID ] . Points += float64 ( c . Points . BestLap ) } } } } race2 , race2OK := event . Sessions [ SessionTypeSecondRace ] if race2OK && race2 . Results != nil { fastestLap := race2 . Results . FastestLap ( ) for pos , driver := range c . ResultsForClass ( race2 . Results . Result ) { if driver . TotalTime <= 0 { continue } if _ , ok := entrants [ driver . DriverGUID ] ; ok { entrants [ driver . DriverGUID ] . Points += c . PointForPos ( pos ) * c . Points . SecondRaceMultiplier if fastestLap . DriverGUID == driver . DriverGUID { entrants [ driver . DriverGUID ] . Points += float64 ( c . Points . BestLap ) * c . Points . SecondRaceMultiplier } } } } } for _ , entrant := range entrants { if entrant . Entrant . Name == " " { continue } out = append ( out , entrant ) } sort . Slice ( out , func ( i , j int ) bool { if out [ i ] . Points == out [ j ] . Points { return out [ i ] . Entrant . Name < out [ j ] . Entrant . Name } return out [ i ] . Points > out [ j ] . Points } ) return out }
Standings returns the current Driver Standings for the Championship.
Standings returns the current Driver Standings for the Championship .
// if an entrant is removed from a championship this can panic, hence the ok check // if an entrant is removed from a championship this can panic, hence the ok check // if an entrant is removed from a championship this can panic, hence the ok check