-
DimensionName
: string dimension name in a matrix -
FeatureName
: string feature name in a matrix -
MatrixEntry
:id
: ID entry idranks
:{ [dimension: string]: { [feature: string]: Rank } }
entry ranksscores
:{ [dimension: string]: { [feature: string]: Score } }
entry scores
-
MatrixLeaderboardQueryFilter
: filter query resultsdimensions
?: DimensionName[] dimensions to include in the result. If undefined or empty, all dimensions will be includedfeatures
?: FeatureName[] features to include in the result. If undefined or empty, all features will be included
❗ Note: filters only affect the values returned, not the leaderboards searched (leaderboards searched are set using dimensionToSort
and featureToSort
)
client
: Redis connection objectbaseKey
: string prefix for the Redis key of all leaderboards in the matrixoptions
: LeaderboardMatrixOptions configurationdimensions
: DimensionDefinition[] dimensionsDimensionDefinition
:name
: DimensionName dimension name (string)cycle
?: PeriodicLeaderboardCycle cycle if the dimension is periodic
features
: FeatureDefinition[] featuresFeatureDefinition
:name
: FeatureName feature name (string)options
: LeaderboardOptions feature's leaderboard options
now
?: NowFunction: function to evaluate the current time for periodic leaderboards
const mlb = new LeaderboardMatrix(client, "mlb:test", {
dimensions: [
{ name: "global" },
{
name: "per-month",
cycle: 'monthly'
}
],
features: [{
name: "kills",
options: {
updatePolicy: 'replace',
sortPolicy: 'high-to-low'
}
}, {
name: "seconds",
options: {
updatePolicy: 'best',
sortPolicy: 'low-to-high'
}
}]
});
-
getLeaderboard(dimension: DimensionName, feature: FeatureName, time?: Date)
: Leaderboard |null
get a leaderboard in the matrixdimension
: DimensionName dimension namefeature
: FeatureName feature nametime
?: Date time (for periodic leaderboards). If not provided,now()
will be used
Note: returns null if the dimension/feature pair is invalid
-
getRawLeaderboard(dimension: DimensionName, feature: FeatureName)
: Leaderboard | PeriodicLeaderboard |null
get the raw leaderboard objectdimension
: DimensionName dimension namefeature
: FeatureName feature name
The difference with
getLeaderboard
is that you get the underlying periodic leaderboard wrapper instead of a specific leaderboard of a periodic cycle.
Remember that insert/update is the same operation.
-
update(entries: MatrixEntryUpdateQuery | MatrixEntryUpdateQuery[], dimensions?: DimensionName[], updatePolicy?: UpdatePolicy)
: Promise<any> update one or more entries. If one of the entries does not exists, it will be createdentries
: MatrixEntryUpdateQuery | MatrixEntryUpdateQuery[] entry or list of entries to updateMatrixEntryUpdateQuery
:id
: ID entry idvalues
:{ [feature: string] : number | Score }
features to update
dimensions
?: DimensionName[] filter the update to only this dimensions. If empty or undefined, all dimensions will be updatedupdatePolicy
?: UpdatePolicy override every default update policy only for this update
The update behaviour is determined by the sort and update policies of each leaderboard in the matrix (or overriden by
updatePolicy
)await mlb.update([{ id: "player-1", values: { kills: 27, time: 427 } }], ["global"]); // update only the global dimension
remove(ids: ID | ID[], dimensions?: DimensionName[], features?: FeatureName[])
: Promise<void> remove one or more entries from the leaderboardsids
: ID | ID[] ids to removedimensions
?: DimensionName[] dimensions to remove from. If empty or undefined, entries will be removed from all dimensionsfeatures
?: FeatureName[] features to remove from. If empty or undefined, entries will be removed from all features
find(ids: ID, filter?: MatrixLeaderboardQueryFilter)
: Promise<MatrixEntry | null> retrieve an entry. If it doesn't exist, it returns nullid
: ID entry idfilter
?: MatrixLeaderboardQueryFilter filter to apply
await mlb.find("player-1");
{ id: "player-1", ranks: { global: { kills: 1, time: 1 } }, scores: { global: { kills: 27, time: 427 } } }
When you retrieve a list of entries, you must specify the dimension and feature you want to sort. Then the filter is applied and you can retrieve data from all other leaderboards in the matrix.
-
list(dimensionToSort: DimensionName, featureToSort: FeatureName, lower: Rank, upper: Rank, filter?: MatrixLeaderboardQueryFilter)
: Promise<MatrixEntry[]> retrieve entries between ranksdimensionToSort
: DimensionName dimension to perform the sortingfeatureToSort
: FeatureName feature to perform the sortinglower
: number lower bound to query (inclusive)upper
: number upper bound to query (inclusive)filter
?: MatrixLeaderboardQueryFilter filter to apply
-
top(dimensionToSort: DimensionName, featureToSort: FeatureName, max: number = 10, filter?: MatrixLeaderboardQueryFilter)
: Promise<MatrixEntry[]> retrieve the top entriesdimensionToSort
: DimensionName dimension to perform the sortingfeatureToSort
: FeatureName feature to perform the sortingmax
?: number max number of entries to returnfilter
?: MatrixLeaderboardQueryFilter filter to apply
-
bottom(dimensionToSort: DimensionName, featureToSort: FeatureName, max: number = 10, filter?: MatrixLeaderboardQueryFilter)
: Promise<MatrixEntry[]> retrieve the bottom entries (from worst to better)dimensionToSort
: DimensionName dimension to perform the sortingfeatureToSort
: FeatureName feature to perform the sortingmax
?: number max number of entries to returnfilter
: MatrixLeaderboardQueryFilter filter to apply
-
around(dimensionToSort: DimensionName, featureToSort: FeatureName, id: ID, distance: number, fillBorders: boolean = false, filter?: MatrixLeaderboardQueryFilter)
: Promise<MatrixEntry[]> retrieve the entries around an entrydimensionToSort
: DimensionName dimension to perform the sortingfeatureToSort
: FeatureName feature to perform the sortingid
: ID id of the entry at the centerdistance
: number number of entries at each side of the queried entryfillBorders
?: FeatureName include entries at the other side if the entry is too close to one of the bordersfilter
?: MatrixLeaderboardQueryFilter filter to apply
For details, see the simple leaderboard version of
around()
. -
showcase(dimensionOrder: DimensionName[], featureToSort: FeatureName, threshold: number, filter: MatrixLeaderboardQueryFilter)
: Promise<MatrixShowcase | null> returns the topthreshold
entries from a leaderboard that has at leastthreshold
entriesdimensionOrder
: DimensionName[] order to test the dimensionsfeatureToSort
: FeatureName feature to perform the sortingthreshold
: number minimum number of entries that should be present in the leaderboardfilter
?: MatrixLeaderboardQueryFilter filter to apply
The
dimensionOrder
defines the order to check the leaderboards, andfeatureToSort
the feature (which is fixed).
If no dimension meet the threshold, then the dimension with the highest number of entries will be used to query the entries.
If all dimensions have 0 entries, then returns nullNote: this function actually does two round trips to Redis!
MatrixShowcase
:dimension
: DimensionName dimension chosenfeature
: FeatureName feature chosenentries
: MatrixEntry[] entries
count()
: Promise<MatrixCount> retrieve the number of entries in each leaderboardMatrixCount
:{ [dimension: string ]: { [feature: string]: number } }