Beispiel #1
0
/**
* Gather and parse assessments made about user
*	Input: set of assessments already filtered
*	Output: karma term
*/
function userKarma_decisionMaking($valorationlist)
{
    if (sizeof($valorationlist) <= 0) {
        return elgg_echo('hflts:karma:none');
    }
    $count = 0;
    $data = array('_', '_');
    $enablePesos = elgg_get_plugin_setting('weight_assessments', 'hflts');
    $C_weight = null;
    $enableExpertos = elgg_get_plugin_setting('weight_experts', 'hflts');
    $E_weight = null;
    if (is_array($valorationlist)) {
        foreach ($valorationlist as $evaluation) {
            $data[$count] = array('ref' => $evaluation->user_guid, 'co_codigo' => $evaluation->owner_guid);
            //more to come
            if (!is_array($evaluation->criterion1)) {
                $data[$count]['U1'] = $evaluation->criterion1;
                $data[$count]['L1'] = $evaluation->criterion1;
            } else {
                $n = count($evaluation->criterion1) - 1;
                $data[$count]['U1'] = $evaluation->criterion1[$n];
                $data[$count]['L1'] = $evaluation->criterion1[0];
            }
            if (!is_array($evaluation->criterion2)) {
                $data[$count]['U2'] = $evaluation->criterion2;
                $data[$count]['L2'] = $evaluation->criterion2;
            } else {
                $n = count($evaluation->criterion2) - 1;
                $data[$count]['U2'] = $evaluation->criterion2[$n];
                $data[$count]['L2'] = $evaluation->criterion2[0];
            }
            if (!is_array($evaluation->criterion3)) {
                $data[$count]['U3'] = $evaluation->criterion3;
                $data[$count]['L3'] = $evaluation->criterion3;
            } else {
                $n = count($evaluation->criterion3) - 1;
                $data[$count]['U3'] = $evaluation->criterion3[$n];
                $data[$count]['L3'] = $evaluation->criterion3[0];
            }
            if (!is_array($evaluation->criterion4)) {
                $data[$count]['U4'] = $evaluation->criterion4;
                $data[$count]['L4'] = $evaluation->criterion4;
            } else {
                $n = count($evaluation->criterion4) - 1;
                $data[$count]['U4'] = $evaluation->criterion4[$n];
                $data[$count]['L4'] = $evaluation->criterion4[0];
            }
            if ($enablePesos) {
                $C_weight[$count] = array($evaluation->weight1, $evaluation->weight2, $evaluation->weight3, $evaluation->weight4);
            }
            if ($enableExpertos) {
                $expert = get_user($evaluation->owner_guid);
                $E_weight[$count] = $expert->userpoints_points;
            }
            //$evaluation->delete();//to clean
            $count++;
        }
    }
    $computed_weight = relativeUserExpertise($E_weight);
    if ($count >= 2) {
        $method = new AggregationHFLTS($evaluation->user_guid);
        $method->setData($data, $C_weight, $E_weight, $count, $evaluation->granularity);
        $model->collectiveValoration = $method->run();
        unset($method);
        //destroys the object
        //set valoration on user's profile
        $user = get_user($evaluation->user_guid);
        //system_message($count . "# " . $user->username . " @ " . $model->collectiveValoration);
        return $model->collectiveValoration;
    } else {
        return elgg_echo("hflts:karma:none");
    }
}
function update_allusers_expertise()
{
    $base = elgg_get_plugin_setting('base_expertise', 'hflts');
    //system_message("Computing with B=" . $base . " %");
    $options = array('type' => 'user', 'limit' => $limit, 'offset' => $offset);
    //,
    $entities = elgg_get_entities_from_metadata($options);
    $i = 0;
    //counter
    $points = array();
    $values = array();
    if (is_array($entities)) {
        foreach ($entities as $entity) {
            $entity->karma = userKarma($entity->guid);
            //recalculo todo de cara a overview
            $points[$i] = $entity->userpoints_points;
            $i++;
        }
    }
    $values = relativeUserExpertise($points);
    $i = 0;
    foreach ($entities as $entity) {
        $entity->expertise = $values[$i];
        //system_message($entity->name ." with ". $entity->expertise);
        $i++;
    }
}
Beispiel #3
0
 /**
  * get from the system the values needed in the model. Called from driver, from icon,... but not from collective
  * input: array of $size assessments 
  * input: array of $size x M criteria weights
  * input: array of $size x 1 expert weights
  */
 public function setData($values, $C_weight, $E_weight, $size, $granularity)
 {
     if ($size == 0) {
         return;
     }
     $this->data = $values;
     if ($this->information) {
         echo "#" . $size . ' Dt: <pre>';
         print_r($this->data);
         echo '</pre><br>';
     }
     if (sizeof($values) != $size) {
         //return;
         system_message($size . "  DMCM setData " . sizeof($values));
     }
     //
     $this->P = $this->num = $size;
     //no necesariamente dos valoraciones vienen de 2 expertos
     $this->G = $granularity;
     // compute the averaged expert preference over criteria. Not normalized
     $this->superE = $C_weight;
     if ($C_weight != null) {
         $this->W = averagedUserPreference($C_weight, $this->M);
     }
     if ($E_weight != null) {
         $this->E = relativeUserExpertise($E_weight);
     }
     //Idea: no normalizar aqui sino fuera en driver + mcdm lib
     if ($this->information) {
         echo '! W: <pre>';
         print_r($this->W);
         echo '</pre><br>';
         echo '! E: <pre>';
         print_r($this->E);
         echo '</pre><br>';
         echo '! superE: <pre>';
         print_r($this->superE);
         echo '</pre><br>';
     }
 }