Skip to content

Commit

Permalink
moving from 1:5 to 0:5 scale and 1:3 to 0:2 scale.
Browse files Browse the repository at this point in the history
  • Loading branch information
paretoman committed Aug 8, 2017
1 parent 1b8f5d3 commit 719f883
Show file tree
Hide file tree
Showing 7 changed files with 41 additions and 26 deletions.
Binary file modified play/img/ballot_range.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified play/img/ballot_range3.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified play/img/ballot_rate.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified play/img/ballot_three.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
4 changes: 2 additions & 2 deletions play/js/Ballot.js
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ function ScoreBallot(config){
self.update = function(ballot){
for(var cID in ballot){
var score = ballot[cID];
self.boxes[cID].gotoFrame(score-1);
self.boxes[cID].gotoFrame(score);
}
};

Expand All @@ -48,7 +48,7 @@ function ThreeBallot(config){
self.update = function(ballot){
for(var cID in ballot){
var score = ballot[cID];
self.boxes[cID].gotoFrame(score-1+1);
self.boxes[cID].gotoFrame(score);
}
};

Expand Down
59 changes: 37 additions & 22 deletions play/js/Voters.js
Original file line number Diff line number Diff line change
Expand Up @@ -201,18 +201,23 @@ function dostrategy(x,y,minscore,maxscore,rangescore,strategy,lastwinner,frontru
} else if (strategy == "normalize frontrunners only" || strategy == "starnormfrontrunners") {
var fnorm = 1/ (maxfront-minfront);
var normit = function(d) {return (d-minfront)*fnorm;}
if (strategy == "starnormfrontrunners") maxscore--;
var gs = function(d) { return minscore+Math.round((maxscore-minscore)*(1-normit(d))); }
var thresholdit = function(d) {return (d<=minfront) ? maxscore : (d>=maxfront) ? minscore : gs(d)}
radiusFirst = minfront;
radiusLast = maxfront;
}
radiusLast = maxfront;
}
}
var scores2 = dista.map(thresholdit);
var assignit = function(d,i) { scores[ candidates[i].id ] = d; }
scores2.map(assignit)
if (strategy == "starnormfrontrunners") maxscore++;
scores[mini] = maxscore;
if (strategy == "starnormfrontrunners") {
for(i in candidates){
var c = candidates[i].id
if (scores[c]==maxscore && c!=mini) {
scores[c]=maxscore-1;
}}}


}// otherwise, there is no strategy strategy == "no strategy. judge on an absolute scale."

