Vote Result Analytics Function
Goal
This function receives a JSON object detailing vote distribution retrieved from a database query. Its purpose is to process this data, calculate various statistics, and compile them into a structured JSON object.
Statistics to calculate
- Majority: Determines whether the yes or no votes obtained more than 50% + 1 of the total votes.
- Vote Rates: Includes percentages of yes, no, and abstain votes.
- Various Majority Types: Simple, absolute, and supermajority conditions.
- Consensus: Flags indicating whether yes or no votes achieved consensus.
Various Majorities
- Simple Majority: Requires 50% + 1 of counted votes (abstain votes are not taken into account).
- Absolute Majority: Requires 50% + 1 of ALL votes (abstain votes are counted).
- Super majority: Contains conditions:
- "2 3": Flags if a vote received two-thirds of the vote.
- "3 4": Flags if a vote received three-fourths of the vote.
- "4 5": Flags if a vote received four-fifths of the vote.
Return JSON format
{
"total votes":99,
"yes":33,
"no":33,
"pass":33,
"percentages":{
"yes":33.3,
"no":33.3,
"pass":33.3
},
"majority":{
"simple majority":{
"yes":false,
"no":true,
"pass":false
},
"absolute majority":{
"yes":false,
"no":false
},
"supermajority":{
"2 3":{
"yes":false,
"no":false
},
"3 4":{
"yes":false,
"no":false
},
"4 5":{
"yes":false,
"no":false
}
}
},
"consensus":{
"yes":false,
"no":false
}
}
Arguments
- JSON Object: Contains the count of voters and the count of specified votes (yes, no, abstain).
Returns
- JSON Object: Contains all calculated statistics pertinent to the specified vote.
Function Name: calculateVoteStatistics
Vote Result Analytics Function
Goal
This function receives a JSON object detailing vote distribution retrieved from a database query. Its purpose is to process this data, calculate various statistics, and compile them into a structured JSON object.
Statistics to calculate
Various Majorities
Return JSON format
{ "total votes":99, "yes":33, "no":33, "pass":33, "percentages":{ "yes":33.3, "no":33.3, "pass":33.3 }, "majority":{ "simple majority":{ "yes":false, "no":true, "pass":false }, "absolute majority":{ "yes":false, "no":false }, "supermajority":{ "2 3":{ "yes":false, "no":false }, "3 4":{ "yes":false, "no":false }, "4 5":{ "yes":false, "no":false } } }, "consensus":{ "yes":false, "no":false } }Arguments
Returns
Function Name:
calculateVoteStatistics