def integrations(): db_query = Queries() session_data = Session() check_profile_verified(session_data) favorite_activities = db_query.get_user_favorite_activity(current_user.id) return render_template("integrations.html", title='Integrations', session_data=session_data, favorite_activities=favorite_activities)
def running_10_km(): session_data = Session() check_profile_verified(session_data) db_query = Queries() position = db_query.get_position_best_run(current_user.id, Competition.Run10km) return render_template("running.html", title="Running-10", distance='10km', position=ordinal(position), session_data=session_data)
def _store_activity(user, data): strava_activity_id = data['object_id'] activity_data = get_activity(user.strava_access_token, strava_activity_id) activity = create_activity_from_strava_json(activity_data, user, strava_activity_id) db_query = Queries(credit=True) db_query.save_new_user_activities(activity.user_id, activity)
def cycling(): session_data = Session() check_profile_verified(session_data) db_query = Queries() total_distance = db_query.get_total_distance_by_user_on_bike(current_user.id) position = db_query.get_position_total_distance_on_bike(current_user.id) return render_template("cycling.html", title="Cycling", total_distance=total_distance, position=ordinal(position), session_data=session_data)
def _update_activity(data): strava_activity_id = data['object_id'] # parse data to update new_title = data['updates']['title'] if 'title' in data['updates'].keys( ) else None new_type = data['updates']['type'] if 'type' in data['updates'].keys( ) else None is_private = data['updates']['private'] if 'private' in data[ 'updates'].keys() else False # changed to private -> delete activity if is_private: db_query = Queries(credit=True) db_query.delete_activity_by_strava_id(strava_activity_id) return # create dict for update query data_to_update = dict() if new_title: data_to_update['name'] = new_title if new_type: data_to_update['type'] = _get_activity_type(new_type) # update database db_query = Queries(credit=True) db_query.update_activity_info(strava_activity_id, data_to_update)
def display_credits(): if request.method == 'GET': form = CreditsForm('credits_form') return render_template('credits.html', title='Credits', authorized=False, form=form) else: form = CreditsForm(request.form) if form.validate_on_submit(): if form.password.data == 'KTV2020': # TODO: Obsoleted db_query = Queries(credit=True) students = db_query.get_students() return render_template('credits.html', title='Credits', authorized=True, students=students) else: form.password.errors.append('Specified password is invalid!') return render_template('credits.html', title='Credits', authorized=False, form=form) else: return render_template('credits.html', title='Credits', authorized=False, form=form)
def home(): session_data = Session() db_query = Queries(credit=True) add_activity_form = AddActivityForm() if add_activity_form.validate_on_submit(): filename = secure_filename(add_activity_form.file.data.filename) path = os.path.join(__file__, os.pardir) add_activity_form.file.data.save(os.path.join( os.path.abspath(path), current_app.config['UPLOAD_FILE_DIR'], filename)) if add_activity_form.activity.data == ActivityType.Ride.name: a_type = ActivityType.Ride elif add_activity_form.activity.data == ActivityType.Run.name: a_type = ActivityType.Run else: a_type = ActivityType.Walk activity = current_app.config['PROCESSOR'].process_input_data(filename) current_app.config['PROCESSOR'].landing_cleanup(filename) distance = activity[0] seconds = activity[1].total_seconds() start_time = activity[2] if distance == 0: session_data.warning('Activity of zero distance ignored.') elif start_time is None: if a_type == ActivityType.Run: a_type = ActivityType.Walk start_time = datetime.datetime.now().replace(microsecond=0) full_time = datetime.time() avg_time = datetime.time() new_activity = Activity(datetime=start_time, distance=distance, duration=full_time, average_duration_per_km=avg_time, type=a_type) db_query.save_new_user_activities(current_user.id, new_activity) session_data.info(str(a_type) + ' activity of ' + str(distance) + ' km added.') else: avg_seconds = round(seconds / distance) full_time = (datetime.datetime(2000, 1, 1, 0) + datetime.timedelta(seconds=seconds)).time() avg_time = (datetime.datetime(2000, 1, 1, 0) + datetime.timedelta(seconds=avg_seconds)).time() new_activity = Activity(datetime=start_time, distance=distance, duration=full_time, average_duration_per_km=avg_time, type=a_type) db_query.save_new_user_activities(current_user.id, new_activity) session_data.info(str(a_type) + ' activity of ' + str(distance) + ' km added.') return redirect(url_for('main.home')) check_profile_verified(session_data) total_foot = db_query.get_total_distance_by_user_on_foot(current_user.id) or 0 total_bike = db_query.get_total_distance_by_user_on_bike(current_user.id) or 0 total_credit = None if current_user.type == UserType.Student: total_credit = round(total_foot + total_bike / 2, 2) return render_template("personal_dashboard.html", title='Home', form=add_activity_form, total_foot=total_foot, total_bike=total_bike, total_credit=total_credit, season=db_query.SEASON_COMPETITION, season_credit=db_query.SEASON_CREDIT, session_data=session_data)
def matfyz_challenges(): db_query = Queries() checkpoints = db_query.get_challenge_parts_to_display() checkpoints_enriched = [] order = 1 for (dist, place) in checkpoints.items(): checkpoints_enriched.append({'order': order, 'dist': dist, 'place': place}) order = order + 1 current_checkpoint = db_query.get_current_challenge_part() if current_user.is_authenticated: session_data = Session() check_profile_verified(session_data) return render_template("matfyz_challenges.html", title='Matfyz Challenges', checkpoints=checkpoints_enriched, current_checkpoint=current_checkpoint, session_data=session_data) else: return render_template("matfyz_challenges_public.html", title='Matfyz Challenges', checkpoints=checkpoints_enriched, current_checkpoint=current_checkpoint)
def _get_user(data): db_query = Queries(credit=True) db_res = db_query.get_user_by_strava_id(data['owner_id']) if len(db_res) != 1: return None return db_res[0]
def _delete_activity(data): strava_activity_id = data['object_id'] db_query = Queries(credit=True) db_query.delete_activity_by_strava_id(strava_activity_id)
def statistics(): db_query = Queries() stats = db_query.get_stats() return render_template("statistics.html", title='Statistics', stats=stats)
def __init__(self): super(object, self).__init__() self._DB_QUERY = Queries()