Beispiel #1
0
def get_stopstalk_rating_history():
    user_id = request.vars.get("user_id", None)
    custom = request.vars.get("custom", None)
    if user_id is None or custom is None:
        return dict(final_rating=[])
    user_id = int(user_id)
    custom = (custom == "True")
    stopstalk_handle = utilities.get_stopstalk_handle(user_id, custom)
    redis_cache_key = "get_stopstalk_rating_history_" + stopstalk_handle

    # Check if data is present in REDIS
    data = current.REDIS_CLIENT.get(redis_cache_key)
    if data:
        return json.loads(data)

    stable = db.submission
    query = (stable["custom_user_id" if custom else "user_id"] == user_id)
    rows = db(query).select(stable.time_stamp,
                            stable.problem_link,
                            stable.status,
                            stable.site,
                            orderby=stable.time_stamp)

    final_rating = utilities.get_stopstalk_rating_history_dict(rows)

    result = dict(final_rating=sorted(final_rating.items()))
    current.REDIS_CLIENT.set(redis_cache_key,
                             json.dumps(result, separators=(",", ":")),
                             ex=1 * 60 * 60)
    return result
Beispiel #2
0
def update_stopstalk_rating(user_id, user_submissions, custom):
    global commit_to_db_counter

    final_rating = utilities.get_stopstalk_rating_history_dict(
        user_submissions)
    if final_rating == {}:
        print user_id, custom, "No submissions"
        return

    atable = db.auth_user
    cftable = db.custom_friend

    today = str(datetime.datetime.now().date())
    current_rating = sum(final_rating[today])

    print user_id, custom, current_rating

    update_params = dict(stopstalk_rating=int(current_rating))
    if custom:
        cftable(user_id).update_record(**update_params)
    else:
        atable(user_id).update_record(**update_params)

    commit_to_db_counter += 1
    if commit_to_db_counter > 10:
        # Don't hold the records in memory, keep commiting after every 10 records
        # to avoid the lock wait timeouts
        db.commit()
        commit_to_db_counter = 0
Beispiel #3
0
def get_stopstalk_rating_history():
    user_id = request.vars.get("user_id", None)
    custom = request.vars.get("custom", None)
    if user_id is None or custom is None:
        return dict(final_rating=[])
    user_id = int(user_id)
    stable = db.submission
    query = (stable["custom_user_id" if
                    (custom == "True") else "user_id"] == user_id)
    rows = db(query).select(stable.time_stamp,
                            stable.problem_link,
                            stable.status,
                            stable.site,
                            orderby=stable.time_stamp)

    final_rating = utilities.get_stopstalk_rating_history_dict(rows)
    return dict(final_rating=sorted(final_rating.items()))
def update_stopstalk_rating(user_id, user_submissions, custom):
    final_rating = utilities.get_stopstalk_rating_history_dict(user_submissions)
    if final_rating == {}:
        print user_id, custom, "No submissions"
        return

    atable = db.auth_user
    cftable = db.custom_friend

    today = str(datetime.datetime.now().date())
    current_rating = sum(final_rating[today])

    print user_id, custom, current_rating

    update_params = dict(stopstalk_rating=int(current_rating))
    if custom:
        cftable(user_id).update_record(**update_params)
    else:
        atable(user_id).update_record(**update_params)