Exemplo n.º 1
0
    def __init__(self, dbAlias, query, values_list, qs_mp=None):
        '''
        Initialize MPQuerySet with either raw SQL in @query or a QuerySet in @qs_mp.
        Use @values_list to request just the fields (columns) needed.  The class variables
        rest_colums and kml_columns are typical value_lists.  Note: specifying a values_list
        appears to break the correct serialization of geometry types in the json response.
        Called by stoqs/views/__init__.py when MeasuredParameter REST requests are made.
        '''
        self.isRawQuerySet = False
        if query is None and qs_mp is not None:
            logger.debug('query is None and qs_mp is not None')
            self.query = postgresifySQL(str(qs_mp.query))
            self.mp_query = qs_mp
        elif query is not None and qs_mp is None:
            logger.debug('query is not None and qs_mp is None')
            self.query = query
            query = PQuery.addPrimaryKey(query)
            self.mp_query = MeasuredParameter.objects.using(dbAlias).raw(query)
            self.isRawQuerySet = True
        else:
            raise Exception(
                'Either query or qs_mp must be not None and the other be None.'
            )

        self.dbAlias = dbAlias
        self.values_list = values_list
        self.ordering = ('id', )
Exemplo n.º 2
0
    def getMeasuredParametersQS(self, values_list=[]):
        '''
        Return query set of MeasuremedParameters given the current constraints.  If no parameter is selected return None.
        @values_list can be assigned with additional columns that are supported by PQuerySet(). Note that specificiation
        of a values_list will break the JSON serialization of geometry types.
        '''
        qparams = self._getQueryParms()
        if values_list:
            qs_mp = MeasuredParameter.objects.using(self.request.META['dbAlias']).select_related(depth=2).filter(**qparams).values(*values_list)
        else:
            qs_mp = MeasuredParameter.objects.using(self.request.META['dbAlias']).filter(**qparams)

        # Wrap PQuerySet around either RawQuerySet or GeoQuerySet to control the __iter__() items for lat/lon etc.
        qs_mpq = PQuerySet(None, values_list, qs_mp=qs_mp)
        if self.kwargs.has_key('parametervalues'):
            if self.kwargs['parametervalues'] != [{}]:
                # A depth of 4 is needed in order to see Platform
                qs_mp = MeasuredParameter.objects.using(self.request.META['dbAlias']).select_related(depth=4).filter(**qparams)
                sql = postgresifySQL(str(qs_mp.query))
                self.logger.debug('\n\nsql before query = %s\n\n', sql)
                sql = self.addParameterValuesSelfJoins(sql, self.kwargs['parametervalues'], select_items=self.rest_select_items)
                self.logger.debug('\n\nsql after parametervalue query = %s\n\n', sql)
                qs_mpq = PQuerySet(sql, values_list)

        if qs_mpq:
            self.logger.debug('qs_mpq.query = %s', str(qs_mpq.query))
            
        else:
            self.logger.debug("No queryset returned for qparams = %s", pprint.pformat(qparams))

        return qs_mpq
Exemplo n.º 3
0
    def __init__(self, dbAlias, query, values_list, qs_mp=None):
        '''
        Initialize MPQuerySet with either raw SQL in @query or a QuerySet in @qs_mp.
        Use @values_list to request just the fields (columns) needed.  The class variables
        rest_colums and kml_columns are typical value_lists.  Note: specifying a values_list
        appears to break the correct serialization of geometry types in the json response.
        Called by stoqs/views/__init__.py when MeasuredParameter REST requests are made.
        '''
        self.isRawQuerySet = False
        if query is None and qs_mp is not None:
            logger.debug('query is None and qs_mp is not None')
            self.query = postgresifySQL(str(qs_mp.query))
            self.mp_query = qs_mp
        elif query is not None and qs_mp is None:
            logger.debug('query is not None and qs_mp is None')
            self.query = query
            query = PQuery.addPrimaryKey(query)
            self.mp_query = MeasuredParameter.objects.using(dbAlias).raw(query)
            self.isRawQuerySet = True
        else:
            raise Exception('Either query or qs_mp must be not None and the other be None.')

        self.dbAlias = dbAlias
        self.values_list = values_list
        self.ordering = ('id',)
