-
Notifications
You must be signed in to change notification settings - Fork 0
module first commit - Первая итерация #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
xails-git
wants to merge
2
commits into
main
Choose a base branch
from
first-iteratin
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
Changes from all commits
Commits
Show all changes
2 commits
Select commit
Hold shift + click to select a range
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
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,3 +1,3 @@ | ||
| module github.com/Yandex-Practicum/go1fl-sprint5-final | ||
| module github.com/moduleFitnessTrexter02 | ||
|
|
||
| go 1.23.6 | ||
| go 1.24.0 |
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,11 +1,29 @@ | ||
| package actioninfo | ||
|
|
||
| import ( | ||
| ... | ||
| "fmt" | ||
| ) | ||
|
|
||
| // создайте интерфейс DataParser | ||
| ... | ||
| type DataParser interface { | ||
| Parse(string) error | ||
| ActionInfo() (string, error) | ||
| } | ||
|
|
||
| // создайте функцию Info() | ||
| ... | ||
| func Info(dataset []string, dp DataParser) { | ||
| for _, v := range dataset { | ||
|
|
||
| err := dp.Parse(v) | ||
| if err != nil { | ||
| fmt.Printf("error dp.Parse: %v", err) | ||
| continue | ||
| } | ||
| data, err := dp.ActionInfo() | ||
| if err != nil { | ||
| fmt.Printf("[Ошибка] %v\n\n", err) | ||
| continue | ||
| } | ||
| fmt.Println(data) | ||
| } | ||
| } | ||
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,19 +1,61 @@ | ||
| package daysteps | ||
|
|
||
| import ( | ||
| ... | ||
| "fmt" | ||
| "strconv" | ||
| "strings" | ||
| "time" | ||
|
|
||
| "github.com/moduleFitnessTrexter02/internal/personaldata" | ||
| "github.com/moduleFitnessTrexter02/internal/spentenergy" | ||
| ) | ||
|
|
||
| const ( | ||
| StepLength = 0.65 | ||
| ) | ||
|
|
||
| // создайте структуру DaySteps | ||
| ... | ||
|
|
||
| type DaySteps struct { | ||
| Steps int | ||
| Duration time.Duration | ||
| personaldata.Personal | ||
| } | ||
|
|
||
| // создайте метод Parse() | ||
| ... | ||
| func (ds *DaySteps) Parse(datastring string) (err error) { | ||
|
|
||
| parts := strings.Split(datastring, ",") | ||
| if len(parts) != 2 { | ||
| return fmt.Errorf("invalid format: expected 2 parts, got %d", len(parts)) | ||
| } | ||
|
|
||
| stepsStr := strings.TrimSpace(parts[0]) | ||
| ds.Steps, err = strconv.Atoi(stepsStr) | ||
| if err != nil { | ||
| return fmt.Errorf("steps conversion error: %w", err) | ||
| } | ||
|
|
||
| durationStr := strings.TrimSpace(parts[1]) | ||
| ds.Duration, err = time.ParseDuration(durationStr) | ||
| if err != nil { | ||
| return fmt.Errorf("duration parsing error: %w", err) | ||
| } | ||
|
|
||
| return nil | ||
| } | ||
|
|
||
| // создайте метод ActionInfo() | ||
| ... | ||
| func (ds DaySteps) ActionInfo() (string, error) { | ||
| if ds.Duration <= 0 { | ||
| return "", fmt.Errorf("duration <= 0 error") | ||
| } | ||
| if ds.Weight <= 0 { | ||
| return "", fmt.Errorf("weight <= 0 error") | ||
| } | ||
|
|
||
| calcDistanse := spentenergy.Distance(ds.Steps) | ||
| calories := spentenergy.WalkingSpentCalories(ds.Steps, ds.Personal.Weight, ds.Personal.Height, ds.Duration) | ||
|
|
||
| return fmt.Sprintf("Количество шагов: %d.\nДистанция составила %f км.\nВы сожгли %f ккал.", ds.Steps, calcDistanse, calories), nil | ||
|
|
||
| } |
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,10 +1,17 @@ | ||
| package personaldata | ||
|
|
||
| import ... | ||
| import ( | ||
| "fmt" | ||
| ) | ||
|
|
||
| // Ниже создайте структуру Personal | ||
| ... | ||
| type Personal struct { | ||
| Name string | ||
| Weight float64 | ||
| Height float64 | ||
| } | ||
|
|
||
| // Ниже создайте метод Print() | ||
| ... | ||
|
|
||
| func (p Personal) Print() { | ||
| fmt.Printf("Имя: %s\nВес: %.2f\nРост: %.2f\n", p.Name, p.Height, p.Weight) | ||
| } |
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
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,16 +1,78 @@ | ||
| package trainings | ||
|
|
||
| import ( | ||
| ... | ||
| "fmt" | ||
| "strconv" | ||
| "strings" | ||
| "time" | ||
|
|
||
| "github.com/moduleFitnessTrexter02/internal/personaldata" | ||
| "github.com/moduleFitnessTrexter02/internal/spentenergy" | ||
| ) | ||
|
|
||
| // создайте структуру Training | ||
| ... | ||
|
|
||
| type Training struct { | ||
| Steps int | ||
| TrainingType string | ||
| Duration time.Duration | ||
| personaldata.Personal | ||
| } | ||
|
|
||
| // создайте метод Parse() | ||
| ... | ||
| func (t *Training) Parse(datastring string) (err error) { | ||
| parts := strings.Split(datastring, ",") | ||
| if len(parts) != 3 { | ||
| return fmt.Errorf("invalid format: expected 3 parts, got %d", len(parts)) | ||
| } | ||
|
|
||
| // Очищаем пробелы | ||
| stepsStr := strings.TrimSpace(parts[0]) | ||
| typeStr := strings.TrimSpace(parts[1]) | ||
| durationStr := strings.TrimSpace(parts[2]) | ||
|
|
||
| // Парсим шаги | ||
| t.Steps, err = strconv.Atoi(stepsStr) | ||
| if err != nil { | ||
| return fmt.Errorf("steps conversion error: %w", err) | ||
| } | ||
|
|
||
| // Проверяем тип тренировки | ||
| if typeStr != "Ходьба" && typeStr != "Бег" { | ||
| return fmt.Errorf("invalid activity type: %s, expected 'Ходьба' or 'Бег'", typeStr) | ||
| } | ||
| t.TrainingType = typeStr | ||
|
|
||
| // Парсим продолжительность | ||
| t.Duration, err = time.ParseDuration(durationStr) | ||
| if err != nil { | ||
| return fmt.Errorf("duration parsing error: %w", err) | ||
| } | ||
|
|
||
| return nil | ||
| } | ||
|
|
||
| // создайте метод ActionInfo() | ||
| ... | ||
| func (t Training) ActionInfo() (string, error) { | ||
| // 1. Исправление опечатки | ||
| calcDistance := spentenergy.Distance(t.Steps) | ||
| if calcDistance <= 0 { | ||
| return "", fmt.Errorf("distance calculation error: result is %f (non-positive)", calcDistance) | ||
| } | ||
|
|
||
| averageSpeed := spentenergy.MeanSpeed(t.Steps, t.Duration) | ||
|
|
||
| var calories float64 | ||
|
|
||
| switch t.TrainingType { | ||
| case "Бег": | ||
| calories = spentenergy.RunningSpentCalories(t.Steps, t.Personal.Weight, t.Duration) | ||
|
|
||
| case "Ходьба": | ||
| calories = spentenergy.WalkingSpentCalories(t.Steps, t.Personal.Weight, t.Personal.Height, t.Duration) | ||
|
|
||
| default: | ||
| return "", fmt.Errorf("unknown training type: %s", t.TrainingType) | ||
| } | ||
| return fmt.Sprintf( | ||
| "Тип тренировки: %s\nДлительность: %v\nДистанция: %.2f км\nСкорость: %.2f км/ч\nСожгли калорий: %.2f", t.TrainingType, t.Duration, calcDistance, averageSpeed, 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.
кажется опечатка с вторым переводом строки \n