Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- def group_user_actions(fund_id, date_from, date_to):
- result_actions = db.session \
- .query(
- FundUser.id.label('fund_user_id'),
- db.func.count(Action.id).label('number_of_actions')
- ) \
- .outerjoin(Action, db.and_(
- Action.fund_user_id == FundUser.id,
- Action.date >= date_from,
- Action.date <= date_to
- )) \
- .filter(
- FundUser.fund_id == fund_id,
- FundUser.role != 'client'
- ) \
- .group_by(FundUser.id) \
- .all()
- result_sessions = db.session \
- .query(
- FundUser.id.label('fund_user_id'),
- db.func.sum(Session.duration).label('duration')
- ) \
- .outerjoin(Session, db.and_(
- Session.fund_user_id == FundUser.id,
- Session.end >= date_from,
- Session.end <= date_to
- )) \
- .filter(
- FundUser.fund_id == fund_id,
- FundUser.role != 'client'
- ) \
- .group_by(FundUser.id) \
- .all()
- return {'actions': result_actions, 'sessions': result_sessions}
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement