Example #1
0
def dashboard():
    user = g.current_user
    league = g.current_league
    return dict(
        report_form=ReportForm(get_active_users()),
        current_ranking=get_user_standing(league['id'], user['id']),
        ranking=get_league_ranking(league['id']),
        history=search_matches(league['id'], user_id=user['id']))
Example #2
0
def report():
    if not g.current_league['active']:
        abort(403)
    form = ReportForm(get_active_users(), request.form)
    if not form.validate():
        return dict(form=form)
    is_win = form.result.data == '1'
    cur_user = g.current_user['id']
    opp_user = form.opponent.data
    (winner, loser) = (cur_user, opp_user) if is_win else (opp_user, cur_user)
    create_match(g.current_league['id'], winner, loser)
    return redirect(url_for('dashboard'))
Example #3
0
def generate_matches(db, truncate=False):
    """
    Generates new matches between players in a league.
    """
    if truncate:
        db.truncate_table('match')
    users = get_active_users(db)
    leagues = get_active_leagues(db)
    for league in leagues:
        logger().info('creating matches for league: %s' % league['name'])
        matches = []
        for i in range(randint(0, 25)):
            shuffle(users)
            winner = users[0]['id']
            loser = users[1]['id']
            matches.append([league, winner, loser])
        match_date = datetime.now() - timedelta(days=100)
        diff_hours = round(100.0/len(matches), 2)
        for match in matches:
            match_date = match_date + timedelta(hours=diff_hours*24)
            match_time = mktime(match_date.timetuple())
            create_match(
                db, match[0]['id'], match[1], match[2], match_date=match_time)