Exemplo n.º 1
0
 public function generateChart($post_id)
 {
     $post = Doctrine_Core::getTable('WallPost')->find($post_id);
     $params = json_decode($post->params, true);
     if ($post->type == 'xy') {
         $chart = new PointChart();
         $chart->setPointsXY($params['data']);
         $chart->setXLabelById($params['x']);
         $chart->setYLabelById($params['y']);
         include_partial('xyImage', array('chart' => $chart));
     } else {
         if ($post->type == 'bubble') {
             $chart = new BubbleChart();
             $chart->setPointsXY($params['data']);
             $chart->setXLabelById($params['x']);
             $chart->setYLabelById($params['y']);
             $chart->setZLabelById($params['z']);
             include_partial('bubbleImage', array('chart' => $chart));
         } else {
             if ($post->type == 'cumulative') {
                 $chart = new CumulativeGainChart();
                 $chart->setPointsXY($params['data']);
                 $chart->setXLabelById($params['x']);
                 include_partial('cumulativeImage', array('chart' => $chart));
             } else {
                 if ($post->type == 'cost') {
                     $costAnalyze = new CostAnalyze();
                     $costAnalyze->setCriterionId($params['criterion_id']);
                     $costAnalyze->setBScore($params['b_score']);
                     $costAnalyze->setPool($params['pool']);
                     $costAnalyze->setUnallocated($params['unallocated']);
                     if (array_key_exists('red_line', $params)) {
                         $costAnalyze->setRedLine($params['red_line']);
                     }
                     $costAnalyze->setOrder($params['order']);
                     $analyze = $costAnalyze;
                     include_partial('costImage', array('analyze' => $analyze));
                 } else {
                     if ($post->type == 'partition') {
                         $releases = Doctrine_Query::create()->from('ProjectRelease r')->leftJoin('r.ProjectReleaseAlternative ra')->leftJoin('ra.Alternative a')->where('r.decision_id = ? AND r.criterion_id = ?', array($this->decision->id, $params['criterion_id']))->execute();
                         include_partial('partitionImage', array('releases' => $releases));
                     } else {
                         $stackedBarChart = $radarChart = null;
                         $criteriaAnalyze = new CriteriaAnalyze();
                         $criteriaAnalyze->setDecisionId($this->decision->id);
                         $criteriaAnalyze->setCriteriaValues($params['graph']);
                         if ($post->type == 'criteria') {
                             $analyze = $criteriaAnalyze;
                         } else {
                             $stackedBarChart = new StackedBarChart();
                             $stackedBarChart->setDecisionId($this->decision->id);
                             $stackedBarChart->setCriteriaValues($criteriaAnalyze->getCriteriaValues());
                             $stackedBarChart->load();
                             if ($post->type == 'radar') {
                                 $radarChart = new RadarChart();
                                 $radarChart->setData($stackedBarChart->getData());
                                 $radarChart->setAlternativeNames($stackedBarChart->getAlternativesNames());
                                 $radarChart->setCriteriaNames($stackedBarChart->getCriteriaNames());
                                 if (array_key_exists('filter', $params)) {
                                     $radarChart->setFilterData($params['filter']);
                                 }
                                 $radarChart->prepareData();
                                 $analyze = $radarChart;
                             } else {
                                 $analyze = $stackedBarChart;
                             }
                         }
                         include_partial($post->type . 'Image', array('analyze' => $analyze, 'radarChart' => $radarChart, 'stackedBarChart' => $stackedBarChart, 'criteriaAnalyze' => $criteriaAnalyze));
                     }
                 }
             }
         }
     }
 }
