Skip to content
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
14 changes: 7 additions & 7 deletions docs/UserGuide.md
Original file line number Diff line number Diff line change
Expand Up @@ -106,9 +106,9 @@ Here are some recommended biceps exercises:
### 4. BMI
Calculate your BMI and tells user if they are underweight, normal weight, overweight or obese. <BR/>

Range of accepted Weight: 1.5kg - 700kg
Range of accepted Weight: 1.5kg - 700kg (takes in decimal values)

Range of accepted Height: 0.2m - 3.0m
Range of accepted Height: 0.2m - 3.0m (takes in decimal values)

Format: `bmi /w <weight_in_kg> /h <height_in_m>`

Expand All @@ -120,7 +120,7 @@ Your BMI is: 23.15, you are of normal weight.
### 5. Add workout
Adds a workout log with the exercise name, weight lifted, number of reps, number of sets, and date.

Range of accepted weight: 1kg - 1000kg
Range of accepted weight: 1kg - 1000kg (takes in decimal values)

Range of accepted reps: 1 - 1000

Expand Down Expand Up @@ -166,7 +166,7 @@ Example of usage: `add water /ml 1000 /d 02/02/2025 /t 1700`
### 8. Add Personal Best
Record a personal best log with the exercise name, weight lifted, and date.

Range of accepted weight: 1kg - 1000kg
Range of accepted weight: 1kg - 1000kg (takes in decimal values)

Format: `add pb <exercise> /w <weight_in_kg> /d <DD/MM/YYYY>`

Expand All @@ -181,16 +181,16 @@ Example of usage: `add pb bench /w 120 /d 02/02/2025`
Add a cardio log with the exercise name, speed, incline, duration, and date.

Speed
- Range: 1 - 50
- Range: 1 - 50 (takes in decimal values)
- Units: kilometers per hour (km/h)

Incline
- Range: 0 - 15
- Range: 0 - 15 (takes in decimal values)
- Units: percentage
- Description: Indicates the incline grade, where a 1% incline represents a 1-unit rise in height for every 100 units of horizontal distance.

Duration
- Range: 1 - 1440
- Range: 1 - 1440 (takes in decimal values)
- Units: minutes

