-
Notifications
You must be signed in to change notification settings - Fork 0
first #1
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
mirzhil
wants to merge
1
commit into
main
Choose a base branch
from
first_branch
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.
Open
first #1
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,20 +1,59 @@ | ||||||
| package daysteps | ||||||
|
|
||||||
| import ( | ||||||
| "fmt" | ||||||
| "log" | ||||||
| "strconv" | ||||||
| "strings" | ||||||
| "time" | ||||||
|
|
||||||
| "github.com/Yandex-Practicum/tracker/internal/spentcalories" | ||||||
| ) | ||||||
|
|
||||||
| const ( | ||||||
| // Длина одного шага в метрах | ||||||
| stepLength = 0.65 | ||||||
| // Количество метров в одном километре | ||||||
| mInKm = 1000 | ||||||
| mInKm = 1000 | ||||||
| ) | ||||||
|
|
||||||
| func parsePackage(data string) (int, time.Duration, error) { | ||||||
| // TODO: реализовать функцию | ||||||
| parts := strings.Split(data, ",") | ||||||
| if len(parts) != 2 { | ||||||
| return 0, 0, fmt.Errorf("invalid input format") | ||||||
| } | ||||||
|
|
||||||
| steps, err := strconv.Atoi(parts[0]) | ||||||
| if err != nil || steps <= 0 { | ||||||
| return 0, 0, fmt.Errorf("invalid steps: %v", err) | ||||||
| } | ||||||
|
|
||||||
| duration, err := time.ParseDuration(parts[1]) | ||||||
| if err != nil { | ||||||
| return 0, 0, fmt.Errorf("invalid duration: %v", err) | ||||||
| } | ||||||
|
|
||||||
| if duration <= 0 { | ||||||
| return 0, 0, fmt.Errorf("invalid duration") | ||||||
| } | ||||||
|
|
||||||
| return steps, duration, nil | ||||||
| } | ||||||
|
|
||||||
| func DayActionInfo(data string, weight, height float64) string { | ||||||
| // TODO: реализовать функцию | ||||||
| steps, duration, err := parsePackage(data) | ||||||
| if err != nil || steps <= 0 { | ||||||
| log.Println("ошибка:", err.Error()) | ||||||
|
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. Можно просто
Suggested change
|
||||||
| return "" | ||||||
| } | ||||||
|
|
||||||
| distance := float64(steps) * stepLength | ||||||
| distanceKm := distance / mInKm | ||||||
|
|
||||||
| calories, err := spentcalories.WalkingSpentCalories(steps, weight, height, duration) | ||||||
| if err != nil { | ||||||
| log.Println("ошибка:", err.Error()) | ||||||
| return "" | ||||||
| } | ||||||
|
|
||||||
| return fmt.Sprintf("Количество шагов: %d.\nДистанция составила %.2f км.\nВы сожгли %.2f ккал.\n", | ||||||
| steps, distanceKm, calories) | ||||||
| } | ||||||
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,38 +1,102 @@ | ||
| package spentcalories | ||
|
|
||
| import ( | ||
| "fmt" | ||
| "strconv" | ||
| "strings" | ||
| "time" | ||
| ) | ||
|
|
||
| // Основные константы, необходимые для расчетов. | ||
| const ( | ||
| lenStep = 0.65 // средняя длина шага. | ||
| mInKm = 1000 // количество метров в километре. | ||
| minInH = 60 // количество минут в часе. | ||
| stepLengthCoefficient = 0.45 // коэффициент для расчета длины шага на основе роста. | ||
| walkingCaloriesCoefficient = 0.5 // коэффициент для расчета калорий при ходьбе | ||
| lenStep = 0.65 | ||
| mInKm = 1000 | ||
| minInH = 60 | ||
| stepLengthCoefficient = 0.45 | ||
| walkingCaloriesCoefficient = 0.5 | ||
| ) | ||
|
|
||
| func parseTraining(data string) (int, string, time.Duration, error) { | ||
| // TODO: реализовать функцию | ||
| parts := strings.Split(data, ",") | ||
| if len(parts) != 3 { | ||
| return 0, "", 0, fmt.Errorf("invalid input format") | ||
| } | ||
|
|
||
| steps, err := strconv.Atoi(parts[0]) | ||
| if err != nil { | ||
| return 0, "", 0, fmt.Errorf("invalid step count: %v", err) | ||
| } | ||
|
|
||
| duration, err := time.ParseDuration(parts[2]) | ||
| if err != nil { | ||
| return 0, "", 0, fmt.Errorf("invalid duration: %v", err) | ||
| } | ||
|
|
||
| if steps <= 0 { | ||
| return 0, "", 0, fmt.Errorf("invalid steps: %d", steps) | ||
| } | ||
| if duration <= 0 { | ||
| return 0, "", 0, fmt.Errorf("invalid duration: %s", parts[2]) | ||
| } | ||
|
|
||
| return steps, parts[1], duration, nil | ||
| } | ||
|
|
||
| func distance(steps int, height float64) float64 { | ||
| // TODO: реализовать функцию | ||
| stepLen := height * stepLengthCoefficient | ||
| return float64(steps) * stepLen / mInKm | ||
| } | ||
|
|
||
| func meanSpeed(steps int, height float64, duration time.Duration) float64 { | ||
| // TODO: реализовать функцию | ||
| } | ||
|
|
||
| func TrainingInfo(data string, weight, height float64) (string, error) { | ||
| // TODO: реализовать функцию | ||
| if duration <= 0 { | ||
| return 0 | ||
| } | ||
| dist := distance(steps, height) | ||
| hours := duration.Hours() | ||
| return dist / hours | ||
| } | ||
|
|
||
| func RunningSpentCalories(steps int, weight, height float64, duration time.Duration) (float64, error) { | ||
| // TODO: реализовать функцию | ||
| if steps <= 0 || weight <= 0 || height <= 0 || duration <= 0 { | ||
| return 0, fmt.Errorf("invalid input values") | ||
| } | ||
| speed := meanSpeed(steps, height, duration) | ||
| minutes := duration.Minutes() | ||
| return (weight * speed * minutes) / minInH, nil | ||
| } | ||
|
|
||
| func WalkingSpentCalories(steps int, weight, height float64, duration time.Duration) (float64, error) { | ||
| // TODO: реализовать функцию | ||
| if steps <= 0 || weight <= 0 || height <= 0 || duration <= 0 { | ||
| return 0, fmt.Errorf("invalid input values") | ||
| } | ||
| speed := meanSpeed(steps, height, duration) | ||
| minutes := duration.Minutes() | ||
| cals := (weight * speed * minutes) / minInH | ||
| return cals * walkingCaloriesCoefficient, nil | ||
| } | ||
|
|
||
| func TrainingInfo(data string, weight, height float64) (string, error) { | ||
| steps, activity, duration, err := parseTraining(data) | ||
| if err != nil { | ||
| return "", err | ||
| } | ||
|
|
||
| dist := distance(steps, height) | ||
| speed := meanSpeed(steps, height, duration) | ||
| var calories float64 | ||
|
|
||
| switch activity { | ||
| case "Бег": | ||
| calories, err = RunningSpentCalories(steps, weight, height, duration) | ||
| case "Ходьба": | ||
| calories, err = WalkingSpentCalories(steps, weight, height, duration) | ||
| default: | ||
| return "", fmt.Errorf("неизвестный тип тренировки") | ||
| } | ||
|
|
||
| if err != nil { | ||
| return "", err | ||
| } | ||
|
|
||
| return fmt.Sprintf("Тип тренировки: %s\nДлительность: %.2f ч.\nДистанция: %.2f км.\nСкорость: %.2f км/ч\nСожгли калорий: %.2f\n", | ||
| activity, duration.Hours(), dist, speed, calories), nil | ||
| } |
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.
При оборачивании нужно использовать
%w(wrap), а просто при выводе в консоль%vThere 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.
Нужно везде поправить