Exemplo n.º 4
0
    def getSampledParametersQS(self, values_list=[], orderedFlag=True):
        '''
        Return query set of SampledParameters given the current constraints.  If no parameter is selected return None.
        @values_list can be assigned with additional columns that are supported by SPQuerySet(). Note that specificiation
        of a values_list will break the JSON serialization of geometry types. @orderedFlag may be set to False to reduce
        memory and time taken for queries that don't need ordered values.  If parameterID is not none then that parameter
        is added to the filter - used for parameterPlatformPNG generation.
        '''
        qparams = self._getQueryParms(group=SAMPLED)
        logger.debug('Building qs_sp...')
        if values_list == []:
            # If no .values(...) added to QS then items returned by iteration on qs_sp are model objects, not out wanted dictionaries
            values_list = SPQuerySet.rest_columns
            qs_sp = SampledParameter.objects.using(self.request.META['dbAlias']).filter(**qparams).values(*values_list)
        else:
            # May need select_related(...)
            qs_sp = SampledParameter.objects.using(self.request.META['dbAlias']).filter(**qparams).values(*values_list)

        # Save ordered queryset with no parameter in the filter for X3D display to get roll, pitch, and yaw
        self.qs_sp_no_parm = qs_sp

        # If the parametertimeplotid is selected from the UI then we need to have that filter in the QuerySet
        # before doing the raw SQL construction.  Use the qs_mp_no_parm member for QuerySets that shouldn't
        # be filtered by the parametertimeplotid, e.g. parametertime, 3D animation, etc
        if self.parameterID:
            logger.debug('Adding parameter__id=%d filter to qs_sp', int(self.parameterID))
            qs_sp = qs_sp.filter(parameter__id=int(self.parameterID))

        if orderedFlag:
            qs_sp = qs_sp.order_by('sample__instantpoint__activity__name', 'sample__instantpoint__timevalue')

        # Wrap SPQuerySet around either RawQuerySet or GeoQuerySet to control the __iter__() items for lat/lon etc.
        if self.kwargs.has_key('parametervalues'):
            if self.kwargs['parametervalues']:
                # A depth of 4 is needed in order to see Platform
                qs_sp = SampledParameter.objects.using(self.request.META['dbAlias']).select_related(
                            'sample__instantpoint__activity__platform').filter(**qparams)
                if orderedFlag:
                    qs_sp = qs_sp.order_by('sample__instantpoint__activity__name', 'sample__instantpoint__timevalue')
                sql = postgresifySQL(str(qs_sp.query))
                logger.debug('\n\nsql before query = %s\n\n', sql)
                pq = PQuery(self.request)
                sql = pq.addParameterValuesSelfJoins(sql, self.kwargs['parametervalues'], select_items=self.sampled_rest_select_items)
                logger.debug('\n\nsql after parametervalue query = %s\n\n', sql)
                qs_spq = SPQuerySet(self.request.META['dbAlias'], sql, values_list)
            else:
                logger.debug('Building SPQuerySet for SampledParameter...')
                qs_spq = SPQuerySet(self.request.META['dbAlias'], None, values_list, qs_sp=qs_sp)
        else:
            logger.debug('Building SPQuerySet for SampledParameter...')
            qs_spq = SPQuerySet(self.request.META['dbAlias'], None, values_list, qs_sp=qs_sp)

        if qs_spq is None:
            logger.debug('qs_spq.query = %s', str(qs_spq.query))
        else:
            logger.debug("No queryset returned for qparams = %s", pprint.pformat(qparams))

        return qs_spq