Expand All @@ -230,7 +235,10 @@ function ScoreVoter(model){

var self = this;
self.model = model;

var maxscore = 5;
var minscore = 0;
var scorearray = [];
for (var i=minscore; i<= maxscore; i++) scorearray.push(i)
self.radiusStep = window.HACK_BIG_RANGE ? 61 : 25; // step: x<25, 25<x<50, 50<x<75, 75<x<100, 100<x

self.getScore = function(x2){
Expand All @@ -245,9 +253,8 @@ function ScoreVoter(model){

self.getBallot = function(x, y, strategy, config){


self.model.idlastwinner = "square"
var scoresfirstlast = dostrategy(x,y,1,5,[1,2,3,4,5],strategy,self.model.idlastwinner,self.model.frontrunnerSet,self.model.candidates,self.radiusStep,self.getScore)
var scoresfirstlast = dostrategy(x,y,minscore,maxscore,scorearray,strategy,self.model.idlastwinner,self.model.frontrunnerSet,self.model.candidates,self.radiusStep,self.getScore)

self.radiusFirst = scoresfirstlast.radiusFirst
self.radiusLast = scoresfirstlast.radiusLast
Expand All @@ -262,12 +269,12 @@ function ScoreVoter(model){
// RETINA
x = x*2;
y = y*2;

var step = (self.radiusLast - self.radiusFirst)/4;
var scorange = maxscore - minscore
var step = (self.radiusLast - self.radiusFirst)/scorange;
// Draw big ol' circles.
for(var i=1;i<5;i++){
for(var i=0;i<scorange;i++){
ctx.beginPath();
ctx.arc(x, y, (step*(i-.5) + self.radiusFirst)*2, 0, Math.TAU, false);
ctx.arc(x, y, (step*(i+.5) + self.radiusFirst)*2, 0, Math.TAU, false);
ctx.lineWidth = (5-i)*2;
ctx.strokeStyle = "#888";
ctx.setLineDash([]);
Expand All @@ -281,8 +288,6 @@ function ScoreVoter(model){

// There are #Candidates*5 slices
// Fill 'em in in order -- and the rest is gray.
var maxscore = 5;
var minscore = 0;
var totalSlices = self.model.candidates.length*(maxscore-minscore);
var leftover = totalSlices;
var slices = [];
Expand Down Expand Up @@ -312,7 +317,10 @@ function ThreeVoter(model){

var self = this;
self.model = model;

var maxscore = 2;
var minscore = 0;
var scorearray = [];
for (var i=minscore; i<= maxscore; i++) scorearray.push(i)
self.radiusStep = window.HACK_BIG_RANGE ? 61 : 25; // step: x<25, 25<x<50, 50<x<75, 75<x<100, 100<x

self.getScore = function(x2){
Expand All @@ -322,27 +330,34 @@ function ThreeVoter(model){
return 0;
};

self.getBallot = function(x, y, strategy, config){
self.getBallot = function(x, y, strategy, config){

self.model.idlastwinner = "square"
var scoresfirstlast = dostrategy(x,y,0,2,[0,1,2],strategy,self.model.idlastwinner,self.model.frontrunnerSet,self.model.candidates,self.radiusStep,self.getScore)
var scoresfirstlast = dostrategy(x,y,minscore,maxscore,scorearray,strategy,self.model.idlastwinner,self.model.frontrunnerSet,self.model.candidates,self.radiusStep,self.getScore)

self.radiusFirst = scoresfirstlast.radiusFirst
self.radiusLast = scoresfirstlast.radiusLast
self.dottedCircle = scoresfirstlast.dottedCircle
var scores = scoresfirstlast.scores
return scores

};

self.drawBG = function(ctx, x, y, ballot){

// RETINA
x = x*2;
y = y*2;

var scorange = maxscore - minscore
var step = (self.radiusLast - self.radiusFirst)/scorange;
// Draw big ol' circles.
for(var i=1;i<5;i++){
for(var i=0;i<scorange;i++){
ctx.beginPath();
ctx.arc(x, y, (self.radiusStep*i)*2, 0, Math.TAU, false);
ctx.arc(x, y, (step*(i+.5) + self.radiusFirst)*2, 0, Math.TAU, false);
ctx.lineWidth = (5-i)*2;
ctx.strokeStyle = "#888";
ctx.setLineDash([]);
if (self.dottedCircle) ctx.setLineDash([5, 15]);
ctx.stroke();
}

Expand All @@ -352,13 +367,13 @@ function ThreeVoter(model){

// There are #Candidates*5 slices
// Fill 'em in in order -- and the rest is gray.
var totalSlices = self.model.candidates.length*2;
var totalSlices = self.model.candidates.length*(maxscore-minscore);
var leftover = totalSlices;
var slices = [];
for(var i=0; i<self.model.candidates.length; i++){
var c = self.model.candidates[i];
var cID = c.id;
var score = ballot[cID];
var score = ballot[cID] - minscore;
leftover -= score;
slices.push({
num: score,
Expand Down
4 changes: 2 additions & 2 deletions play/js/main_ballot.js
Original file line number Diff line number Diff line change
Expand Up @@ -85,8 +85,8 @@ function main(config){
{name:h1("square"),realname:"square",margin:4},
{name:h1("triangle"),realname:"triangle",margin:4},
{name:h1("hexagon"),realname:"hexagon",margin:4},
{name:h1("pentagon"),realname:"pentagon",margin:4},
{name:h1("bob"),realname:"bob"}
//{name:h1("pentagon"),realname:"pentagon",margin:4},
//{name:h1("bob"),realname:"bob"}
];
var onChooseFrun = function(data){

Expand Down

0 comments on commit 719f883

Please sign in to comment.