From f170e53202967f230ba5d987731abc5de90fa782 Mon Sep 17 00:00:00 2001 From: PatrikB Date: Mon, 2 Sep 2024 02:28:33 +0200 Subject: [PATCH] Selective options - Only type 3 results can choose evaluation plots with aggregation functions --- controllers/results.php | 2 ++ core/util.php | 31 +++++++++++++++++++++++-------- 2 files changed, 25 insertions(+), 8 deletions(-) diff --git a/controllers/results.php b/controllers/results.php index 5328fdf59..f239bcf09 100644 --- a/controllers/results.php +++ b/controllers/results.php @@ -47,6 +47,7 @@ public function build() { $this->view->assign('type', intval($this->get['type'])); $plots = Util::getDefaultResultPlots(); $system->getResultPlots($plots); + $plots = Util::filterAllowedPlots($plots, $this->get['type']); $this->view->assign('plots', $plots); } else if (!empty($this->get['experimentId']) && !empty($this->get['type']) && !empty($this->get['resultId'])) { $experiment = Factory::getExperimentFactory()->get($this->get['experimentId']); @@ -62,6 +63,7 @@ public function build() { $plots = Util::getDefaultResultPlots(); $system->getResultPlots($plots); + $plots = Util::filterAllowedPlots($plots, $this->get['type']); $this->view->assign('plots', $plots); } else { throw new Exception("No system/experiment id / type provided!"); diff --git a/core/util.php b/core/util.php index a84bbc5c0..b6295f07c 100644 --- a/core/util.php +++ b/core/util.php @@ -201,14 +201,7 @@ public static function scanForPlots($path, $type = "") { // TODO: check if override happens $plot = new Plot($path . $entry); if ($plot->isValid()) { - # Return only evaluation plots - if($type == 'eval' && strpos(gettype($plot), 'For Evaluations') != false) { - $plots[] = $plot; - } - # Return non-evaluation plots - if(strpos(gettype($plot), 'For Evaluations') === false) { - $plots[] = $plot; - } + $plots[] = $plot; } } return $plots; @@ -222,6 +215,28 @@ public static function getDefaultResultPlots() { return self::scanForPlots(SERVER_ROOT . "/libraries/graphs/"); } + /** + * Filters the plots that are either for evaluations or not + * @return Plot[] + */ + public static function filterAllowedPlots($plots, $type=0) { + $validPlots = []; + if($type==3) { + foreach ($plots as $plot) { + if(strpos(gettype($plot), 'Evaluations') != false) { + $validPlots[] = $plot; + } + } + } + else { + foreach ($plots as $plot) { + if(strpos(gettype($plot), 'Evaluations') === false) { + $validPlots[] = $plot; + } + } + } + return $validPlots; + } /** * @return Element[] * @throws Exception