generated from Yandex-Practicum/go-sprint-four
-
Notifications
You must be signed in to change notification settings - Fork 0
First iteration #2
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Open
an2kab
wants to merge
4
commits into
main
Choose a base branch
from
first-iteration
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
+53
−40
Open
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,17 +1,17 @@ | ||
| package ftracker | ||
|
|
||
| import ( | ||
| "fmt" | ||
| "math" | ||
| "fmt" | ||
| "math" | ||
| ) | ||
|
|
||
| // Основные константы, необходимые для расчетов. | ||
| const ( | ||
| lenStep = 0.65 // средняя длина шага. | ||
| mInKm = 1000 // количество метров в километре. | ||
| minInH = 60 // количество минут в часе. | ||
| kmhInMsec = 0.278 // коэффициент для преобразования км/ч в м/с. | ||
| cmInM = 100 // количество сантиметров в метре. | ||
| lenStep = 0.65 // средняя длина шага. | ||
| mInKm = 1000 // количество метров в километре. | ||
| minInH = 60 // количество минут в часе. | ||
| kmhInMsec = 0.278 // коэффициент для преобразования км/ч в м/с. | ||
| cmInM = 100 // количество сантиметров в метре. | ||
| ) | ||
|
|
||
| // distance возвращает дистанцию(в километрах), которую преодолел пользователь за время тренировки. | ||
|
|
@@ -20,7 +20,7 @@ const ( | |
| // | ||
| // action int — количество совершенных действий (число шагов при ходьбе и беге, либо гребков при плавании). | ||
| func distance(action int) float64 { | ||
| return float64(action) * lenStep / mInKm | ||
| return float64(action) * lenStep / mInKm | ||
| } | ||
|
|
||
| // meanSpeed возвращает значение средней скорости движения во время тренировки. | ||
|
|
@@ -30,11 +30,11 @@ func distance(action int) float64 { | |
| // action int — количество совершенных действий(число шагов при ходьбе и беге, либо гребков при плавании). | ||
| // duration float64 — длительность тренировки в часах. | ||
| func meanSpeed(action int, duration float64) float64 { | ||
| if duration == 0 { | ||
| return 0 | ||
| } | ||
| distance := distance(action) | ||
| return distance / duration | ||
| if duration == 0 { | ||
| return 0 | ||
| } | ||
| distance := distance(action) | ||
| return distance / duration | ||
| } | ||
|
|
||
| // ShowTrainingInfo возвращает строку с информацией о тренировке. | ||
|
|
@@ -45,22 +45,22 @@ func meanSpeed(action int, duration float64) float64 { | |
| // trainingType string — вид тренировки(Бег, Ходьба, Плавание). | ||
| // duration float64 — длительность тренировки в часах. | ||
| func ShowTrainingInfo(action int, trainingType string, duration, weight, height float64, lengthPool, countPool int) string { | ||
| // ваш код здесь | ||
| switch { | ||
| // ваш код здесь | ||
| switch { | ||
| case trainingType == "Бег": | ||
| distance := ... // вызовите здесь необходимую функцию | ||
| speed := ... // вызовите здесь необходимую функцию | ||
| calories := ... // вызовите здесь необходимую функцию | ||
| distance := distance(action) // вызовите здесь необходимую функцию | ||
| speed := meanSpeed(action, duration) // вызовите здесь необходимую функцию | ||
| calories := RunningSpentCalories(action, weight, duration) // вызовите здесь необходимую функцию | ||
| return fmt.Sprintf("Тип тренировки: %s\nДлительность: %.2f ч.\nДистанция: %.2f км.\nСкорость: %.2f км/ч\nСожгли калорий: %.2f\n", trainingType, duration, distance, speed, calories) | ||
| case trainingType == "Ходьба": | ||
| distance := ... // вызовите здесь необходимую функцию | ||
| speed := ... // вызовите здесь необходимую функцию | ||
| calories := ... // вызовите здесь необходимую функцию | ||
| distance := distance(action) // вызовите здесь необходимую функцию | ||
| speed := meanSpeed(action, duration) // вызовите здесь необходимую функцию | ||
| calories := WalkingSpentCalories(action, duration, weight, height) // вызовите здесь необходимую функцию | ||
| return fmt.Sprintf("Тип тренировки: %s\nДлительность: %.2f ч.\nДистанция: %.2f км.\nСкорость: %.2f км/ч\nСожгли калорий: %.2f\n", trainingType, duration, distance, speed, calories) | ||
| case trainingType == "Плавание": | ||
| distance := ... // вызовите здесь необходимую функцию | ||
| speed := ... // вызовите здесь необходимую функцию | ||
| calories := ... // вызовите здесь необходимую функцию | ||
| distance := distance(action) // вызовите здесь необходимую функцию | ||
| speed := swimmingMeanSpeed(lengthPool, countPool, duration) // вызовите здесь необходимую функцию | ||
| calories := SwimmingSpentCalories(lengthPool, countPool, duration, weight) // вызовите здесь необходимую функцию | ||
| return fmt.Sprintf("Тип тренировки: %s\nДлительность: %.2f ч.\nДистанция: %.2f км.\nСкорость: %.2f км/ч\nСожгли калорий: %.2f\n", trainingType, duration, distance, speed, calories) | ||
| default: | ||
| return "неизвестный тип тренировки" | ||
|
|
@@ -69,8 +69,8 @@ func ShowTrainingInfo(action int, trainingType string, duration, weight, height | |
|
|
||
| // Константы для расчета калорий, расходуемых при беге. | ||
| const ( | ||
| runningCaloriesMeanSpeedMultiplier = 18 // множитель средней скорости. | ||
| runningCaloriesMeanSpeedShift = 1.79 // среднее количество сжигаемых калорий при беге. | ||
| runningCaloriesMeanSpeedMultiplier = 18 // множитель средней скорости. | ||
| runningCaloriesMeanSpeedShift = 1.79 // среднее количество сжигаемых калорий при беге. | ||
| ) | ||
|
|
||
| // RunningSpentCalories возвращает количество потраченных колорий при беге. | ||
|
|
@@ -81,14 +81,18 @@ const ( | |
| // weight float64 — вес пользователя. | ||
| // duration float64 — длительность тренировки в часах. | ||
| func RunningSpentCalories(action int, weight, duration float64) float64 { | ||
| // ваш код здесь | ||
| ... | ||
| // ваш код здесь | ||
|
|
||
| calories := ((runningCaloriesMeanSpeedMultiplier * meanSpeed(action, duration) * | ||
| runningCaloriesMeanSpeedShift) * weight) / mInKm * duration * minInH | ||
|
|
||
| return calories | ||
| } | ||
|
|
||
| // Константы для расчета калорий, расходуемых при ходьбе. | ||
| const ( | ||
| walkingCaloriesWeightMultiplier = 0.035 // множитель массы тела. | ||
| walkingSpeedHeightMultiplier = 0.029 // множитель роста. | ||
| walkingCaloriesWeightMultiplier = 0.035 // множитель массы тела. | ||
| walkingSpeedHeightMultiplier = 0.029 // множитель роста. | ||
| ) | ||
|
|
||
| // WalkingSpentCalories возвращает количество потраченных калорий при ходьбе. | ||
|
|
@@ -100,14 +104,20 @@ const ( | |
| // weight float64 — вес пользователя. | ||
| // height float64 — рост пользователя. | ||
| func WalkingSpentCalories(action int, duration, weight, height float64) float64 { | ||
| // ваш код здесь | ||
| ... | ||
| // ваш код здесь | ||
| speedMs := meanSpeed(action, duration) * kmhInMsec | ||
| k1 := walkingCaloriesWeightMultiplier * weight | ||
| k2 := math.Pow(speedMs, 2) / (height / 100) | ||
|
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. нужно использовать cmInM и тут возможно деление на 0 |
||
| k3 := k2 * walkingSpeedHeightMultiplier * weight | ||
| calories := (k1 + k3) * duration * minInH | ||
|
|
||
| return calories | ||
| } | ||
|
|
||
| // Константы для расчета калорий, расходуемых при плавании. | ||
| const ( | ||
| swimmingCaloriesMeanSpeedShift = 1.1 // среднее количество сжигаемых колорий при плавании относительно скорости. | ||
| swimmingCaloriesWeightMultiplier = 2 // множитель веса при плавании. | ||
| swimmingCaloriesMeanSpeedShift = 1.1 // среднее количество сжигаемых колорий при плавании относительно скорости. | ||
| swimmingCaloriesWeightMultiplier = 2 // множитель веса при плавании. | ||
| ) | ||
|
|
||
| // swimmingMeanSpeed возвращает среднюю скорость при плавании. | ||
|
|
@@ -118,10 +128,10 @@ const ( | |
| // countPool int — сколько раз пользователь переплыл бассейн. | ||
| // duration float64 — длительность тренировки в часах. | ||
| func swimmingMeanSpeed(lengthPool, countPool int, duration float64) float64 { | ||
| if duration == 0 { | ||
| return 0 | ||
| } | ||
| return float64(lengthPool) * float64(countPool) / mInKm / duration | ||
| if duration == 0 { | ||
| return 0 | ||
| } | ||
| return float64(lengthPool) * float64(countPool) / mInKm / duration | ||
| } | ||
|
|
||
| // SwimmingSpentCalories возвращает количество потраченных калорий при плавании. | ||
|
|
@@ -133,6 +143,9 @@ func swimmingMeanSpeed(lengthPool, countPool int, duration float64) float64 { | |
| // duration float64 — длительность тренировки в часах. | ||
| // weight float64 — вес пользователя. | ||
| func SwimmingSpentCalories(lengthPool, countPool int, duration, weight float64) float64 { | ||
| // ваш код здесь | ||
| ... | ||
| // ваш код здесь | ||
| k1 := swimmingMeanSpeed(lengthPool, countPool, duration) + swimmingCaloriesMeanSpeedShift | ||
| calories := k1 * swimmingCaloriesWeightMultiplier * weight * duration | ||
|
|
||
| return calories | ||
| } | ||
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
k1 k2 И так далее - плохие названия для переменных
они ничего не говорят о том для чего они