<commit_before><?php

namespace alojaweb\inc;

use alojaweb\inc\dbscan\DBSCAN;
use alojaweb\inc\dbscan\Cluster;
use alojaweb\inc\dbscan\Point;

class DBUtils
{
    public static $TASK_METRICS = [
        'Duration',
        'Bytes Read',
        'Bytes Written',
        'FILE_BYTES_WRITTEN',
        'FILE_BYTES_READ',
        'HDFS_BYTES_WRITTEN',
        'HDFS_BYTES_READ',
        'Spilled Records',
        'SPLIT_RAW_BYTES',
        'Map input records',
        'Map output records',
        'Map input bytes',
        'Map output bytes',
        'Map output materialized bytes',
        'Reduce input groups',
        'Reduce input records',
        'Reduce output records',
        'Reduce shuffle bytes',
        'Combine input records',
        'Combine output records',
    ];

    private $dbConn;
    private $container;

    public function __construct($container)
    {
        $this->container = $container;
    }

    public function init()
    {
        $this->dbConn = new \PDO($this->container['config']['db_conn_chain'], $this->container['config']['mysql_user'], $this->container['config']['mysql_pwd']);

        $this->dbConn->setAttribute(\PDO::ATTR_ERRMODE, \PDO::ERRMODE_EXCEPTION);
        $this->dbConn->setAttribute(\PDO::ATTR_EMULATE_PREPARES, false);
    }

    public function get_rows($sql, $params = array())
    {
        $md5_sql = md5($sql.http_build_query($params, '', ','));
        $file_path = "{$this->container['config']['db_cache_path']}/CACHE_$md5_sql.sql";

        if ($this->container['env'] == 'dev' || $_SERVER['HTTP_HOST'] == 'localhost' || (isset($_GET['NO_CACHE']) && strlen($_GET['NO_CACHE']) > 0)) {
            $use_cache = false;
        } else {
            $use_cache = true;
        }

        if (!$this->dbConn) $this->init();

        //check for cache first
        if ($use_cache &&
                file_exists($file_path) &&
                ($rows = file_get_contents($file_path)) &&
                ($rows = unserialize(gzuncompress($rows)))
        ) {
            $this->container['log']->addDebug('CACHED: '.$sql);
        } else {
            $this->container['log']->addDebug('NO CACHE: '.$sql);

            try {
                $sth = $this->dbConn->prepare($sql);
                $sth->execute($params);
            } catch (Exception $e) {
                throw new \Exception($e->getMessage(). " SQL: $sql");
            }

            $rows = $sth->fetchAll(\PDO::FETCH_ASSOC);

            //save cache
            if ($use_cache && $rows) {
                file_put_contents($file_path, gzcompress(serialize($rows), 9));
            }
        }

        return $rows;
    }

    public function executeQuery($sql, $params = array()) {
        try {
          $this->container['log']->addDebug('Executing query: '.$sql);
          $sth = $this->dbConn->prepare($sql);
          $sth->execute($params);
        } catch (Exception $e) {
          throw new \Exception($e->getMessage(). " SQL: $sql");
        }

        return true;
    }

    public static function getFilterExecs($execsAlias = "e")
    {
        //Trick to avoid bugs on empty alias
        if($execsAlias != ' ')
            $execsAlias = "$execsAlias.";

        return " AND 1=1 ";

        if (isset($_COOKIE['g']) && $_COOKIE['g'] == 'godmode') {
            return " " ;
        } else {
            return " AND ${execsAlias}id_cluster NOT IN (06, 16, 19, 30, 31, 33, 38) ";
        }
    }

