Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
Helios Server
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Wiki
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Snippets
Build
Pipelines
Jobs
Pipeline schedules
Artifacts
Deploy
Releases
Package registry
Container registry
Model registry
Operate
Environments
Terraform modules
Monitor
Incidents
Analyze
Value stream analytics
Contributor analytics
CI/CD analytics
Repository analytics
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
TO
Helios Server
Commits
1654ad08
Commit
1654ad08
authored
14 years ago
by
Ben Adida
Browse files
Options
Downloads
Patches
Plain Diff
added winners
parent
326777c4
No related branches found
No related tags found
No related merge requests found
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
helios/crypto/electionalgs.py
+36
-1
36 additions, 1 deletion
helios/crypto/electionalgs.py
helios/templates/election_view.html
+1
-1
1 addition, 1 deletion
helios/templates/election_view.html
with
37 additions
and
2 deletions
helios/crypto/electionalgs.py
+
36
−
1
View file @
1654ad08
...
...
@@ -363,6 +363,29 @@ class EncryptedVote(HeliosObject):
encrypted_answers
=
[
EncryptedAnswer
.
fromElectionAndAnswer
(
election
,
answer_num
,
answers
[
answer_num
])
for
answer_num
in
range
(
len
(
answers
))]
return
cls
(
encrypted_answers
=
encrypted_answers
,
election_hash
=
election
.
hash
,
election_uuid
=
election
.
uuid
)
def
one_question_winner
(
question
,
result
,
num_cast_votes
):
"""
determining the winner for one question
"""
# sort the answers , keep track of the index
counts
=
sorted
(
enumerate
(
result
),
key
=
lambda
(
x
):
x
[
1
])
counts
.
reverse
()
# if there's a max > 1, we assume that the top MAX win
if
question
[
'
max
'
]
>
1
:
return
[
c
[
0
]
for
c
in
counts
[:
max
]]
# if max = 1, then depends on absolute or relative
if
question
[
'
result_type
'
]
==
'
absolute
'
:
if
counts
[
0
][
1
]
>=
(
num_cast_votes
/
2
+
1
):
return
[
counts
[
0
][
0
]]
else
:
return
[]
if
question
[
'
result_type
'
]
==
'
relative
'
:
return
[
counts
[
0
][
0
]]
class
Election
(
HeliosObject
):
FIELDS
=
[
'
uuid
'
,
'
questions
'
,
'
name
'
,
'
short_name
'
,
'
description
'
,
'
voters_hash
'
,
'
openreg
'
,
...
...
@@ -399,10 +422,22 @@ class Election(HeliosObject):
else
:
return
"
Closed
"
@property
def
winners
(
self
):
"""
Depending on the type of each question, determine the winners
returns an array of winners for each question, aka an array of arrays.
assumes that if there is a max to the question, that
'
s how many winners there are.
"""
return
[
one_question_winner
(
self
.
questions
[
i
],
self
.
result
[
i
],
self
.
num_cast_votes
)
for
i
in
range
(
len
(
self
.
questions
))]
@property
def
pretty_result
(
self
):
if
not
self
.
result
:
return
None
# get the winners
winners
=
self
.
winners
raw_result
=
self
.
result
prettified_result
=
[]
...
...
@@ -416,7 +451,7 @@ class Election(HeliosObject):
for
j
in
range
(
len
(
q
[
'
answers
'
])):
a
=
q
[
'
answers
'
][
j
]
count
=
raw_result
[
i
][
j
]
pretty_question
.
append
({
'
answer
'
:
a
,
'
count
'
:
count
})
pretty_question
.
append
({
'
answer
'
:
a
,
'
count
'
:
count
,
'
winner
'
:
(
j
in
winners
[
i
])
})
prettified_result
.
append
({
'
question
'
:
q
[
'
short_name
'
],
'
answers
'
:
pretty_question
})
...
...
This diff is collapsed.
Click to expand it.
helios/templates/election_view.html
+
1
−
1
View file @
1654ad08
...
...
@@ -141,7 +141,7 @@ all voters will be notified that the tally is ready.
<b><span
style=
"font-size:0.8em;"
>
Question #{{forloop.counter}}
</span><br
/>
{{question.question}}
</b><br
/>
<table
class=
"pretty"
style=
"width: auto;"
>
{% for answer in question.answers %}
<tr><td
style=
"padding-right:80px;
"
>
{{answer.answer}}
</td><td
align=
"right
"
>
{{answer.count}}
</td></tr>
<tr><td
style=
"padding-right:80px;
{% if answer.winner %}font-weight:bold;{% endif %}"
>
{{answer.answer}}
</td><td
align=
"right"
style=
"{% if answer.winner %}font-weight:bold;{% endif %}
"
>
{{answer.count}}
</td></tr>
{% endfor %}
</table>
{% endfor %}
...
...
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment