def bar_chart(): """Will send the relevant information to the run graph page in order to construct a bar chart that will show the users last five runs.""" number_of_runs = request.args.get("number_of_runs") if number_of_runs == None: number_of_runs = 5 user = model.get_user_by_email(flask_session["email"]) runs = model.get_collection_of_runs(user.id, runs_to_get = number_of_runs) run_list_of_dictionaries = [] #Changing date in order to jsonify for run in runs: run_list_of_dictionaries.append({'date': run[0].strftime("%m-%d-%Y"), 'distance': run[1], "score": run[2]}) json_runs = json.dumps(run_list_of_dictionaries) return json_runs
def dashboard(): """Displays relevant info for the user, that he or she will see upon logging in.""" if flask_session.get("email") == None: flash("You must sign in to view that page.") return redirect("/") user = model.get_user_by_email(flask_session["email"]) runs = model.get_collection_of_runs(user.id, runs_to_get = 4) instagrams = [] for run in runs: instagram = model.get_instagram(run[3]) if len(instagram[0].text_ans) > 20: instagrams.append(instagram[0].text_ans) #looks for more instagrams if the first search didn't return very many if len(instagrams) < 4: instagrams = [] runs = model.get_collection_of_runs(user.id, runs_to_get = 8) for run in runs: instagram = model.get_instagram(run[3]) if len(instagram[0].text_ans) > 20: instagrams.append(instagram[0].text_ans) if len(instagrams) > 4: instagrams = instagrams[:4] #gets outstanding subgoals outstanding_subgoals = model.get_outstanding_subgoals(user) possible_matches = [] for subgoal in outstanding_subgoals: runs_after_date = model.get_runs_after_date(user, subgoal.goal.set_date) for run in runs_after_date: if run.approx_dist >= model.distance_int_dictionary[subgoal.description]: possible_matches.append((subgoal, run)) # gets outstanding goals outstanding_goals = model.get_outstanding_goals(user) possible_goal_matches = [] for goal in outstanding_goals: for run in runs_after_date: if run.approx_dist >= model.distance_int_dictionary[goal.description]: possible_goal_matches.append((goal, run)) # The page variable determines which tabs are active. page = "user_landing" return render_template("user_landing.html", instagrams=instagrams, possible_matches = possible_matches, possible_goal_matches = possible_goal_matches, goal_dictionary = model.goal_dictionary, page = page)