<commit_before><?php
/*
 *  Copyright (c) 2012-2015  <NAME> <<EMAIL>>,
 *                           <NAME> <<EMAIL>>,
 *                           AIP E-Science (www.aip.de)
 *
 *  This program is free software: you can redistribute it and/or modify
 *  it under the terms of the GNU Affero General Public License as
 *  published by the Free Software Foundation, either version 3 of the
 *  License, or (at your option) any later version.
 *
 *  This program is distributed in the hope that it will be useful,
 *  but WITHOUT ANY WARRANTY; without even the implied warranty of
 *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 *  GNU Affero General Public License for more details.
 *
 *  You should have received a copy of the GNU Affero General Public License
 *  along with this program.  If not, see <http://www.gnu.org/licenses/>.
 */

class Query_Model_Jobs extends Daiquiri_Model_Table {

    /**
     * Constructor. Sets resource object.
     */
    public function __construct() {
        $this->setResource(Query_Model_Resource_AbstractQuery::factory());

        $this->_cols = array('id','database','table',$this->getResource()->getTimeField(),'status');
        $resourceClass = get_class($this->getResource());
        if ($resourceClass::$hasQueues) {
            $this->_cols[] = 'queue';
        } 
    }

    /**
     * Returns the columns of the jobs table specified by some parameters. 
     * @param array $params get params of the request
     * @return array $response
     */
    public function cols(array $params = array()) {
        $cols = array();
        foreach ($this->_cols as $colname) {
            $col = array(
                'name' => $colname,
                'sortable' => 'true'
            );
            if ($colname === 'id') {
                $col['width'] = '120px';
            } else if (in_array($colname, array('database', 'table'))) {
                $col['width'] = '120px';
            } else if ($colname === 'username') {
                $col['width'] = '60px';
            } else if (in_array($colname, array('queue', 'status'))) {
                $col['width'] = '40px';
                $col['sortable'] = 'false';
            } else {
                $col['width'] = '100px';
            }
            $cols[] = $col;
        }

        $cols[] = array(
            'name' => 'options',
            'width' => '100px',
            'sortable' => 'false',
            'search' => 'false'
        );
        
        return array('cols' => $cols, 'status' => 'ok');
    }

    /**
     * Returns the rows of the jobs table specified by some parameters. 
     * @param array $params get params of the request
     * @return array $response
     */
    public function rows(array $params = array()) {
        // parse params
        $sqloptions = $this->getModelHelper('pagination')->sqloptions($params);

        // get the data from the database
        $dbRows = $this->getResource()->fetchRows($sqloptions);

        // loop through the table and add options
        $rows = array();
        foreach ($dbRows as $dbRow) {
            $row = array();
            foreach ($this->_cols as $col) {
                $row[] = $dbRow[$col];<commit_msg>job query table fixed<commit_after><?php
/*
 *  Copyright (c) 2012-2015  <NAME> <<EMAIL>>,
 *                           <NAME> <<EMAIL>>,
 *                           AIP E-Science (www.aip.de)
 *
 *  This program is free software: you can redistribute it and/or modify
 *  it under the terms of the GNU Affero General Public License as
 *  published by the Free Software Foundation, either version 3 of the
 *  License, or (at your option) any later version.
 *
 *  This program is distributed in the hope that it will be useful,
 *  but WITHOUT ANY WARRANTY; without even the implied warranty of
 *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 *  GNU Affero General Public License for more details.
 *
 *  You should have received a copy of the GNU Affero General Public License
 *  along with this program.  If not, see <http://www.gnu.org/licenses/>.
 */

class Query_Model_Jobs extends Daiquiri_Model_Table {

    /**
     * Constructor. Sets resource object.
     */
    public function __construct() {
        $this->setResource(Query_Model_Resource_AbstractQuery::factory());

        $this->_cols = array('id','database','table',$this->getResource()->getTimeField(),'status');
        $resourceClass = get_class($this->getResource());
        if ($resourceClass::$hasQueues) {
            $this->_cols[] = 'queue';
        } 
    }

    /**
     * Returns the columns of the jobs table specified by some parameters.
     * @param array $params get params of the request
     * @return array $response
     */
    public function cols(array $params = array()) {
        $cols = array();
        foreach ($this->_cols as $colname) {
            $col = array(
                'name' => $colname,
                'sortable' => true
            );
            if (in_array($colname, array('id','database','table','timeSubmit'))) {
                $col['width'] = 160;
            } else if (in_array($colname, array('queue', 'status'))) {
                $col['width'] = 70;
                $col['sortable'] = false;
            } else {
                $col['width'] = 100;
            }
            $cols[] = $col;
        }

        $cols[] = array(
            'name' => 'options',
            'width' => '100px',
            'sortable' => 'false',
            'search' => 'false'
        );

        return array('cols' => $cols, 'status' => 'ok');
    }

    /**
     * Returns the rows of the jobs table specified by some parameters.
     * @param array $params get params of the request
     * @return array $response
     */
    public function rows(array $params = array()) {
        // parse params
        if (!isset($params['sort'])) {
            $params['sort'] = 'timeSubmit DESC';
        }
        $sqloptions = $this->getModelHelper('pagination')->sqloptions($params);

        // get the data from the database
        $dbRows = $this->getResource()->fetchRows($sqloptions);

        // loop through the table and add options
        $rows = array();
        foreach ($dbRows as $dbRow) {
            $row = array();
            foreach ($this->_cols as $col) {
                $row[] = $dbRow[$col];
{'fraction_non_alphanumeric': 0.13654934003771213, 'fraction_numerical': 0.007071024512884978, 'mean_word_length': 2.0208827717133366, 'pattern_counts': {'":': 0, '<': 19, '<?xml version=': 0, '>': 57, 'https://': 0, 'lorem ipsum': 0, 'www.': 4, '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': '2619920', 'n_tokens_mistral': 1788, 'n_tokens_neox': 1716, 'n_words': 552}