IntroductionArchitectureSurvey LifecycleQualtrics IntegrationVoting MethodsExisting methodsCreate your method
Voting methods
Existing methods
QVSR currently supports 2 voting methods, Linear and Quadratic.
- Linear is 1 credit per vote.
- Quadratic is y = x², where x is the number of votes.
| Votes | Total Cost | Marginal Cost |
|---|---|---|
| 1 | 1 | 1 |
| 2 | 4 | 3 |
| 3 | 9 | 5 |
| 4 | 16 | 7 |
| 5 | 25 | 9 |
Create your method
To create new voting methods you can follow this:
src/components/Survey/methods
// survey object is expected as paramconst NewVotingMethod = (survey) => {const { credits, preferredFunction } = survey.configconst [availableCredits, setAvailableCredits] = React.useState(parseInt(credits))const [questions, setQuestions] = React.useState([])React.useEffect(() => {const newQuestions = survey.setup.questions.map((question, index) => ({label: question.value,vote: 0,id: question.id,})).sort(() => 0.5 - Math.random())setQuestions(newQuestions)}, [preferredFunction, survey])React.useEffect(() => {if (questions) {const totalCost = questions.reduce((cost, q, i) => (q.vote < 0 ? cost + q.vote * -1 : cost + q.vote), 0)setAvailableCredits(credits - totalCost)}}, [questions, credits])function canVote(index, number) {...}function vote(index, number) {...}return { availableCredits, questions, vote, canVote }}
We expect that your method API returns a canVote, vote functions. availableCredits variable and questions with the following structure:
question = {label: 'question example',vote: 0,id: 0, // question.id}
And set the new method on index:
import Quadratic from './quadratic'import Linear from './linear'const useMethod = (survey) => {const { preferredFunction } = survey.configconst functions = {Quadratic,Linear,NewVotingMethod,}return functions[preferredFunction](survey)}export default useMethod