Format: `add cardio <exercise> /s <speed> /i <incline> /t <duration> /d <DD/MM/YYYY>`
Expand Down
Binary file modified docs/images/DeleteSD.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file removed docs/images/DeleteSD1.png
Binary file not shown.
6 changes: 3 additions & 3 deletions src/main/java/seedu/healthbud/LogList.java
Original file line number Diff line number Diff line change
Expand Up @@ -201,9 +201,9 @@ public int getCardioSum(String date) throws InvalidDateFormatException, InvalidD
for (Log log : logs) {
if (log instanceof Cardio && DateParser.formatDate(log.getDate()).equals(date)) {
Cardio cardio = (Cardio) log;
int speed = Integer.parseInt(cardio.getSpeed());
int duration = Integer.parseInt(cardio.getDuration());
int incline = Integer.parseInt(cardio.getIncline());
double speed = Double.parseDouble(cardio.getSpeed());
double duration = Double.parseDouble(cardio.getDuration());
double incline = Double.parseDouble(cardio.getIncline());

// Calories = ((speed * 2) + (incline * 5)) * (duration / 60.0) * 100
totalCardio += (int) (((speed * 2) + (incline * 5)) * (duration / 60.0) * 100);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ public static AddCardioCommand parse(LogList cardioLogs, String input)

input = input.replaceFirst("add cardio", "").trim();

String name = input.substring(0, input.indexOf("/")).trim();
String name = input.substring(0, input.indexOf("/")).trim().replaceAll("\\s+", " ");

if (input.isEmpty()) {
throw new InvalidCardioException();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ public static AddMealCommand parse(LogList mealLogs, String input)

input = input.substring("add meal".length()).trim();

String name = input.substring(0, input.indexOf("/")).trim();
String name = input.substring(0, input.indexOf("/")).trim().replaceAll("\\s+", " ");;

Map<String, String> param = ParserParameters.parseParameters(input.substring(name.length()));
Set<String> allowedKeys = new HashSet<>(Arrays.asList("cal", "d", "t"));
Expand All @@ -56,7 +56,7 @@ public static AddMealCommand parse(LogList mealLogs, String input)
}

if (!param.get("cal").matches("\\d+")) {
throw new InvalidMealException();
throw new HealthBudException("Calorie count must be a positive integer.");
}

int cal = Integer.parseInt(param.get("cal"));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ public static AddPersonalBestCommand parse(LogList pbLogs, String input)

input = input.substring("add pb".length()).trim();

String name = input.substring(0, input.indexOf("/")).trim();
String name = input.substring(0, input.indexOf("/")).trim().replaceAll("\\s+", " ");

Map<String, String> param = ParserParameters.parseParameters(input.substring(name.length()));
Set<String> allowedKeys = new HashSet<>(Arrays.asList("w", "d"));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ public static AddWorkoutCommand parse(LogList workoutLogs, String input)

input = input.substring("add workout".length()).trim();

String name = input.substring(0, input.indexOf("/")).trim();
String name = input.substring(0, input.indexOf("/")).trim().replaceAll("\\s+", " ");

Map<String, String> param = ParserParameters.parseParameters(input.substring(name.length()));
Set<String> allowedKeys = new HashSet<>(Arrays.asList("r", "d", "s", "w"));
Expand All @@ -57,9 +57,11 @@ public static AddWorkoutCommand parse(LogList workoutLogs, String input)
throw new InvalidWorkoutException();
}

if (!param.get("r").matches("^-?\\d+$") || !param.get("s").matches("^-?\\d+$") ||
!param.get("w").matches("^-?\\d+(\\.\\d+)?$")) {
throw new InvalidWorkoutException();
if (!param.get("r").matches("^-?\\d+$") || !param.get("s").matches("^-?\\d+$") ) {
throw new HealthBudException("Reps and sets should be positive integers.");
}
if (!param.get("w").matches("^-?\\d+(\\.\\d+)?$")) {
throw new HealthBudException("Weight must be a positive number.");
}

int rep = Integer.parseInt(param.get("r"));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
import seedu.healthbud.exception.InvalidDateException;
import seedu.healthbud.exception.InvalidDateFormatException;
import seedu.healthbud.exception.InvalidTrackException;
import seedu.healthbud.parser.DateParser;

/**
* TrackGoalParser is responsible for parsing the input command to create a TrackGoalCommand.
Expand Down Expand Up @@ -38,13 +39,12 @@ public static TrackGoalCommand parse(String input, LogList goalLogs, LogList pbL
throw new InvalidTrackException();
}

String date = parts[3];
String rawDate = parts[3];

try {
return new TrackGoalCommand(date, goalLogs, pbLogs, mealLogs, workoutLogs, waterLogs, cardioLogs);
} catch (EmptyTrackException e) {
throw new EmptyTrackException();
}
String formattedDate = DateParser.formatDate(rawDate);

return new TrackGoalCommand(formattedDate, goalLogs, pbLogs,
mealLogs, workoutLogs, waterLogs, cardioLogs);
}
}

10 changes: 9 additions & 1 deletion src/main/java/seedu/healthbud/storage/Storage.java
Original file line number Diff line number Diff line change
Expand Up @@ -192,6 +192,8 @@ public static Log parseStringToMealLog(String line) {
throw new IllegalArgumentException("Invalid meal format");
}

parts[1] = parts[1].trim().replaceAll("\\s+", " ");

int cal = Integer.parseInt(parts[2]);
if (!parts[2].matches("\\d+") || cal < 0 || cal > 10000) {
throw new IllegalArgumentException("Invalid calorie format");
Expand Down Expand Up @@ -228,6 +230,8 @@ public static Log parseStringToWorkoutLog(String line) {
throw new IllegalArgumentException("Invalid workout format");
}

parts[1] = parts[1].trim().replaceAll("\\s+", " ");

if (!parts[2].matches("\\d+") || parts[2].equals("0")) {
throw new IllegalArgumentException("Invalid reps format");
}
Expand Down Expand Up @@ -269,6 +273,8 @@ public static Log parseStringToCardioLog(String line) {
throw new IllegalArgumentException("Invalid cardio format");
}

parts[1] = parts[1].trim().replaceAll("\\s+", " ");

if (!parts[2].matches("^-?\\d+(\\.\\d+)?$") ||
!parts[3].matches("^-?\\d+(\\.\\d+)?$") ||
!parts[4].matches("^-?\\d+(\\.\\d+)?$")) {
Expand Down Expand Up @@ -298,7 +304,7 @@ public static Log parseStringToCardioLog(String line) {
throw new IllegalArgumentException("Invalid date format");
}

return new Cardio(parts[1], parts[2], trimmedDuration, trimmedIncline, trimmedSpeed);
return new Cardio(parts[1], trimmedDuration, trimmedIncline, trimmedSpeed, parts[5]);
}

/**
Expand Down Expand Up @@ -356,6 +362,8 @@ public static Log parseStringToPersonalBestLog(String line) {
throw new IllegalArgumentException("Invalid personal best format");
}

parts[1] = parts[1].trim().replaceAll("\\s+", " ");

double weight = Double.parseDouble(parts[2]);

if (!parts[2].matches("\\d+") || weight <= 0 || weight > 10000) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ void mealLog_nonNumericCalories_expectThrowsInvalidMealException() {
LogList mealLogs = new LogList();
String input = "add meal chicken rice /cal high /d 12-01-2025 /t 2100";

assertThrows(InvalidMealException.class, () -> AddMealParser.parse(mealLogs, input));
assertThrows(HealthBudException.class, () -> AddMealParser.parse(mealLogs, input));
}

@Test
Expand Down Expand Up @@ -164,7 +164,7 @@ void mealLog_caloriesExceedLimit_expectHealthBudException() {
void mealLog_caloriesNegative_expectHealthBudException() {
LogList mealLogs = new LogList();
String input = "add meal fries /cal -100 /d 12-01-2025 /t 2100";
assertThrows(InvalidMealException.class, () -> AddMealParser.parse(mealLogs, input));
assertThrows(HealthBudException.class, () -> AddMealParser.parse(mealLogs, input));
}

@Test
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -82,7 +82,7 @@ void workoutLog_nonNumericReps_throwsException() {
LogList workoutLogs = new LogList();
String input = "add workout squats /r ten /s 3 /d 25-12-2023 /w 50";

assertThrows(InvalidWorkoutException.class, () ->
assertThrows(HealthBudException.class, () ->
AddWorkoutParser.parse(workoutLogs, input));
}

Expand All @@ -91,7 +91,7 @@ void workoutLog_nonNumericSets_throwsException() {
LogList workoutLogs = new LogList();
String input = "add workout squats /r 10 /s three /d 25-12-2023 /w 50";

assertThrows(InvalidWorkoutException.class, () ->
assertThrows(HealthBudException.class, () ->
AddWorkoutParser.parse(workoutLogs, input));
}

Expand All @@ -100,7 +100,7 @@ void workoutLog_nonNumericWeight_throwsException() {
LogList workoutLogs = new LogList();
String input = "add workout squats /r 10 /s 3 /d 25-12-2023 /w fifty";

assertThrows(InvalidWorkoutException.class, () ->
assertThrows(HealthBudException.class, () ->
AddWorkoutParser.parse(workoutLogs, input));
}

Expand Down