public function mlparamEvaluationAction() { $rows = $categories = $series = ''; $must_wait = 'NO'; try { $dbml = new \PDO($this->container->get('config')['db_conn_chain_ml'], $this->container->get('config')['mysql_user'], $this->container->get('config')['mysql_pwd']); $dbml->setAttribute(\PDO::ATTR_ERRMODE, \PDO::ERRMODE_EXCEPTION); $dbml->setAttribute(\PDO::ATTR_EMULATE_PREPARES, false); $db = $this->container->getDBUtils(); $where_configs = ''; $preset = null; if (count($_GET) <= 1 || count($_GET) == 2 && array_key_exists('parameval', $_GET) || count($_GET) == 2 && array_key_exists('current_model', $_GET)) { $preset = Utils::setDefaultPreset($db, 'mlparameval'); } $selPreset = isset($_GET['presets']) ? $_GET['presets'] : "none"; $params = array(); $param_names = array('benchs', 'nets', 'disks', 'mapss', 'iosfs', 'replications', 'iofilebufs', 'comps', 'blk_sizes', 'id_clusters', 'datanodess', 'bench_types', 'vm_sizes', 'vm_coress', 'vm_RAMs', 'types'); // Order is important foreach ($param_names as $p) { $params[$p] = Utils::read_params($p, $where_configs, FALSE); sort($params[$p]); } $money = Utils::read_params('money', $where_configs); $paramEval = isset($_GET['parameval']) && $_GET['parameval'] != '' ? $_GET['parameval'] : 'maps'; $minExecs = isset($_GET['minexecs']) ? $_GET['minexecs'] : -1; $minExecsFilter = ""; // FIXME PATCH FOR PARAM LIBRARIES WITHOUT LEGACY $where_configs = str_replace("AND .", "AND ", $where_configs); $where_configs = str_replace("`id_cluster`", "e.`id_cluster`", $where_configs); if ($minExecs > 0) { $minExecsFilter = "HAVING COUNT(*) > {$minExecs}"; } $filter_execs = DBUtils::getFilterExecs(); $options = Utils::getFilterOptions($db); $paramOptions = array(); foreach ($options[$paramEval] as $option) { if ($paramEval == 'id_cluster') { $paramOptions[] = $option['name']; } else { if ($paramEval == 'comp') { $paramOptions[] = Utils::getCompressionName($option[$paramEval]); } else { if ($paramEval == 'net') { $paramOptions[] = Utils::getNetworkName($option[$paramEval]); } else { if ($paramEval == 'disk') { $paramOptions[] = Utils::getDisksName($option[$paramEval]); } else { $paramOptions[] = $option[$paramEval]; } } } } } $benchOptions = $db->get_rows("SELECT DISTINCT bench FROM execs e LEFT JOIN clusters c ON e.id_cluster = c.id_cluster WHERE 1 {$filter_execs} {$where_configs} GROUP BY {$paramEval}, bench order by {$paramEval}"); // get the result rows $query = "SELECT count(*) as count, {$paramEval}, e.id_exec, exec as conf, bench, " . "exe_time, avg(exe_time) avg_exe_time, min(exe_time) min_exe_time " . "from execs e LEFT JOIN clusters c ON e.id_cluster = c.id_cluster WHERE 1 {$filter_execs} {$where_configs}" . "GROUP BY {$paramEval}, bench {$minExecsFilter} order by bench,{$paramEval}"; $rows = $db->get_rows($query); if (!$rows) { throw new \Exception("No results for query!"); } $arrayBenchs = array(); foreach ($paramOptions as $param) { foreach ($benchOptions as $bench) { $arrayBenchs[$bench['bench']][$param] = null; $arrayBenchs[$bench['bench']][$param]['y'] = 0; $arrayBenchs[$bench['bench']][$param]['count'] = 0; } } $series = array(); $bench = ''; foreach ($rows as $row) { if ($paramEval == 'comp') { $row[$paramEval] = Utils::getCompressionName($row['comp']); } else { if ($paramEval == 'id_cluster') { $row[$paramEval] = Utils::getClusterName($row[$paramEval], $db); } else { if ($paramEval == 'net') { $row[$paramEval] = Utils::getNetworkName($row['net']); } else { if ($paramEval == 'disk') { $row[$paramEval] = Utils::getDisksName($row['disk']); } else { if ($paramEval == 'iofilebuf') { $row[$paramEval] /= 1024; } } } } } $arrayBenchs[$row['bench']][$row[$paramEval]]['y'] = round((int) $row['avg_exe_time'], 2); $arrayBenchs[$row['bench']][$row[$paramEval]]['count'] = (int) $row['count']; } // ---------------------------------------------------- // Add predictions to the series // ---------------------------------------------------- $jsonData = $jsonHeader = "[]"; $instance = ""; $arrayBenchs_pred = array(); // FIXME PATCH FOR PARAM LIBRARIES WITHOUT LEGACY $where_configs = str_replace("AND .", "AND ", $where_configs); // compose instance $instance = MLUtils::generateSimpleInstance($param_names, $params, true, $db); $model_info = MLUtils::generateModelInfo($param_names, $params, true, $db); $instances = MLUtils::generateInstances($param_names, $params, true, $db); // model for filling $possible_models = $possible_models_id = array(); MLUtils::findMatchingModels($model_info, $possible_models, $possible_models_id, $dbml); $current_model = ""; if (array_key_exists('current_model', $_GET) && in_array($_GET['current_model'], $possible_models_id)) { $current_model = $_GET['current_model']; } if (!empty($possible_models_id)) { if ($current_model == "") { $query = "SELECT AVG(ABS(exe_time - pred_time)) AS MAE, AVG(ABS(exe_time - pred_time)/exe_time) AS RAE, p.id_learner FROM predictions p, learners l WHERE l.id_learner = p.id_learner AND p.id_learner IN ('" . implode("','", $possible_models_id) . "') AND predict_code > 0 ORDER BY MAE LIMIT 1"; $result = $dbml->query($query); $row = $result->fetch(); $current_model = $row['id_learner']; } $config = $instance . '-' . $current_model . "-parameval"; $query_cache = "SELECT count(*) as total FROM trees WHERE id_learner = '" . $current_model . "' AND model = '" . $model_info . "'"; $is_cached_mysql = $dbml->query($query_cache); $tmp_result = $is_cached_mysql->fetch(); $is_cached = $tmp_result['total'] > 0; $ret_data = null; if (!$is_cached) { // Call to MLFindAttributes, to fetch data $_GET['pass'] = 2; $_GET['unseen'] = 1; $_GET['current_model'] = $current_model; $mlfa1 = new MLFindAttributesController(); $mlfa1->container = $this->container; $ret_data = $mlfa1->mlfindattributesAction(); if ($ret_data == 1) { $must_wait = "YES"; $jsonData = $jsonHeader = '[]'; } else { $is_cached_mysql = $dbml->query($query_cache); $tmp_result = $is_cached_mysql->fetch(); $is_cached = $tmp_result['total'] > 0; } } if ($is_cached) { $must_wait = 'NO'; $query = "SELECT count(*) as count, {$paramEval}, bench, exe_time, avg(pred_time) avg_pred_time, min(pred_time) min_pred_time " . "FROM predictions e WHERE e.id_learner = '" . $current_model . "' {$filter_execs} {$where_configs}" . "GROUP BY {$paramEval}, bench {$minExecsFilter} order by bench, {$paramEval}"; $result = $dbml->query($query); // Initialize array foreach ($paramOptions as $param) { foreach ($benchOptions as $bench) { $arrayBenchs_pred[$bench['bench'] . '_pred'][$param] = null; $arrayBenchs_pred[$bench['bench'] . '_pred'][$param]['y'] = 0; $arrayBenchs_pred[$bench['bench'] . '_pred'][$param]['count'] = 0; } } foreach ($result as $row) { $bench_n = $row['bench'] . '_pred'; $class = $row[$paramEval]; if ($paramEval == 'comp') { $value = Utils::getCompressionName($class); } else { if ($paramEval == 'id_cluster') { $value = Utils::getClusterName($class, $db); } else { if ($paramEval == 'net') { $value = Utils::getNetworkName($class); } else { if ($paramEval == 'disk') { $value = Utils::getDisksName($class); } else { if ($paramEval == 'iofilebuf') { $value = $class / 1024; } else { $value = $class; } } } } } if (!in_array($value, $paramOptions)) { $paramOptions[] = $value; foreach ($benchOptions as $bench) { $arrayBenchs_pred[$bench['bench'] . '_pred'][$value] = null; $arrayBenchs_pred[$bench['bench'] . '_pred'][$value]['y'] = 0; $arrayBenchs_pred[$bench['bench'] . '_pred'][$value]['count'] = 0; $arrayBenchs[$bench['bench']][$value] = null; $arrayBenchs[$bench['bench']][$value]['y'] = 0; $arrayBenchs[$bench['bench']][$value]['count'] = 0; } } $arrayBenchs_pred[$bench_n][$value]['y'] = (int) $row['avg_pred_time']; $arrayBenchs_pred[$bench_n][$value]['count'] = (int) $row['count']; } } } // ---------------------------------------------------- // END - Add predictions to the series // ---------------------------------------------------- asort($paramOptions); foreach ($arrayBenchs as $key => $arrayBench) { $caregories = ''; $data_a = null; $data_p = null; foreach ($paramOptions as $param) { if ($arrayBenchs[$key][$param]['count'] > 0 && empty($arrayBenchs_pred) || !empty($arrayBenchs_pred) && ($arrayBenchs_pred[$key . '_pred'][$param]['count'] > 0 || $arrayBenchs[$key][$param]['count'] > 0)) { $data_a[] = $arrayBenchs[$key][$param]; if (!empty($arrayBenchs_pred)) { $data_p[] = $arrayBenchs_pred[$key . '_pred'][$param]; } $categories = $categories . "'{$param} " . Utils::getParamevalUnit($paramEval) . "',"; // FIXME - Redundant n times performed... don't care now } } $series[] = array('name' => $key, 'data' => $data_a); if (!empty($arrayBenchs_pred)) { $series[] = array('name' => $key . '_pred', 'data' => $data_p); } } $series = json_encode($series); if (!empty($arrayBenchs_pred)) { $colors = "['#7cb5ec','#9cd5fc','#434348','#636368','#90ed7d','#b0fd9d','#f7a35c','#f7c37c','#8085e9','#a0a5f9','#f15c80','#f17ca0','#e4d354','#f4f374','#8085e8','#a0a5f8','#8d4653','#ad6673','#91e8e1','#b1f8f1']"; } else { $colors = "['#7cb5ec','#434348','#90ed7d','#f7a35c','#8085e9','#f15c80','#e4d354','#8085e8','#8d4653','#91e8e1']"; } } catch (\Exception $e) { $this->container->getTwig()->addGlobal('message', $e->getMessage() . "\n"); $series = $jsonHeader = $colors = '[]'; $instance = $current_model = ''; $possible_models = $possible_models_id = array(); $must_wait = 'NO'; } echo $this->container->getTwig()->render('mltemplate/mlconfigperf.html.twig', array('selected' => 'mlparameval', 'title' => 'Improvement of Hadoop Execution by SW and HW Configurations', 'categories' => $categories, 'series' => $series, 'benchs' => $params['benchs'], 'nets' => $params['nets'], 'disks' => $params['disks'], 'blk_sizes' => $params['blk_sizes'], 'comps' => $params['comps'], 'id_clusters' => $params['id_clusters'], 'mapss' => $params['mapss'], 'replications' => $params['replications'], 'iosfs' => $params['iosfs'], 'iofilebufs' => $params['iofilebufs'], 'datanodess' => $params['datanodess'], 'bench_types' => $params['bench_types'], 'vm_sizes' => $params['vm_sizes'], 'vm_coress' => $params['vm_coress'], 'vm_RAMs' => $params['vm_RAMs'], 'types' => $params['types'], 'money' => $money, 'paramEval' => $paramEval, 'instance' => $instance, 'models' => '<li>' . implode('</li><li>', $possible_models) . '</li>', 'models_id' => $possible_models_id, 'current_model' => $current_model, 'gammacolors' => $colors, 'must_wait' => $must_wait, 'preset' => $preset, 'selPreset' => $selPreset, 'options' => Utils::getFilterOptions($db))); }
public function mlcrossvar3dfaAction() { $jsonData = array(); $message = $instance = $possible_models_id = ''; $maxx = $minx = $maxy = $miny = $maxz = $minz = 0; $must_wait = 'NO'; try { $dbml = new \PDO($this->container->get('config')['db_conn_chain_ml'], $this->container->get('config')['mysql_user'], $this->container->get('config')['mysql_pwd']); $dbml->setAttribute(\PDO::ATTR_ERRMODE, \PDO::ERRMODE_EXCEPTION); $dbml->setAttribute(\PDO::ATTR_EMULATE_PREPARES, false); $db = $this->container->getDBUtils(); $where_configs = ''; $preset = null; if (count($_GET) <= 1 || count($_GET) == 2 && array_key_exists('current_model', $_GET) || count($_GET) == 3 && array_key_exists('variable1', $_GET) && array_key_exists('variable2', $_GET) || count($_GET) == 4 && array_key_exists('current_model', $_GET) && array_key_exists('variable1', $_GET) && array_key_exists('variable2', $_GET)) { $preset = Utils::setDefaultPreset($db, 'mlcrossvar3dfa'); } $selPreset = isset($_GET['presets']) ? $_GET['presets'] : "none"; $params = array(); $param_names = array('benchs', 'nets', 'disks', 'mapss', 'iosfs', 'replications', 'iofilebufs', 'comps', 'blk_sizes', 'id_clusters', 'datanodess', 'bench_types', 'vm_sizes', 'vm_coress', 'vm_RAMs', 'types'); // Order is important foreach ($param_names as $p) { $params[$p] = Utils::read_params($p, $where_configs, FALSE); sort($params[$p]); } $cross_var1 = array_key_exists('variable1', $_GET) ? $_GET['variable1'] : 'maps'; $cross_var2 = array_key_exists('variable2', $_GET) ? $_GET['variable2'] : 'net'; $unseen = array_key_exists('unseen', $_GET) && $_GET['unseen'] == 1; $where_configs = str_replace("AND .", "AND ", $where_configs); $cross_var1 = str_replace("id_cluster", "e.id_cluster", $cross_var1); $cross_var2 = str_replace("id_cluster", "e.id_cluster", $cross_var2); // compose instance $instance = MLUtils::generateSimpleInstance($param_names, $params, $unseen, $db); $model_info = MLUtils::generateModelInfo($param_names, $params, $unseen, $db); // Model for filling MLUtils::findMatchingModels($model_info, $possible_models, $possible_models_id, $dbml); $current_model = ""; if (array_key_exists('current_model', $_GET) && in_array($_GET['current_model'], $possible_models_id)) { $current_model = $_GET['current_model']; } // Call to MLFindAttributes, to fetch data $_GET['pass'] = 1; $_GET['unseen'] = $unseen; $mlfa1 = new MLFindAttributesController(); $mlfa1->container = $this->container; $ret_data = $mlfa1->mlfindattributesAction(); $rows = null; if ($ret_data == 1) { $must_wait = "YES"; $jsonData = '[]'; $categories1 = $categories2 = "''"; } else { if ($ret_data == -1) { $must_wait = "NO"; $jsonData = '[]'; $categories1 = $categories2 = "''"; $message = "There are no prediction models trained for such parameters. Train at least one model in 'ML Prediction' section. [" . $instance . "]"; } else { // Get stuff from the DB $query = "SELECT " . $cross_var1 . " AS V1, " . $cross_var2 . " AS V2, AVG(p.pred_time) as V3, p.instance\n\t\t\t\t\tFROM predictions as p\n\t\t\t\t\tWHERE p.id_learner " . ($current_model != '' ? "='" . $current_model . "'" : "IN (SELECT id_learner FROM trees WHERE model='" . $model_info . "')") . $where_configs . "\n\t\t\t\t\tGROUP BY p.instance\n\t\t\t\t\tORDER BY RAND() LIMIT 5000;"; // FIXME - CLUMPSY PATCH FOR BYPASS THE BUG FROM HIGHCHARTS... REMEMBER TO ERASE THIS LINE WHEN THE BUG IS SOLVED $rows = $dbml->query($query); if (empty($rows)) { throw new \Exception('No data matches with your critteria.'); } } } if ($must_wait == "NO") { $map_var1 = $map_var2 = array(); $count_var1 = $count_var2 = 0; $categories1 = $categories2 = ''; $var1_categorical = in_array($cross_var1, array("net", "disk", "bench", "vm_OS", "provider", "vm_size", "type", "bench_type")); $var2_categorical = in_array($cross_var2, array("net", "disk", "bench", "vm_OS", "provider", "vm_size", "type", "bench_type")); foreach ($rows as $row) { $entry = array(); if ($var1_categorical) { if (!array_key_exists($row['V1'], $map_var1)) { $map_var1[$row['V1']] = $count_var1++; $categories1 = $categories1 . ($categories1 != '' ? "," : "") . "\"" . $row['V1'] . "\""; } $entry['y'] = $map_var1[$row['V1']] * (rand(990, 1010) / 1000); } else { $entry['y'] = (int) $row['V1'] * (rand(990, 1010) / 1000); } if ($entry['y'] > $maxy) { $maxy = $entry['y']; } if ($entry['y'] < $miny) { $miny = $entry['y']; } if ($var2_categorical) { if (!array_key_exists($row['V2'], $map_var2)) { $map_var2[$row['V2']] = $count_var2++; $categories2 = $categories2 . ($categories2 != '' ? "," : "") . "\"" . $row['V2'] . "\""; } $entry['x'] = $map_var2[$row['V2']] * (rand(990, 1010) / 1000); } else { $entry['x'] = (int) $row['V2'] * (rand(990, 1010) / 1000); } if ($entry['x'] > $maxx) { $maxx = $entry['x']; } if ($entry['x'] < $minx) { $minx = $entry['x']; } $entry['z'] = -1 * (int) $row['V3'] * (rand(990, 1010) / 1000); if ($entry['z'] > $maxz) { $maxz = $entry['z']; } if ($entry['z'] < $minz) { $minz = $entry['z']; } $entry['name'] = $row['instance']; //$row['V1']." - ".$row['V2']." - ".max(100,(int)$row['V3']); $jsonData[] = $entry; } $jsonData = json_encode($jsonData); if ($categories1 != '') { $categories1 = "[" . $categories1 . "]"; } else { $categories1 = "''"; } if ($categories2 != '') { $categories2 = "[" . $categories2 . "]"; } else { $categories2 = "''"; } } $dbml = null; $cross_var1 = str_replace("e.id_cluster", "id_cluster", $cross_var1); $cross_var2 = str_replace("e.id_cluster", "id_cluster", $cross_var2); } catch (\Exception $e) { $this->container->getTwig()->addGlobal('message', $e->getMessage() . "\n"); $jsonData = '[]'; $cross_var1 = $cross_var2 = ''; $categories1 = $categories2 = ''; $maxx = $minx = $maxy = $miny = $maxz = $minz = 0; $must_wait = "NO"; $dbml = null; $possible_models = $possible_models_id = array(); } echo $this->container->getTwig()->render('mltemplate/mlcrossvar3dfa.html.twig', array('selected' => 'mlcrossvar3dfa', 'jsonData' => $jsonData, 'variable1' => $cross_var1, 'variable2' => $cross_var2, 'categories1' => $categories1, 'categories2' => $categories2, 'maxx' => $maxx, 'minx' => $minx, 'maxy' => $maxy, 'miny' => $miny, 'maxz' => $maxz, 'minz' => $minz, 'benchs' => $params['benchs'], 'nets' => $params['nets'], 'disks' => $params['disks'], 'blk_sizes' => $params['blk_sizes'], 'comps' => $params['comps'], 'id_clusters' => $params['id_clusters'], 'mapss' => $params['mapss'], 'replications' => $params['replications'], 'iosfs' => $params['iosfs'], 'iofilebufs' => $params['iofilebufs'], 'datanodess' => $params['datanodess'], 'bench_types' => $params['bench_types'], 'vm_sizes' => $params['vm_sizes'], 'vm_coress' => $params['vm_coress'], 'vm_RAMs' => $params['vm_RAMs'], 'types' => $params['types'], 'message' => $message, 'instance' => $instance, 'model_info' => $model_info, 'current_model' => $current_model, 'unseen' => $unseen, 'models' => '<li>' . implode('</li><li>', $possible_models) . '</li>', 'models_id' => $possible_models_id, 'must_wait' => $must_wait, 'preset' => $preset, 'selPreset' => $selPreset, 'options' => Utils::getFilterOptions($db))); }
public function mlparamEvaluationAction() { $rows = $categories = $series = $instance = $model_info = $config = $current_model = $slice_info = ''; $arrayBenchs_pred = $possible_models = $possible_models_id = $other_models = array(); $jsonData = $jsonHeader = "[]"; $must_wait = 'NO'; try { $dbml = new \PDO($this->container->get('config')['db_conn_chain'], $this->container->get('config')['mysql_user'], $this->container->get('config')['mysql_pwd']); $dbml->setAttribute(\PDO::ATTR_ERRMODE, \PDO::ERRMODE_EXCEPTION); $dbml->setAttribute(\PDO::ATTR_EMULATE_PREPARES, false); $db = $this->container->getDBUtils(); if (array_key_exists('parameval', $_GET)) { $paramEval = isset($_GET['parameval']) && Utils::get_GET_string('parameval') != '' ? Utils::get_GET_string('parameval') : 'maps'; unset($_GET["parameval"]); } $this->buildFilters(array('current_model' => array('type' => 'selectOne', 'default' => null, 'label' => 'Model to use: ', 'generateChoices' => function () { return array(); }, 'parseFunction' => function () { $choice = isset($_GET['current_model']) ? $_GET['current_model'] : array(""); return array('whereClause' => '', 'currentChoice' => $choice); }, 'filterGroup' => 'MLearning'), 'minExecs' => array('default' => 0, 'type' => 'inputNumber', 'label' => 'Minimum executions:', 'parseFunction' => function () { return 0; }, 'filterGroup' => 'basic'), 'minexetime' => array('default' => 0), 'valid' => array('default' => 0), 'filter' => array('default' => 0), 'prepares' => array('default' => 0))); $this->buildFilterGroups(array('MLearning' => array('label' => 'Machine Learning', 'tabOpenDefault' => true, 'filters' => array('current_model')))); $where_configs = $this->filters->getWhereClause(); $params = array(); $param_names = array('bench', 'net', 'disk', 'maps', 'iosf', 'replication', 'iofilebuf', 'comp', 'blk_size', 'id_cluster', 'datanodes', 'vm_OS', 'vm_cores', 'vm_RAM', 'provider', 'vm_size', 'type', 'bench_type', 'hadoop_version'); // Order is important $params = $this->filters->getFiltersSelectedChoices($param_names); foreach ($param_names as $p) { if (!is_null($params[$p]) && is_array($params[$p])) { sort($params[$p]); } } $params_additional = array(); $param_names_additional = array('datefrom', 'dateto', 'minexetime', 'maxexetime', 'valid', 'filter'); // Order is important $params_additional = $this->filters->getFiltersSelectedChoices($param_names_additional); $param_variables = $this->filters->getFiltersSelectedChoices(array('current_model', 'minExecs')); $param_current_model = $param_variables['current_model']; $minExecs = $param_variables['minExecs']; $where_configs = str_replace("AND .", "AND ", $where_configs); $where_configs = str_replace("id_cluster", "e.id_cluster", $where_configs); $minExecsFilter = ""; if ($minExecs > 0) { $minExecsFilter = "HAVING COUNT(*) > {$minExecs}"; } $filter_execs = DBUtils::getFilterExecs(); $options = $this->filters->getFilterChoices(); $paramOptions = array(); foreach ($options[$paramEval] as $option) { if ($paramEval == 'comp') { $paramOptions[] = Utils::getCompressionName($option); } else { if ($paramEval == 'net') { $paramOptions[] = Utils::getNetworkName($option); } else { if ($paramEval == 'disk') { $paramOptions[] = Utils::getDisksName($option); } else { $paramOptions[] = $option; } } } } $param_eval_query = $paramEval == 'id_cluster' ? 'e.id_cluster' : $paramEval; $benchOptions = $db->get_rows("SELECT DISTINCT bench FROM aloja2.execs e LEFT JOIN aloja2.clusters c ON e.id_cluster = c.id_cluster WHERE 1 {$filter_execs} {$where_configs} GROUP BY {$param_eval_query}, bench order by {$param_eval_query}"); // get the result rows $query = "SELECT count(*) as count, {$param_eval_query}, e.id_exec, exec as conf, bench, " . "exe_time, avg(exe_time) avg_exe_time, min(exe_time) min_exe_time " . "from aloja2.execs e LEFT JOIN aloja2.clusters c ON e.id_cluster = c.id_cluster WHERE 1 {$filter_execs} {$where_configs}" . "GROUP BY {$param_eval_query},bench {$minExecsFilter} order by bench,{$param_eval_query}"; $rows = $db->get_rows($query); if (!$rows) { throw new \Exception("No results for query!"); } $arrayBenchs = array(); foreach ($paramOptions as $param) { foreach ($benchOptions as $bench) { $arrayBenchs[$bench['bench']][$param] = null; $arrayBenchs[$bench['bench']][$param]['y'] = 0; $arrayBenchs[$bench['bench']][$param]['count'] = 0; } } $series = array(); $bench = ''; foreach ($rows as $row) { if ($paramEval == 'comp') { $row[$paramEval] = Utils::getCompressionName($row['comp']); } else { if ($paramEval == 'net') { $row[$paramEval] = Utils::getNetworkName($row['net']); } else { if ($paramEval == 'disk') { $row[$paramEval] = Utils::getDisksName($row['disk']); } else { if ($paramEval == 'iofilebuf') { $row[$paramEval] /= 1024; } } } } $arrayBenchs[$row['bench']][$row[$paramEval]]['y'] = round((int) $row['avg_exe_time'], 2); $arrayBenchs[$row['bench']][$row[$paramEval]]['count'] = (int) $row['count']; } // ---------------------------------------------------- // Add predictions to the series // ---------------------------------------------------- $param_variables = $this->filters->getFiltersSelectedChoices(array('current_model')); $param_current_model = $param_variables['current_model']; $where_configs = str_replace("AND .", "AND ", $where_configs); // compose instance $instance = MLUtils::generateSimpleInstance($this->filters, $param_names, $params, true); $model_info = MLUtils::generateModelInfo($this->filters, $param_names, $params, true); $slice_info = MLUtils::generateDatasliceInfo($this->filters, $param_names_additional, $params_additional); // model for filling MLUtils::findMatchingModels($model_info, $possible_models, $possible_models_id, $dbml); $current_model = ''; if (!is_null($possible_models_id) && in_array($param_current_model, $possible_models_id)) { $current_model = $param_current_model; } // Other models for filling $where_models = ''; if (!empty($possible_models_id)) { $where_models = " WHERE id_learner NOT IN ('" . implode("','", $possible_models_id) . "')"; } $result = $dbml->query("SELECT id_learner FROM aloja_ml.learners" . $where_models); foreach ($result as $row) { $other_models[] = $row['id_learner']; } if (!empty($possible_models_id)) { if ($current_model == "") { $query = "SELECT AVG(ABS(exe_time - pred_time)) AS MAE, AVG(ABS(exe_time - pred_time)/exe_time) AS RAE, p.id_learner FROM aloja_ml.predictions p, aloja_ml.learners l WHERE l.id_learner = p.id_learner AND p.id_learner IN ('" . implode("','", $possible_models_id) . "') AND predict_code > 0 ORDER BY MAE LIMIT 1"; $result = $dbml->query($query); $row = $result->fetch(); $current_model = $row['id_learner']; } $config = $instance . '-' . $current_model . ' ' . $slice_info . "-parameval"; $query_cache = "SELECT count(*) as total FROM aloja_ml.trees WHERE id_learner = '" . $current_model . "' AND model = '" . $model_info . "'"; $is_cached_mysql = $dbml->query($query_cache); $tmp_result = $is_cached_mysql->fetch(); $is_cached = $tmp_result['total'] > 0; $ret_data = null; if (!$is_cached) { // Call to MLFindAttributes, to fetch data $_GET['pass'] = 2; $_GET['unseen'] = 1; $_GET['current_model'] = $current_model; $mlfa1 = new MLFindAttributesController(); $mlfa1->container = $this->container; $ret_data = $mlfa1->mlfindattributesAction(); if ($ret_data == 1) { $must_wait = "YES"; $jsonData = $jsonHeader = '[]'; } else { $is_cached_mysql = $dbml->query($query_cache); $tmp_result = $is_cached_mysql->fetch(); $is_cached = $tmp_result['total'] > 0; } } if ($is_cached) { $must_wait = 'NO'; $query = "SELECT count(*) as count, {$param_eval_query}, bench, exe_time, avg(pred_time) avg_pred_time, min(pred_time) min_pred_time " . "FROM aloja_ml.predictions e WHERE e.id_learner = '" . $current_model . "' {$filter_execs} {$where_configs}" . "GROUP BY {$param_eval_query}, bench {$minExecsFilter} order by bench,{$param_eval_query}"; $result = $dbml->query($query); // Initialize array foreach ($paramOptions as $param) { foreach ($benchOptions as $bench) { $arrayBenchs_pred[$bench['bench'] . '_pred'][$param] = null; $arrayBenchs_pred[$bench['bench'] . '_pred'][$param]['y'] = 0; $arrayBenchs_pred[$bench['bench'] . '_pred'][$param]['count'] = 0; } } foreach ($result as $row) { $bench_n = $row['bench'] . '_pred'; $class = $row[$paramEval]; if ($paramEval == 'comp') { $value = Utils::getCompressionName($class); } else { if ($paramEval == 'id_cluster') { $value = Utils::getClusterName($class, $db); } else { if ($paramEval == 'net') { $value = Utils::getNetworkName($class); } else { if ($paramEval == 'disk') { $value = Utils::getDisksName($class); } else { if ($paramEval == 'iofilebuf') { $value = $class / 1024; } else { $value = $class; } } } } } if (!in_array($value, $paramOptions)) { $paramOptions[] = $value; foreach ($benchOptions as $bench) { $arrayBenchs_pred[$bench['bench'] . '_pred'][$value] = null; $arrayBenchs_pred[$bench['bench'] . '_pred'][$value]['y'] = 0; $arrayBenchs_pred[$bench['bench'] . '_pred'][$value]['count'] = 0; $arrayBenchs[$bench['bench']][$value] = null; $arrayBenchs[$bench['bench']][$value]['y'] = 0; $arrayBenchs[$bench['bench']][$value]['count'] = 0; } } $arrayBenchs_pred[$bench_n][$value]['y'] = (int) $row['avg_pred_time']; $arrayBenchs_pred[$bench_n][$value]['count'] = (int) $row['count']; } } } // ---------------------------------------------------- // END - Add predictions to the series // ---------------------------------------------------- asort($paramOptions); foreach ($arrayBenchs as $key => $arrayBench) { $caregories = ''; $data_a = null; $data_p = null; foreach ($paramOptions as $param) { if ($arrayBenchs[$key][$param]['count'] > 0 && empty($arrayBenchs_pred) || !empty($arrayBenchs_pred) && ($arrayBenchs_pred[$key . '_pred'][$param]['count'] > 0 || $arrayBenchs[$key][$param]['count'] > 0)) { $data_a[] = $arrayBenchs[$key][$param]; if (!empty($arrayBenchs_pred)) { $data_p[] = $arrayBenchs_pred[$key . '_pred'][$param]; } $categories = $categories . "'{$param} " . Utils::getParamevalUnit($paramEval) . "',"; // FIXME - Redundant n times performed... don't care now } } $series[] = array('name' => $key, 'data' => $data_a); if (!empty($arrayBenchs_pred)) { $series[] = array('name' => $key . '_pred', 'data' => $data_p); } } $series = json_encode($series); if (!empty($arrayBenchs_pred)) { $colors = "['#7cb5ec','#9cd5fc','#434348','#636368','#90ed7d','#b0fd9d','#f7a35c','#f7c37c','#8085e9','#a0a5f9','#f15c80','#f17ca0','#e4d354','#f4f374','#8085e8','#a0a5f8','#8d4653','#ad6673','#91e8e1','#b1f8f1']"; } else { $colors = "['#7cb5ec','#434348','#90ed7d','#f7a35c','#8085e9','#f15c80','#e4d354','#8085e8','#8d4653','#91e8e1']"; } } catch (\Exception $e) { $this->container->getTwig()->addGlobal('message', $e->getMessage() . "\n"); $series = $jsonHeader = $colors = '[]'; $must_wait = 'NO'; } $return_params = array('title' => 'Improvement of Hadoop Execution by SW and HW Configurations', 'categories' => $categories, 'series' => $series, 'paramEval' => $paramEval, 'instance' => $instance, 'models' => '<li>' . implode('</li><li>', $possible_models) . '</li>', 'models_id' => $possible_models_id, 'current_model' => $current_model, 'gammacolors' => $colors, 'model_info' => $model_info, 'slice_info' => $slice_info, 'must_wait' => $must_wait); $this->filters->setCurrentChoices('current_model', array_merge($possible_models_id, array('---Other models---'), $other_models)); return $this->render('mltemplate/mlparameval.html.twig', $return_params); }
public function mlcrossvar3dfaAction() { $jsonData = $possible_models = $possible_models_id = $other_models = array(); $message = $instance = $possible_models_id = ''; $categories1 = $categories2 = "''"; $maxx = $minx = $maxy = $miny = $maxz = $minz = 0; $must_wait = 'NO'; try { $dbml = new \PDO($this->container->get('config')['db_conn_chain'], $this->container->get('config')['mysql_user'], $this->container->get('config')['mysql_pwd']); $dbml->setAttribute(\PDO::ATTR_ERRMODE, \PDO::ERRMODE_EXCEPTION); $dbml->setAttribute(\PDO::ATTR_EMULATE_PREPARES, false); $db = $this->container->getDBUtils(); $this->buildFilters(array('variable2' => array('type' => 'selectOne', 'default' => array('net'), 'table' => 'execs', 'label' => 'Variable 2: ', 'generateChoices' => function () { return array('bench', 'net', 'disk', 'maps', 'iosf', 'replication', 'iofilebuf', 'comp', 'blk_size', 'id_cluster', 'datanodes', 'bench_type', 'vm_size', 'vm_cores', 'vm_RAM', 'type', 'hadoop_version', 'provider', 'vm_OS', 'exe_time', 'pred_time', 'TOTAL_MAPS'); }, 'beautifier' => function ($value) { $labels = array('bench' => 'Benchmark', 'net' => 'Network', 'disk' => 'Disk', 'maps' => 'Maps', 'iosf' => 'I/O Sort Factor', 'replication' => 'Replication', 'iofilebuf' => 'I/O File Buffer', 'comp' => 'Compression', 'blk_size' => 'Block size', 'id_cluster' => 'Cluster', 'datanodes' => 'Datanodes', 'bench_type' => 'Benchmark Suite', 'vm_size' => 'VM Size', 'vm_cores' => 'VM cores', 'vm_RAM' => 'VM RAM', 'type' => 'Cluster type', 'hadoop_version' => 'Hadoop Version', 'provider' => 'Provider', 'vm_OS' => 'VM OS', 'exe_time' => 'Exeuction time', 'pred_time' => 'Prediction time', 'TOTAL_MAPS' => 'Total execution maps'); return $labels[$value]; }, 'parseFunction' => function () { $value = isset($_GET['variable2']) ? $_GET['variable2'] : array('net'); return array('currentChoice' => $value, 'whereClause' => ""); }), 'variable1' => array('type' => 'selectOne', 'default' => array('maps'), 'table' => 'execs', 'label' => 'Variable 1: ', 'generateChoices' => function () { return array('bench', 'net', 'disk', 'maps', 'iosf', 'replication', 'iofilebuf', 'comp', 'blk_size', 'id_cluster', 'datanodes', 'bench_type', 'vm_size', 'vm_cores', 'vm_RAM', 'type', 'hadoop_version', 'provider', 'vm_OS', 'exe_time', 'pred_time', 'TOTAL_MAPS'); }, 'beautifier' => function ($value) { $labels = array('bench' => 'Benchmark', 'net' => 'Network', 'disk' => 'Disk', 'maps' => 'Maps', 'iosf' => 'I/O Sort Factor', 'replication' => 'Replication', 'iofilebuf' => 'I/O File Buffer', 'comp' => 'Compression', 'blk_size' => 'Block size', 'id_cluster' => 'Cluster', 'datanodes' => 'Datanodes', 'bench_type' => 'Benchmark Suite', 'vm_size' => 'VM Size', 'vm_cores' => 'VM cores', 'vm_RAM' => 'VM RAM', 'type' => 'Cluster type', 'hadoop_version' => 'Hadoop Version', 'provider' => 'Provider', 'vm_OS' => 'VM OS', 'exe_time' => 'Exeuction time', 'pred_time' => 'Prediction time', 'TOTAL_MAPS' => 'Total execution maps'); return $labels[$value]; }, 'parseFunction' => function () { $value = isset($_GET['variable1']) ? $_GET['variable1'] : array('maps'); return array('currentChoice' => $value, 'whereClause' => ""); }), 'current_model' => array('type' => 'selectOne', 'default' => null, 'label' => 'Model to use: ', 'generateChoices' => function () { return array(); }, 'parseFunction' => function () { $choice = isset($_GET['current_model']) ? $_GET['current_model'] : array(""); return array('whereClause' => '', 'currentChoice' => $choice); }, 'filterGroup' => 'MLearning'), 'unseen' => array('type' => 'checkbox', 'default' => 1, 'label' => 'Predict with unseen atributes ⚠', 'parseFunction' => function () { $choice = isset($_GET['unseen']) && !isset($_GET['unseen']) ? 0 : 1; return array('whereClause' => '', 'currentChoice' => $choice); }, 'filterGroup' => 'MLearning'), 'minexetime' => array('default' => 0), 'valid' => array('default' => 0), 'filter' => array('default' => 0), 'prepares' => array('default' => 1))); $this->buildFilterGroups(array('MLearning' => array('label' => 'Machine Learning', 'tabOpenDefault' => true, 'filters' => array('current_model', 'unseen')))); $where_configs = $this->filters->getWhereClause(); $model_html = ''; $model_info = $db->get_rows("SELECT id_learner, model, algorithm, dataslice FROM aloja_ml.learners"); foreach ($model_info as $row) { $model_html = $model_html . "<li><b>" . $row['id_learner'] . "</b> => " . $row['algorithm'] . " : " . $row['model'] . " : " . $row['dataslice'] . "</li>"; } $params = array(); $param_names = array('bench', 'net', 'disk', 'maps', 'iosf', 'replication', 'iofilebuf', 'comp', 'blk_size', 'id_cluster', 'datanodes', 'vm_OS', 'vm_cores', 'vm_RAM', 'provider', 'vm_size', 'type', 'bench_type', 'hadoop_version'); // Order is important $params = $this->filters->getFiltersSelectedChoices($param_names); foreach ($param_names as $p) { if (!is_null($params[$p]) && is_array($params[$p])) { sort($params[$p]); } } $params_additional = array(); $param_names_additional = array('datefrom', 'dateto', 'minexetime', 'maxexetime', 'valid', 'filter'); // Order is important $params_additional = $this->filters->getFiltersSelectedChoices($param_names_additional); $variables = $this->filters->getFiltersSelectedChoices(array('variable1', 'variable2', 'current_model', 'unseen')); $cross_var1 = $variables['variable1']; $cross_var2 = $variables['variable2']; $param_current_model = $variables['current_model']; $unseen = $variables['unseen'] ? true : false; $where_configs = str_replace("AND .", "AND ", $where_configs); $cross_var1 = str_replace("id_cluster", "e.id_cluster", $cross_var1); $cross_var2 = str_replace("id_cluster", "e.id_cluster", $cross_var2); // compose instance $instance = MLUtils::generateSimpleInstance($this->filters, $param_names, $params, true); $model_info = MLUtils::generateModelInfo($this->filters, $param_names, $params, true); $slice_info = MLUtils::generateDatasliceInfo($this->filters, $param_names_additional, $params_additional); // Model for filling MLUtils::findMatchingModels($model_info, $possible_models, $possible_models_id, $dbml); $current_model = in_array($param_current_model, $possible_models_id) ? $param_current_model : ''; // Other models for filling $where_models = ''; if (!empty($possible_models_id)) { $where_models = " WHERE id_learner NOT IN ('" . implode("','", $possible_models_id) . "')"; } $result = $dbml->query("SELECT id_learner FROM aloja_ml.learners" . $where_models); foreach ($result as $row) { $other_models[] = $row['id_learner']; } // Call to MLPrediction, to create a model if (empty($possible_models_id)) { $_GET['pass'] = 1; $mltc1 = new MLPredictionController(); // FIXME - Choose the default modeling algorithm $mltc1->container = $this->container; $ret_learn = $mltc1->mlpredictionAction(); $rows = null; if ($ret_data == 1) { $must_wait = "YES"; throw new \Exception("WAIT"); } else { if ($ret_data == -1) { throw new \Exception("There was an error when creating a model for [" . $instance . "]"); } } } // Call to MLFindAttributes, to generate data if ($current_model != '') { $_GET['pass'] = 2; $mlfa1 = new MLFindAttributesController(); $mlfa1->container = $this->container; $ret_data = $mlfa1->mlfindattributesAction(); $rows = null; if ($ret_data == 1) { $must_wait = "YES"; throw new \Exception("WAIT"); } else { if ($ret_data == -1) { throw new \Exception("There was an error when creating predictions for [" . $instance . "]"); } } } // Get stuff from the DB $query = "SELECT " . $cross_var1 . " AS V1, " . $cross_var2 . " AS V2, AVG(e.pred_time) as V3, e.instance\n\t\t\t\tFROM aloja_ml.predictions as e\n\t\t\t\tWHERE e.id_learner " . ($current_model != '' ? "='" . $current_model . "'" : "IN (SELECT id_learner FROM aloja_ml.trees WHERE model='" . $model_info . "')") . $where_configs . "\n\t\t\t\tGROUP BY e.instance\n\t\t\t\tORDER BY RAND() LIMIT 5000;"; // FIXME - CLUMPSY PATCH FOR BYPASS THE BUG FROM HIGHCHARTS... REMEMBER TO ERASE THIS LINE WHEN THE BUG IS SOLVED $rows = $db->get_rows($query); if (empty($rows)) { if ($current_model == '') { throw new \Exception('No data matches with your critteria. Try to select a specific model to generate data.'); } else { throw new \Exception('No data matches with your critteria.'); } } // Show the results $map_var1 = $map_var2 = array(); $count_var1 = $count_var2 = 0; $categories1 = $categories2 = ''; $var1_categorical = in_array($cross_var1, array("net", "disk", "bench", "vm_OS", "provider", "vm_size", "type", "bench_type")); $var2_categorical = in_array($cross_var2, array("net", "disk", "bench", "vm_OS", "provider", "vm_size", "type", "bench_type")); foreach ($rows as $row) { $entry = array(); if ($var1_categorical) { if (!array_key_exists($row['V1'], $map_var1)) { $map_var1[$row['V1']] = $count_var1++; $categories1 = $categories1 . ($categories1 != '' ? "," : "") . "\"" . $row['V1'] . "\""; } $entry['y'] = $map_var1[$row['V1']] * (rand(990, 1010) / 1000); } else { $entry['y'] = (int) $row['V1'] * (rand(990, 1010) / 1000); } if ($entry['y'] > $maxy) { $maxy = $entry['y']; } if ($entry['y'] < $miny) { $miny = $entry['y']; } if ($var2_categorical) { if (!array_key_exists($row['V2'], $map_var2)) { $map_var2[$row['V2']] = $count_var2++; $categories2 = $categories2 . ($categories2 != '' ? "," : "") . "\"" . $row['V2'] . "\""; } $entry['x'] = $map_var2[$row['V2']] * (rand(990, 1010) / 1000); } else { $entry['x'] = (int) $row['V2'] * (rand(990, 1010) / 1000); } if ($entry['x'] > $maxx) { $maxx = $entry['x']; } if ($entry['x'] < $minx) { $minx = $entry['x']; } $entry['z'] = (int) $row['V3'] * (rand(990, 1010) / 1000); if ($entry['z'] > $maxz) { $maxz = $entry['z']; } if ($entry['z'] < $minz) { $minz = $entry['z']; } $entry['name'] = $row['instance']; //$row['V1']." - ".$row['V2']." - ".max(100,(int)$row['V3']); $jsonData[] = $entry; } $jsonData = json_encode($jsonData); if ($categories1 != '') { $categories1 = "[" . $categories1 . "]"; } else { $categories1 = "''"; } if ($categories2 != '') { $categories2 = "[" . $categories2 . "]"; } else { $categories2 = "''"; } } catch (\Exception $e) { if ($e->getMessage() != "WAIT") { $this->container->getTwig()->addGlobal('message', $e->getMessage() . "\n"); } $jsonData = '[]'; } $dbml = null; $return_params = array('jsonData' => $jsonData, 'variable1' => str_replace("e.id_cluster", "id_cluster", $cross_var1), 'variable2' => str_replace("e.id_cluster", "id_cluster", $cross_var2), 'categories1' => $categories1, 'categories2' => $categories2, 'maxx' => $maxx, 'minx' => $minx, 'maxy' => $maxy, 'miny' => $miny, 'maxz' => $maxz, 'minz' => $minz, 'instance' => $instance, 'model_info' => $model_info, 'slice_info' => $slice_info, 'models' => '<li>' . implode('</li><li>', $possible_models) . '</li>', 'must_wait' => $must_wait, 'models' => $model_html, 'current_model' => $current_model); $this->filters->setCurrentChoices('current_model', array_merge(array("Aggregation of Models"), $possible_models_id, !empty($other_models) ? array('---Other models---') : array(), $other_models)); return $this->render('mltemplate/mlcrossvar3dfa.html.twig', $return_params); }