Exemplo n.º 5
0
    def getSampledParametersQS(self, values_list=[], orderedFlag=True):
        '''
        Return query set of SampledParameters given the current constraints.  If no parameter is selected return None.
        @values_list can be assigned with additional columns that are supported by SPQuerySet(). Note that specificiation
        of a values_list will break the JSON serialization of geometry types. @orderedFlag may be set to False to reduce
        memory and time taken for queries that don't need ordered values.  If parameterID is not none then that parameter
        is added to the filter - used for parameterPlatformPNG generation.
        '''
        qparams = self._getQueryParms(group=SAMPLED)
        logger.debug('Building qs_sp...')
        if values_list == []:
            # If no .values(...) added to QS then items returned by iteration on qs_sp are model objects, not out wanted dictionaries
            values_list = SPQuerySet.rest_columns
            qs_sp = SampledParameter.objects.using(self.request.META['dbAlias']).filter(**qparams).values(*values_list)
        else:
            # May need select_related(...)
            qs_sp = SampledParameter.objects.using(self.request.META['dbAlias']).filter(**qparams).values(*values_list)

        # Save ordered queryset with no parameter in the filter for X3D display to get roll, pitch, and yaw
        self.qs_sp_no_parm = qs_sp

        # If the parametertimeplotid is selected from the UI then we need to have that filter in the QuerySet
        # before doing the raw SQL construction.  Use the qs_mp_no_parm member for QuerySets that shouldn't
        # be filtered by the parametertimeplotid, e.g. parametertime, 3D animation, etc
        if self.parameterID:
            logger.debug('Adding parameter__id=%d filter to qs_sp', int(self.parameterID))
            qs_sp = qs_sp.filter(parameter__id=int(self.parameterID))

        if orderedFlag:
            qs_sp = qs_sp.order_by('sample__instantpoint__activity__name', 'sample__instantpoint__timevalue')

        # Wrap SPQuerySet around either RawQuerySet or GeoQuerySet to control the __iter__() items for lat/lon etc.
        if self.kwargs.has_key('parametervalues'):
            if self.kwargs['parametervalues']:
                # A depth of 4 is needed in order to see Platform
                qs_sp = SampledParameter.objects.using(self.request.META['dbAlias']).select_related(
                            'sample__instantpoint__activity__platform').filter(**qparams)
                if orderedFlag:
                    qs_sp = qs_sp.order_by('sample__instantpoint__activity__name', 'sample__instantpoint__timevalue')
                sql = postgresifySQL(str(qs_sp.query))
                logger.debug('\n\nsql before query = %s\n\n', sql)
                pq = PQuery(self.request)
                sql = pq.addParameterValuesSelfJoins(sql, self.kwargs['parametervalues'], select_items=self.sampled_rest_select_items)
                logger.debug('\n\nsql after parametervalue query = %s\n\n', sql)
                qs_spq = SPQuerySet(self.request.META['dbAlias'], sql, values_list)
            else:
                logger.debug('Building SPQuerySet for SampledParameter...')
                qs_spq = SPQuerySet(self.request.META['dbAlias'], None, values_list, qs_sp=qs_sp)
        else:
            logger.debug('Building SPQuerySet for SampledParameter...')
            qs_spq = SPQuerySet(self.request.META['dbAlias'], None, values_list, qs_sp=qs_sp)

        if qs_spq is None:
            logger.debug('qs_spq.query = %s', str(qs_spq.query))
        else:
            logger.debug("No queryset returned for qparams = %s", pprint.pformat(qparams))

        return qs_spq
Exemplo n.º 6
0
    def getMeasuredParametersQS(self, values_list=[], orderedFlag=True):
        '''
        Return query set of MeasuremedParameters given the current constraints.  If no parameter is selected return None.
        @values_list can be assigned with additional columns that are supported by MPQuerySet(). Note that specificiation
        of a values_list will break the JSON serialization of geometry types. @orderedFlag may be set to False to reduce
        memory and time taken for queries that don't need ordered values.  If parameterID is not none then that parameter
        is added to the filter - used for parameterPlatformPNG generation.
        '''
        qparams = self._getQueryParms()
        logger.debug('Building qs_mp...')
        if values_list == []:
            # If no .values(...) added to QS then items returned by iteration on qs_mp are model objects, not out wanted dictionaries
            logger.debug('... with values_list = []; using default rest_columns')
            qs_mp = MeasuredParameter.objects.using(self.request.META['dbAlias']).filter(**qparams).values(*MPQuerySet.rest_columns)
        else:
            logger.debug('... with values_list = %s', values_list)
            qs_mp = MeasuredParameter.objects.using(self.request.META['dbAlias']).select_related(depth=2).filter(**qparams).values(*values_list)

        if self.parameterID:
            logger.debug('Adding parameter__id=%d filter to qs_mp', int(self.parameterID))
            qs_mp = qs_mp.filter(parameter__id=int(self.parameterID))

        if orderedFlag:
            qs_mp = qs_mp.order_by('measurement__instantpoint__activity__name', 'measurement__instantpoint__timevalue')

        # Wrap MPQuerySet around either RawQuerySet or GeoQuerySet to control the __iter__() items for lat/lon etc.
        if self.kwargs.has_key('parametervalues'):
            if self.kwargs['parametervalues']:
                # A depth of 4 is needed in order to see Platform
                qs_mp = MeasuredParameter.objects.using(self.request.META['dbAlias']).select_related(depth=4).filter(**qparams)

                if self.parameterID:
                    logger.debug('Adding parameter__id=%d filter to qs_mp', int(self.parameterID))
                    qs_mp = qs_mp.filter(parameter__id=int(self.parameterID))

                if orderedFlag:
                    qs_mp = qs_mp.order_by('measurement__instantpoint__activity__name', 'measurement__instantpoint__timevalue')

                sql = postgresifySQL(str(qs_mp.query))
                logger.debug('\n\nsql before query = %s\n\n', sql)
                pq = PQuery(self.request)
                sql = pq.addParameterValuesSelfJoins(sql, self.kwargs['parametervalues'], select_items=self.rest_select_items)
                logger.debug('\n\nsql after parametervalue query = %s\n\n', sql)
                qs_mpq = MPQuerySet(sql, values_list)
            else:
                logger.debug('Building MPQuerySet with qs_mpquery = %s', str(qs_mp.query))
                qs_mpq = MPQuerySet(None, values_list, qs_mp=qs_mp)
        else:
            logger.debug('Building MPQuerySet with qs_mpquery = %s', str(qs_mp.query))
            qs_mpq = MPQuerySet(None, values_list, qs_mp=qs_mp)

        if qs_mpq is None:
            logger.debug('qs_mpq.query = %s', str(qs_mpq.query))
        else:
            logger.debug("No queryset returned for qparams = %s", pprint.pformat(qparams))

        return qs_mpq
