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)); } } } } } }
/** * @param sfWebRequest $request */ public function executeExport(sfWebRequest $request) { //$this->forward404Unless(in_array($this->getUser()->getGuardUser()->account_type, array('Pro', 'Enterprice'))); $decision_id = $request->getParameter('decision_id', false); $decision = DecisionTable::getInstance()->getDecisionForUser($this->getUser()->getGuardUser(), $decision_id); $this->forward404Unless($decision); header('Content-type: application/force-download'); header('Content-Disposition: attachment; filename="' . $decision->name . '.xlsx"'); $criteriaAnalyze = new CriteriaAnalyze(); $criteriaAnalyze->setDecisionId($decision_id); $criteriaAnalyze->load(); $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(); $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(); $excelExporter = new AlternativesExcelExporter($stackedBarChart); $excelExporter->export(); exit; }
/** * @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) . '}'); }
/** * @param Response $response * @param ProfilerLog $result * @throws Exception */ protected function plot_charts(Response $response, ProfilerLog $result) { CanvasJS::init_canvasJS_header($response); $chart = new TimeFractionChart(); $chart->set_title("Fractions of Time"); $chart->set_canvas_css_style("height: 300px; width: 450px; float: left; clear: both"); $chart->load_data($result->getFractionsData()); $chart->write($response); $chart = new ProgressChart(); $script_data = $result->getScriptData(); $chart->set_title("Processes over Time"); $chart->set_canvas_css_style("height: 300px; width: 100%; float: right;"); $chart->append_properties(['axisX' => ['maximum' => $script_data['duration']]]); $chart->load_data($result->getProcData()); $chart->write($response); $chart = new StackedBarChartDup(); $duplicate_proc_data = $result->getDuplicateProcData(); if (count($duplicate_proc_data) > 0) { $height = 20 * (6 + count($duplicate_proc_data->getAllValuesX())); $maxY = $duplicate_proc_data->getAllDataPoints()->getMaxY(); $chart->set_title("Redundant Processes"); $chart->set_canvas_css_style("height: {$height}px; min-width: 100%; float: left;"); $chart->append_properties(['axisY2' => ['maximum' => 1.1 * $maxY]]); $chart->load_data($duplicate_proc_data); $chart->write($response); } $chart = new StackedBarChart(); $sql_data = $result->getSqlData(); $height = 20 * (6 + count($sql_data->getAllValuesX())); $maxY = $sql_data->getAllDataPoints()->getMaxY(); $chart->set_title("SQL-Selects by Table and Row Count"); $chart->set_canvas_css_style("height: {$height}px; min-width: 100%; float: left;"); $chart->append_properties(['axisY2' => ['maximum' => 1.1 * $maxY]]); $chart->load_data($sql_data); $chart->write($response); }
private function getUpdateActionResponse($criteriaAnalyze, $decision_id, $revert = false, $response = array()) { // 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->setSaveGraph(false); $stackedBarChart->setCriteriaValues($criteriaAnalyze->getCriteriaValues()); $stackedBarChart->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(); } $response[] = '"stackedBarChart":{' . implode(',', $stacked_bar_chart) . '}'; return $this->renderText('{' . implode(',', $response) . '}'); }