Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
Tracker from Sprint 1
import datetime as dt
FORMAT = '%H:%M:%S'
WEIGHT = 75 # Вес.
HEIGHT = 175 # Рост.
K_1 = 0.035 # Коэффициент для подсчета калорий.
K_2 = 0.029 # Коэффициент для подсчета калорий.
STEP_M = 0.65 # Длина шага в метрах.
storage_data = {}
def check_correct_data(data):
corr = False if len(data) != 2 or None in data else True
return corr
def check_correct_time(time):
if storage_data:
corr = False if time <= max(storage_data) else True
return corr
def get_step_day(steps):
steps_day = sum(storage_data.values()) + steps
return steps_day
def get_distance(steps):
dist_day = (steps * STEP_M) / 1000
return dist_day
def get_spent_calories(dist, current_time):
time_delta = current_time - dt.datetime(1900, 1, 1)
minutes = int(time_delta.total_seconds() / 60)
hours = minutes / 60
mean_speed = dist / hours
spent_calories = (K_1 * WEIGHT + (mean_speed ** 2 / HEIGHT) * K_2 * WEIGHT) * minutes
return spent_calories
def get_achievement(dist):
if dist >= 6.5:
return 'Отличный результат! Цель достигнута.'
elif dist >= 3.9:
return 'Неплохо! День был продуктивным.'
elif dist >= 2:
return 'Маловато, но завтра наверстаем!'
else:
return 'Лежать тоже полезно. Главное — участие, а не победа!'
def show_message(pack_time, day_steps, dist, spent_calories, achievement):
print(f'''
Время: {pack_time.time()}.
Количество шагов за сегодня: {day_steps}.
Дистанция составила {dist:.2f} км.
Вы сожгли {spent_calories:.2f} ккал.
{achievement}
''')
def accept_package(data):
if not check_correct_data(data):
return 'Некорректные данные'
pack_time = dt.datetime.strptime(data[0], FORMAT)
if check_correct_time(pack_time) is False:
return 'Некорректное значение времени'
day_steps = get_step_day(data[1])
dist = get_distance(day_steps)
spent_calories = get_spent_calories(dist, pack_time)
achievement = get_achievement(dist)
show_message(pack_time, day_steps, dist, spent_calories, achievement)
storage_data[pack_time] = int(data[1])
return storage_data
package_0 = ('2:00:01', 505)
package_1 = (None, 3211)
package_2 = ('9:36:02', 15000)
package_3 = ('9:36:02', 9000)
package_4 = ('8:01:02', 7600)
accept_package(package_0)
accept_package(package_1)
accept_package(package_2)
accept_package(package_3)
accept_package(package_4)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment