Transitive Proxy Voting

Events happening in the community are now at Drupal community events on www.drupal.org.
A.Kotov's picture

Hello, I am looking for way to organize Transitive Proxy Voting on Drupal.

http://en.wikipedia.org/wiki/Proxy_voting#Delegated_voting

On Wordpress there is complete distribution using this type of voting. https://adhocracy.de/

Is it possible to make it by Advanced Poll?

AttachmentSize
200px-Democracy.svg_.png17.99 KB

Comments

General Code

A.Kotov's picture

i wrote some code with example to show how it should work in general.
it should not be difficult to use it one of the voting modules

<?php
/**
* Created by
* User: Sasha
* Date: 27/09/14
* Time: 11:27
*/

$vote_results = array( // default vote results scheme. could be more choices
0 => 0,//for No
1 => 0 // for Yes
);

// fill data testing

$a = array( // user voting data array
'name'=> 'a',
'vote_weight' => 1, // everybody stars with 1
// 'vote' => 0, // this one did not vote
'delegate' => 'f' // to whom vote is delegated, could be done by Flag or Entity Reference
);

$b = array(
'name'=> 'b',
'vote_weight' => 1,
'vote' => array(
0 => 0,
1 => 1
),
// 'delegate' => 'f' // this one did not delegate to anybody
);

$c = array(
'name'=> 'c',
'vote_weight' => 1,

'delegate' => 'e'

);

$d = array(
'name'=> 'd',
'vote_weight' => 1,
// 'vote' => 0,
'delegate' => 'b'
);

$e = array(
'name'=> 'e',
'vote_weight' => 1,
'vote' => array(
0 => 0,
1 => 1
),
'delegate' => 'g'
);
$f = array(
'name'=> 'f',
'vote_weight' => 1,
'vote' => array(
0 => 1,
1 => 0
),
'delegate' => 'c'
);

$g = array(
'name'=> 'g',
'vote_weight' => 1,
'vote' => array(
0 => 0,
1 => 1
),

);

$list = array($a,$b,$c,$d,$e,$f,$g); // array of users' voting data

$work_list = $list;

print_r(ripple_voting($list,$vote_results));

/**
* make one pass through the list
*/

function vote_round(&$work_list,&$vote_results){

foreach ($work_list as $key => &$user) {

// echo $key.' '. $user;
// $delegated = implode(",",(is_delegate_of_names($work_list, $user)));
// $votes = isset($user['vote']) ? implode(',',$user['vote']): ' ';

// echo $key.' '.$delegated. ' ('.$user['name'].') '. $votes .' '. $user['delegate'];
// echo "\n";
if (!is_delegate($work_list,$user)){ // first we sort out who has no deligated votes to others
if (isset($user['vote'])){// if he voted - accept his vote with its wight

        foreach ($user['vote'] as &$value) {
            if (is_numeric($value)) {
                $value = $value * $user['vote_weight'];
            }
        }
        $vote_results = array_add($user['vote'],$vote_results);
            unset($work_list[$key]); // and throw from the list
                     }else {    // if he did not vote
                foreach($work_list as $key_d => &$user_d) {  //we look if he delegated his vote to smbd
            if ($user_d['name'] == $user['delegate']){
              $user_d['vote_weight'] += $user['vote_weight']; // and add his "weight" to this smbd
                          }
          unset($work_list[$key]); // and throw from the list
       }
    }
}

}
return array( // return results of one array pass
'work_list' =>$work_list,
'vote_results' => $vote_results
);
}

/**
* make rounds till complete sort out of the list
*/

function ripple_voting ($work_list,$vote_results){

do {
    $result = vote_round($work_list,$vote_results);
    $work_list = $result['work_list'];
    $vote_results = $result['vote_results'];
} while ($work_list);
return  $vote_results;

}

/**
* check if user has smbd who delegated vote to him
*/

function is_delegate($list,$user){
$delegate_of = array();
foreach ($list as $key => $other_user) {
if($other_user['delegate'] == $user['name']){
$delegate_of[] = $other_user;
}
} return $delegate_of;
}

/**
* debug function. returns string of users has smbd who delegated vote to them
*/

function is_delegate_of_names($list,$user){
$delegate_of = array();
foreach ($list as $key => $other_user) {
if($other_user['delegate'] == $user['name']){
$delegate_of[] = $other_user['name'];
}
}
return $delegate_of;
}

/**
* help function to add votes to result array
*/

function array_add($to_be_added_to,$to_be_added){
foreach($to_be_added_to as $k => $v)
array_key_exists($k,$to_be_added) ? $to_be_added[$k] += $v : $to_be_added[$k] = $v;
return $to_be_added;
}

Advanced Poll

Group organizers

Group notifications

This group offers an RSS feed. Or subscribe to these personalized, sitewide feeds: