예제 #1
0
def _event_recommendation(event: Union[Event, 'EventData'],
                          with_params: Dict[str, Any] = None) -> List[User]:
    recommendations = []
    with session_scope() as session:
        users = list(User.get_all(session))
        event = Event.get_by_id(session, event.id)
        capacity = len(users)
        if with_params is not None and 'avg_prob' in with_params:
            avprob = float(with_params['avg_prob'])
            capacity = event.servings / avprob if avprob > 0 else len(users)
            shuffle(users)
            pushed = 0
        for user in users:
            if should_recommend(user, event) and pushed <= capacity:
                user_rec = UserRecommendedEvent(event.id, user.id)
                session.add(user_rec)
                session.expunge(user)
                recommendations.append(user)
                pushed += 1
            elif pushed > capacity:
                break
    return recommendations
예제 #2
0
def get_all_users() -> List[UserData]:
    with session_scope() as session:
        users = User.get_all(session)
        return UserData.list(users)