Exemplo n.º 7
0
 def __init__(self, query, values_list, qs_mp=None):
     '''
     Initialize PQuerySet with either raw SQL in @query or a QuerySet in @qs_mp.
     Use @values_list to request just the fields (columns) needed.  The class variables
     rest_colums and kml_columns are typical value_lists.  Note: specifying a values_list
     appears to break the correct serialization of geometry types in the json response.
     Called by stoqs/views/__init__.py when MeasuredParameter REST requests are made.
     '''
     self.query = query or postgresifySQL(str(qs_mp.query))
     self.values_list = values_list
     self.ordering = ('timevalue,')
     if qs_mp is None:
         self.mp_query = MeasuredParameter.objects.raw(query)
     else:
         if qs_mp.exists():
             self.mp_query = qs_mp
         else:
             self.mp_query = MeasuredParameter.objects.raw(query)
Exemplo n.º 8
0
 def __init__(self, query, values_list, qs_mp=None):
     '''
     Initialize PQuerySet with either raw SQL in @query or a QuerySet in @qs_mp.
     Use @values_list to request just the fields (columns) needed.  The class variables
     rest_colums and kml_columns are typical value_lists.  Note: specifying a values_list
     appears to break the correct serialization of geometry types in the json response.
     Called by stoqs/views/__init__.py when MeasuredParameter REST requests are made.
     '''
     self.query = query or postgresifySQL(str(qs_mp.query))
     self.values_list = values_list
     self.ordering = ('timevalue,')
     if qs_mp is None:
         self.mp_query = MeasuredParameter.objects.raw(query)
     else:
         if qs_mp.exists():
             self.mp_query = qs_mp
         else:
             self.mp_query = MeasuredParameter.objects.raw(query)
Exemplo n.º 9
0
    def getMeasuredParametersQS(self, values_list=[]):
        '''
        Return query set of MeasuremedParameters given the current constraints.  If no parameter is selected return None.
        @values_list can be assigned with additional columns that are supported by PQuerySet(). Note that specificiation
        of a values_list will break the JSON serialization of geometry types.
        '''
        qparams = self._getQueryParms()
        if values_list:
            qs_mp = MeasuredParameter.objects.using(
                self.request.META['dbAlias']).filter(**qparams).values(
                    *values_list)
        else:
            qs_mp = MeasuredParameter.objects.using(
                self.request.META['dbAlias']).filter(**qparams)

        # Wrap PQuerySet around either RawQuerySet or GeoQuerySet to control the __iter__() items for lat/lon etc.
        qs_mpq = PQuerySet(None, values_list, qs_mp=qs_mp)
        if self.kwargs.has_key('parametervalues'):
            if self.kwargs['parametervalues'] != [{}]:
                # A depth of 4 is needed in order to see Platform
                qs_mp = MeasuredParameter.objects.using(
                    self.request.META['dbAlias']).select_related(
                        'measurement__instantpoint__activity__platform'
                    ).filter(**qparams)
                sql = postgresifySQL(str(qs_mp.query))
                self.logger.debug('\n\nsql before query = %s\n\n', sql)
                sql = self.addParameterValuesSelfJoins(
                    sql,
                    self.kwargs['parametervalues'],
                    select_items=self.rest_select_items)
                self.logger.debug(
                    '\n\nsql after parametervalue query = %s\n\n', sql)
                qs_mpq = PQuerySet(sql, values_list)

        if qs_mpq:
            self.logger.debug('qs_mpq.query = %s', str(qs_mpq.query))

        else:
            self.logger.debug("No queryset returned for qparams = %s",
                              pprint.pformat(qparams))

        return qs_mpq
