mast/queries.py
def _get_top_users_total_distance_query(self, activity_types: list):
        """
        Returns query for top users in the total distance in specified activity types.
        :param activity_types: Types of activities we want to sum to total distance.
        :returns: Query returning User and total distance.
        """
        total_distances = db.session.query(Activity.user_id.label('user_id'),
                                           func.sum(Activity.distance).label('total_distance')). \
            filter(func.date(Activity.datetime) >= self.SEASON.start_date,
                   func.date(Activity.datetime) <= self.SEASON.end_date,
                   Activity.type.in_(activity_types)). \
            group_by(Activity.user_id). \
            subquery(with_labels=True)
        return db.session.query(User, total_distances.c.total_distance). \
            select_from(User). \
            join(total_distances, User.id == total_distances.c.user_id). \
            filter(User.competing,
                   User.verified). \
            order_by(total_distances.c.total_distance.desc())

        Returns query for top users in the total distance in specified activity types.
        :param activity_types: Types of activities we want to sum to total distance.
        :returns: Query returning User and total distance.
        
Returns query for top users in the total distance in specified activity types.
Returns query for top users in the total distance in specified activity types .
def _get_top_users_total_distance_query(self, activity_types: list):
        total_distances = db.session.query(Activity.user_id.label('user_id'),
                                           func.sum(Activity.distance).label('total_distance')). \
            filter(func.date(Activity.datetime) >= self.SEASON.start_date,
                   func.date(Activity.datetime) <= self.SEASON.end_date,
                   Activity.type.in_(activity_types)). \
            group_by(Activity.user_id). \
            subquery(with_labels=True)
        return db.session.query(User, total_distances.c.total_distance). \
            select_from(User). \
            join(total_distances, User.id == total_distances.c.user_id). \
            filter(User.competing,
                   User.verified). \
            order_by(total_distances.c.total_distance.desc())
def _get_top_users_total_distance_query ( self , activity_types : list ) : total_distances = db . session . query ( Activity . user_id . label ( 'user_id' ) , func . sum ( Activity . distance ) . label ( 'total_distance' ) ) . filter ( func . date ( Activity . datetime ) >= self . SEASON . start_date , func . date ( Activity . datetime ) <= self . SEASON . end_date , Activity . type . in_ ( activity_types ) ) . group_by ( Activity . user_id ) . subquery ( with_labels = True ) return db . session . query ( User , total_distances . c . total_distance ) . select_from ( User ) . join ( total_distances , User . id == total_distances . c . user_id ) . filter ( User . competing , User . verified ) . order_by ( total_distances . c . total_distance . desc ( ) )
Returns query for top users in the total distance in specified activity types.
Returns query for top users in the total distance in specified activity types .
"""
        Returns query for top users in the total distance in specified activity types.
        :param activity_types: Types of activities we want to sum to total distance.
        :returns: Query returning User and total distance.
        """
Query returning User and total distance.
Query returning User and total distance .
self
activity_types
list
Types of activities we want to sum to total distance.
Types of activities we want to sum to total distance .