Esempio n. 1
0
def pay_event_today():
    # Retrieve all registered posters.
    queried_posters = (PayPosters.query.order_by(
        PayPosters.poster_id.asc()).limit(20).all())

    posters = []
    for seq, poster in enumerate(queried_posters):
        posters.append(
            RepeatedElement({
                "seq": seq + 1,
                "posterid": poster.poster_id,
                "geofilter": 0,
            }))

    return {
        "date": current_date(),
        "postertime": 5,
        "posterinfo": posters,
        "introinfo": {
            "seq": 1,
            "cntid": 1,
            "cnttype": 1,
            "dispsec": 5,
            "dimg": 1,
            "random": 0,
            "linktype": 5,
            "linkid": 1,
        },
    }
Esempio n. 2
0
def pay_event_today_v1025(queried_posters):
    posters = []
    for seq, poster in enumerate(queried_posters):
        posters.append(
            RepeatedElement({
                "seq": seq + 1,
                "posterid": poster.poster_id,
                "geofilter": 0,
            }))

    return {
        "date": current_date(),
        "postertime": 5,
        "posterinfo": posters,
        "introinfo": {
            "seq": 1,
            "cntid": 1,
            "cnttype": 1,
            "dispsec": 5,
            "dimg": 1,
            "random": 0,
            "linktype": 5,
            "linkid": 1,
        },
    }
Esempio n. 3
0
def calendar():
    teachers = userdb.execute(
        "SELECT * FROM users WHERE permission = 'teacher'")
    centres = userdb.execute("SELECT centres FROM centres")
    return render_template("calendar.html",
                           currentDate=current_date(),
                           teachers=getfullname(teachers),
                           centres=centres)
Esempio n. 4
0
def event_today():
    # Retrieve all registered posters.
    queried_posters = Posters.query.order_by(
        Posters.poster_id.asc()).limit(20).all()
    queried_miis = (ConciergeMiis.query.order_by(
        ConciergeMiis.mii_id.asc()).limit(20).all())
    # Create a dictionary and append contents.
    # We require separate posterinfos, so we use RepeatedElement.
    posters = []
    miiinfos = []
    for seq, poster in enumerate(queried_posters):
        posters.append(
            RepeatedElement({
                # Seq is indexed by 1, whereas a normal index is 0.
                "seq": seq + 1,
                "posterid": poster.poster_id,
            }))

    for seq, mii in enumerate(queried_miis):
        miiinfos.append(RepeatedElement({"seq": seq + 1, "miiid": mii.mii_id}))

    return {
        "date":
        current_date(),
        "frameid":
        2,
        "color":
        "000000",
        "postertime":
        5,
        "posterinfo":
        posters,
        "miiinfo":
        miiinfos,
        "newsinfo": {
            "page": 1,
            "news": "Welcome back to Wii Room!"
        },
        "adinfo": (
            RepeatedKey({
                "pref": 2,
                "adid": 1,
            }),
            RepeatedKey({
                "pref": 1,
                "adid": 1,
            }),
        ),
        "introinfo": {
            "seq": 1,
            "cntid": 1,
            "cnttype": 1,
            "dispsec": 5,
            "dimg": 1,
            "random": 0,
            "linktype": 0,
        },
    }
Esempio n. 5
0
def pay_event_today_v770(queried_posters):
    poster_id_one = queried_posters[0].poster_id
    poster_id_two = queried_posters[1].poster_id

    return {
        "date": current_date(),
        "postertime": 5,
        "posterid1": poster_id_one,
        "posterid2": poster_id_two,
        "introinfo": {
            "seq": 1,
            # Movie IDs must be 16 digits.
            "intromovid": f"{1:16}",
            "linktype": 1,
            "movieid": 1,
        },
    }
Esempio n. 6
0
def get_totd_text():
    """
    Get the text for the Top of the Day post.
    :return: The body for the post.
    """
    sections = []

    # Most Upvoted Posts
    top_submissions = sorted([
        submission
        for submission in get_reddit().subreddit("all").top("day", limit=5)
    ],
                             key=lambda x: x.score,
                             reverse=True)
    items = [format_item(i, item) for i, item in enumerate(top_submissions)]
    sections.append(get_templates()["section_template"].format(
        section_title="Most Upvoted Posts of the Day",
        section_note="",
        title_body="Title",
        items="\n".join(items),
    ))

    # Most Upvoted Comments
    comments = []
    for submission in top_submissions:
        comments.extend([[comment, comment.score]
                         for comment in submission.comments
                         if isinstance(comment, Comment)])
    top_comments = sorted(comments, key=lambda x: x[1], reverse=True)
    items = [
        format_item(i, item) for i, item in enumerate(
            [comment_info[0] for comment_info in top_comments[:5]])
    ]
    sections.append(get_templates()["section_template"].format(
        section_title="Most Upvoted Comments of the Day",
        section_note=
        "\n\n^(Note: These may not be entirely accurate. Currently these are out of the comments taken from the top 5 submissions.)",
        title_body="Body",
        items="\n".join(items),
    ))

    submission_text = get_templates()["main"].format(
        date=current_date(), sections="\n\n".join(sections))
    return submission_text
Esempio n. 7
0
def calendar():
    teachers = userdb.execute(
        "SELECT * FROM users WHERE permission = 'teacher'")
    return render_template("calendar.html", currentDate=current_date())
Esempio n. 8
0
def event_today():
    # Retrieve all registered posters.
    queried_posters = Posters.query.order_by(
        Posters.poster_id.asc()).limit(20).all()
    queried_miis = (ConciergeMiis.query.order_by(
        ConciergeMiis.mii_id.asc()).limit(20).all())
    # Create a dictionary and append contents.
    # We require separate posterinfos, so we use RepeatedElement.
    posters = []
    miiinfos = []
    newsinfos = []
    for seq, poster in enumerate(queried_posters):
        posters.append(
            RepeatedElement({
                # Seq is indexed by 1, whereas a normal index is 0.
                "seq": seq + 1,
                "posterid": poster.poster_id,
            }))

    for seq, mii in enumerate(queried_miis):
        miiinfos.append(RepeatedElement({"seq": seq + 1, "miiid": mii.mii_id}))
    for page, news in enumerate(News.query.all()):
        newsinfos.append(RepeatedElement({"page": page + 1, "news": news.msg}))

    return_dict = {
        "date":
        current_date(),
        "frameid":
        2,
        "color":
        "000000",
        "postertime":
        5,
        "posterinfo":
        posters,
        "adinfo": (
            RepeatedKey({
                "pref": 2,
                "adid": 1,
            }),
            RepeatedKey({
                "pref": 1,
                "adid": 1,
            }),
        ),
        "introinfo": {
            "seq": 1,
            "cntid": 1,
            "cnttype": 1,
            "dispsec": 5,
            "dimg": 1,
            "random": 0,
            "linktype": 0,
        },
    }

    if is_v770():
        # v770 expects only one poster.
        # As we've already queried the DB, insert the first poster.
        poster_id = posters[0].contents["posterid"]
        return_dict["posterid"] = poster_id
    else:
        # v1025 expects multiple posters, similar to how we've queried.
        return_dict["posterinfo"] = posters

    if newsinfos:
        return_dict["newsinfo"] = newsinfos

    if miiinfos:
        return_dict["miiinfo"] = miiinfos

    return return_dict
Esempio n. 9
0
def timejournal():
    """Show journal for the day"""
    # If POST or GET
    if request.method == "POST" or request.method == "GET":
        # Get the date the user selects. If user does not submit a date, get the current date.
        if not request.form.get("date"):
            date = current_date()
        else:
            date = request.form.get("date")

        # Get the information for all activities the user did on that chosen date
        rows = db.execute(
            "SELECT name, category, timespent, notes, rating, minutes FROM activities WHERE userid = :user_id AND date = :date ORDER BY start",
            user_id=session["user_id"],
            date=date)

        # If no activities logged for that date and user, display an empty journal message.
        if len(rows) == 0:
            return render_template("nothing.html", date=date)

        # Calculate total number of hours spent in each category
        sleep_hours = 0
        class_hours = 0
        schoolwork_hours = 0
        extracurricular_hours = 0
        work_hours = 0
        exercise_hours = 0
        food_hours = 0
        fun_hours = 0
        other_hours = 0
        sad_hours = 0
        happy_hours = 0
        for row in rows:
            if row["category"] == "Sleep":
                sleep_hours += row["timespent"]
            if row["rating"] == "disliked":
                sad_hours += row["timespent"]
            if row["rating"] == "liked":
                happy_hours += row["timespent"]
            if row["category"] == "Class":
                class_hours += row["timespent"]
            if row["category"] == "Schoolwork":
                schoolwork_hours += row["timespent"]
            if row["category"] == "Extracurricular":
                extracurricular_hours += row["timespent"]
            if row["category"] == "Work":
                work_hours += row["timespent"]
            if row["category"] == "Exercise":
                exercise_hours += row["timespent"]
            if row["category"] == "Food":
                food_hours += row["timespent"]
            if row["category"] == "Fun":
                fun_hours += row["timespent"]
            if row["category"] == "Other":
                other_hours += row["timespent"]
        # Create a dictionary to store the category and the corresponding total hours spent doing things in that category
        category_hours = {}
        category_hours["Sleep"] = sleep_hours
        category_hours["Class"] = class_hours
        category_hours["Schoolwork"] = schoolwork_hours
        category_hours["Extracurricular"] = extracurricular_hours
        category_hours["Work"] = work_hours
        category_hours["Exercise"] = exercise_hours
        category_hours["Food"] = food_hours
        category_hours["Fun"] = fun_hours
        category_hours["Other"] = other_hours
        total_hours = sleep_hours + class_hours + schoolwork_hours + extracurricular_hours + work_hours + exercise_hours + food_hours + fun_hours + other_hours
        hours_remaining = 24 - total_hours
        # Create a list of all categories
        category_list = {
            "Sleep", "Class", "Schoolwork", "Extracurricular", "Work",
            "Exercise", "Food", "Fun", "Other"
        }

        # Get all of the total hours spent in each category for a user on a specific date
        summary_rows = db.execute(
            "SELECT * FROM timesummary WHERE userid = :user_id AND date = :date",
            user_id=session["user_id"],
            date=date)
        # If there is no information stored about category time totals for a user on a specific date, add the information to the database based on the above calculated category hours
        if len(summary_rows) < 1:
            # Iterate through category list, for each of the categories, insert the total hours into the database
            for category in category_list:
                db.execute(
                    "INSERT INTO timesummary (userid, date, category, total, minutes) VALUES (:user_id, :date, :category_name, :total, :minutes)",
                    user_id=session["user_id"],
                    date=date,
                    category_name=category,
                    total=category_hours[category],
                    minutes=round((category_hours[category]) * 60))
            # Insert the number of total hours the user spent in activites rated as "liked" on a specific day
            db.execute(
                "INSERT INTO timesummary (userid, date, category, total, minutes) VALUES (:user_id, :date, :emotion, :total, :minutes)",
                user_id=session["user_id"],
                date=date,
                emotion="Happy",
                total=happy_hours,
                minutes=round(happy_hours * 60))
            # Insert the number of total hours the user spent in activites rated as "disliked" on a specific day
            db.execute(
                "INSERT INTO timesummary (userid, date, category, total, minutes) VALUES (:user_id, :date, :emotion, :total, :minutes)",
                user_id=session["user_id"],
                date=date,
                emotion="Sad",
                total=sad_hours,
                minutes=round(sad_hours * 60))

        # If there already exists information stored about category time totals for a user on a specific date, update the information to the database based on the above calculated category hours (since users may have added new activity entries for a date)
        else:
            # Iterate through category list, for each of the categories, update the total hours into the databse
            for category in category_list:
                db.execute(
                    "UPDATE timesummary SET total = :total, minutes = :minutes WHERE userid = :user_id AND category = :category_name AND date = :date",
                    total=category_hours[category],
                    user_id=session["user_id"],
                    category_name=category,
                    date=date,
                    minutes=round((category_hours[category]) * 60))
            # Update the number of total hours the user spent in activites rated as "liked" on a specific day
            db.execute(
                "UPDATE timesummary SET total = :total, minutes = :minutes WHERE userid = :user_id AND category = :emotion AND date = :date",
                user_id=session["user_id"],
                date=date,
                emotion="Happy",
                total=happy_hours,
                minutes=round(happy_hours * 60))
            # Update the number of total hours the user spent in activites rated as "disliked" on a specific day
            db.execute(
                "UPDATE timesummary SET total = :total, minutes = :minutes WHERE userid = :user_id AND category = :emotion AND date = :date",
                user_id=session["user_id"],
                date=date,
                emotion="Sad",
                total=sad_hours,
                minutes=round(sad_hours * 60))

        # Get all of the total hours spent in each category for a user on a specific date (updated)
        summary_rows = db.execute(
            "SELECT * FROM timesummary WHERE userid = :user_id AND date = :date AND total != 0 AND category != 'Happy' AND category != 'Sad' ORDER BY total DESC",
            user_id=session["user_id"],
            date=date)

        # Advice
        list_of_advice = []
        # If the user logged less than 7 hours spent for activities in the "sleep" category, recommend for the user to sleep more.
        if sleep_hours < 7:
            advice = "You should sleep more. Research shows that getting seven to eight hours of sleep every night is good for your health."
            list_of_advice.append(advice)
        # If the user logged more hours spent doing activities that they rated as "disliked" than "liked", recommend for the user to do more activities that they enjoy doing.
        if happy_hours < sad_hours:
            advice = "You're doing more things that make you unhappy than that make you happy. Try to do more of what you love!"
            list_of_advice.append(advice)
        # If the user logged less than half an hour spent for activities in the "exercise" category, recommend for the user to exercise more.
        if exercise_hours < 0.5:
            advice = "You should exercise more. You should aim for at least 30 minutes of physical activity of moderate intensity every day."
            list_of_advice.append(advice)
        # If the user logged less than 1 hour spent for activities in the "food" category, check to make sure the user is eating enough.
        if food_hours < 1:
            advice = "Make sure you are eating proper meals. You didn't spend much time eating today."
            list_of_advice.append(advice)
        # If there is no advice, just say they are doing great.
        if len(list_of_advice) == 0:
            list_of_advice.append(
                "You're doing great! Keep doing what you're doing.")

        list_of_data = [["Activity", "Hours per Day"],
                        ["Not logged", hours_remaining]]
        for activity in summary_rows:
            list_to_add = []
            list_to_add.append(activity["category"])
            list_to_add.append(activity["total"])
            list_of_data.append(list_to_add)
        pie_data = json.dumps(list_of_data)

        return render_template("timelog.html",
                               rows=rows,
                               summary_rows=summary_rows,
                               date=date,
                               list_of_advice=list_of_advice,
                               list_of_data=list_of_data,
                               pie_data=pie_data)