コード例 #1
0
ファイル: actions.class.php プロジェクト: sensorsix/app
 /**
  * @param sfWebRequest $request
  */
 public function executeGenerateImage(sfWebRequest $request)
 {
     $decision_id = $request->getParameter('decision_id', false);
     $this->forward404Unless(Doctrine::getTable('Decision')->find($decision_id));
     $type = $request->getParameter('type');
     if ($type == 'xy') {
         $this->chart = new PointChart();
         $this->chart->setPointsXY($request->getParameter('data'));
         $this->chart->setXLabelById($request->getParameter('x'));
         $this->chart->setYLabelById($request->getParameter('y'));
     } else {
         if ($type == 'bubble') {
             $this->chart = new BubbleChart();
             $this->chart->setPointsXY($request->getParameter('data'));
             $this->chart->setXLabelById($request->getParameter('x'));
             $this->chart->setYLabelById($request->getParameter('y'));
             $this->chart->setZLabelById($request->getParameter('z'));
         } else {
             if ($type == 'cumulative') {
                 $this->chart = new CumulativeGainChart();
                 $this->chart->setPointsXY($request->getParameter('data'));
                 $this->chart->setXLabelById($request->getParameter('x'));
             } else {
                 if ($type == 'cost') {
                     $costAnalyze = new CostAnalyze();
                     $costAnalyze->setCriterionId($request->getParameter('criterion_id'));
                     $costAnalyze->setBScore($request->getParameter('b_score'));
                     $costAnalyze->setPool($request->getParameter('pool'));
                     $costAnalyze->setUnallocated($request->getParameter('unallocated'));
                     $costAnalyze->setRedLine($request->getParameter('red_line', array()));
                     $costAnalyze->setOrder($request->getParameter('order'));
                     $this->analyze = $costAnalyze;
                 } else {
                     if ($type == 'partition') {
                         $this->releases = Doctrine_Query::create()->from('ProjectRelease r')->leftJoin('r.ProjectReleaseAlternative ra')->leftJoin('ra.Alternative a')->where('r.decision_id = ? AND r.criterion_id = ?', array($decision_id, $request->getParameter('criterion_id')))->execute();
                     } else {
                         $criteriaAnalyze = new CriteriaAnalyze();
                         $criteriaAnalyze->setDecisionId($decision_id);
                         $criteriaAnalyze->setCriteriaValues($request->getParameter('graph', array()));
                         if ($type == 'criteria') {
                             $this->analyze = $criteriaAnalyze;
                         } else {
                             $stackedBarChart = new StackedBarChart();
                             $stackedBarChart->setDecisionId($decision_id);
                             $stackedBarChart->setCriteriaValues($criteriaAnalyze->getCriteriaValues());
                             $stackedBarChart->load();
                             if ($type == 'radar') {
                                 $radarChart = new RadarChart();
                                 $radarChart->setData($stackedBarChart->getData());
                                 $radarChart->setAlternativeNames($stackedBarChart->getAlternativesNames());
                                 $radarChart->setCriteriaNames($stackedBarChart->getCriteriaNames());
                                 $radarChart->setFilterData($request->getParameter('filter'));
                                 $radarChart->prepareData();
                                 $this->analyze = $radarChart;
                             } else {
                                 $this->analyze = $stackedBarChart;
                             }
                         }
                     }
                 }
             }
         }
     }
     $this->setTemplate($type . 'Image');
     $this->setLayout('html_to_image');
 }
コード例 #2
0
ファイル: ChartsHandler.php プロジェクト: sensorsix/app
 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));
                     }
                 }
             }
         }
     }
 }
コード例 #3
0
ファイル: actions.class.php プロジェクト: sensorsix/app
 /**
  * @param sfWebRequest $request
  * @return sfView
  */
 public function executeSave(sfWebRequest $request)
 {
     $this->forward404Unless($request->isXmlHttpRequest());
     $measurement = $request->getParameter('measurement');
     $decision_id = $request->getParameter('decision_id');
     $user = $this->getUser()->getGuardUser();
     $keys = array_keys($measurement);
     $alternative_id = array_shift($keys);
     $keys = array_keys($measurement[$alternative_id]);
     $criterion_id = array_shift($keys);
     $value = $measurement[$alternative_id][$criterion_id];
     $alternativeMeasurement = AlternativeMeasurementTable::getInstance()->getOneForDashboard($user, $decision_id, $alternative_id, $criterion_id);
     if (is_object($alternativeMeasurement)) {
         $alternativeMeasurement->score = $value;
         $alternativeMeasurement->save();
     } else {
         $response = ResponseTable::getInstance()->getOneForDashboard($user, $decision_id);
         if (is_object($response)) {
             $alternativeMeasurement = new AlternativeMeasurement();
             $alternativeMeasurement->score = $value;
             $alternativeMeasurement->alternative_head_id = $alternative_id;
             $alternativeMeasurement->criterion_id = $criterion_id;
             $alternativeMeasurement->Response = $response;
             $alternativeMeasurement->save();
         }
     }
     Doctrine_Query::create()->delete()->from('Graph')->where('decision_id = ?', $decision_id)->execute();
     $criteriaAnalyze = new CriteriaAnalyze();
     $criteriaAnalyze->setDecisionId($decision_id);
     $criteriaAnalyze->load();
     $stackedBarChart = new StackedBarChart();
     $stackedBarChart->setDecisionId($decision_id);
     $stackedBarChart->setCriteriaValues($criteriaAnalyze->getCriteriaValues());
     $stackedBarChart->load();
     $costAnalyze = new CostAnalyze();
     $costAnalyze->setDecisionId($decision_id);
     $costAnalyze->setSortedAlternativeIds($stackedBarChart->getSortedAlternativeIds());
     $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();
     $stacked_bar_chart[] = '"data":' . $stackedBarChart->getJsonData();
     $stacked_bar_chart[] = '"alternatives":' . $stackedBarChart->getAlternativesJson();
     $stacked_bar_chart[] = '"criteria":' . $stackedBarChart->getCriteriaJson();
     $cumulative_chart[] = '"costData":' . $cumulativeChart->getJsonCostData();
     $cumulative_chart[] = '"benefitData":' . $cumulativeChart->getJsonData();
     $cumulative_chart[] = '"criteria":' . json_encode($costAnalyze->getCriteria());
     $cumulative_chart[] = '"alternatives":' . $cumulativeChart->getAlternativesJson();
     $response = array();
     $response[] = '"cumulativeChart":{' . implode(',', $cumulative_chart) . '}';
     $response[] = '"stackedBarChart":{' . implode(',', $stacked_bar_chart) . '}';
     $this->getResponse()->setHttpHeader('Content-Type', 'application/json; charset=utf-8');
     return $this->renderText('{' . implode(',', $response) . '}');
 }