ILIAS  release_5-4 Revision v5.4.26-12-gabc799a52e6
ILIAS\Exercise\PeerReview\ExcPeerReviewDistribution Class Reference

Calculates peer review distribution (rater to peer assignments) More...

+ Collaboration diagram for ILIAS\Exercise\PeerReview\ExcPeerReviewDistribution:

Public Member Functions

 __construct (array $user_ids, $num_assignments)
 ExcPeerReviewDistribution constructor. More...
 
 getUserOrder ()
 Get user order. More...
 
 getPeersOfRater ($user_id)
 Get peers of rater. More...
 

Protected Member Functions

 initDistribution ()
 Init distribution. More...
 
 randomUserOrder ($user_ids)
 Random user order. More...
 

Protected Attributes

 $user_ids = []
 
 $user_order = []
 
 $num_assignments
 

Detailed Description

Calculates peer review distribution (rater to peer assignments)

This is a simple algorithm, that ensures that each rater has $num_assignments peers to review and each peer has $num_assignments raters.

It starts by creating a random order of the users. After that it assignes the next $num_assignments users to a rater with index $i ($i+1 to $i+$numassignments) as peers. (Starting back from 0 if the counter exceeds the number of users)

Note that this will not include all theoretical combinations, but the randomization is good enough and the code much easier to maintain.

u0 u1 u2 u3 u4 (raters) u0 2 1 u1 1 2 u2 2 1 u3 2 1 u4 2 1 (peers)

Example above for 5 users and 2 assignments.

Author
Alexander Killing killi.nosp@m.ng@l.nosp@m.eifos.nosp@m..de

Definition at line 32 of file class.ExcPeerReviewDistribution.php.

Constructor & Destructor Documentation

◆ __construct()

ILIAS\Exercise\PeerReview\ExcPeerReviewDistribution::__construct ( array  $user_ids,
  $num_assignments 
)

ExcPeerReviewDistribution constructor.

Parameters
int[]$user_ids
int$num_assignments

Definition at line 54 of file class.ExcPeerReviewDistribution.php.

References ILIAS\Exercise\PeerReview\ExcPeerReviewDistribution\$num_assignments, and ILIAS\Exercise\PeerReview\ExcPeerReviewDistribution\initDistribution().

55  {
56  $this->user_ids = array_values($user_ids); // ensure numerical indexing
57 
58  // we cannot assign more users to a single user than count($user_ids) - 1
59  $num_assignments = min($num_assignments, count($user_ids) - 1);
60 
61  // we cannot create a negative number of assignments
63 
64  $this->num_assignments = $num_assignments;
65  $this->initDistribution();
66  }
+ Here is the call graph for this function:

Member Function Documentation

◆ getPeersOfRater()

ILIAS\Exercise\PeerReview\ExcPeerReviewDistribution::getPeersOfRater (   $user_id)

Get peers of rater.

Parameters
int$user_id
Returns
int[]

Definition at line 108 of file class.ExcPeerReviewDistribution.php.

References $key, and ILIAS\Exercise\PeerReview\ExcPeerReviewDistribution\$num_assignments.

109  {
110  $peers = [];
111  $key = array_search($user_id, $this->user_order);
112  if ($key === false) {
113  return [];
114  }
115  for ($j = 1; $j <= $this->num_assignments; $j++) {
116  $peer_key = ($key + $j) % (count($this->user_order));
117  $peers[] = $this->user_order[$peer_key];
118  }
119  return $peers;
120  }
$key
Definition: croninfo.php:18

◆ getUserOrder()

ILIAS\Exercise\PeerReview\ExcPeerReviewDistribution::getUserOrder ( )

◆ initDistribution()

ILIAS\Exercise\PeerReview\ExcPeerReviewDistribution::initDistribution ( )
protected

Init distribution.

Definition at line 71 of file class.ExcPeerReviewDistribution.php.

References ILIAS\Exercise\PeerReview\ExcPeerReviewDistribution\randomUserOrder().

Referenced by ILIAS\Exercise\PeerReview\ExcPeerReviewDistribution\__construct().

72  {
73  $this->user_order = $this->randomUserOrder($this->user_ids);
74  }
+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ randomUserOrder()

ILIAS\Exercise\PeerReview\ExcPeerReviewDistribution::randomUserOrder (   $user_ids)
protected

Random user order.

Parameters
array
Returns
array

Definition at line 81 of file class.ExcPeerReviewDistribution.php.

References ILIAS\Exercise\PeerReview\ExcPeerReviewDistribution\$user_ids.

Referenced by ILIAS\Exercise\PeerReview\ExcPeerReviewDistribution\initDistribution().

81  : array
82  {
83  $order = [];
84  while (count($user_ids) > 0) {
85  $next = rand(0, count($user_ids) - 1);
86  $order[] = $user_ids[$next];
87  unset($user_ids[$next]);
88  $user_ids = array_values($user_ids); // re-index
89  }
90  return $order;
91  }
+ Here is the caller graph for this function:

Field Documentation

◆ $num_assignments

ILIAS\Exercise\PeerReview\ExcPeerReviewDistribution::$num_assignments
protected

◆ $user_ids

ILIAS\Exercise\PeerReview\ExcPeerReviewDistribution::$user_ids = []
protected

◆ $user_order

ILIAS\Exercise\PeerReview\ExcPeerReviewDistribution::$user_order = []
protected

The documentation for this class was generated from the following file: