Skip to content

Commit

Permalink
added a progress number
Browse files Browse the repository at this point in the history
  • Loading branch information
benadida committed Oct 20, 2008
1 parent a0f9bc4 commit 15de1b6
Show file tree
Hide file tree
Showing 5 changed files with 58 additions and 14 deletions.
6 changes: 3 additions & 3 deletions index.yaml
Expand Up @@ -10,14 +10,14 @@ indexes:
# automatically uploaded to the admin console when you next deploy
# your application using appcfg.py.

# Used 5 times in query history.
# Used 6 times in query history.
- kind: ElectionExponent
properties:
- name: election
- name: exponent
direction: desc

# Used 68 times in query history.
# Used 79 times in query history.
- kind: KeyShare
properties:
- name: election
Expand All @@ -43,7 +43,7 @@ indexes:
- name: tallied_at
- name: cast_id

# Used 149 times in query history.
# Used 168 times in query history.
- kind: Voter
properties:
- name: election
Expand Down
1 change: 0 additions & 1 deletion static/booth.css
Expand Up @@ -56,7 +56,6 @@ body {
#footer {
border-top: 1px solid #666;
position: absolute;
bottom: 0px;
margin: auto;
width: 860px;
text-align: center;
Expand Down
44 changes: 39 additions & 5 deletions static/helios.js
Expand Up @@ -36,6 +36,26 @@ UTILS.select_element_content = function(element) {
}
};

// a progress tracker
UTILS.PROGRESS = Class.extend({
init: function() {
this.n_ticks = 0.0;
this.current_tick = 0.0;
},

addTicks: function(n_ticks) {
this.n_ticks += n_ticks;
},

tick: function() {
this.current_tick += 1.0;
},

progress: function() {
return Math.round((this.current_tick / this.n_ticks) * 100);
}
});

//
// Helios Stuff
//
Expand Down Expand Up @@ -144,7 +164,7 @@ UTILS.generate_plaintexts = function(pk, num) {


HELIOS.EncryptedAnswer = Class.extend({
init: function(question, answer, pk) {
init: function(question, answer, pk, progress) {
// if nothing in the constructor
if (question == null)
return;
Expand All @@ -154,15 +174,15 @@ HELIOS.EncryptedAnswer = Class.extend({
this.answer = answer;

// do the encryption
var enc_result = this.doEncryption(question, answer, pk);
var enc_result = this.doEncryption(question, answer, pk, null, progress);

this.choices = enc_result.choices;
this.randomness = enc_result.randomness;
this.individual_proofs = enc_result.individual_proofs;
this.overall_proof = enc_result.overall_proof;
},

doEncryption: function(question, answer, pk, randomness) {
doEncryption: function(question, answer, pk, randomness, progress) {
var choices = [];
var individual_proofs = [];
var overall_proof = null;
Expand Down Expand Up @@ -203,6 +223,9 @@ HELIOS.EncryptedAnswer = Class.extend({
// generate proof that this ciphertext is a 0 or a 1
individual_proofs[i] = choices[i].generateDisjunctiveProof(plaintexts, plaintext_index, randomness[i], ElGamal.disjunctive_challenge_generator);
}

if (progress)
progress.tick();
}

if (generate_new_randomness) {
Expand All @@ -219,6 +242,8 @@ HELIOS.EncryptedAnswer = Class.extend({
// prove that the sum is 0 or 1 (can be "blank vote" for this answer)
// num_selected_answers is 0 or 1, which is the index into the plaintext that is actually encoded
overall_proof = hom_sum.generateDisjunctiveProof(plaintexts, num_selected_answers, rand_sum, ElGamal.disjunctive_challenge_generator);
if (progress)
progress.tick();
}

return {
Expand Down Expand Up @@ -307,7 +332,7 @@ HELIOS.EncryptedAnswer.fromJSONObject = function(d, election) {
};

HELIOS.EncryptedVote = Class.extend({
init: function(election, answers) {
init: function(election, answers, progress) {
// empty constructor
if (election == null)
return;
Expand All @@ -323,9 +348,18 @@ HELIOS.EncryptedVote = Class.extend({
var n_questions = election.questions.length;
this.encrypted_answers = [];

if (progress) {
// set up the number of ticks
$(election.questions).each(function(q_num, q) {
// + 1 for the overall proof
progress.addTicks(q.answers.length + 1);
});
}
progress.addTicks(0, n_questions);

// loop through questions
for (var i=0; i<n_questions; i++) {
this.encrypted_answers[i] = new HELIOS.EncryptedAnswer(election.questions[i], answers[i], election.pk);
this.encrypted_answers[i] = new HELIOS.EncryptedAnswer(election.questions[i], answers[i], election.pk, progress);
}
},

Expand Down
2 changes: 0 additions & 2 deletions static/main.css
Expand Up @@ -9,7 +9,6 @@ body {
#content {
position: absolute;
padding: 20px 30px 20px 30px;
bottom: 0px;
top: 0px;
margin-left: 100px;
margin-top: 0px;
Expand Down Expand Up @@ -42,7 +41,6 @@ body {

#footer {
border-top: 1px solid #666;
position: absolute;
bottom: 0px;
margin: auto;
width: 860px;
Expand Down
19 changes: 16 additions & 3 deletions templates/election/vote.tmpl
Expand Up @@ -115,7 +115,13 @@ BOOTH.click_checkbox = function(question_num, answer_num, checked_p) {
}
};

BOOTH.show_processing_before = function(str_to_execute) {
BOOTH.show_processing_before = function(str_to_execute, long_p) {
/*if (long_p) {
\$('#processing_div').html("<h3 align='center'>This operation may take up to 45 seconds to complete. Please be patient!<br />You may get a JavaScript warning that this operation is taking a while. You should click 'continue' until your vote is fully encrypted.</h3>");
} else {
\$('#processing_div').html("<h3 align='center'>Processing, this will take just a few seconds.</h3>");
}*/

BOOTH.show(\$('#processing_div'));

// add a timeout so browsers like Safari actually display the processing message
Expand All @@ -142,14 +148,21 @@ BOOTH.show_confirm = function() {
BOOTH.show(\$('#confirm_div')).processTemplate({'questions' : BOOTH.election.questions, 'choices' : choices});
};

BOOTH.check_encryption_status = function() {
\$('#processing_div').html("<h3 align='center'>Progress: " + BOOTH.progress.progress() + "%</h3>");
};

BOOTH.seal_ballot_raw = function() {
BOOTH.encrypted_ballot = new HELIOS.EncryptedVote(BOOTH.election, BOOTH.ballot.answers);
BOOTH.progress = new UTILS.PROGRESS();
var progress_interval = setInterval("BOOTH.check_encryption_status()", 1000);
BOOTH.encrypted_ballot = new HELIOS.EncryptedVote(BOOTH.election, BOOTH.ballot.answers, BOOTH.progress);
clearInterval(progress_interval);
\$('#seal_div').processTemplate({'encrypted_vote_hash' : BOOTH.encrypted_ballot.get_hash()});
BOOTH.show(\$('#seal_div'));
};

BOOTH.seal_ballot = function() {
BOOTH.show_processing_before("BOOTH.seal_ballot_raw()");
BOOTH.show_processing_before("BOOTH.seal_ballot_raw()", true);
};

BOOTH.audit_ballot = function() {
Expand Down

0 comments on commit 15de1b6

Please sign in to comment.