Skip to content

Commit

Permalink
Merge 6a93c53 into 9659e64
Browse files Browse the repository at this point in the history
  • Loading branch information
kwekke committed Oct 24, 2019
2 parents 9659e64 + 6a93c53 commit 7a515bb
Show file tree
Hide file tree
Showing 23 changed files with 430 additions and 58 deletions.
2 changes: 2 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,8 @@ src/main/resources/docs/

# Storage/log files
/data/
!data/exercisedatabase.json

/config.json
/preferences.json
/*.log.*
Expand Down
51 changes: 51 additions & 0 deletions data/exercisedatabase.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,51 @@
{
"jsonResources" : [ {
"name" : "Push ups",
"date" : "26/09/2019",
"calories" : "30",
"quantity" : "60",
"unit" : "counts",
"muscles" : [ "Triceps" ],
"customProperties" : { }
}, {
"name" : "Sit ups",
"date" : "26/09/2019",
"calories" : "30",
"quantity" : "60",
"unit" : "counts",
"muscles" : [ "Abs" ],
"customProperties" : { }
}, {
"name" : "Run",
"date" : "22/09/2019",
"calories" : "300",
"quantity" : "2.4",
"unit" : "km",
"muscles" : [ "Legs", "cardio" ],
"customProperties" : { }
}, {
"name" : "Bench Press",
"date" : "22/09/2019",
"calories" : "50",
"quantity" : "30",
"unit" : "counts",
"muscles" : [ "Chest", "Triceps" ],
"customProperties" : { }
}, {
"name" : "Squat",
"date" : "22/09/2019",
"calories" : "50",
"quantity" : "30",
"unit" : "counts",
"muscles" : [ "Legs", "Back" ],
"customProperties" : { }
}, {
"name" : "Deadlift",
"date" : "22/09/2019",
"calories" : "50",
"quantity" : "30",
"unit" : "counts",
"muscles" : [ "Legs", "Back" ],
"customProperties" : { }
} ]
}
4 changes: 2 additions & 2 deletions docs/UserGuide.adoc
Original file line number Diff line number Diff line change
Expand Up @@ -486,9 +486,9 @@ e.g. `schedule n/cardio d/19/9/2019`
e.g. `resolve n/cardio`
* *Suggest basic* : `suggest s/basic`
* *Suggest possible* : `suggest s/possible [m/MUSCLE]...`
e.g. `suggest t/possible m/chest`
e.g. `suggest s/possible m/chest`
* *Suggest intensity* : `suggest s/intensity i/INDEX`
eg. `suggest intensity 1`
eg. `suggest s/intensity 1`
* *Custom* : `custom s/PREFIX_NAME f/FULL_NAME p/PARAMETER_TYPE`
e.g. `custom s/c f/End Date p/Date`
* *Exit* : `exit`
2 changes: 0 additions & 2 deletions src/main/java/seedu/exercise/MainApp.java
Original file line number Diff line number Diff line change
Expand Up @@ -87,9 +87,7 @@ public void init() throws Exception {
scheduleBookStorage, userPrefsStorage, propertyBookStorage);

initLogging(config);

model = initModelManager(storage, userPrefs);

logic = new LogicManager(model, storage);

ui = new UiManager(logic);
Expand Down
1 change: 1 addition & 0 deletions src/main/java/seedu/exercise/logic/LogicManager.java
Original file line number Diff line number Diff line change
Expand Up @@ -126,6 +126,7 @@ public Conflict getConflict() {
*/
private void saveAllData() throws IOException {
storage.saveExerciseBook(model.getExerciseBookData());
storage.saveExerciseDatabase(model.getExerciseDatabaseData());
storage.saveScheduleBook(model.getAllScheduleData());
storage.saveRegimeBook(model.getAllRegimeData());
storage.savePropertyBook(model.getPropertyBook());
Expand Down
Original file line number Diff line number Diff line change
@@ -1,26 +1,34 @@
package seedu.exercise.logic.commands;

import static java.util.Objects.requireNonNull;
import static seedu.exercise.logic.parser.CliSyntax.PREFIX_SUGGEST;
import static seedu.exercise.model.Model.PREDICATE_SHOW_ALL_EXERCISES;
import static seedu.exercise.logic.parser.CliSyntax.PREFIX_SUGGEST_TYPE;
import static seedu.exercise.model.util.SampleDataUtil.getBasicExercises;

import java.util.Arrays;
import java.util.List;

import seedu.exercise.logic.commands.exceptions.CommandException;
import seedu.exercise.model.Model;
import seedu.exercise.model.resource.Exercise;

/**
* Lists basic exercises in the exercise database to the user.
*/
public class SuggestBasicCommand extends SuggestCommand {

public static final String MESSAGE_SUCCESS = "Listed all suggested basic exercises.";

public static final String MESSAGE_USAGE_SUGGEST_BASIC = "Parameters: "
+ PREFIX_SUGGEST + "SUGGEST TYPE ";
+ PREFIX_SUGGEST_TYPE + "SUGGEST_TYPE" + "\n"
+ "\t\tExample: " + COMMAND_WORD + " "
+ PREFIX_SUGGEST_TYPE + "basic";

public static final String MESSAGE_SUCCESS = "Listed all suggested basic exercises.";
public static final String SUGGEST_TYPE = "basic";

@Override
public CommandResult execute(Model model) throws CommandException {
requireNonNull(model);
model.updateSuggestedExerciseList(PREDICATE_SHOW_ALL_EXERCISES);
List<Exercise> basicExercises = Arrays.asList(getBasicExercises());
model.setSuggestions(basicExercises);
return new CommandResult(MESSAGE_SUCCESS);
}

Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package seedu.exercise.logic.commands;

import static seedu.exercise.logic.commands.SuggestBasicCommand.MESSAGE_USAGE_SUGGEST_BASIC;
import static seedu.exercise.logic.commands.SuggestPossibleCommand.MESSAGE_USAGE_SUGGEST_POSSIBLE;

/**
* Represents an SuggestCommand with hidden internal logic and the ability to be executed.
Expand All @@ -13,6 +14,7 @@ public abstract class SuggestCommand extends Command {

public static final String MESSAGE_USAGE = COMMAND_WORD
+ ": Suggests exercise.\n"
+ "BASIC: " + MESSAGE_USAGE_SUGGEST_BASIC + "\n";
+ "BASIC: " + MESSAGE_USAGE_SUGGEST_BASIC + "\n"
+ "POSSIBLE: " + MESSAGE_USAGE_SUGGEST_POSSIBLE;

}
Original file line number Diff line number Diff line change
@@ -0,0 +1,72 @@
package seedu.exercise.logic.commands;

import static java.util.Objects.requireNonNull;
import static seedu.exercise.logic.parser.CliSyntax.PREFIX_MUSCLE;
import static seedu.exercise.logic.parser.CliSyntax.PREFIX_SUGGEST_TYPE;

import java.util.Map;
import java.util.Set;
import java.util.function.Predicate;

import seedu.exercise.logic.commands.exceptions.CommandException;
import seedu.exercise.model.Model;
import seedu.exercise.model.property.Muscle;
import seedu.exercise.model.resource.Exercise;

/**
* Lists possible exercises to the user.
*/
public class SuggestPossibleCommand extends SuggestCommand {

public static final String MESSAGE_USAGE_SUGGEST_POSSIBLE = "Parameters: "
+ PREFIX_SUGGEST_TYPE + "SUGGEST_TYPE "
+ "[" + PREFIX_MUSCLE + "MUSCLE] "
+ "[" + "CUSTOM_PROPERTY_PREFIX" + "/" + "VALUE]" + "\n"
+ "\t\tExample: " + COMMAND_WORD + " "
+ PREFIX_SUGGEST_TYPE + "possible "
+ PREFIX_MUSCLE + "Legs";

public static final String MESSAGE_SUCCESS = "Listed suggested exercises.";
public static final String SUGGEST_TYPE = "possible";


private Set<Muscle> targetMuscles;
private Map<String, String> targetCustomPropertiesMap;

public SuggestPossibleCommand(Set<Muscle> targetMuscles, Map<String, String> targetCustomPropertiesMap) {
this.targetMuscles = targetMuscles;
this.targetCustomPropertiesMap = targetCustomPropertiesMap;
}

@Override
public CommandResult execute(Model model) throws CommandException {
requireNonNull(model);
model.updateSuggestedExerciseList(getPredicate());
return new CommandResult(MESSAGE_SUCCESS);
}

private Predicate<Exercise> getPredicate() {
return exercise -> {
Set<Muscle> exercisesMuscles = exercise.getMuscles();
for (Muscle muscle : targetMuscles) {
if (!(exercisesMuscles.contains(muscle))) {
return false;
}
}

Map<String, String> exerciseCustomProperties = exercise.getCustomProperties();
for (String key : targetCustomPropertiesMap.keySet()) {
if (!(targetCustomPropertiesMap.get(key).equals(exerciseCustomProperties.get(key)))) {
return false;
}
}
return true;
};
}

@Override
public boolean equals(Object other) {
return other == this // short circuit if same object
|| (other instanceof SuggestPossibleCommand); // instanceof handles nulls
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,9 @@
*/
public class AddCommandParser implements Parser<AddCommand> {

public static final String ADD_CATEGORY_EXERCISE = "exercise";
public static final String ADD_CATEGORY_REGIME = "regime";

/**
* Parses the given {@code String} of arguments in the context of the AddCommand
* and returns an AddCommand object for execution.
Expand All @@ -50,11 +53,11 @@ public AddCommand parse(String args) throws ParseException {

String category = ParserUtil.parseCategory(argMultimap.getValue(PREFIX_CATEGORY).get());

if (category.equals("exercise")) {
if (category.equals(ADD_CATEGORY_EXERCISE)) {
return parseExercise(argMultimap);
}

if (category.equals("regime")) {
if (category.equals(ADD_CATEGORY_REGIME)) {
return parseRegime(argMultimap);
}

Expand Down
2 changes: 1 addition & 1 deletion src/main/java/seedu/exercise/logic/parser/CliSyntax.java
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ public class CliSyntax {
public static final Prefix PREFIX_CUSTOM_NAME = new Prefix("s/");
public static final Prefix PREFIX_FULL_NAME = new Prefix("f/");
public static final Prefix PREFIX_PARAMETER_TYPE = new Prefix("p/");
public static final Prefix PREFIX_SUGGEST = new Prefix("g/");
public static final Prefix PREFIX_SUGGEST_TYPE = new Prefix("s/");

/* A set consisting of property prefix definitions for add and edit commands */
public static final Set<Prefix> PREFIXES_SET = new HashSet<>();
Expand Down
42 changes: 25 additions & 17 deletions src/main/java/seedu/exercise/logic/parser/ParserUtil.java
Original file line number Diff line number Diff line change
@@ -1,6 +1,10 @@
package seedu.exercise.logic.parser;

import static java.util.Objects.requireNonNull;
import static seedu.exercise.logic.parser.AddCommandParser.ADD_CATEGORY_EXERCISE;
import static seedu.exercise.logic.parser.AddCommandParser.ADD_CATEGORY_REGIME;
import static seedu.exercise.logic.parser.SuggestCommandParser.SUGGEST_TYPE_BASIC;
import static seedu.exercise.logic.parser.SuggestCommandParser.SUGGEST_TYPE_POSSIBLE;
import static seedu.exercise.model.property.PropertyBook.getCustomProperties;

import java.util.ArrayList;
Expand Down Expand Up @@ -167,8 +171,10 @@ public static Set<Muscle> parseMuscles(Collection<String> muscles) throws ParseE
public static String parseCategory(String category) throws ParseException {
requireNonNull(category);
String trimmedCategory = category.trim();
if (!trimmedCategory.equals("exercise") && !trimmedCategory.equals("regime")) {
throw new ParseException("Category can only be \'exercise\' or \'regime\'");
if (!trimmedCategory.equals(ADD_CATEGORY_EXERCISE)
&& !trimmedCategory.equals(ADD_CATEGORY_REGIME)) {
throw new ParseException("Category can only be \'" + ADD_CATEGORY_EXERCISE + "\'"
+ " or \'" + ADD_CATEGORY_REGIME + "\'");
}
return trimmedCategory;
}
Expand Down Expand Up @@ -253,6 +259,23 @@ static ParameterType parseParameterType(String parameterType) throws ParseExcept
}
}

/**
* Parses a {@code String suggestType} into a String.
* Leading and trailing whitespaces will be trimmed.
*
* @throws ParseException
*/
public static String parseSuggestType(String suggestType) throws ParseException {
requireNonNull(suggestType);
String trimmedSuggestType = suggestType.trim();
if (!trimmedSuggestType.equals(SUGGEST_TYPE_BASIC)
&& !trimmedSuggestType.equals(SUGGEST_TYPE_POSSIBLE)) {
throw new ParseException("Suggest type can only be \'" + SUGGEST_TYPE_BASIC + "\'"
+ " or \'" + SUGGEST_TYPE_POSSIBLE + "\'");
}
return trimmedSuggestType;
}

/**
* Formats a single word by capitalising the first letter and setting the remaining
* as lowercase.
Expand Down Expand Up @@ -321,19 +344,4 @@ private static String parseNumber(String number) throws ParseException {
return trimmedNumber;
}


/**
* Parses a {@code String suggestType} into a String.
* Leading and trailing whitespaces will be trimmed.
*
* @throws ParseException
*/
public static String parseSuggestType(String suggestType) throws ParseException {
requireNonNull(suggestType);
String trimmedSuggestType = suggestType.trim();
if (!trimmedSuggestType.equals("basic")) {
throw new ParseException("Suggest type can only be \'basic\'");
}
return trimmedSuggestType;
}
}
Loading

0 comments on commit 7a515bb

Please sign in to comment.