Changes for release
This commit is contained in:
@@ -14,10 +14,10 @@
|
|||||||
}
|
}
|
||||||
</style>
|
</style>
|
||||||
<form id="my-form" style="background-color:#E0E0E0" action="/plur_vote" method="post">
|
<form id="my-form" style="background-color:#E0E0E0" action="/plur_vote" method="post">
|
||||||
This page is an experiment in voting. Half of the people who visit this site 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.<br>
|
||||||
where a voter selects their top candidate, and the winner is the candidate with the most votes. The other
|
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.<br>
|
||||||
half use Range Voting where voters score all familiar candidates based on how happy they would be should
|
In Range Voting, voters score all candidates <i>that they know</i> based on how happy they would be should that candidate win. <br>
|
||||||
that candidate win. You have been randomly selected to vote using Plurality Voting.
|
<b>You have been randomly selected to vote using Plurality Voting.</b>
|
||||||
<br>
|
<br>
|
||||||
<br>
|
<br>
|
||||||
|
|
||||||
@@ -30,7 +30,8 @@
|
|||||||
</table>
|
</table>
|
||||||
|
|
||||||
<br>
|
<br>
|
||||||
<button type="submit" value="submit">Submit</button>
|
<button type="submit" value="submit">Submit</button><br>
|
||||||
|
Or, just show me the <a href="results">Results</a>
|
||||||
</form>
|
</form>
|
||||||
</body>
|
</body>
|
||||||
|
|
||||||
|
|||||||
@@ -14,10 +14,10 @@
|
|||||||
}
|
}
|
||||||
</style>
|
</style>
|
||||||
<form id="my-form" style="background-color:#E0E0E0" action="/range_vote" method="post" oninput=UpdateValues(event)>
|
<form id="my-form" style="background-color:#E0E0E0" action="/range_vote" method="post" oninput=UpdateValues(event)>
|
||||||
This page is an experiment in voting. Half of the people who visit this site will use 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.<br>
|
||||||
Voters select their top candidate, and the winner is the candidate with the most votes. The other
|
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.<br>
|
||||||
half will use Range Voting: Voters score all candidates <i>that they know</i> based on how happy they would be should
|
In Range Voting, voters score all candidates <i>that they know</i> based on how happy they would be should that candidate win. <br>
|
||||||
that candidate win. <b>You have been randomly selected to vote using Range Voting.</b>
|
<b>You have been randomly selected to vote using Range Voting.</b>
|
||||||
<br>
|
<br>
|
||||||
<br>
|
<br>
|
||||||
|
|
||||||
@@ -31,7 +31,8 @@
|
|||||||
</table>
|
</table>
|
||||||
|
|
||||||
<br>
|
<br>
|
||||||
<button type="submit" value="submit">Submit</button>
|
<button type="submit" value="submit">Submit</button><br>
|
||||||
|
Or, just show me the <a href="results">Results</a>
|
||||||
</form>
|
</form>
|
||||||
</body>
|
</body>
|
||||||
|
|
||||||
|
|||||||
62
rangevote.js
62
rangevote.js
@@ -2,13 +2,13 @@ var express = require('express')
|
|||||||
var bodyParser = require('body-parser')
|
var bodyParser = require('body-parser')
|
||||||
var fs=require('fs')
|
var fs=require('fs')
|
||||||
var hashindex=require('hash-index')
|
var hashindex=require('hash-index')
|
||||||
var fc=require("./filechunker.js");
|
var fileChunker=require("./filechunker.js");
|
||||||
|
|
||||||
var app = express()
|
var app = express()
|
||||||
|
|
||||||
var TemplateVoteRange=new fc("./rangevote.html");
|
var TemplateVoteRange=new fileChunker("./rangevote.html");
|
||||||
var TemplateVotePlur =new fc("./plurvote.html");
|
var TemplateVotePlur =new fileChunker("./plurvote.html");
|
||||||
|
var TemplateResults =new fileChunker("./results.html");
|
||||||
|
|
||||||
var Candidates=[
|
var Candidates=[
|
||||||
"Chris Christie",
|
"Chris Christie",
|
||||||
@@ -179,32 +179,56 @@ function RangeVote(ip,entries)
|
|||||||
AddToRangeResult(NewVote,1);
|
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+"<tr>"+
|
||||||
|
"<td>"+c+"</td>"+
|
||||||
|
"<td>"+Experiment.PlurResult.get(key)+"</td>"+
|
||||||
|
"<td>"+Math.round(100.0*Experiment.PlurResult.get(key)/Experiment.PlurCount)+"%</td>"+
|
||||||
|
"</tr>";
|
||||||
|
}
|
||||||
|
|
||||||
|
let strRange="";
|
||||||
|
for (let c of Candidates)
|
||||||
|
{
|
||||||
|
let key=CanId(c);
|
||||||
|
if (Experiment.RangePower.get(key)>0)
|
||||||
|
strRange=strRange+"<tr>"+
|
||||||
|
"<td>"+c+"</td>"+
|
||||||
|
"<td>"+Experiment.RangePower.get(key)+"</td>"+
|
||||||
|
"<td>"+Math.round(Experiment.RangeResult.get(key)/Experiment.RangePower.get(key))+"%</td>"+
|
||||||
|
"</tr>";
|
||||||
|
}
|
||||||
|
|
||||||
|
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
|
// POST /login gets urlencoded bodies
|
||||||
app.post('/range_vote', urlencodedParser, function (req, res) {
|
app.post('/range_vote', urlencodedParser, function (req, res) {
|
||||||
RangeVote(req.socket.remoteAddress,Object.entries(req.body));
|
RangeVote(req.socket.remoteAddress,Object.entries(req.body));
|
||||||
let str="Results from "+Experiment.RangeVotes.size+" Voters:<br>";
|
|
||||||
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)<br>';
|
|
||||||
}
|
|
||||||
Persist();
|
Persist();
|
||||||
res.send(str);
|
SendResults(req,res);
|
||||||
})
|
})
|
||||||
|
|
||||||
|
|
||||||
app.post('/plur_vote', urlencodedParser, function (req, res) {
|
app.post('/plur_vote', urlencodedParser, function (req, res) {
|
||||||
PlurVote(req.socket.remoteAddress,req.body.pick);
|
PlurVote(req.socket.remoteAddress,req.body.pick);
|
||||||
let str="Results from "+Experiment.PlurVotes.size+" Voters:<br>";
|
|
||||||
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)+'%<br>';
|
|
||||||
}
|
|
||||||
Persist();
|
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"); })
|
app.listen(3000,function(req,res) { console.log("Listening for connections"); })
|
||||||
|
|
||||||
|
|||||||
34
results.html
34
results.html
@@ -10,30 +10,34 @@
|
|||||||
<style>
|
<style>
|
||||||
form, table, th, td {
|
form, table, th, td {
|
||||||
border:1px solid black;
|
border:1px solid black;
|
||||||
border-collapse: collapse;
|
border-collapse: collapse;
|
||||||
|
background-color: #E0E0E0;
|
||||||
}
|
}
|
||||||
</style>
|
</style>
|
||||||
Here are the results by Range Voting:
|
|
||||||
|
Here are the results by Plurality Voting based on <!-- INJECT --> voters:
|
||||||
<br>
|
<br>
|
||||||
|
|
||||||
<table>
|
<table>
|
||||||
<tr>
|
<tr>
|
||||||
<th> </th>
|
|
||||||
<th>Candidate</th>
|
<th>Candidate</th>
|
||||||
|
<th># Votes</th>
|
||||||
|
<th>% Votes</th>
|
||||||
|
</tr>
|
||||||
|
<!-- INJECT -->
|
||||||
|
</table>
|
||||||
|
<br>
|
||||||
|
|
||||||
|
Here are the results by Range Voting based on <!-- INJECT --> voters:
|
||||||
|
<br>
|
||||||
|
<table>
|
||||||
|
<tr>
|
||||||
|
<th>Candidate</th>
|
||||||
|
<th># Voters</th>
|
||||||
|
<th>% Happiness</th>
|
||||||
</tr>
|
</tr>
|
||||||
<!-- INJECT -->
|
<!-- INJECT -->
|
||||||
</table>
|
</table>
|
||||||
|
|
||||||
<br>
|
|
||||||
And here are the results by Plurality Voting:
|
|
||||||
<table>
|
|
||||||
<tr>
|
|
||||||
<th> </th>
|
|
||||||
<th>Candidate</th>
|
|
||||||
</tr>
|
|
||||||
<!-- INJECT -->
|
|
||||||
</table>
|
|
||||||
|
|
||||||
<br>
|
<br>
|
||||||
|
|
||||||
</body>
|
</body>
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user