Exemplo n.º 10
0
    def __init__(self, query, values_list, qs_sp=None):
        """
        Initialize SPQuerySet with either raw SQL in @query or a QuerySet in @qs_sp.
        Use @values_list to request just the fields (columns) needed.  The class variables
        rest_colums and kml_columns are typical value_lists.  Note: specifying a values_list
        appears to break the correct serialization of geometry types in the json response.
        Called by stoqs/views/__init__.py when SampledParameter REST requests are made.
        """
        if query is None and qs_sp is not None:
            logger.debug("query is None and qs_sp is not None")
            self.query = postgresifySQL(str(qs_sp.query))
            self.sp_query = qs_sp
        elif query is not None and qs_sp is None:
            logger.debug("query is not None and qs_sp is None")
            self.query = query
            self.sp_query = SampledParameter.objects.raw(query)
        else:
            raise Exception("Either query or qs_sp must be not None and the other be None.")

        self.values_list = values_list
        self.ordering = ("id",)
Exemplo n.º 11
0
    def __init__(self, query, values_list, qs_sp=None):
        '''
        Initialize SPQuerySet with either raw SQL in @query or a QuerySet in @qs_sp.
        Use @values_list to request just the fields (columns) needed.  The class variables
        rest_colums and kml_columns are typical value_lists.  Note: specifying a values_list
        appears to break the correct serialization of geometry types in the json response.
        Called by stoqs/views/__init__.py when SampledParameter REST requests are made.
        '''
        if query is None and qs_sp is not None:
            logger.debug('query is None and qs_sp is not None')
            self.query = postgresifySQL(str(qs_sp.query))
            self.sp_query = qs_sp
        elif query is not None and qs_sp is None:
            logger.debug('query is not None and qs_sp is None')
            self.query = query
            self.sp_query = SampledParameter.objects.raw(query)
        else:
            raise Exception(
                'Either query or qs_sp must be not None and the other be None.'
            )

        self.values_list = values_list
        self.ordering = ('id', )
Exemplo n.º 12
0
    def getSampledParametersQS(self, values_list=[], orderedFlag=True):
        """
        Return query set of SampledParameters given the current constraints.  If no parameter is selected return None.
        @values_list can be assigned with additional columns that are supported by SPQuerySet(). Note that specificiation
        of a values_list will break the JSON serialization of geometry types. @orderedFlag may be set to False to reduce
        memory and time taken for queries that don't need ordered values.  If parameterID is not none then that parameter
        is added to the filter - used for parameterPlatformPNG generation.
        """
        qparams = self._getQueryParms(group=SAMPLED)
        logger.debug("Building qs_sp...")
        if values_list == []:
            # If no .values(...) added to QS then items returned by iteration on qs_sp are model objects, not out wanted dictionaries
            values_list = SPQuerySet.rest_columns
            qs_sp = SampledParameter.objects.using(self.request.META["dbAlias"]).filter(**qparams).values(*values_list)
        else:
            qs_sp = (
                SampledParameter.objects.using(self.request.META["dbAlias"])
                .select_related(depth=2)
                .filter(**qparams)
                .values(*values_list)
            )

        if self.parameterID:
            logger.debug("Adding parameter__id=%d filter to qs_sp", int(self.parameterID))
            qs_sp = qs_sp.filter(parameter__id=int(self.parameterID))

        if orderedFlag:
            qs_sp = qs_sp.order_by("sample__instantpoint__activity__name", "sample__instantpoint__timevalue")

        # Wrap SPQuerySet around either RawQuerySet or GeoQuerySet to control the __iter__() items for lat/lon etc.
        if self.kwargs.has_key("parametervalues"):
            if self.kwargs["parametervalues"]:
                # A depth of 4 is needed in order to see Platform
                qs_sp = (
                    SampledParameter.objects.using(self.request.META["dbAlias"])
                    .select_related(depth=4)
                    .filter(**qparams)
                )
                if orderedFlag:
                    qs_sp = qs_sp.order_by("sample__instantpoint__activity__name", "sample__instantpoint__timevalue")
                sql = postgresifySQL(str(qs_sp.query))
                logger.debug("\n\nsql before query = %s\n\n", sql)
                pq = PQuery(self.request)
                sql = pq.addParameterValuesSelfJoins(
                    sql, self.kwargs["parametervalues"], select_items=self.sampled_rest_select_items
                )
                logger.debug("\n\nsql after parametervalue query = %s\n\n", sql)
                qs_spq = SPQuerySet(sql, values_list)
            else:
                logger.debug("Building SPQuerySet for SampledParameter...")
                qs_spq = SPQuerySet(None, values_list, qs_sp=qs_sp)
        else:
            logger.debug("Building SPQuerySet for SampledParameter...")
            qs_spq = SPQuerySet(None, values_list, qs_sp=qs_sp)

        if qs_spq is None:
            logger.debug("qs_spq.query = %s", str(qs_spq.query))
        else:
            logger.debug("No queryset returned for qparams = %s", pprint.pformat(qparams))

        return qs_spq
