Reduce¶
The reduce system takes key:value
pairs as input from the map
operation. The input needs to meet certain conditions and the reduce
produces a new set of key:value
pairs. The reduce operation can be
either min
, max
, count
, sum
or average
. The output
of the reduce operation consists in a summary of all the inputs that
were processed.
For example, the following reduction counts the reactions by player:
{
"id": "countByPlayerReaction",
"where": {
"key": ["players", "<playerId>", "reaction"],
"name": "<reaction>"
},
"key": ["reaction", "<playerId>", "<reaction>"],
"values": ["$count"],
"period": 250
}
The reduction output would look like this:
[
{"key": ["reaction", "playerA", "like"], "value": {"count": 8}},
{"key": ["reaction", "playerA", "love"], "value": {"count": 3}},
{"key": ["reaction", "playerA", "sad"], "value": {"count": 5}},
{"key": ["reaction", "playerA", "mad"], "value": {"count": 1}},
{"key": ["reaction", "playerB", "like"], "value": {"count": 22}},
{"key": ["reaction", "playerB", "love"], "value": {"count": 10}},
{"key": ["reaction", "playerB", "sad"], "value": {"count": 1}},
{"key": ["reaction", "playerB", "mad"], "value": {"count": 4}}
]
Reduce schema¶
id¶
Some string uniquely referencing the reduction rule, for possible modification after its creation.
where¶
Conditions to be met in order to produce another key:value
pair.
See Where schema for details.
period¶
The period in milliseconds. Determines the frequency of the reduction. A 250 ms period would means that the game would received the reduce 4 times per seconds.
key¶
An array of strings representing the new key produced.
Each string can be either:
- Alphanumeric string: A plain literal value.
<anyText>
: A named value taken from the input key.
value¶
An array of operations used to merge the inputs and generate the outputs. Each operation listed will produce one output.
Possible operations are:
$min
: Returns the minimum value among all inputs.$max
: Returns the maximum value among all inputs.$count
: Returns the number of times the key was encountered.$sum
: Returns the sum of all input values added together.