|
|
@ -7,9 +7,14 @@ gives a single grade to each of the candidates. |
|
|
|
The candidates are then sorted by their median grade. |
|
|
|
|
|
|
|
https://en.wikipedia.org/wiki/Majority_Judgment |
|
|
|
The constitutive details of the poll are up to you. |
|
|
|
The constitutive details of the poll are up to you, of course, |
|
|
|
the poll can be imperative or informative. |
|
|
|
""" |
|
|
|
|
|
|
|
const NOT_OPENED := -1 |
|
|
|
const NOT_CLOSED := -1 |
|
|
|
|
|
|
|
|
|
|
|
# Minimum length: 4 unicode characters (? TBD) |
|
|
|
# Maximum length: 256 unicode characters (? TBD) |
|
|
|
export(String) var title:String setget set_title, get_title |
|
|
@ -36,6 +41,10 @@ export(Array, Resource) var candidates:Array setget set_candidates, get_candidat |
|
|
|
export(Array, Resource) var judgments:Array setget set_judgments, get_judgments |
|
|
|
|
|
|
|
|
|
|
|
# Seconds since UNIX EPOCH (01-01-1970) |
|
|
|
export var opened_at:int = NOT_OPENED |
|
|
|
export var closed_at:int = NOT_CLOSED |
|
|
|
|
|
|
|
|
|
|
|
# Don't pass parameters in _init(). |
|
|
|
# ResourceLoader.load() won't like it. |
|
|
@ -43,7 +52,7 @@ func _init(): |
|
|
|
pass |
|
|
|
|
|
|
|
|
|
|
|
# Instead, use a factory approach |
|
|
|
# Instead, use a factory approach. |
|
|
|
static func make(__title, __grading, __candidates): |
|
|
|
var poll = load("res://addons/majority_judgment/MajorityJudgmentPoll.gd").new() |
|
|
|
poll.set_title(__title) |
|
|
@ -52,7 +61,6 @@ static func make(__title, __grading, __candidates): |
|
|
|
return poll |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
func set_title(__title:String) -> void: |
|
|
|
title = __title |
|
|
|
|
|
|
@ -116,6 +124,24 @@ func get_judgments() -> Array: |
|
|
|
return judgments |
|
|
|
|
|
|
|
|
|
|
|
func is_open() -> bool: |
|
|
|
var now = App.get_now() |
|
|
|
return ( |
|
|
|
(NOT_OPENED != opened_at and opened_at <= now) |
|
|
|
and |
|
|
|
(NOT_CLOSED == closed_at or closed_at >= now) |
|
|
|
) |
|
|
|
|
|
|
|
|
|
|
|
func is_closed() -> bool: |
|
|
|
return not is_open() |
|
|
|
|
|
|
|
|
|
|
|
func open() -> void: |
|
|
|
assert(NOT_OPENED == opened_at, "Cannot open() an already opened poll.") |
|
|
|
opened_at = App.get_now() |
|
|
|
|
|
|
|
|
|
|
|
func tally() -> MajorityJudgmentPollTally: |
|
|
|
if not has_judgments(): |
|
|
|
return null |
|
|
|