Exemplo n.º 1
0
    def _init_name_shortcuts(self):
        ''' initialize the name shortcuts

        e.g {'haflux': 'emline_gflux_ha_6564',
             'g_r': 'elpetro_mag_g_r',
             'abs_g_r': 'elpetro_absmag_g_r'}

        '''
        from marvin.utils.datamodel.query.base import query_params
        short = query_params.list_params(name_type='short')
        name = query_params.list_params(name_type='name')
        self._nameShortcuts = OrderedDict(zip(short, name))
Exemplo n.º 2
0
 def test_list_params(self, data, groups):
     params = query_params.list_params(groups=groups)
     if not groups:
         myparams = data['spaxelmeta'] + data['nsa'] + data['spectral']
     else:
         paramlist = [data[g] for g in groups]
         myparams = list(itertools.chain.from_iterable(paramlist))
     assert set(myparams).issubset(set(params))
Exemplo n.º 3
0
    def index(self):

        # Attempt to retrieve search parameters
        form = processRequest(request=request)
        self.search['formparams'] = form
        self.search['latest_dr'] = self._release.lower() if 'DR' in self._release else config._get_latest_release(dr_only=True).lower()

        # set the search form and form validation
        searchform = self.mf.SearchForm(form)
        searchform.returnparams.choices = [(k.lower(), k) for k in query_params.list_params()]

        # Add the forms and parameters
        self.search['paramdata'] = query_params
        self.search['guideparams'] = [{'id': p.full, 'optgroup': group.name, 'type': 'double' if p.dtype == 'float' else p.dtype, 'validation': {'step': 'any'}} for group in query_params for p in group]
        self.search['searchform'] = searchform
        self.search['placeholder'] = getRandomQuery()
        self.search['returnurl'] = 'https://sdss-marvin.readthedocs.io/en/stable/datamodel/{0}.html#{0}query'.format(
            current_session['release'].lower().replace('-', ''))

        # If form parameters then try to do a search
        if form:
            self.search.update({'results': None, 'errmsg': None})

            args = av.manual_parse(self, request, use_params='search')
            # get form parameters
            searchvalue = form['searchbox']  # search filter input
            returnparams = form.getlist('returnparams', type=str)  # dropdown select
            self.search.update({'returnparams': returnparams})
            current_session.update({'searchvalue': searchvalue, 'returnparams': returnparams})

            # if main form passes validation then do search
            if searchform.validate():
                # try the query
                try:
                    q, res = doQuery(search_filter=searchvalue, release=self._release, return_params=returnparams)
                except (MarvinError, KeyError) as e:
                    self.search['errmsg'] = 'Could not perform query: {0}'.format(refine_error(e))
                except NotImplementedError as e:  # DAP queries disabled
                    self.search['errmsg'] = 'Could not perform query: {0}'.format(e)
                else:
                    self.search['filter'] = q.search_filter
                    self.search['count'] = res.totalcount
                    self.search['runtime'] = res.query_time.total_seconds()
                    if res.count > 0:
                        cols = res.columns.remote
                        rows = res.getDictOf(format_type='listdict')
                        output = {'total': res.totalcount, 'rows': rows, 'columns': cols, 'limit': None, 'offset': None}
                    else:
                        output = None
                    self.search['results'] = output
                    self.search['reslen'] = len(res.results)
                    if returnparams:
                        returnparams = [str(r) for r in returnparams]
                    rpstr = 'return_params={0} <br>'.format(returnparams) if returnparams else ''
                    qstr = ', return_params=returnparams' if returnparams else ''
                    self.search['querystring'] = ("<html><samp>from marvin.tools.query import Query<br>\
                        myfilter='{0}'<br> {1}\
                        q = Query(search_filter=myfilter{2})<br>\
                        r = q.run()<br></samp></html>".format(searchvalue, rpstr, qstr))

        return render_template('search.html', **self.search)