sol.models.tourney -- Tournaments

class sol.models.tourney.Rank(points, bucholz, netscore, totscore, position, rate)
bucholz: int

Alias for field number 1

netscore: int

Alias for field number 2

points: int

Alias for field number 0

position: int

Alias for field number 4

rate: int

Alias for field number 5

totscore: int

Alias for field number 3

class sol.models.tourney.RankingStats(retired)

An interim object used keep the ongoing values needed to compute the ranking of a single competitor.

drawn() None

Update stats after a tie.

lost(netscore: int) None

Update stats after a lost match.

rank(position: int | None, rate: int | None) Rank

Return the final Rank.

won(netscore: int, against_phantom: bool) None

Update stats after a winned match.

bucholz

Bucholz.

netscore

Net score.

played_matches

Number of played matches.

points

Overall points.

real_points

Points made against real competitors.

retired

Whether it is a retired competitor.

totscore

Total score.

virtual_points

Estimated further points, after retirement.

class sol.models.tourney.Tourney(**kwargs)

A single tournament.

class AbstractVisitor(tourney, pivot, competitors, done)

Abstract visitor.

Parameters:
  • tourney -- a Tourney instance

  • pivot -- a Competitor instance

  • competitors -- a list of possible opponents

  • done -- the set of already played pairings

This is an iterator class, used by the method Tourney._combine(): it yields all possible competitors to pivot in some order, without repeating already played matches present in done, a set containing previous matches (both (a, b) and (b, a)).

The iteration honors the tourney's delaycompatriotpairing: when True, players with the same nationality of the pivot will be considered last.

Concrete subclasses must reimplement the method computeVisitOrder(), that determines the actual order.

computeVisitOrder()

Return a sequence of positions, the indexes into the list self.competitors.

class RoundrobinSeedsVisitor(tourney, pivot, competitors, done)

Visit the competitors in reverse order.

Given that the list of competitors is sorted by their rank, this emits the usual Round-robin pairings.

computeVisitOrder()

Return a sequence of positions, the indexes into the list self.competitors.

class SwissDazedVisitor(tourney, pivot, competitors, done)

Visit the competitors, giving precedence to the competitors with the same points.

This starts looking at the competitors with the same points as the pivot, and then goes on with the others: this is to postpone as much as possible the match between the strongest competitors.

computeVisitOrder()

First count how many competitors have the same points as the pivot, then if possible iterate over the second half of them, then over the first half, and finally over the remaining ones.

countSamePointsAsPivot()

Return the count of competitors with the same points as the pivot.

class SwissSerialVisitor(tourney, pivot, competitors, done)

Visit the competitors in order.

Given that the list of competitors is sorted by their rank, this effectively tries to combine players with the same strength.

computeVisitOrder()

Simply return range(len(self.competitors)).

class SwissStaggeredVisitor(tourney, pivot, competitors, done)

Visit the competitors, giving precedence to the competitors with the same points.

This is similar to DazedVisitor except that when there are 50 or more competitors with the same points, instead of splitting them in two halves of the same size it uses an arbitrary offset of 25 (i.e. the 1st competitor is paired with the 26th, the 2nd with the 27th, and so on): this should placate the gripes about unfair pairings between strongest and weakest competitors at the first turn.

computeVisitOrder()

First count how many competitors have the same points as the pivot, then if possible iterate over the second half of them, then over the first half, and finally over the remaining ones.

_addMatches(turn: int, pairings: Iterable[tuple[Competitor, Competitor | None]]) None

Add matches to the tourney for the given turn as indicated by pairings.

_areFinalTurnsEnoughForPrizing() tuple[bool, int, Counter[Competitor]]

Determine whether final rounds are enough to complete the tourney with prize-giving.

_assignAsisPrizes()

Assign decreasing integer numbers as final prizes, down to 1 to the last competitor.

_assignBoards(matches) None

Assign a table to each match, possibly the least used by both competitors.

_assignCentesimalPrizes()

Assigns 100 to the winner, 1 to the last, linear interpolation to the others.

_assignFixed40Prizes()

Assign fixed prizes to the first 40 competitors.

_assignFixedPrizes(prizes=None)

Assign fixed prizes to the first 16 competitors.

_assignMillesimalPrizes()

Assign 1000 points to the winner stepping down in fixed amount.

_combine(competitors: list[Competitor | None], done: set[tuple[Competitor, Competitor | None]], _level=0) list[tuple[Competitor, Competitor | None]]

Build the next round, based on current ranking.

This recursively tries to build the next round, pairing together competitors that did not already played against each other.

_computeFinalWins() tuple[int, Counter[Competitor]]

Compute the number of matches won by each competitor in the finals

_makeAllTurns() None

Create all possible turns in a training tournament using the circle method.

_makeFirstKnockoutTurn() None

Create first turn of a knockout tourney.

_makeFirstTurn() None

Create the first round of a tourney, pairing competitors in a random way.

