<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_Form_ConeQuery extends Query_Form_AbstractFormQuery {

    /**
     * Gets the SQL query contructed from the form fields.
     * @return string $sql
     */
    public function getQuery() {
        if (!isset($this->_formOptions['table'])) {
            throw new Exception('no table was specified');
        }
        if (!isset($this->_formOptions['raField'])) {
            throw new Exception('no ra field was specified');
        }
        if (!isset($this->_formOptions['decField'])) {
            throw new Exception('no dec field was specified');
        }

        $ra     = $this->_escape($this->getValue('cone_ra'));
        $dec    = $this->_escape($this->getValue('cone_dec'));
        $radius = $this->_escape($this->getValue('cone_radius'));

        $sql = "SELECT angdist({$ra},{$dec},`{$this->_formOptions['raField']}`,`{$this->_formOptions['decField']}`)";
        $sql .= " * 3600.0 AS distance_arcsec, s.* FROM {$this->_formOptions['table']} AS s";
        $sql .= " WHERE angdist({$ra},{$dec},`{$this->_formOptions['raField']}`,`{$this->_formOptions['decField']}`)";
        $sql .= " < {$radius} / 3600.0;";

        return $sql;
    }

    /**
     * Gets the content of the tablename field.
     * @return string $tablename
     */
    public function getTablename() {
        return $this->getValue('cone_tablename');
    }

    /**
     * Gets the selected queue.
     * @return string $queue
     */
    public function getQueue() {
        return $this->getValue('cone_queues');
    }

    /**
     * Initializes the form.
     */
    public function init() {

        $html = '<div class="daiquiri-query-bar" style="width:145px;">
                   <ul class="nav-pills pull-left">
                      <li><a ng-click="showSimbadSearch = !showSimbadSearch" href style="width:121px;">{{showSimbadSearch?"Hide Simbad search":"Show Simbad search"}}</a></li>
                   </ul>
                 </div>
                 <div ng-show="showSimbadSearch" ng-init="showSimbadSearch = false">
                  <div id="simbad-resolver" ng-controller="simbadForm">
                    <div id="simbad-form">
                        <input type="text" name="simbad-identifier" id="simbad-input" ng-model="query"
                               ng-keydown="simbadInput($event);" />
                        <input type="button" value="Search on Simbad" class="btn pull-right" id="simbad-submit" ng-click="simbadSearch()" />
                    </div>

                    <ul id="simbad-results" class="daiquiri-widget nav nav-pills nav-stacked">
                        <li ng-repeat="item in result.data" class="nav-item" ng-dblclick="$parent.inputSourceConeSearch(item.coord1,item.coord2)">
                              <a href="">
                                  <div class="object">{{item.object}}</div>
                                  <div class="type">{{item.type}}</div>
                                  <div class="coords">{{item.coord1}} &nbsp; {{item.coord2}}</div>
                              </a>
                        </li>
                        <li ng-show="result.data.length==0" class="simbad-results-empty">
                            No results for "{{result.query}}"
                        </li>
                    </ul>
                  </div>
                  <div class="daiquiri-query-bar-hint"><commit_msg>nicer simbad button<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_Form_ConeQuery extends Query_Form_AbstractFormQuery {

    /**
     * Gets the SQL query contructed from the form fields.
     * @return string $sql
     */
    public function getQuery() {
        if (!isset($this->_formOptions['table'])) {
            throw new Exception('no table was specified');
        }
        if (!isset($this->_formOptions['raField'])) {
            throw new Exception('no ra field was specified');
        }
        if (!isset($this->_formOptions['decField'])) {
            throw new Exception('no dec field was specified');
        }

        $ra     = $this->_escape($this->getValue('cone_ra'));
        $dec    = $this->_escape($this->getValue('cone_dec'));
        $radius = $this->_escape($this->getValue('cone_radius'));

        $sql = "SELECT angdist({$ra},{$dec},`{$this->_formOptions['raField']}`,`{$this->_formOptions['decField']}`)";
        $sql .= " * 3600.0 AS distance_arcsec, s.* FROM {$this->_formOptions['table']} AS s";
        $sql .= " WHERE angdist({$ra},{$dec},`{$this->_formOptions['raField']}`,`{$this->_formOptions['decField']}`)";
        $sql .= " < {$radius} / 3600.0;";

        return $sql;
    }

    /**
     * Gets the content of the tablename field.
     * @return string $tablename
     */
    public function getTablename() {
        return $this->getValue('cone_tablename');
    }

    /**
     * Gets the selected queue.
     * @return string $queue
     */
    public function getQueue() {
        return $this->getValue('cone_queues');
    }

    /**
     * Initializes the form.
     */
    public function init() {

        $html = '<div class="daiquiri-query-bar" style="width:150px;">
                   <ul class="nav-pills pull-left">
                      <li><a ng-click="showSimbadSearch = !showSimbadSearch" href style="width:126px;text-align:center;">{{showSimbadSearch?"Hide Simbad search":"Show Simbad search"}}</a></li>
                   </ul>
                 </div>
                 <div ng-show="showSimbadSearch" ng-init="showSimbadSearch = false">
                  <div id="simbad-resolver" ng-controller="simbadForm">
                    <div id="simbad-form">
                        <input type="text" name="simbad-identifier" id="simbad-input" ng-model="query"
                               ng-keydown="simbadInput($event);" />
                        <input type="button" value="Search on Simbad" class="btn pull-right" id="simbad-submit" ng-click="simbadSearch()" />
                    </div>

                    <ul id="simbad-results" class="daiquiri-widget nav nav-pills nav-stacked">
                        <li ng-repeat="item in result.data" class="nav-item" ng-dblclick="$parent.inputSourceConeSearch(item.coord1,item.coord2)">
                              <a href="">
                                  <div class="object">{{item.object}}</div>
                                  <div class="type">{{item.type}}</div>
                                  <div class="coords">{{item.coord1}} &nbsp; {{item.coord2}}</div>
                              </a>
                        </li>
                        <li ng-show="result.data.length==0" class="simbad-results-empty">
                            No results for "{{result.query}}"
                        </li>
                    </ul>
                  </div>
                  <div class="daiquiri-query-bar-hint">
{'fraction_non_alphanumeric': 0.14626409774436092, 'fraction_numerical': 0.007048872180451127, 'mean_word_length': 1.9662020905923345, 'pattern_counts': {'":': 2, '<': 81, '<?xml version=': 0, '>': 109, 'https://': 0, 'lorem ipsum': 0, 'www.': 4, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 10, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '4492067', 'n_tokens_mistral': 2434, 'n_tokens_neox': 2307, 'n_words': 593}