def createRun( db_instance, id_, runner_id, distance=1000, start_date=datetime.datetime(year=2018, month=1, day=1), elapsed_time=3600, average_speed=2): run_count = db_instance.session.query(Run).count() run = Run() run.id = id_ run.name = 'test run ' + str(run.id) run.strava_id = None run.distance = distance run.start_date = start_date run.elapsed_time = elapsed_time run.average_speed = average_speed run.average_heartrate = None run.total_elevation_gain = 0 run.runner_id = runner_id db_instance.session.add(run) assert db_instance.session.query(Run).count() == (run_count + 1)
def activity2run(user, activity): run = Run() run.runner = user run.strava_id = activity.id run.name = activity.name run.distance = activity.distance run.elapsed_time = activity.elapsed_time.total_seconds() run.average_speed = activity.average_speed run.average_heartrate = activity.average_heartrate run.total_elevation_gain = activity.total_elevation_gain run.start_date = activity.start_date return run
def activity2run(user, activity): """Used by fetch_runs to convert a strava run into a DB entry.""" run = Run() run.runner = user run.strava_id = activity.id run.name = activity.name run.distance = activity.distance run.elapsed_time = activity.elapsed_time.total_seconds() run.average_speed = activity.average_speed run.average_heartrate = activity.average_heartrate run.total_elevation_gain = activity.total_elevation_gain run.start_date = activity.start_date return run
def new_predefined_run_test(user): run = Run() run.runner = user run.strava_id = 10 # a random number 100 - 1.000.000, we hope is unique run.name = "Run " + str(run.strava_id) run.distance = 20000.0 # 50m - 10 km run.elapsed_time = 200.0 # 30s - 1h run.average_speed = run.distance / run.elapsed_time run.average_heartrate = None run.total_elevation_gain = 3.0 # 0m - 25m run.start_date = datetime.now() db.session.add(run) db.session.commit() return run
def new_run(user, strava_id=randint(100, 100000000), name=None, distance=uniform(50.0, 10000.0), elapsed_time=uniform(30.0, 3600.0), average_heartrate=None, total_elevation_gain=uniform(0.0, 25.0), start_date=datetime.now()): if name is None: name = "Run %s" % strava_id run = Run() run.runner = user run.strava_id = strava_id # a random number 100 - 1.000.000, we hope is unique run.name = name run.distance = distance # 50m - 10 km run.elapsed_time = elapsed_time # 30s - 1h run.average_speed = run.distance / run.elapsed_time run.average_heartrate = average_heartrate run.total_elevation_gain = total_elevation_gain # 0m - 25m run.start_date = start_date db.session.add(run) db.session.commit()