Exemplo n.º 2
0
 /**
  * @param $criteriaAnalyze
  * @param $decision_id
  * @param bool $revert
  * @param array $response
  * @return sfView
  */
 private function getUpdateActionResponse($criteriaAnalyze, $decision_id, $revert = false, $response = array())
 {
     $logicalFilter = new LogicalFilterView();
     $logicalFilter->setDecisionId($decision_id);
     $logicalFilter->load();
     $roleFilter = new RoleFilterView();
     $roleFilter->setDecisionId($decision_id);
     $roleFilter->load();
     $statusFilter = new StatusFilterView();
     $statusFilter->setDecisionId($decision_id);
     $statusFilter->load();
     $tagFilter = new TagFilterView();
     $tagFilter->setDecisionId($decision_id);
     $tagFilter->load();
     // When user changes the weights of criteria all dependent values
     // should be recalculated automatically in the alternatives chart
     $stackedBarChart = new StackedBarChart();
     $stackedBarChart->setDecisionId($decision_id);
     $stackedBarChart->setCriteriaValues($criteriaAnalyze->getCriteriaValues());
     $stackedBarChart->setRoleFilterData($roleFilter->getData());
     $stackedBarChart->setStatusFilterData($statusFilter->getData());
     $stackedBarChart->setTagFilterData($tagFilter->getDataForSQL());
     $stackedBarChart->setFilteredAlternativesIds($logicalFilter->getFilteredAlternativesIds());
     $stackedBarChart->load();
     $radarChart = new RadarChart();
     $radarChart->setData($stackedBarChart->getData());
     $radarChart->setAlternativeNames($stackedBarChart->getAlternativesNames());
     $radarChart->setCriteriaNames($stackedBarChart->getCriteriaNames());
     $radarChart->prepareData();
     $pointChart = new PointChart();
     $pointChart->setDecisionId($decision_id);
     $pointChart->setCriteriaValues($criteriaAnalyze->getCriteriaValues());
     $pointChart->setRoleFilterData($roleFilter->getData());
     $pointChart->setStatusFilterData($statusFilter->getData());
     $pointChart->setTagFilterData($tagFilter->getDataForSQL());
     $pointChart->setFilteredAlternativesIds($logicalFilter->getFilteredAlternativesIds());
     $pointChart->load();
     $pointChart->setTotalBenefit($stackedBarChart->getTotalBenefit());
     $bubbleChart = new BubbleChart();
     $bubbleChart->setDecisionId($decision_id);
     $bubbleChart->setCriteriaValues($criteriaAnalyze->getCriteriaValues());
     $bubbleChart->setRoleFilterData($roleFilter->getData());
     $bubbleChart->setStatusFilterData($statusFilter->getData());
     $bubbleChart->setTagFilterData($tagFilter->getDataForSQL());
     $bubbleChart->setFilteredAlternativesIds($logicalFilter->getFilteredAlternativesIds());
     $bubbleChart->setTotalBenefit($stackedBarChart->getTotalBenefit());
     $bubbleChart->load();
     $costAnalyze = new CostAnalyze();
     $costAnalyze->setDecisionId($decision_id);
     $costAnalyze->setSortedAlternativeIds($stackedBarChart->getSortedAlternativeIds());
     $costAnalyze->setFilteredAlternativesIds($logicalFilter->getFilteredAlternativesIds());
     $costAnalyze->setCumulativeData($stackedBarChart->getCumulativeData());
     $costAnalyze->load();
     $cumulativeChart = new CumulativeGainChart();
     $cumulativeChart->setDecisionId($decision_id);
     $cumulativeChart->setSortedAlternativeIds($stackedBarChart->getSortedAlternativeIds());
     $cumulativeChart->setMeasurement($stackedBarChart->getCumulativeData());
     $cumulativeChart->setCostData($costAnalyze->getData());
     $cumulativeChart->setAlternativeNames($costAnalyze->getAlternativeNames());
     $cumulativeChart->setCriterionNames($costAnalyze->getCriteria());
     $cumulativeChart->load();
     $this->getResponse()->setHttpHeader('Content-Type', 'application/json; charset=utf-8');
     $stacked_bar_chart[] = '"data":' . $stackedBarChart->getJsonData();
     $stacked_bar_chart[] = '"alternatives":' . $stackedBarChart->getAlternativesJson();
     $stacked_bar_chart[] = '"criteria":' . $stackedBarChart->getCriteriaJson();
     if ($revert) {
         $response[] = '"criteriaData":' . $criteriaAnalyze->getJsonData();
     }
     $point_chart[] = '"data":' . $pointChart->getJsonData();
     $point_chart[] = '"criteria":' . json_encode($pointChart->getCriteriaNames());
     $bubble_chart[] = '"data":' . $bubbleChart->getJsonData();
     $bubble_chart[] = '"criteria":' . json_encode($pointChart->getCriteriaNames());
     $response[] = '"stackedBarChart":{' . implode(',', $stacked_bar_chart) . '}';
     $response[] = '"pointChart":{' . implode(',', $point_chart) . '}';
     $response[] = '"bubbleChart":{' . implode(',', $bubble_chart) . '}';
     $cumulative_chart[] = '"costData":' . $cumulativeChart->getJsonCostData();
     $cumulative_chart[] = '"benefitData":' . $cumulativeChart->getJsonData();
     $cumulative_chart[] = '"criteria":' . json_encode($costAnalyze->getCriteria());
     $cumulative_chart[] = '"alternatives":' . $cumulativeChart->getAlternativesJson();
     $response[] = '"cumulativeChart":{' . implode(',', $cumulative_chart) . '}';
     $cost_analyze[] = '"alternatives":' . $costAnalyze->getAlternativesJson();
     $cost_analyze[] = '"order":' . $costAnalyze->getAlternativeOrderJson();
     $cost_analyze[] = '"data":' . $costAnalyze->getJsonData();
     $cost_analyze[] = '"bScoreData":' . $costAnalyze->getCumulativeJsonData();
     $response[] = '"radarChart":' . $radarChart->getJsonData();
     $response[] = '"costOrder":{' . implode(',', $cost_analyze) . '}';
     return $this->renderText('{' . implode(',', $response) . '}');
 }