ProcessStatistics
Apply statistics grammar to a partial set of statistics. Global statistics are defined through the brainCloud portal.
The operations available are much richer than the standard increment operation available via IncrementGlobalStats()
.
For example:
{
"INNING": "INC#1", // Increment by one
"INNINGSREM": "DEC#1", // Decrement by one
"OUTS": "RESET", // Reset to the defined initial value
"POINTS": "INC_TO_LIMIT#5#30", // Increment by 5, but to a max of 30
"PLAYERS": "SET#8", // Set to the specified value
"HIGHESTHR": "MAX#3", // Set to the specified value if larger
"ESTIMATE": "MIN#5", // Set to the specified value if smaller
"GAME" : "5" // Missing stat grammar will treat the operation as an increment
}
The above example would:
- Increment
INNING
by1
- Decrement
INNINGSREM
by1
- Reset
OUTS
to its pre-defined initial value - Increment
POINTS
by5
, but to a maximum of30
- Set
PLAYERS
to8
- Set
HIGHESTHR
to3
, or remain at current higher value - Set
ESTIMATE
to5
, or remain at current lower value - Increment
GAME
by5
For the full statistics grammar see the statistics grammar section.
Service | Operation |
---|---|
globalGameStatistics | PROCESS_STATISTICS |
Method Parameters
Parameter | Description |
---|---|
statistics | A collection containing the statistics to process |
Usage
http://localhost:3000
- C#
- C++
- Objective-C
- Java
- JavaScript
- Dart
- Cloud Code
- Raw
string statistics = "{\"INNING\":\"INC#1\",\"INNINGSREM\":\"DEC#1\",\"OUTS\":\"RESET\",\"POINTS\":\"INC_TO_LIMIT#5#30\",\"PLAYERS\":\"SET#8\",\"HIGHESTHR\":\"MAX#3\",\"ESTIMATE\":\"MIN#5\"}";
SuccessCallback successCallback = (response, cbObject) =>
{
Debug.Log(string.Format("Success | {0}", response));
};
FailureCallback failureCallback = (status, code, error, cbObject) =>
{
Debug.Log(string.Format("Failed | {0} {1} {2}", status, code, error));
};
_bc.GlobalGameStatisticsService.ProcessStatistics(statistics, successCallback, failureCallback);
const char *statistics = "{\"INNING\":\"INC#1\",\"INNINGSREM\":\"DEC#1\",\"OUTS\":\"RESET\",\"POINTS\":\"INC_TO_LIMIT#5#30\",\"PLAYERS\":\"SET#8\",\"HIGHESTHR\":\"MAX#3\",\"ESTIMATE\":\"MIN#5\"}";
_bc->getGlobalGameStatisticsService()->processStatistics(statistics, this);
NSString *statistics = @"{\"INNING\":\"INC#1\",\"INNINGSREM\":\"DEC#1\",\"OUTS\":\"RESET\",\"POINTS\":\"INC_TO_LIMIT#5#30\",\"PLAYERS\":\"SET#8\",\"HIGHESTHR\":\"MAX#3\",\"ESTIMATE\":\"MIN#5\"}";
BCCompletionBlock successBlock; // define callback
BCErrorCompletionBlock failureBlock; // define callback
[[_bc globalGameStatisticsService] processStatistics:statistics
completionBlock:successBlock
errorCompletionBlock:failureBlock
cbObject:nil];
String statistics = "{\"INNING\":\"INC#1\",\"INNINGSREM\":\"DEC#1\",\"OUTS\":\"RESET\",\"POINTS\":\"INC_TO_LIMIT#5#30\",\"PLAYERS\":\"SET#8\",\"HIGHESTHR\":\"MAX#3\",\"ESTIMATE\":\"MIN#5\"}";
this; // implements IServerCallback
_bc.getGlobalGameStatisticsService().processStatistics(statistics, this);
public void serverCallback(ServiceName serviceName, ServiceOperation serviceOperation, JSONObject jsonData)
{
System.out.print(String.format("Success | %s", jsonData.toString()));
}
public void serverError(ServiceName serviceName, ServiceOperation serviceOperation, int statusCode, int reasonCode, String jsonError)
{
System.out.print(String.format("Failed | %d %d %s", statusCode, reasonCode, jsonError.toString()));
}
var statistics = {
"INNING": "INC#1",
"INNINGSREM": "DEC#1",
"OUTS": "RESET",
"POINTS": "INC_TO_LIMIT#5#30",
"PLAYERS": "SET#8",
"HIGHESTHR": "MAX#3",
"ESTIMATE": "MIN#5"
};
_bc.globalGameStatistics.processStatistics(statistics, result =>
{
var status = result.status;
console.log(status + " : " + JSON.stringify(result, null, 2));
});
var statistics = {
"INNING": "INC#1",
"INNINGSREM": "DEC#1",
"OUTS": "RESET",
"POINTS": "INC_TO_LIMIT#5#30",
"PLAYERS": "SET#8",
"HIGHESTHR": "MAX#3",
"ESTIMATE": "MIN#5"
};
ServerResponse result = await _bc.globalGameStatisticsService.processStatistics(statistics:statistics);
if (result.statusCode == 200) {
print("Success");
} else {
print("Failed ${result.error['status_message'] ?? result.error}");
}
var statistics = {
"INNING": "INC#1",
"INNINGSREM": "DEC#1",
"OUTS": "RESET",
"POINTS": "INC_TO_LIMIT#5#30",
"PLAYERS": "SET#8",
"HIGHESTHR": "MAX#3",
"ESTIMATE": "MIN#5"
};
var globalStatisticsProxy = bridge.getGlobalStatisticsServiceProxy();
var postResult = globalStatisticsProxy.processStatistics(statistics);
if (postResult.status == 200) {
// Success!
}
var statistics = {
"INNING": "INC#1",
"INNINGSREM": "DEC#1",
"OUTS": "RESET",
"POINTS": "INC_TO_LIMIT#5#30",
"PLAYERS": "SET#8",
"HIGHESTHR": "MAX#3",
"ESTIMATE": "MIN#5"
};
var globalStatisticsProxy = bridge.getGlobalStatisticsServiceProxy();
var postResult = globalStatisticsProxy.processStatistics(statistics);
if (postResult.status == 200) {
// Success!
}
JSON Response
{
"data": {
"statisticsExceptions": {
"INNINGSREM": "minApplied"
},
"statistics": {
"OUTS": 0,
"HIGHESTHR": 4,
"PLAYERS": 8,
"INNINGSREM": 0,
"INNING": 2,
"POINTS": 11,
"ESTIMATE": 5
}
},
"status": 200
}