public function modify_score($score, $vote, $old_vote, $metric, $context_id) { $vote_diff = $vote - $old_vote; if ($vote !== $old_vote) { if ($vote === null) { $score['count']--; } elseif ($old_vote === null) { $score['count']++; } } $score['average'] += $vote_diff; $score['value'] = $score['average']; return parent::modify_score($score, $vote, $old_vote, $metric, $context_id); }
public function modify_score($score, $vote, $old_vote, $metric, $context_id) { $vote_diff = $vote - $old_vote; if (!isset($score['data']['positive'])) { $score['data']['positive_votes'] = 0; } if ($vote !== $old_vote) { if ($vote === null) { $score['count']--; if ($old_vote > 0) { $score['data']['positive_votes']--; } } elseif ($old_vote === null) { $score['count']++; if ($vote > 0) { $score['data']['positive_votes']++; } } } $score['average'] += $vote_diff; $score['value'] = self::calculate_wilson_score($score['data']['positive_votes'], $score['count']); return parent::modify_score($score, $vote, $old_vote, $metric, $context_id); }
public function get_vote($metric, $context_id, $user_id) { $vote = array(); $null = true; foreach ($metric['options']['fields'] as $index => $field) { $field_context = $context_id . self::FIELD_KEY . $index; $vote[$index] = parent::get_vote($metric, $field_context, $user_id); if ($vote[$index] !== null) { $null = false; } } if ($null) { return null; } else { return self::calculate_total($vote, $metric['options']); } }
public function modify_score($score, $vote, $old_vote, $metric, $context_id) { $vote_diff = $vote - $old_vote; $score['average'] = $score['average'] * $score['count']; if ($vote !== $old_vote) { if ($vote === null) { $score['count']--; } elseif ($old_vote === null) { $score['count']++; } } if ($score['count'] == 0) { $score['average'] = 0; $score['value'] = 0; } else { $score['average'] = ($score['average'] + $vote_diff) / $score['count']; $score['value'] = self::calculate_bayesian_score($score['average'], $score['count'], $metric['options']['max']); } return parent::modify_score($score, $vote, $old_vote, $metric, $context_id); }
public function modify_score($score, $vote, $old_vote, $metric, $context_id) { if ($vote !== $old_vote) { if ($vote === null) { $score['count']--; } elseif ($old_vote === null) { $score['count']++; } } // Initialize the data array if (empty($score['data']['votes'])) { $answers_count = count(preg_split("/\r\n|\n|\r/", $metric['options']['answers'])); for ($i = 0; $i < $answers_count; $i++) { $score['data']['votes'][$i] = 0; } } // Tally votes if ($old_vote !== null) { $score['data']['votes'][$old_vote]--; } if ($vote !== null) { $score['data']['votes'][$vote]++; } // Get the index for the highest value in our scores array. $score['average'] = array_keys($score['data']['votes'], max($score['data']['votes']))[0]; $score['value'] = $score['average']; return parent::modify_score($score, $vote, $old_vote, $metric, $context_id); }