Exemplo n.º 1
0
 public function __construct(\alojaweb\inc\DBUtils $dbConnection)
 {
     $this->dbConnection = $dbConnection;
     /* In this array there are the filter names with its default options
      * that will be overwritten by the given custom defaults and options if given
      * Array with filter => filter specific settings
      *
      * Specific settings is an array with
      * types: inputText, inputNumber[{le,ge}], inputDate[{le,ge}], selectOne, selectMultiple, checkbox[Negated]
      * default: null (any), array(values)
      * table: associated DB table name
      * parseFunction: function to parse special filter, for filters that need a lot of customization
      *
      * Very custom filters such as advanced filters not in this array
      *
      */
     $this->filters = array('bench' => array('table' => 'execs', 'default' => array('terasort', 'wordcount'), 'type' => 'selectMultiple', 'label' => 'Benchmarks:'), 'datasize' => array('database' => 'aloja2', 'table' => 'execs', 'default' => null, 'type' => 'selectMultiple', 'label' => 'Datasize: ', 'beautifier' => function ($value) {
         return Utils::beautifyDatasize($value);
     }, 'parseFunction' => 'parseDatasize'), 'scale_factor' => array('table' => 'execs', 'default' => null, 'type' => 'selectMultiple', 'label' => 'Scale factor: '), 'bench_type' => array('table' => 'execs', 'default' => array('HiBench'), 'type' => 'selectOne', 'label' => 'Bench suite:'), 'net' => array('table' => 'execs', 'default' => null, 'type' => 'selectMultiple', 'label' => 'Network:', 'beautifier' => function ($value) {
         return Utils::getNetworkName($value);
     }), 'disk' => array('table' => 'execs', 'default' => null, 'type' => 'selectMultiple', 'label' => 'Disk:'), 'blk_size' => array('table' => 'execs', 'default' => null, 'type' => 'selectMultiple', 'label' => 'Block size (b):', 'beautifier' => function ($value) {
         return $value . ' MB';
     }), 'comp' => array('table' => 'execs', 'default' => null, 'type' => 'selectMultiple', 'label' => 'Compression (c):', 'beautifier' => function ($value) {
         return Utils::getCompressionName($value);
     }), 'id_cluster' => array('table' => 'execs', 'default' => null, 'type' => 'selectMultiple', 'label' => 'Clusters (CL):', 'beautifier' => function ($value) {
         return $this->filters['id_cluster']['namesClusters'][$value];
     }, 'generateChoices' => function () {
         $choices = $this->dbConnection->get_rows("select distinct id_cluster,CONCAT_WS('/',LPAD(id_cluster,2,0),c.vm_size,CONCAT(c.datanodes,'Dn')) as name  from aloja2.execs e join aloja2.clusters c using (id_cluster) WHERE 1 " . DBUtils::getFilterExecs(' ') . " ORDER BY c.name ASC");
         $returnChoices = array();
         foreach ($choices as $choice) {
             $returnChoices[] = $choice['id_cluster'];
             //Not nice, but saves multiple queries to DB in the beautifier
             $this->filters['id_cluster']['namesClusters'][$choice['id_cluster']] = $choice['name'];
         }
         return $returnChoices;
     }), 'maps' => array('table' => 'execs', 'default' => null, 'type' => 'selectMultiple', 'label' => 'Maps:', 'beautifier' => function ($value) {
         if ($value == 0) {
             return 'N/A';
         } else {
             return $value;
         }
     }), 'replication' => array('table' => 'execs', 'default' => null, 'type' => 'selectMultiple', 'label' => 'Replication (r):'), 'iosf' => array('table' => 'execs', 'default' => null, 'type' => 'selectMultiple', 'label' => 'I/O sort factor (I):'), 'iofilebuf' => array('table' => 'execs', 'default' => null, 'type' => 'selectMultiple', 'label' => 'I/O file buffer:', 'beautifier' => function ($value) {
         $suffix = ' KB';
         if ($value >= 1024) {
             $value /= 1024;
             $suffix = ' MB';
         }
         return $value . $suffix;
     }), 'provider' => array('table' => 'clusters', 'default' => null, 'type' => 'selectMultiple', 'label' => 'Provider:'), 'vm_OS' => array('table' => 'clusters', 'default' => null, 'type' => 'selectMultiple', 'label' => 'VM OS:'), 'datanodes' => array('table' => 'clusters', 'default' => null, 'type' => 'selectMultiple', 'label' => 'Cluster datanodes:'), 'vm_size' => array('table' => 'clusters', 'default' => null, 'type' => 'selectMultiple', 'label' => 'VM Size:'), 'vm_cores' => array('table' => 'clusters', 'default' => null, 'type' => 'selectMultiple', 'label' => 'VM cores:'), 'vm_RAM' => array('table' => 'clusters', 'default' => null, 'type' => 'selectMultiple', 'label' => 'VM RAM:', 'beautifier' => function ($value) {
         if ($value * 10 % 10 != 0) {
             return number_format($value, 1) . ' GB';
         } else {
             return number_format($value, 0) . ' GB';
         }
     }), 'type' => array('table' => 'clusters', 'default' => null, 'type' => 'selectMultiple', 'label' => 'Cluster type:'), 'hadoop_version' => array('table' => 'execs', 'default' => null, 'type' => 'selectMultiple', 'label' => 'Hadoop version:'), 'minexetime' => array('table' => 'execs', 'field' => 'exe_time', 'default' => Utils::in_dev() ? 1 : 50, 'type' => 'inputNumberge', 'label' => 'Min exec time:'), 'maxexetime' => array('table' => 'execs', 'field' => 'exe_time', 'default' => null, 'type' => 'inputNumberle', 'label' => 'Max exec time:'), 'datefrom' => array('table' => 'execs', 'field' => 'start_time', 'default' => null, 'type' => 'inputDatege', 'label' => 'Date from:'), 'dateto' => array('table' => 'execs', 'field' => 'end_time', 'default' => null, 'type' => 'inputDatele', 'label' => 'Date to:'), 'money' => array('table' => 'mixed', 'field' => '(clustersAlias.cost_hour/3600)*execsAlias.exe_time', 'default' => null, 'type' => 'inputNumberle', 'label' => 'Max cost (US$):'), 'valid' => array('table' => 'execs', 'field' => 'valid', 'type' => 'checkbox', 'default' => 1, 'label' => 'Only valid execs'), 'filter' => array('table' => 'execs', 'field' => 'filter', 'type' => 'checkbox', 'default' => 1, 'label' => 'Filter', 'parseFunction' => function () {
         $whereClause = "";
         if (isset($_GET['filter'])) {
             $values = 1;
         } else {
             if (!$this->formisSubmitted()) {
                 $values = $this->filters['filter']['default'];
             } else {
                 $values = 0;
             }
         }
         if ($values) {
             $whereClause = " AND execsAlias.filter = 0 ";
         }
         return array('currentChoice' => $values, 'whereClause' => $whereClause);
     }), 'prepares' => array('table' => 'execs', 'type' => 'checkbox', 'default' => Utils::in_dev() ? 1 : 0, 'label' => 'Include prepares', 'parseFunction' => function () {
         $whereClause = "";
         $values = 0;
         if (isset($_GET['prepares'])) {
             $values = 1;
         } else {
             $values = $this->filters['prepares']['default'];
             if (!$values) {
                 $whereClause = " AND execsAlias.bench NOT LIKE 'prep_%' ";
             }
         }
         return array('currentChoice' => $values, 'whereClause' => $whereClause);
     }), 'perf_details' => array('table' => 'execs', 'type' => 'checkbox', 'default' => 0, 'label' => 'Only execs with perf details'), 'prediction_model' => array('type' => 'selectOne', 'default' => null, 'label' => 'Reference Model: ', 'generateChoices' => function () {
         $query = "SELECT DISTINCT id_learner FROM aloja_ml.predictions";
         $retval = $this->dbConnection->get_rows($query);
         return array_column($retval, "id_learner");
     }, 'parseFunction' => function () {
         $choice = isset($_GET['prediction_model']) ? Utils::get_GET_stringArray('prediction_model') : array("");
         if ($choice = array("")) {
             $query = "SELECT DISTINCT id_learner FROM aloja_ml.predictions LIMIT 1";
             $choice = $this->dbConnection->get_rows($query)[0]['id_learner'];
         }
         return array('whereClause' => '', 'currentChoice' => $choice);
     }, 'filterGroup' => 'MLearning'), 'upred' => array('type' => 'checkbox', 'default' => 0, 'label' => 'Use predictions', 'parseFunction' => function () {
         $choice = !isset($_GET['upred']) ? 0 : 1;
         return array('whereClause' => '', 'currentChoice' => $choice);
     }, 'filterGroup' => 'MLearning'), 'uobsr' => array('type' => 'checkbox', 'default' => 1, 'label' => 'Use observations', 'parseFunction' => function () {
         $choice = !isset($_GET['uobsr']) && $this->formIssubmitted() ? 0 : 1;
         return array('whereClause' => '', 'currentChoice' => $choice);
     }, 'filterGroup' => 'MLearning'), 'warning' => array('field' => 'outlier', 'table' => 'ml_predictions', 'type' => 'checkbox', 'default' => 0, 'label' => 'Show warnings', 'parseFunction' => function () {
         $learner = $this->filters['prediction_model']['currentChoice'];
         $whereClause = "";
         $values = isset($_GET['warning']) ? 1 : 0;
         if ($values && !empty($learner)) {
             $whereClause = " AND (ml_predictionsAlias.outlier <= {$values} OR ml_predictionsAlias.outlier IS NULL) " . "AND (ml_predictionsAlias.id_learner = '{$learner[0]}' OR ml_predictionsAlias.id_learner IS NULL)";
         }
         return array('currentChoice' => $values, 'whereClause' => $whereClause);
     }, 'filterGroup' => 'MLearning'), 'outlier' => array('table' => 'ml_predictions', 'type' => 'checkbox', 'default' => 0, 'label' => 'Show outliers', 'parseFunction' => function () {
         $learner = $this->filters['prediction_model']['currentChoice'];
         $whereClause = "";
         $values = isset($_GET['outlier']) ? 2 : 0;
         if ($values && !empty($learner)) {
             $whereClause = " AND (ml_predictionsAlias.outlier <= 2 OR ml_predictionsAlias.outlier IS NULL) " . "AND (ml_predictionsAlias.id_learner = '{$learner}' OR ml_predictionsAlias.id_learner IS NULL)";
             $values = 1;
         } else {
             if (!empty($learner) && !isset($_GET['warning'])) {
                 $whereClause = " AND (ml_predictionsAlias.outlier = 0 OR ml_predictionsAlias.outlier IS NULL) " . "AND (ml_predictionsAlias.id_learner = '{$learner}' OR ml_predictionsAlias.id_learner IS NULL)";
             }
         }
         return array('currentChoice' => $values, 'whereClause' => $whereClause);
     }, 'filterGroup' => 'MLearning'));
     $this->aliasesTables = array('execs' => 'e', 'clusters' => 'c', 'ml_predictions' => 'p');
     //To render groups on template. Rows are of 2 columns each. emptySpace puts an empty element on the rendered row
     $this->filterGroups = array('basic' => array('label' => 'Basic filters', 'filters' => array('money', 'bench', 'bench_type', 'datasize', 'scale_factor', 'id_cluster', 'net', 'disk'), 'tabOpenDefault' => true), 'hardware' => array('label' => 'Hardware', 'filters' => array('datanodes', 'vm_size', 'vm_cores', 'vm_RAM', 'type', 'provider', 'vm_OS'), 'tabOpenDefault' => false), 'hadoop' => array('label' => 'Hadoop', 'filters' => array('maps', 'comp', 'replication', 'blk_size', 'iosf', 'iofilebuf', 'hadoop_version'), 'tabOpenDefault' => false), 'advanced' => array('label' => 'Advanced filters', 'filters' => array('valid', 'filter', 'prepares', 'perf_details', 'datefrom', 'dateto', 'minexetime', 'maxexetime'), 'tabOpenDefault' => false), 'MLearning' => array('label' => 'Machine Learning', 'filters' => array('prediction_model', 'upred', 'uobsr', 'warning', 'outlier'), 'tabOpenDefault' => true));
 }