Exemplo n.º 13
0
    def getMeasuredParametersQS(self, values_list=[], orderedFlag=True):
        '''
        Return query set of MeasuremedParameters given the current constraints.  If no parameter is selected return None.
        @values_list can be assigned with additional columns that are supported by MPQuerySet(). Note that specificiation
        of a values_list will break the JSON serialization of geometry types. @orderedFlag may be set to False to reduce
        memory and time taken for queries that don't need ordered values.  If parameterID is not none then that parameter
        is added to the filter - used for parameterPlatformPNG generation.
        '''
        qparams = self._getQueryParms()
        logger.debug('Building qs_mp...')
        if values_list == []:
            # If no .values(...) added to QS then items returned by iteration on qs_mp are model objects, not out wanted dictionaries
            logger.debug(
                '... with values_list = []; using default rest_columns')
            qs_mp = MeasuredParameter.objects.using(
                self.request.META['dbAlias']).filter(**qparams).values(
                    *MPQuerySet.rest_columns)
        else:
            logger.debug('... with values_list = %s', values_list)
            qs_mp = MeasuredParameter.objects.using(
                self.request.META['dbAlias']).select_related(depth=2).filter(
                    **qparams).values(*values_list)

        # Save a queryset with no parameter in the filter
        self.qs_mp_no_order_no_parm = qs_mp
        if self.parameterID:
            logger.debug('Adding parameter__id=%d filter to qs_mp',
                         int(self.parameterID))
            qs_mp = qs_mp.filter(parameter__id=int(self.parameterID))

        if orderedFlag:
            qs_mp = qs_mp.order_by('measurement__instantpoint__activity__name',
                                   'measurement__instantpoint__timevalue')

        # Wrap MPQuerySet around either RawQuerySet or GeoQuerySet to control the __iter__() items for lat/lon etc.
        if self.kwargs.has_key('parametervalues'):
            if self.kwargs['parametervalues']:
                # A depth of 4 is needed in order to see Platform
                qs_mp = MeasuredParameter.objects.using(
                    self.request.META['dbAlias']).select_related(
                        depth=4).filter(**qparams)

                if self.parameterID:
                    logger.debug('Adding parameter__id=%d filter to qs_mp',
                                 int(self.parameterID))
                    qs_mp = qs_mp.filter(parameter__id=int(self.parameterID))

                if orderedFlag:
                    qs_mp = qs_mp.order_by(
                        'measurement__instantpoint__activity__name',
                        'measurement__instantpoint__timevalue')

                sql = postgresifySQL(str(qs_mp.query))
                logger.debug('\n\nsql before query = %s\n\n', sql)
                pq = PQuery(self.request)
                sql = pq.addParameterValuesSelfJoins(
                    sql,
                    self.kwargs['parametervalues'],
                    select_items=self.rest_select_items)
                logger.debug('\n\nsql after parametervalue query = %s\n\n',
                             sql)
                qs_mpq = MPQuerySet(sql, values_list)
            else:
                logger.debug('Building MPQuerySet with qs_mpquery = %s',
                             str(qs_mp.query))
                qs_mpq = MPQuerySet(None, values_list, qs_mp=qs_mp)
        else:
            logger.debug('Building MPQuerySet with qs_mpquery = %s',
                         str(qs_mp.query))
            qs_mpq = MPQuerySet(None, values_list, qs_mp=qs_mp)

        if qs_mpq is None:
            logger.debug('qs_mpq.query = %s', str(qs_mpq.query))
        else:
            logger.debug("No queryset returned for qparams = %s",
                         pprint.pformat(qparams))

        return qs_mpq
