def current_standing(): try: activate_access_token() username = session['username'] user_data = db['user_data'].find_one({'_id':username}) v_contest_start_time = user_data['v_contest_start_time'] contest_start_time = user_data['contest_start_time'] duration = user_data['duration'] is_running = user_data['is_running'] contest_code = user_data['contest_code'] contest_name = user_data['contest_name'] problems = user_data['problems'] if(is_running == False): username = session['username'] return render_template("home.html", username = username, contest_code_display = False) friends = request.args.get("friends") # if friends == True, then user wants friends ranklist, each case you need # send a variable named friends, whose value can be True and False # if friends variable is True, that means data you sent is of friends. # there might be confusion as both GET variable and varible which we are sending # both are named as friends. fmt = '%Y-%m-%d %H:%M:%S' v_contest_start_time = datetime.datetime.strptime(v_contest_start_time, fmt + ".%f") v_contest_start_time = time_slice(v_contest_start_time) now = time_slice(datetime.datetime.now()) # print(v_contest_start_time , now) fetch_submission() obj = ranking(contest_code , problems , contest_start_time , v_contest_start_time , now , friends) username = session['username'] user = {} user['rank'] = 0 user['name'] = '*' + username user['entry'] = False user['Total Score'] = 0 user['Penalty'] = 0 user['Total'] = 0 for problem in problems: user[problem] = 0 user[problem+"Time"] = 0 #Fetching the user details to show seperately in the ranklist on the top friend = user for val in obj: if val['name'] == '*' + username: friend = val break return render_template("rankings.html", obj=obj , problems = problems, username = username, contest_code = contest_code, contest_code_display = True , friends = friends , friend = friend) except: return render_template('error.html')
def contest_page(contest_code): try: activate_access_token() username = session['username'] user_data = db['user_data'].find_one({'_id':username}) v_contest_start_time = user_data['v_contest_start_time'] contest_start_time = user_data['contest_start_time'] duration = user_data['duration'] is_running = user_data['is_running'] contest_code = user_data['contest_code'] contest_name = user_data['contest_name'] problems = user_data['problems'] if(is_running == False): username = session['username'] return render_template("home.html", username = username, contest_code_display = False) fmt = '%Y-%m-%d %H:%M:%S' time_now = time_slice(datetime.datetime.now()) v_contest_start_time = datetime.datetime.strptime(str(v_contest_start_time), fmt + ".%f") end_time = v_contest_start_time + datetime.timedelta(minutes = int(float(duration))) v_contest_start_time = time_slice(v_contest_start_time) end_time = time_slice(end_time) tstamp1 = datetime.datetime.strptime(str(time_now) , fmt) tstamp2 = datetime.datetime.strptime(str(end_time) , fmt) p = tstamp2 - tstamp1 p = p.total_seconds() fetch_submission() obj = ranking(contest_code , problems , contest_start_time , v_contest_start_time , time_now , False) #Fetches the user details to display the status of the problems #in the dashboard . Green tick for correct answer , red cross for wrong answer username = session['username'] user = {} user['rank'] = 0 user['name'] = '*' + username user['entry'] = False user['Total Score'] = 0 user['Penalty'] = 0 user['Total'] = 0 for problem in problems: user[problem] = 0 user[problem+"Time"] = 0 friend = user for val in obj: if val['name'] == '*' + username: friend = val break obj = dashboard(contest_code , problems , contest_start_time , v_contest_start_time , time_now) return render_template("contestpage.html",contest_code = contest_code, name = contest_name, mins = duration, problems = problems , obj = obj , time = p, username = username, contest_code_display = True , friend = friend) except: return render_template('error.html')