コード例 #1
0
def record():
    user = users.get_current_user()
    if not signed_up(user):
            return redirect('/')

    return render_template(
            "record.html",
            nick=user_store.get_nick(user))
コード例 #2
0
def signup():
    user = users.get_current_user()
    default_nick = ""
    if signed_up(user):
        default_nick = user_store.get_nick(user)

    return render_template("signup.html",
                           email=user.email(),
                           default_nick=default_nick)
コード例 #3
0
def dashboard():
    user = users.get_current_user()
    if not signed_up(user):
        return redirect('/')
    recents = []
    recent_stuffs = user_store.get_recent_points(user, 7)
    today_date = datetime.date.today()
    # if we're on the nth day of the week (n=0 is Monday), the Monday of the
    # week was n days ago...
    week_start_date = today_date - datetime.timedelta(today_date.weekday())
    # ... and the Sunday on which this week will end is 6 days later.
    this_week_end_date = week_start_date + datetime.timedelta(6)
    week_points = 0
    if recent_stuffs:
        for date, points in recent_stuffs:
            recents.append({
                'date':str(date),
                'points':str(points)
                })
            if date >= week_start_date and date <= this_week_end_date:
                week_points += points

    this_nick = user_store.get_nick(user)
    scoreboard = user_store.get_scoreboard()
    nicks = []
    weeks = []
    glowsticks = []
    team_scores_to_sort = []
    all_week_end_dates = set()
    team_victorweeks = 0
    for (nick, d) in scoreboard:
        nicks.append({"v":nick,"e":nick == this_nick})
        glowsticks.append({"v":0,"e":False})
        all_week_end_dates.update(d.keys())

    for week_end_date in reversed(sorted(all_week_end_dates)):
        # Get the points scored by each user
        points_num = [d.get(week_end_date, 0) for (_, d) in scoreboard]

        # Convert that to strings
        points = [{"v":str(p),"e":False} for p in points_num]

        # Update the total glowsticks, and while we're there set any necessary
        # emphasis on the points
        if points_calculator.is_team_victorweek(week_end_date, points_num):
            team_victorweeks += 1
        winning_score = max(points_num)
        for (i, p) in enumerate(points_num):
            if p == winning_score:
                glowsticks[i]["v"] += 1
                points[i].update({"e":True})

        weeks.append({"date":str(week_end_date), "points":points})
        team_scores_to_sort.append((
            -sum(points_num),
            {"date":str(week_end_date), "points":str(sum(points_num))}
            ))

    # Set emphasis on the glowsticks
    if len(nicks) > 0:
        winning_glowsticks = max([g["v"] for g in glowsticks])
        for d in glowsticks:
            if d["v"] == winning_glowsticks:
                d["e"] = True


    # Sort team scores in descending order (hence the minus when creating the
    # list)
    team_scores_to_sort.sort()
    team_scores = [score for (_, score) in team_scores_to_sort]

    return render_template(
            "dashboard.html",
            nick=this_nick,
            recents=recents,
            week_end_date=str(this_week_end_date),
            week_points=str(week_points),
            nicks=nicks,
            glowsticks=glowsticks,
            weeks=weeks,
            team_scores=team_scores,
            team_victorweeks=team_victorweeks)
コード例 #4
0
def signed_up(user):
    if user_store.get_nick(user):
        return True
    return False