Exemplo n.º 1
0
	def test_get_by_id(self):
		# note: 1-to-1 relationship User<=>Profile. Thus we need a User.
		user = User('user', '*****@*****.**')
		user.save()
		new_profile = Profile(user)
		new_profile.save()
		retrieved_profile = Profile.get_by_id(new_profile.id)
		assert(retrieved_profile == new_profile)
Exemplo n.º 2
0
def _create_workout_from_polar_exercise(profile_id, exercise_json, fit_path):
	category = _get_workout_category_from_polar_exercise(exercise_json['category'],exercise_json['sub_category'])
	if category is None:
		print(str(dt.datetime.utcnow()), "Unable to create workout from Polar exercise, no category found ({0},{1})".format(exercise_json['category'],exercise_json['sub_category']))
		return 0
	
	profile = Profile.get_by_id(profile_id)
	if profile is None:
		print(str(dt.datetime.utcnow()), "Unable to create workout from Polar exercise, profile not found ({0})".format(profile_id))
	
	# save Workout using meta data first
	new_workout = None
	try:
		new_workout = WorkoutModel(profile_id, category, category.name, exercise_json['start_at'], exercise_json['distance'], exercise_json['duration'], 0, fit_path, False)
		new_workout.save()
	except:
		db.session.rollback()
		new_workout = None
	
	# if we have valid workout, try save and parse of FIT file if available
	if new_workout is not None and fit_path is not None:
		new_workout.register_extended_data()
		parsed_summary = new_workout.extended_summary
		if parsed_summary is not None:	
			new_workout.name = get_autogenerated_workout_name(parsed_summary.latitude, parsed_summary.longitude, new_workout.category_name)
			new_workout.duration = parsed_summary.duration

			if category.supports_gps_data:
				new_workout.distance = parsed_summary.distance
				new_workout.climb = parsed_summary.elevation
		try:
			new_workout.save()
		except:
			db.session.rollback()
			new_workout = None          

	# finally, save any changes and register goal status
	if new_workout is not None:
		try:
			add_workout_data_to_goals(profile, new_workout)
		except:
			db.session.rollback()
		return new_workout.id
	print(str(dt.datetime.utcnow()), "Unable to save workout for some unknown reason.")
	return 0