Merge branch 'dev' into alternate_weather_api
This commit is contained in:
@ -160,6 +160,8 @@ def create_workout(
|
||||
else float(new_workout.distance) / (duration.seconds / 3600)
|
||||
)
|
||||
new_workout.max_speed = new_workout.ave_speed
|
||||
new_workout.ascent = workout_data.get('ascent')
|
||||
new_workout.descent = workout_data.get('descent')
|
||||
return new_workout
|
||||
|
||||
|
||||
@ -239,6 +241,12 @@ def edit_workout(
|
||||
else float(workout.distance) / (workout.duration.seconds / 3600)
|
||||
)
|
||||
workout.max_speed = workout.ave_speed
|
||||
|
||||
if 'ascent' in workout_data:
|
||||
workout.ascent = workout_data.get('ascent')
|
||||
|
||||
if 'descent' in workout_data:
|
||||
workout.descent = workout_data.get('descent')
|
||||
return workout
|
||||
|
||||
|
||||
@ -333,6 +341,14 @@ def process_one_gpx_file(
|
||||
raise WorkoutException('fail', 'Error during workout save.', e)
|
||||
|
||||
|
||||
def is_gpx_file(filename: str) -> bool:
|
||||
return (
|
||||
'.' in filename
|
||||
and filename.rsplit('.', 1)[1].lower()
|
||||
in current_app.config['WORKOUT_ALLOWED_EXTENSIONS']
|
||||
)
|
||||
|
||||
|
||||
def process_zip_archive(
|
||||
common_params: Dict, extract_dir: str, stopped_speed_threshold: float
|
||||
) -> List:
|
||||
@ -341,21 +357,33 @@ def process_zip_archive(
|
||||
does not exceed defined limit.
|
||||
"""
|
||||
with zipfile.ZipFile(common_params['file_path'], "r") as zip_ref:
|
||||
max_file_size = current_app.config['max_single_file_size']
|
||||
gpx_files_count = 0
|
||||
files_with_invalid_size_count = 0
|
||||
for zip_info in zip_ref.infolist():
|
||||
if is_gpx_file(zip_info.filename):
|
||||
gpx_files_count += 1
|
||||
if zip_info.file_size > max_file_size:
|
||||
files_with_invalid_size_count += 1
|
||||
|
||||
if gpx_files_count > current_app.config['gpx_limit_import']:
|
||||
raise WorkoutException(
|
||||
'fail', 'the number of files in the archive exceeds the limit'
|
||||
)
|
||||
|
||||
if files_with_invalid_size_count > 0:
|
||||
raise WorkoutException(
|
||||
'fail',
|
||||
'at least one file in zip archive exceeds size limit, '
|
||||
'please check the archive',
|
||||
)
|
||||
|
||||
zip_ref.extractall(extract_dir)
|
||||
|
||||
new_workouts = []
|
||||
gpx_files_limit = current_app.config['gpx_limit_import']
|
||||
gpx_files_ok = 0
|
||||
|
||||
for gpx_file in os.listdir(extract_dir):
|
||||
if (
|
||||
'.' in gpx_file
|
||||
and gpx_file.rsplit('.', 1)[1].lower()
|
||||
in current_app.config['WORKOUT_ALLOWED_EXTENSIONS']
|
||||
):
|
||||
gpx_files_ok += 1
|
||||
if gpx_files_ok > gpx_files_limit:
|
||||
break
|
||||
if is_gpx_file(gpx_file):
|
||||
file_path = os.path.join(extract_dir, gpx_file)
|
||||
params = common_params
|
||||
params['file_path'] = file_path
|
||||
|
Reference in New Issue
Block a user