_makeNextAAATurn() None

Create next turn, out of all possible pairings.

_makeNextKnockoutTurn(competitors: list[Competitor | None]) list[tuple[Competitor, Competitor | None]]

Couple the first with the last, the second with the second-last and so on.

_makeNextRoundrobinCircleTurn() None

Create next round-robin turn mechanically pairing competitors using the circle method.

_makeNextTurn() None

Build the next round of the game.

allPlayers()

Generator that return all involved players.

assignPrizes()

Consolidate final points.

caption(html=None, localized=True)

Return a possibly HTML-decorated caption of the entity.

Parameters:
  • html -- either None (the default) or a boolean value

  • localized -- a boolean value, True by default

Return type:

str

If html is None or True then the result may be an HTML representation of the entity, otherwise it is plain text.

If localized is False then the localization is turned off.

classmethod check_insert(session: Session, fields: dict[str, Any], user_id: str | int) None

Check new tournament validity.

check_update(fields: dict[str, Any], user_id: str | int) None

Perform various validity checks.

computeRanking(turn=None) list[tuple[Competitor, Rank]]

Recompute competitors ranking.

Parameters:

turn -- if given, compute the ranking up to that turn

Returns:

a list of tuples, each containing one of the competitors and a Rank instance, sorted on the second item in descending order

Compute each competitor rank by examining the matches of this tourney, summing up each other's current ranking position as the bucholz.

createKnockout(date, ncompetitors, newidowner=None)

Create a "knockout" tourney with ncompetitors top players.

makeFinalTurn()

Generate the final matches.

makeNextTurn() None

Setup the next round.

If there are no matches, build up the first round using a random coupler. Otherwise, using current ranking, create the next round pairing any given competitor with a not-yet-met other one that follows him in the ranking.

replay(date, newidowner=None)

Clone this tourney, creating new one at given date.

Of the original, only the competitors are copied. This is particularly useful for doubles (or team), so that the players get copied in the same order.

resetPrizes()

Reset assigned final points.

serialize(serializer: Serializer) SerializedTourney

Reduce a single tourney to a simple dictionary.

Parameters:

serializer -- a Serializer instance

Return type:

dict

Returns:

a plain dictionary containing a flatified view of this tourney

updateRanking() None

Recompute and update competitors ranking.

_guid: Mapped[str]

An UUID key.

championship: Mapped[Championship]

The championship of this tournament.

competitors: Mapped[list[Competitor]]

List of competitors.

countdownstarted: Mapped[int | None]

Timestamp of the start of the clock countdown, milliseconds since Unix epoch.

couplings: Mapped[str]

Kind of pairing method used to build next round. It may be serial, dazed, staggered or seeds, the latter valid only for knockout or round-robin tourneys.

currentturn: Mapped[int]

The current round.

date: Mapped[dtdate]

Event date.

delaycompatriotpairing: Mapped[int]

Number of rounds for which pairing of players belonging to the same country should be postponed, if possible.

delaytoppairing: Mapped[int]

Number of rounds for which pairing of top players should be postponed, if possible.

description: Mapped[str]

Event description.

duration: Mapped[int]

Duration in minutes of each round, used by the clock.

finalkind: Mapped[str]

Kind of finals. It may be simple or bestof3.

finals: Mapped[int | None]

The number of finals that will be played.

finalturns: Mapped[bool]

Whether the tourney is in final rounds state.

property firstFinalTurn

The number of the first final match, if any.

hosting_club: Mapped[Club]

The club <.Club> that hosts this tourney.

idchampionship: Mapped[int]

Related championship's ID.

idhostingclub: Mapped[int | None]

Hosting club's ID.

idowner: Mapped[int | None]

ID of the user that is responsible for this record.

idrating: Mapped[int | None]

Possible rating ID this tourney uses and updates.

idtourney: Mapped[int]

Primary key.

location: Mapped[str | None]

Event location.

matches: Mapped[list[Match]]

List of matches, sorted by round and board.

matcheskind: Mapped[str]

Kind of matches. It may be simple or bestof3.

modified: Mapped[datetime]

Last update timestamp.

owner: Mapped[User | None]

The owner of this record, admin when None.

phantomscore: Mapped[int]

The score assigned to a player in matches against the Phantom.

prealarm: Mapped[int]

Prealarm before the end of the round.

prized: Mapped[bool]

Whether the tourney is closed, and final prizes updated.

rankedturn: Mapped[int]

The highest round considered in the ranking.

property ranking

Competitors sorted by their rank.

Return type:

sequence

Returns:

sorted list of competitors

rating: Mapped[Rating]

The rating used by this tourney.

retirements: Mapped[str]

Policy used to adjust the bucholz of competitors who played against withdrawn players.

socialurl: Mapped[str | None]

Social site URL.

system: Mapped[str]

The type of tournament, it may be swiss (the default), knockout or roundrobin.