From 11b8deed1d1eb50d542bf534328ff4dab5a99284 Mon Sep 17 00:00:00 2001 From: Teppy Date: Wed, 18 Oct 2023 15:00:45 -0400 Subject: [PATCH] Changes for release --- plurvote.html | 11 +++++---- rangevote.html | 11 +++++---- rangevote.js | 62 ++++++++++++++++++++++++++++++++++---------------- results.html | 34 +++++++++++++++------------ 4 files changed, 74 insertions(+), 44 deletions(-) diff --git a/plurvote.html b/plurvote.html index bdd5ac1..6211d4e 100644 --- a/plurvote.html +++ b/plurvote.html @@ -14,10 +14,10 @@ }
- This page is an experiment in voting. Half of the people who visit this site vote using Plurality Voting - where a voter selects their top candidate, and the winner is the candidate with the most votes. The other - half use Range Voting where voters score all familiar candidates based on how happy they would be should - that candidate win. You have been randomly selected to vote using Plurality Voting. + This page is an experiment in voting. Half of the people who visit this site will use Plurality Voting, and half will use Range Voting.
+ In Plurality Voting, voters select their top candidate, and the winner is the candidate with the most votes. Most elections in the United States use Plurality Voting.
+ In Range Voting, voters score all candidates that they know based on how happy they would be should that candidate win.
+ You have been randomly selected to vote using Plurality Voting.

@@ -30,7 +30,8 @@
- +
+ Or, just show me the Results
diff --git a/rangevote.html b/rangevote.html index 13370c2..84b635d 100644 --- a/rangevote.html +++ b/rangevote.html @@ -14,10 +14,10 @@ }
- This page is an experiment in voting. Half of the people who visit this site will use Plurality Voting: - Voters select their top candidate, and the winner is the candidate with the most votes. The other - half will use Range Voting: Voters score all candidates that they know based on how happy they would be should - that candidate win. You have been randomly selected to vote using Range Voting. + This page is an experiment in voting. Half of the people who visit this site will use Plurality Voting, and half will use Range Voting.
+ In Plurality Voting, voters select their top candidate, and the winner is the candidate with the most votes. Most elections in the United States use Plurality Voting.
+ In Range Voting, voters score all candidates that they know based on how happy they would be should that candidate win.
+ You have been randomly selected to vote using Range Voting.

@@ -31,7 +31,8 @@
- +
+ Or, just show me the Results
diff --git a/rangevote.js b/rangevote.js index fa10aa7..2692ae9 100644 --- a/rangevote.js +++ b/rangevote.js @@ -2,13 +2,13 @@ var express = require('express') var bodyParser = require('body-parser') var fs=require('fs') var hashindex=require('hash-index') -var fc=require("./filechunker.js"); +var fileChunker=require("./filechunker.js"); var app = express() -var TemplateVoteRange=new fc("./rangevote.html"); -var TemplateVotePlur =new fc("./plurvote.html"); - +var TemplateVoteRange=new fileChunker("./rangevote.html"); +var TemplateVotePlur =new fileChunker("./plurvote.html"); +var TemplateResults =new fileChunker("./results.html"); var Candidates=[ "Chris Christie", @@ -179,32 +179,56 @@ function RangeVote(ip,entries) AddToRangeResult(NewVote,1); } +function SendResults(req,res) +{ + let strPlur=""; + for (let c of Candidates) + { + let key=CanId(c); + if (Experiment.PlurResult.get(key)>0) + strPlur=strPlur+""+ + ""+c+""+ + ""+Experiment.PlurResult.get(key)+""+ + ""+Math.round(100.0*Experiment.PlurResult.get(key)/Experiment.PlurCount)+"%"+ + ""; + } + + let strRange=""; + for (let c of Candidates) + { + let key=CanId(c); + if (Experiment.RangePower.get(key)>0) + strRange=strRange+""+ + ""+c+""+ + ""+Experiment.RangePower.get(key)+""+ + ""+Math.round(Experiment.RangeResult.get(key)/Experiment.RangePower.get(key))+"%"+ + ""; + } + + res.send( TemplateResults.Chunks[0]+Experiment.PlurVotes.size+ + TemplateResults.Chunks[1]+strPlur+ + TemplateResults.Chunks[2]+Experiment.RangeVotes.size+ + TemplateResults.Chunks[3]+strRange+ + TemplateResults.Chunks[4]); +} + // POST /login gets urlencoded bodies app.post('/range_vote', urlencodedParser, function (req, res) { RangeVote(req.socket.remoteAddress,Object.entries(req.body)); - let str="Results from "+Experiment.RangeVotes.size+" Voters:
"; - for (let c of Candidates) - { - let key=CanId(c); - if (Experiment.RangePower.get(key)>0) str=str+c+': '+Math.round(Experiment.RangeResult.get(key)/Experiment.RangePower.get(key))+'% ('+Experiment.RangePower.get(key)+' Voters)
'; - } Persist(); - res.send(str); + SendResults(req,res); }) + app.post('/plur_vote', urlencodedParser, function (req, res) { PlurVote(req.socket.remoteAddress,req.body.pick); - let str="Results from "+Experiment.PlurVotes.size+" Voters:
"; - for (let c of Candidates) - { - let key=CanId(c); - if (Experiment.PlurResult.get(key)>0) str=str+c+': '+Math.round(100.0*Experiment.PlurResult.get(key)/Experiment.PlurCount)+'%
'; - } Persist(); - res.send(str); + SendResults(req,res); }) +app.get('/results',urlencodedParser,function(req,res) { + SendResults(req,res); +}) app.listen(3000,function(req,res) { console.log("Listening for connections"); }) - diff --git a/results.html b/results.html index 7943354..ea3d21a 100644 --- a/results.html +++ b/results.html @@ -10,30 +10,34 @@ - Here are the results by Range Voting: + + Here are the results by Plurality Voting based on voters:
- - + + + + +
Candidate# Votes% Votes
+
+ + Here are the results by Range Voting based on voters: +
+ + + + +
Candidate# Voters% Happiness
- -
- And here are the results by Plurality Voting: - - - - - - -
Candidate
-
+