Example #1
0
    def get_all_recordsets(self, participant=Participant()):

        if participant.id_participant is None:
            query = self.session.query(Recordset)
            query.order_by(asc(Recordset.start_timestamp))
            return query.all()
        else:
            query = self.session.query(Recordset).filter(Recordset.id_participant == participant.id_participant)
            query.order_by(asc(Recordset.start_timestamp))
            return query.all()
Example #2
0
def index():
    form = PostForm()
    if form.validate_on_submit():
        new_post = Post(
            body=form.body.data,
            author=current_user._get_current_object()
        )
        db.session.add(new_post)
        db.session.commit()
        return redirect(url_for('.index'))

    page = request.args.get('page', 1, type=int)

    show_followed = False

    if current_user.is_authenticated:
        show_followed = bool(request.cookies.get('show_followed', ''))
    if show_followed:
        query = current_user.followed_posts
    else:
        query = Post.query

    pagination = query.order_by(Post.timestamp.desc()).paginate(
        page, per_page=current_app.config['POSTS_PER_PAGE']
    )
    posts = pagination.items

    return render_template('index.html', posts=posts, pagination=pagination, form=form, show_followed=show_followed)
Example #3
0
 def _order_query(self, query):
     assert isinstance(query, sqlalchemy.orm.query.Query)
     timestep_alias = None
     halo_alias = None
     if self._ordering_requires_join():
         timestep_alias = sqlalchemy.orm.aliased(core.timestep.TimeStep)
         halo_alias = sqlalchemy.orm.aliased(core.halo.SimulationObjectBase)
         query = query.join(halo_alias, self._link_orm_class.halo_to_id == halo_alias.id)\
             .join(timestep_alias)\
             .options(
               contains_eager(self._link_orm_class.halo_to.of_type(halo_alias))\
               .contains_eager(halo_alias.timestep.of_type(timestep_alias))
         )
     query = query.order_by(
         *self._order_by_clause(halo_alias, timestep_alias))
     return query
Example #4
0
 def _query_ordered(self):
     query = self.query
     assert isinstance(query, sqlalchemy.orm.query.Query)
     timestep_alias = None
     halo_alias = None
     if self._ordering_requires_join():
         timestep_alias = sqlalchemy.orm.aliased(core.timestep.TimeStep)
         halo_alias = sqlalchemy.orm.aliased(core.halo.Halo)
         query = query.join(
             halo_alias, self._link_orm_class.halo_to).join(timestep_alias)
         query = query.options(contains_eager("halo_to", alias=halo_alias))
         query = query.options(
             contains_eager("halo_to", "timestep", alias=timestep_alias))
     query = query.order_by(
         *self._order_by_clause(halo_alias, timestep_alias))
     return query
Example #5
0
	def _query_sort(cls, model, info, query, gql_sort):
		for field in gql_sort:
			direction = field.get('direction', 'aesc')
			gql_field = field['field']
			sql_field = smoke_zephyr.utilities.parse_case_camel_to_snake(gql_field)
			if '_' in gql_field or sql_field not in model.metatable().column_names:
				raise ValueError('invalid sort field: ' + gql_field)
			if not gql_middleware.AuthorizationMiddleware.info_has_read_prop_access(info, model, sql_field):
				continue
			if direction == 'aesc':
				field = getattr(model, sql_field)
			elif direction == 'desc':
				field = getattr(model, sql_field).desc()
			else:
				raise ValueError('sort direction must be either \'aesc\' or \'desc\'')
			query = query.order_by(field)
		return query
Example #6
0
    def get_all_sensor_data(self, **kwargs):

        # Initialize from kwargs (and default values)
        convert = kwargs.get('convert', False)
        sensor = kwargs.get('sensor', None)
        channel = kwargs.get('channel', None)
        recordset = kwargs.get('recordset', None)

        # Get all sensor data
        query = self.session.query(SensorData)

        if recordset is not None:
            query = query.filter(
                SensorData.id_recordset == recordset.id_recordset)

        if sensor is not None:
            # print('Should filter sensor id', sensor.id_sensor)
            query = query.filter(SensorData.id_sensor == sensor.id_sensor)

        if channel is not None:
            # print('Should filter channel', channel.id_channel)
            query = query.filter(SensorData.id_channel == channel.id_channel)

        # print(query)
        # Make sure data is ordered by timestamps
        query = query.order_by(SensorData.start_timestamp.asc())

        # And then per channel
        # query = query.order_by(SensorData.channel.asc())

        if not convert:
            return query.all()
        else:
            # Read result, data will be bytes array
            result = query.all()

            # Convert to the right format
            for sensor_data in result:
                # print('data len:', len(sensor_data.data))
                sensor_data.data = DataFormat.from_bytes(
                    sensor_data.data, sensor_data.channel.id_data_format)

            return result
Example #7
0
 def _query_sort(cls, model, info, query, gql_sort):
     for field in gql_sort:
         direction = field.get('direction', 'aesc')
         gql_field = field['field']
         sql_field = smoke_zephyr.utilities.parse_case_camel_to_snake(
             gql_field)
         if '_' in gql_field or sql_field not in model.metatable(
         ).column_names:
             raise ValueError('invalid sort field: ' + gql_field)
         if not gql_middleware.AuthorizationMiddleware.info_has_read_prop_access(
                 info, model, sql_field):
             continue
         if direction == 'aesc':
             field = getattr(model, sql_field)
         elif direction == 'desc':
             field = getattr(model, sql_field).desc()
         else:
             raise ValueError(
                 'sort direction must be either \'aesc\' or \'desc\'')
         query = query.order_by(field)
     return query