I'm novice in programming. Right now I'm developing my first app with Swift and Parse (for backend). My app is for the survey to know the confidence rating of the politician. The rating is equal to those who voted YES percentage within last day. I want to do all the math on the cloud and just send client the result (a number). So that I've researched the docs on Parse but not quite sure what to do. Below is my tryout (not successful though) and I hope you could help me to find and fix the problems.
So I have the score
class (table). A single score
object look like:
{
"objectID": 12eroi87,
"vote": 1, // or 0
"createdAt": Nov 5, 2014, 10:35 // Date
}
Now I have to build some cloud function to do all the math.
Parse.Cloud.define("confidenceRating", function(request, response) {
var query = new Parse.Query("score");
query.equalTo("vote", request.params.vote);
query.find({
success: function(results) {
var sum = 0;
for (var i = 0; i < results.length; ++i) {
sum += results[i].get("vote");
}
response.success(100 * sum / results.length);
},
error: function() {
response.error("something went wrong");
}
});
});
I'm aware the code above is some mess (( No idea how to cut the votes within last day. And finally I have no idea how to call the function with Swift.
Hope I could help! I'd appreciate much if you provide some useful links as well.