Exemplo n.º 2
0
 public function __construct()
 {
     $container = new PimpleContainer();
     if (Utils::in_dev()) {
         ini_set('display_errors', 'On');
         error_reporting(E_ALL);
         //ini_set('memory_limit', '512M');
         $config_file = 'config/config.sample.yml';
         if (!file_get_contents($config_file)) {
             throw new \Exception("Cannot read configuration file: {$config_file}, check that it exists!");
         }
         $container['config'] = Yaml::parse(file_get_contents($config_file));
         $container['env'] = 'dev';
     } else {
         //ini_set('display_errors', 'On');
         //error_reporting(E_ALL);
         //ini_set('memory_limit', '1024M');
         $config_file = 'config/config.yml';
         if (!file_get_contents($config_file)) {
             throw new Exception("Cannot read configuration file: {$config_file}, check that it exists!");
         }
         $container['config'] = Yaml::parse(file_get_contents($config_file));
         $container['env'] = 'prod';
     }
     if (!$container['config']['show_warnings']) {
         error_reporting(E_ERROR | E_PARSE);
     }
     $container['log'] = function ($c) {
         $logLevel = $c['env'] == 'dev' ? Logger::DEBUG : Logger::WARNING;
         // create a log channel
         $log = new Logger('aloja');
         $log->pushHandler(new StreamHandler("logs/aloja_{$c['env']}.log", $logLevel));
         return $log;
     };
     $container['db'] = function ($c) {
         $db = new DBUtils($c);
         return $db;
     };
     $container['request'] = Request::createFromGlobals();
     $container['router'] = function ($c) {
         $router = new Router($c['log'], $c['request']);
         return $router;
     };
     $container['twig'] = function ($c) {
         $loader = new Twig_Loader_Filesystem($c['config']['twig_views_path']);
         $twigOptions = array('debug' => $c['config']['enable_debug']);
         if ($c['config']['in_cache']) {
             $twigOptions['cache'] = $c['config']['twig_cache_path'];
         }
         $twig = new Twig_Environment($loader, $twigOptions);
         $twig->addExtension(new AlojaTwigExtension($c['router']));
         if ($c['config']['enable_debug']) {
             $twig->addExtension(new Twig_Extension_Debug());
         }
         //Twig globals initialization
         $twig->addGlobal('request', $c['request']);
         $twig->addGlobal('PROD', $c['env'] === 'prod');
         $twig->addGlobal('DEV', $c['env'] === 'dev');
         //             $twig->addGlobal('message',null);
         return $twig;
     };
     $this->container = $container;
 }