sol.models.rating
-- Ratings¶
- class sol.models.rating.Rating(**kwargs)¶
A particular rating a tournament can be related to.
- classmethod check_insert(session: Session, fields: dict[str, Any], user_id: str | int) None ¶
Check new rating validity.
- check_update(fields: dict[str, Any], user_id: str | int) None ¶
Check validity of rating's changes.
- getPlayerRating(player: Player, before=None)¶
Return the rate of a player
- Parameters:
player -- a Player instance
before -- a date instance
- Return type:
an instance of glicko2.Rating
If before is not specified fetch the latest rate, otherwise the most recent one preceeding before.
The method considers the referenced rating as well as all those with an higher level.
- isPhantom(competitor: Competitor | None)¶
Determine whether the given competitor is actually a Phantom.
- Parameters:
competitor -- a Competitor instance
This is needed because someone uses a concrete player as Phantom, to customize its name (not everybody have a good sense of humor…)
- recompute(mindate=None, scratch=False)¶
Recompute the whole rating.
- Parameters:
mindate -- either
None
or a datescratch -- a boolean, True to recompute from scratch
If mindate is given, recompute the rating ignoring the tourneys before that date.
- serialize(serializer: Serializer) SerializedRating ¶
Reduce a single rating to a simple dictionary.
- Parameters:
serializer -- a
Serializer
instance- Return type:
dict
- Returns:
a plain dictionary containing a flatified view of this rating
- shouldConsiderTourney(tourney: Tourney)¶
Determine whether the given tourney should be considered.
- Parameters:
tourney -- a Tourney instance
Only singles using the Swiss System should be considered. Also, "online" tournaments are excluded.
- update(data, user_id, *, missing_only=False)¶
Update entity with given data.
- Parameters:
data -- a mapping kind of container
missing_only -- a boolean flag,
False
by defaultuser_id -- either the string "admin" or the ID of the user performing the operation
- Return type:
dict
- Returns:
a mapping between field name and a tuple
(oldvalue, newvalue)
, for each modified field
First call
check_update()
to assert the validity of incoming data, then update the instance fields.If missing_only is
True
then only the fields that are currently empty (that is, their value is eitherNone
or an empty string) are updated. Note that in this case an exception is made forbool
fields: since in SoL they always have a value (i.e. they are never missing), they are always updated.
- championships: Mapped[list[Championship]]¶
Championships
using this rating by default.
- default_deviation: Mapped[int]¶
Default value of deviation (PHI) for the Glicko2 algorithm.
- default_rate: Mapped[int]¶
Default value of rate (MU) for the Glicko2 algorithm.
- default_volatility: Mapped[Decimal]¶
Default value of volatility (SIGMA) for the Glicko2 algorithm.
- description: Mapped[str]¶
Description of the rating.
- higher_rate: Mapped[int]¶
Higher value of the range used to interpolate players rates.
- idrating: Mapped[int]¶
Primary key.
- inherit: Mapped[bool]¶
Whether to lookup rates in higher levels ratings.
- level: Mapped[str]¶
Rating level.
- lower_rate: Mapped[int]¶
Lower value of the range used to interpolate players rates when (almost) all competitors are unrated.
- modified: Mapped[datetime]¶
Last update timestamp.
- outcomes: Mapped[str]¶
Kind of formula used to compute match outcomes.
This is used to determine which formula will be used to compute the match outcomes to feed Glicko2 algorithm. It may be:
- glicko2
standard Glicko, giving 1.0 to the winner and 0.0 to the loser, 0.5 in case of draw, developed with Chess in mind;
- guido
Guido's variant, better suited to Carrom: basically each player is assigned a fraction of his own score divided by the sum of the scores of both players.
- property ranking¶
Players sorted by their latest rate.
- Return type:
sequence
- Returns:
a sorted list of tuples containing the
player
, its latest rate, deviation and volatility, and the number of rates in this rating.
- tau: Mapped[Decimal]¶
Value of TAU for the Glicko2 algorithm.
- property time_span¶
Return the time span of this rating.