Voting - A voter library for async votes and async statistical analysis in javascript
How to install
This module is designed for node.js, but it is also possible to use it in browsers. At the moment this module does not serve a module for browsers, only a commonJS module. If you want to use it in a browser try to 'compile' it for browsers with browserify.
Require the package:
npm install --save voting
How to use it generally / concept
Voters use boolean values in general, but this module is enhanced with "statistical voters"
Use in node.js
At first you have to require this module.
var voting = ;
This module is structured in an associative array (object) and has the following build in voters:
- boolean - Voters that handle boolean decision basis.
- statistics - Voters that evaluate decision basis statistically.
Support of synchronous, asynchronous functions and values
The goal of this module is to provide an easy way to vote for decisions with asynchronous functions, but it should also easy to handle values from synchronous functions.
Persist evaluation
With standard configuration this module persists the evaluated value of a decision basis (abstention).
anyVoter;anyVoter;console; anyVoter;console;
If you do not want to persist values you can switch this option off
anyVoterpersistsEvaluation = false;
Handling of null values
In general null
as value is interpreted as no or skipped decision basis.
voter = decisionBasis: true null true;voter;
Specific use
Boolean votery
more or less the classical voter
And Voter
All decision basis must be true for a positive decision (logical and).
var fs = ;var voting = ; var andVoter = ; andVoter;andVoter;andVoter; andVoter;
Or Voter
One decision basis must be true for a positive decision (logical or).
var user = ; // Just an examplevar resource = ; // Just an examplevar voting = ; var orVoter = ; orVoter;orVoter; orVoter;
Ratio Voter
Get the ratio between true and false decision basis.
var socket = ; // Just an examplevar voting = ; var ratioVoter = ; var i; for i = 0; i < socketusers; i += 1 ratioVoter; // True is yes, false is no, null is an abstention ratioVoter;
Xor Voter
Only one decision basis must be true for a positive decision (logical xor).
var user = ; // Just an examplevar voting = ; var xorVoter = ; xorVoter;xorVoter; // Allow only to do something oncexorVoter;
Statistical voters
- [Average](#average-voter): Get the average of all values as decision.
- [Cv](#coefficient-of-variation-voter): Get the coefficient of variation of all values as decision.
- [Variance](#variance-voter): Get the variance of all values as decision.
Average Voter
Get the average of all values as decision.
var profiles = ; // Just an example var averageVoter = ; var i; for i = 0; i < profileslength; i += 1 averageVoter; averageVoter;
Coefficient of variation Voter
Get the coefficient of variation of all values as decision.
It works quite the same like the average example above but the result is the CV and the class to use is:
voting.statistical.Cv()
Variance Voter
Get the variance of all values as decision.
It works quite the same like the average example above but the result is the variance and the class to use is:
voting.statistical.Variance()
Create own voters
You can use the super class to augment new voters. Here an example how the AND voter is created
var Voter = ; var { Voter;}; BooleanAndVoterprototype = '__proto__': Voterprototype { Voterprototypedecide; return this; };