Reduce

The reduce system takes key:value pairs as input from the Map operation. When the input meets defined conditions, the reduce produces a new set of key:value pairs using a defined operation.

The reduce operation can be min, max, count, sum, or average. The output of the Reduce operation is a summary of all processed inputs.

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 output looks 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

A unique string that refers to the reduce. Used for modifying the reduce after its creation.

where

A schema defining the conditions that trigger producing a new key:value pair. See Where schema for more information.

period

The frequency of the reduction in milliseconds (ms). For example, a 250ms period means that the game would receive the reduce output 4 times per second.

key

An array of strings representing the new key. Each string can be:

  • Alphanumeric string: A plain literal value.
  • <anyText>: A named value taken from the input key.

value

An array of operations which merges the inputs and generates the outputs. Each operation listed produces 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.