    public function get_execs($filter_execs = null)
    {
        if($filter_execs === null)<commit_msg>WEB: Recovering stashed change<commit_after><?php

namespace alojaweb\inc;

use alojaweb\inc\dbscan\DBSCAN;
use alojaweb\inc\dbscan\Cluster;
use alojaweb\inc\dbscan\Point;

class DBUtils
{
    public static $TASK_METRICS = [
        'Duration',
        'Bytes Read',
        'Bytes Written',
        'FILE_BYTES_WRITTEN',
        'FILE_BYTES_READ',
        'HDFS_BYTES_WRITTEN',
        'HDFS_BYTES_READ',
        'Spilled Records',
        'SPLIT_RAW_BYTES',
        'Map input records',
        'Map output records',
        'Map input bytes',
        'Map output bytes',
        'Map output materialized bytes',
        'Reduce input groups',
        'Reduce input records',
        'Reduce output records',
        'Reduce shuffle bytes',
        'Combine input records',
        'Combine output records',
    ];

    private $dbConn;
    private $container;

    public function __construct($container)
    {
        $this->container = $container;
    }

    public function init()
    {
        $this->dbConn = new \PDO($this->container['config']['db_conn_chain'], $this->container['config']['mysql_user'], $this->container['config']['mysql_pwd']);

        $this->dbConn->setAttribute(\PDO::ATTR_ERRMODE, \PDO::ERRMODE_EXCEPTION);
        $this->dbConn->setAttribute(\PDO::ATTR_EMULATE_PREPARES, false);
    }

    public function get_rows($sql, $params = array())
    {
        echo("$sql <br />");
        $md5_sql = md5($sql.http_build_query($params, '', ','));
        $file_path = "{$this->container['config']['db_cache_path']}/CACHE_$md5_sql.sql";

        if ($this->container['env'] == 'dev' || $_SERVER['HTTP_HOST'] == 'localhost' || (isset($_GET['NO_CACHE']) && strlen($_GET['NO_CACHE']) > 0)) {
            $use_cache = false;
        } else {
            $use_cache = true;
        }

        if (!$this->dbConn) $this->init();

        //check for cache first
        if ($use_cache &&
                file_exists($file_path) &&
                ($rows = file_get_contents($file_path)) &&
                ($rows = unserialize(gzuncompress($rows)))
        ) {
            $this->container['log']->addDebug('CACHED: '.$sql);
        } else {
            $this->container['log']->addDebug('NO CACHE: '.$sql);

            try {
                $sth = $this->dbConn->prepare($sql);
                $sth->execute($params);
            } catch (Exception $e) {
                throw new \Exception($e->getMessage(). " SQL: $sql");
            }

            $rows = $sth->fetchAll(\PDO::FETCH_ASSOC);

            //save cache
            if ($use_cache && $rows) {
                file_put_contents($file_path, gzcompress(serialize($rows), 9));
            }
        }

        return $rows;
    }

    public function executeQuery($sql, $params = array()) {
        try {
          $this->container['log']->addDebug('Executing query: '.$sql);
          $sth = $this->dbConn->prepare($sql);
          $sth->execute($params);
        } catch (Exception $e) {
          throw new \Exception($e->getMessage(). " SQL: $sql");
        }

        return true;
    }

    public static function getFilterExecs($execsAlias = "e")
    {
        //Trick to avoid bugs on empty alias
        if($execsAlias != ' ')
            $execsAlias = "$execsAlias.";

        return " AND ${execsAlias}id_cluster NOT IN (select id_cluster from clusters where id_cluster = '35' OR  provider = 'rackspacecbd') " ;

        if (isset($_COOKIE['g']) && $_COOKIE['g'] == 'godmode') {
            return " " ;
        } else {
            return " AND ${execsAlias}id_cluster NOT IN (06, 16, 19, 30, 31, 33, 38) ";
        }
    }

    public function get_execs($filter_execs = null)
    {
        if($filter_execs === null)
{'fraction_non_alphanumeric': 0.16166345359405124, 'fraction_numerical': 0.005783530707793996, 'mean_word_length': 2.1198453608247423, 'pattern_counts': {'":': 0, '<': 6, '<?xml version=': 0, '>': 62, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 2, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '2727133', 'n_tokens_mistral': 2317, 'n_tokens_neox': 2226, 'n_words': 438}