Skip to content
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

Add Calorie Balance #275

Merged
merged 6 commits into from
Nov 13, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
89 changes: 59 additions & 30 deletions docs/UserGuide.md
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ Type `help` to see a list of commands that you will be able to use in the applic
* [Editing your profile: `editprofile`](#editing-your-profile-editprofile)
* [Viewing your profile: `viewprofile`](#viewing-your-profile-viewprofile)
* [Checking your current bmi: `bmi`](#checking-your-current-bmi-bmi)
* [Checking your recommended weight: `checkrecommendedweight`](#checking-your-recommended-weight-checkrecommendedweight)
* [Checking your ideal weight range given height: `checkrecommendedweight`](#checking-your-ideal-weight-range-given-current-height-checkrecommendedweight)
* [Adding a meal: `addmeal`](#adding-a-meal-addmeal)
* [Deleting a meal: `deletemeal`](#deleting-a-meal-deletemeal)
* [Viewing list of all meals: `viewmeal`](#viewing-list-of-all-meals-viewmeal)
Expand All @@ -43,6 +43,7 @@ Type `help` to see a list of commands that you will be able to use in the applic
* [Viewing list of workout: `viewworkout`](#viewing-list-of-all-workouts-viewworkout)
* [Finding workouts by a keyword: `findworkout`](#finding-workouts-by-a-keyword-findworkout)
* [Checking total calories burnt on a specific date: `caloriesburnt`](#checking-total-calories-burnt-on-a-specific-date-caloriesburnt)
* [Checking calorie balance on a specific date: `caloriebalance`](#checking-calorie-balance-on-a-specific-date-caloriebalance)
* [Adding steps: `addsteps`](#Adding-steps-addsteps)
* [Deleting a step entry: `deletesteps`](#Deleting-a-step-entry-deletesteps)
* [Viewing the total number of steps on a specific date: `totalsteps`](#Viewing-the-total-number-of-steps-on-a-specific-date-totalsteps)
Expand Down Expand Up @@ -164,8 +165,9 @@ BMI falls under NORMAL WEIGHT category
```


### Checking your recommended weight: `checkrecommendedweight`
Allows user to check their recommended weight.
### Checking your ideal weight range given current height: `checkrecommendedweight`
Allows the user to check the ideal weight range given their current height. This is calculate based
on a standard formula.

**Example of usage**
```
Expand Down Expand Up @@ -365,15 +367,41 @@ caloriesburnt 2023-11-04
Total calories burnt on 2023-11-04: 230kcal
```

### Check the ideal weight range given current height: `checkrecommendedweight`
Allows the user to check the ideal weight range given their current height. This is calculate based
on a standard formula.
### Checking calorie balance on a specific date: `caloriebalance`
Allows user to check their calorie balance (surplus/deficit) on a specific date.

Format
- caloriebalance <DATE>
- You should type <DATE> in format of yyyy-MM-dd.

**Example of usage**
```
checkrecommendedweight
caloriebalance 2023-11-04
```

**Expected output**

- If the user is in a calorie surplus:
```
You have exceeded your calorie limit on 2023-11-07 by: 4910.0kcal
You are in a calorie surplus!
Try doing more exercises if you want to eat!
```

- If the user is left with 0 in his calorie balance:
```
Your calorie balance on 2023-11-07 is: 0.0kcal
Try doing more exercise if you want to eat!
```

- If the user is in a calorie deficit:
```
Your calorie balance on 2023-11-07 is: 200.0kcal
You are in a calorie deficit!
You can try to eat more!
```


### Adding steps: `addsteps`
Allows user to add their steps walked for a particular day.

Expand Down Expand Up @@ -513,26 +541,27 @@ The contents of workoutList.txt:

## Command Summary

| Features | Commands |
|:-----------------------------------------------------|:-------------------------|
| Viewing help guide | `help` |
| Exiting the application | `exit` |
| Editing your profile | `editprofile` |
| Viewing your profile | `viewprofile` |
| Checking your current bmi | `bmi` |
| Checking your recommended weight | `checkrecommendedweight` |
| Adding a Meal | `addmeal` |
| Deleting a Meal | `deletemeal` |
| Viewing list of all meals | `viewmeal` |
| Finding meals by a keyword | `findmeal` |
| Checking total calories consumed on a specific date | `caloriesconsumed` |
| Adding a workout | `addworkout` |
| Deleting a Workout | `deleteworkout` |
| Viewing list of workout | `viewworkout` |
| Find workouts by a keyword | `findworkout` |
| Checking total calories burnt on a specific date | `caloriesburnt` |
| Adding a step entry | `addsteps` |
| Deleting a step entry | `deletesteps` |
| Viewing the total number of steps on a specific date | `totalsteps` |
| Viewing the list of steps | `viewsteps` |
| Getting a suggestion on your steps walked | `getstepssuggestion` |
| Features | Commands |
|:-----------------------------------------------------|:------------------------------------------------------------|
| Viewing help guide | `help` |
| Exiting the application | `exit` |
| Editing your profile | `editprofile h/<HEIGHT> w/<WEIGHT> g/<GENDER> l/<CALORIES>` |
| Viewing your profile | `viewprofile` |
| Checking your current bmi | `bmi` |
| Checking your recommended weight | `checkrecommendedweight` |
| Adding a Meal | `addmeal <NAME> c/<CALORIES> d/<DATE>` |
| Deleting a Meal | `deletemeal <INDEX>` |
| Viewing list of all meals | `viewmeal` |
| Finding meals by a keyword | `findmeal <KEYWORD>` |
| Checking total calories consumed on a specific date | `caloriesconsumed <DATE>` |
| Adding a workout | `addworkout <NAME> c/<CALORIES> d/<DATE>` |
| Deleting a Workout | `deleteworkout <INDEX>` |
| Viewing list of workout | `viewworkout` |
| Find workouts by a keyword | `findworkout <KEYWORD>` |
| Checking total calories burnt on a specific date | `caloriesburnt <DATE>` |
| Checking calorie balance on a specific date | `caloriebalance <DATE>` |
| Adding a step entry | `addsteps <NUM_OF_STEPS> d/<DATE>` |
| Deleting a step entry | `deletesteps <INDEX>` |
| Viewing the total number of steps on a specific date | `totalsteps <DATE>` |
| Viewing the list of steps | `viewsteps` |
| Getting a suggestion on your steps walked | `getstepssuggestion <DATE>` |
6 changes: 0 additions & 6 deletions docs/team/johndoe.md

This file was deleted.

12 changes: 10 additions & 2 deletions src/main/java/fittrack/FitTrack.java
Original file line number Diff line number Diff line change
Expand Up @@ -82,6 +82,10 @@ private void end() {
save();
}


/**
* Load all files into the program data if any and check if file corrupted.
*/
// @@author J0shuaLeong
private void load() {
try {
Expand Down Expand Up @@ -113,7 +117,7 @@ private void load() {
}

if (userProfile == null) {
initUserProfile();
initUserProfile(); // Function called if user is using FitTrack for the first time
ui.printPrompt();
}
if (mealList == null) {
Expand All @@ -129,6 +133,10 @@ private void load() {
}
// @@author


/**
* Prompt user to enter profile settings if they are first time user.
*/
// @@author J0shuaLeong
public void initUserProfile() {
boolean isInputValid = false;
Expand Down Expand Up @@ -166,7 +174,7 @@ private Storage initializeStorage(String[] args) {
return new Storage();
}
}
// @@author J0shuaLeong
// @@author

private void save() {
try {
Expand Down
7 changes: 7 additions & 0 deletions src/main/java/fittrack/Ui.java
Original file line number Diff line number Diff line change
Expand Up @@ -9,12 +9,15 @@
* Represents the user interface of FitTrack.
*/
public class Ui {

// @@author J0shuaLeong
private static final String LOGO = "___________.__ __ ___________ __\n"
+ "\\_ _____/|__|/ |\\__ ___/___________ ____ | | __\n"
+ " | __) | \\ __\\| | \\_ __ \\__ \\ _/ ___\\| |/ /\n"
+ " | \\ | || | | | | | \\/ __ \\ \\___| <\n"
+ " \\___ / |__||__| |____| |__| (____ /\\___ >__|_ \\";
private static final String LINE = "____________________________________________________________";
// @@author

private final Scanner in;

Expand Down Expand Up @@ -77,6 +80,7 @@ public void printCommandResult(CommandResult commandResult) {
System.out.println(commandResult.getFeedback());
}

// @@author J0shuaLeong
public void printWelcomeBackPrompt() {
System.out.println("Welcome back! How can I help you today?");
printLine();
Expand All @@ -86,6 +90,7 @@ public void printPrompt() {
System.out.println("Hello and welcome! How can I help you today?");
printLine();
}
// @@author

/**
* Prints the profile details of the user after user has
Expand All @@ -111,6 +116,7 @@ public void printException(Exception e) {
System.out.println(e.getMessage());
}

// @@author J0shuaLeong
public void printForceExit() {
System.out.println("Please fix the corrupted file which can be found in" +
" data directory. Exiting the app...");
Expand All @@ -131,6 +137,7 @@ public static void printPromptForCreateNewFile(String fileName) {
System.out.println(String.format(
"\nThe %s file is corrupted. Would you like to create a new one? (Y/N)", fileName));
}
// @@author

public static class ForceExitException extends RuntimeException {
}
Expand Down
2 changes: 2 additions & 0 deletions src/main/java/fittrack/command/BmiCommand.java
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

import fittrack.parser.PatternMatchFailException;

// @@author J0shuaLeong
public class BmiCommand extends Command {
public static final String COMMAND_WORD = "bmi";
private static final String DESCRIPTION =
Expand Down Expand Up @@ -32,3 +33,4 @@ protected String getHelp() {
return HELP;
}
}
//@@author
70 changes: 70 additions & 0 deletions src/main/java/fittrack/command/CalorieBalanceCommand.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,70 @@
package fittrack.command;

import fittrack.data.Date;
import fittrack.data.Meal;
import fittrack.data.Workout;
import fittrack.parser.ParseException;

public class CalorieBalanceCommand extends Command {

public static final String COMMAND_WORD = "caloriebalance";
private static final String DESCRIPTION =
String.format("%s will take your calorie limit you set " +
"and will calculate your current calorie balance for " +
"the day using the calories you burnt during workouts" +
"and the calories you consumed during meals", COMMAND_WORD);
private static final String USAGE =
String.format("Type %s <DATE> to see today's calorie balance.\n" +
"You should type <DATE> in format of yyyy-MM-dd.",
COMMAND_WORD);

public static final String HELP = DESCRIPTION + "\n" + USAGE;

private Date date;

private double calorieBalance;
public CalorieBalanceCommand(String commandLine) {
super(commandLine);
}

@Override
public CommandResult execute() {
calorieBalance = userProfile.getDailyCalorieLimit().value;
for(Workout workout: workoutList.getWorkoutList()) {
if(date.equals(workout.getDate())) {
calorieBalance += workout.getCalories().value;
}
}

for(Meal meal: mealList.getMealList()) {
if(date.equals(meal.getDate())) {
calorieBalance -= meal.getCalories().value;
}
}
if(calorieBalance < 0) {
return new CommandResult("You have exceeded your calorie limit on " + date +
" by: " + (calorieBalance * -1) + "kcal\n" +
"You are in a calorie surplus!\n" +
"Try doing more exercises if you want to eat!");
} else if (calorieBalance == 0) {
return new CommandResult("Your calorie balance on " + date +
" is: " + calorieBalance + "kcal\n"
+ "Try doing more exercise if you want to eat!");
} else {
return new CommandResult("Your calorie balance on " + date +
" is: " + calorieBalance + "kcal\n" +
"You are in a calorie deficit!\n" +
"You can try to eat more!");
}
}

@Override
public void setArguments(String args) throws ParseException {
date = Date.parseDate(args);
}

@Override
protected String getHelp() {
return HELP;
}
}
2 changes: 2 additions & 0 deletions src/main/java/fittrack/command/EditProfileCommand.java
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
import fittrack.UserProfile;
import fittrack.parser.ParseException;

//@@author J0shuaLeong
public class EditProfileCommand extends Command {
public static final String COMMAND_WORD = "editprofile";
private static final String DESCRIPTION =
Expand Down Expand Up @@ -36,3 +37,4 @@ protected String getHelp() {
return HELP;
}
}
// @@author
2 changes: 2 additions & 0 deletions src/main/java/fittrack/command/ViewProfileCommand.java
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

import fittrack.parser.PatternMatchFailException;

// @@author J0shuaLeong
public class ViewProfileCommand extends Command {
public static final String COMMAND_WORD = "viewprofile";
private static final String DESCRIPTION =
Expand Down Expand Up @@ -32,3 +33,4 @@ protected String getHelp() {
return HELP;
}
}
// @@author
5 changes: 4 additions & 1 deletion src/main/java/fittrack/parser/CommandParser.java
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
import fittrack.command.BmiCommand;
import fittrack.command.CaloriesBurntCommand;
import fittrack.command.CaloriesConsumedCommand;
import fittrack.command.CalorieBalanceCommand;
import fittrack.command.CheckRecommendedWeightCommand;
import fittrack.command.Command;
import fittrack.command.CommandResult;
Expand Down Expand Up @@ -41,7 +42,7 @@ public class CommandParser {
"editprofile, viewprofile, bmi, checkrecommendedweight,\n" +
"addmeal, deletemeal, viewmeal, findmeal, caloriesconsumed,\n" +
"addworkout, deleteworkout, viewworkout, findworkout, caloriesburnt,\n" +
"addsteps, deletesteps, viewsteps, totalsteps";
"caloriebalance, addsteps, deletesteps, viewsteps, totalsteps";

private static final String WORD_CG = "word";
private static final String ARGS_CG = "args";
Expand Down Expand Up @@ -98,6 +99,8 @@ public static Command getBlankCommand(String word, String commandLine) {
return new BmiCommand(commandLine);
case CaloriesConsumedCommand.COMMAND_WORD:
return new CaloriesConsumedCommand(commandLine);
case CalorieBalanceCommand.COMMAND_WORD:
return new CalorieBalanceCommand(commandLine);
case CheckRecommendedWeightCommand.COMMAND_WORD:
return new CheckRecommendedWeightCommand(commandLine);
case CaloriesBurntCommand.COMMAND_WORD:
Expand Down
13 changes: 0 additions & 13 deletions src/main/java/fittrack/storage/IllegalStorageValueException.java

This file was deleted.

6 changes: 5 additions & 1 deletion src/main/java/fittrack/storage/MealListDecoder.java
Original file line number Diff line number Diff line change
Expand Up @@ -18,8 +18,12 @@

// @@author J0shuaLeong
public class MealListDecoder {

private static final String NAME_GRP = "name";
private static final String CALORIES_GRP = "calories";
private static final String DATE_GRP = "date";
private static final Pattern MEAL_PATTERN = Pattern.compile(
"(?<name>\\S+)\\s*\\|\\s*(?<calories>\\S+)kcal\\s*\\|\\s*(?<date>\\S+)"
"(?<" + NAME_GRP + ">.+)\\s+\\|\\s+(?<" + CALORIES_GRP + ">\\S+)kcal\\s+\\|\\s+(?<" + DATE_GRP + ">\\S+)?"
);
private static final StorageOperationException CONTENT_CORRUPTION_EXCEPTION = new StorageOperationException(
"Creating new meal list file..."
Expand Down
1 change: 1 addition & 0 deletions src/main/java/fittrack/storage/StepListDecoder.java
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@
import java.util.regex.Matcher;
import java.util.regex.Pattern;

// @@author J0shuaLeong
public class StepListDecoder {
private static final Pattern STEP_PATTERN = Pattern.compile(
"(?<steps>\\d+)\\s*\\|\\s*(?<date>\\d{4}-\\d{2}-\\d{2})"
Expand Down
Loading