first draft of consent system
This commit is contained in:
parent
a28c313982
commit
2386c0e929
@ -42,6 +42,90 @@ new_process_format = {
|
||||
|
||||
}
|
||||
|
||||
-- initialize values
|
||||
function init_consent(policy) {
|
||||
self.start_time = os.time()
|
||||
self.member_count = modpol.orgs.get_org(self.org_id):get_member_count()
|
||||
|
||||
if policy.duration then
|
||||
register_callback(self.start_time + policy.duration)
|
||||
end
|
||||
|
||||
if (duration and (consent_ratio or yes_threshold or no_threshold)) or (yes_threshold) or (consent_ratio) then
|
||||
-- well formed policy
|
||||
else
|
||||
-- invalid
|
||||
end
|
||||
|
||||
}
|
||||
|
||||
-- update vote count
|
||||
function update_consent(user, approve) {
|
||||
if approve then
|
||||
table.insert(yes_votes, user)
|
||||
else
|
||||
table.insert(no_votes, user)
|
||||
|
||||
if not duration then
|
||||
eval_consent()
|
||||
end
|
||||
|
||||
}
|
||||
|
||||
-- evaluate state of vote
|
||||
function eval_consent() {
|
||||
consent_ratio = #yes_votes / (#yes_votes + #no_votes)
|
||||
quorum = (#yes_votes + #no_votes) / member_count
|
||||
|
||||
if policy.duration then
|
||||
|
||||
if policy.consent_ratio then
|
||||
if policy.quorum then
|
||||
if quorum < policy.quorum then
|
||||
fail()
|
||||
end
|
||||
end
|
||||
if consent_ratio >= policy.consent_ratio then
|
||||
pass()
|
||||
else
|
||||
fail()
|
||||
end
|
||||
|
||||
elseif policy.yes_threshold then
|
||||
if #yes_votes >= policy.yes_threshold then
|
||||
pass()
|
||||
else
|
||||
fail()
|
||||
end
|
||||
|
||||
elseif policy.no_threshold then
|
||||
if #no_votes <= policy.no_threshold then
|
||||
fail()
|
||||
else
|
||||
pass()
|
||||
end
|
||||
end
|
||||
|
||||
elseif policy.yes_threshold then
|
||||
if policy.no_threshold then
|
||||
if #no_votes >= policy.no_threshold then
|
||||
fail()
|
||||
end
|
||||
if #yes_votes >= policy.yes_threshold then
|
||||
pass()
|
||||
end
|
||||
|
||||
elseif policy.consent_ratio and policy.quorum then
|
||||
if quorum >= policy.quorum then
|
||||
if consent_ratio >= policy.consent_ratio then
|
||||
pass()
|
||||
else
|
||||
fail()
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
}
|
||||
|
||||
|
||||
policy_table_format = {
|
||||
|
Loading…
x
Reference in New Issue
Block a user