asobi_player_stats (asobi v0.84.0)
View SourceSummary
Functions
Fold one finished match into every participant's stats row (asobi#329).
Functions
-spec associations() -> [#kura_assoc{name :: atom(), type :: belongs_to | has_one | has_many | many_to_many, schema :: module(), foreign_key :: atom() | undefined, ref :: #kura_ref{fields :: [atom()] | undefined, target :: module() | undefined, target_key :: [atom()] | undefined} | undefined, join_through :: binary() | module() | undefined, join_keys :: {atom() | [atom()], atom() | [atom()]} | undefined, through :: [atom()] | undefined, on_delete :: kura_schema:on_delete() | undefined}].
-spec generate_id() -> binary().
-spec init(binary()) -> ok.
Fold one finished match into every participant's stats row (asobi#329).
games_played moves for every participant. wins and losses come from
the result map the game module returned with {finished, Result, State},
which asobi reads for exactly these keys - accepted as atoms or binaries,
because a Lua game's result arrives with binary keys:
winners(list of player ids) orwinner(one player id)losers(list of player ids) orloser(one player id)
Ids that are not in the match roster are ignored. When winners are
declared and losers are not, every other participant is recorded as a
loss; declare losers => [] for a game where losing is not a thing. A
result declaring neither only moves games_played, which is what a draw,
a co-op run, or an unscored sandbox should do.
rating and rating_deviation are deliberately untouched - asobi has no
rating algorithm, and the column names imply a specific one.
Must be called inside asobi_repo:transaction/1 alongside the write that
makes the match final, so the counters cannot drift from the match record.
-spec table() -> binary().