public function call() { try { $survey_code = strtoupper($this->getArgument('survey')); $survey_mng = new SurveyManager(); if (!$survey_code || !$survey_mng->isSurvey($survey_code)) { $answer = new Answer('error', array("error" => "Survey not found"), 'xml'); $answer->setXMLOpt("rootName", "dashboard"); return $answer; } $survey_result_mng = new SurveyResultManager(); $fetchRow = $survey_result_mng->getSurveyFetch($survey_code); $positive_int = 0; $negative_int = 0; $total_emotions = 0; $pp = 0; $mp = 0; $pn = 0; $mn = 0; $pp_intensities = 0; // Added by Roger to calculate new e.mote score $emotion_obj = new Emotion(); $emotions = array(); foreach ($emotion_obj->listEmotions() as $emote) { $emotions[$emote] = array('value' => 0, 'name' => $emote, 'type' => $emotion_obj->getType($emote)); } while ($row = $fetchRow->nextRow()) { if (!array_key_exists($row['emote'], $emotions)) { continue; } $emote = $emotions[$row['emote']]; ++$total_emotions; ++$emotions[$row['emote']]['value']; ++$emote['value']; /* Added by Roger on 2010-01-25 to change calcs according to Jeb's instructions. */ if ($row['intensity_level'] >= 0 && $row['intensity_level'] < 34) { // Is positive or negative, intensity is bottom third ++$mn; } elseif ($row['intensity_level'] >= 34 && $row['intensity_level'] < 66) { // Is positive or negative, intensity is middle third ++$mp; } elseif ($emote['type'] == 'negative') { // Is negative and intensity is >= 66 ++$pn; } else { // Is positive and intensity is >= 66 ++$pp; $pp_intensities += $row['intensity_level']; } if ($emote['type'] == 'negative') { $negative_int += $row['intensity_level'] ? $row['intensity_level'] : 1; } else { $positive_int += $row['intensity_level'] ? $row['intensity_level'] : 1; } /* Old/replaced code start if($emote['type'] == 'negative'){ $negative_int += $row['intensity_level'] ? $row['intensity_level'] : 1; if($row['intensity_level'] > 50) ++$pn; else ++$mn; }else{ $positive_int += $row['intensity_level'] ? $row['intensity_level'] : 1; if($row['intensity_level'] > 50) ++$pp; else ++$mp; } Old code end */ } $emote_score = round($pp_intensities / $pp); // Replaced by Roger 2010-01-25 // $emote_score = (int)(100 * $pp / $total_emotions); $a_bar = array(); usort($emotions, array($this, 'emote_cmp')); foreach ($emotions as $emote_name => $emote) { $color = $emote['type'] == 'negative' ? 'red' : 'green'; array_push($a_bar, array("_attributes" => array("name" => $emote['name'], "value" => $emote['value'], 'color' => $color))); } $result = array('graph' => array(array('bar' => $a_bar, "_attributes" => array("type" => "emotion distribution")), array("slice" => array(array("_attributes" => array("name" => "pp", "value" => $pp)), array("_attributes" => array("name" => "mp", "value" => $mp)), array("_attributes" => array("name" => "pn", "value" => $pn)), array("_attributes" => array("name" => "mn", "value" => $mn))), "_attributes" => array("type" => "intensity distrubition")))); $answer = new Answer('ok', $result, 'xml'); $answer->setXMLOpt("rootName", "dashboard"); $answer->setXMLOpt("rootAttributes", array("emote_score" => $emote_score)); return $answer; } catch (Exception $e) { $answer = new Answer('error', array("error" => $e->getMessage()), 'xml'); $answer->setXMLOpt("rootName", "dashboard"); return $answer; } }