Exemplo n.º 14
0
    def getMeasuredParametersQS(self, values_list=[], orderedFlag=True):
        """
        Return query set of MeasuremedParameters given the current constraints.  If no parameter is selected return None.
        @values_list can be assigned with additional columns that are supported by MPQuerySet(). Note that specificiation
        of a values_list will break the JSON serialization of geometry types. @orderedFlag may be set to False to reduce
        memory and time taken for queries that don't need ordered values.  If parameterID is not none then that parameter
        is added to the filter - used for parameterPlatformPNG generation.
        """
        qparams = self._getQueryParms()
        logger.debug("Building qs_mp...")
        if values_list == []:
            # If no .values(...) added to QS then items returned by iteration on qs_mp are model objects, not out wanted dictionaries
            logger.debug("... with values_list = []; using default rest_columns")
            qs_mp = (
                MeasuredParameter.objects.using(self.request.META["dbAlias"])
                .filter(**qparams)
                .values(*MPQuerySet.rest_columns)
            )
        else:
            logger.debug("... with values_list = %s", values_list)
            # May need select_related(...)
            qs_mp = MeasuredParameter.objects.using(self.request.META["dbAlias"]).filter(**qparams).values(*values_list)

        if orderedFlag:
            qs_mp = qs_mp.order_by("measurement__instantpoint__activity__name", "measurement__instantpoint__timevalue")

        # Save ordered queryset with no parameter in the filter for X3D display to get roll, pitch, and yaw
        self.qs_mp_no_parm = qs_mp

        # If the parametertimeplotid is selected from the UI then we need to have that filter in the QuerySet
        # before doing any raw SQL construction.  Use the qs_mp_no_parm member for QuerySets that shouldn't
        # be filtered by the parametertimeplotid, e.g. parametertime, 3D animation, etc.
        if self.parameterID:
            logger.debug("Adding parameter__id=%d filter to qs_mp", int(self.parameterID))
            qs_mp = qs_mp.filter(parameter__id=int(self.parameterID))

        # Wrap MPQuerySet around either RawQuerySet or GeoQuerySet to control the __iter__() items for lat/lon etc.
        if self.kwargs.has_key("parametervalues"):
            if self.kwargs["parametervalues"]:
                # Start with fresh qs_mp without .values()
                qs_mp = (
                    MeasuredParameter.objects.using(self.request.META["dbAlias"])
                    .select_related("measurement__instantpoint__activity__platform")
                    .filter(**qparams)
                )

                if orderedFlag:
                    qs_mp = qs_mp.order_by(
                        "measurement__instantpoint__activity__name", "measurement__instantpoint__timevalue"
                    )

                sql = postgresifySQL(str(qs_mp.query))
                logger.debug("\n\nsql before query = %s\n\n", sql)
                pq = PQuery(self.request)
                sql = pq.addParameterValuesSelfJoins(
                    sql, self.kwargs["parametervalues"], select_items=self.rest_select_items
                )
                logger.debug("\n\nsql after parametervalue query = %s\n\n", sql)
                qs_mpq = MPQuerySet(self.request.META["dbAlias"], sql, values_list)
            else:
                logger.debug("Building MPQuerySet with qs_mpquery = %s", str(qs_mp.query))
                qs_mpq = MPQuerySet(self.request.META["dbAlias"], None, values_list, qs_mp=qs_mp)
        else:
            logger.debug("Building MPQuerySet with qs_mpquery = %s", str(qs_mp.query))
            qs_mpq = MPQuerySet(self.request.META["dbAlias"], None, values_list, qs_mp=qs_mp)

        if qs_mpq is None:
            logger.debug("qs_mpq.query = %s", str(qs_mpq.query))
        else:
            logger.debug("No queryset returned for qparams = %s", pprint.pformat(qparams))

        return qs_mpq