Skip to content

Commit

Permalink
Merge pull request #232 from keiteo/testBranch
Browse files Browse the repository at this point in the history
FlashCard Tests v1.4 progress
  • Loading branch information
keiteo committed Nov 10, 2019
2 parents bd48922 + 55a7db9 commit bf29a7a
Show file tree
Hide file tree
Showing 15 changed files with 249 additions and 50 deletions.
29 changes: 18 additions & 11 deletions docs/UserGuide.adoc
Original file line number Diff line number Diff line change
Expand Up @@ -313,30 +313,37 @@ Shows the calendar filled with all deadlines in the month. The calendar will be
`calendar`

//end::deadline[]
//@@author keiteo
=== Test mode: `start`

==== Start command: `start [category]`
This command starts the flashcard test mode. If no parameter is supplied, the application will test all
available FlashCards.

E.g. `start`

=== Test mode
image::StartEmptyParam.png[width="600"]

==== Start command
This command starts the flashcard test mode.
If tag(s) are entered, this command starts the FlashCard test from any specific category. Only relevant FlashCards from the tag(s) will
be tested.

`start`
E.g. `start [category]`

Starts the flashcard test from any specific category
`start [category]`
image::StartWithTagParam.png[width="600"]

==== See flashcard answer
==== See flashcard answer: `ans`
This command allows you to check the answer of the flashcard question.

`ans`

==== Rate flashcard
==== Rate flashcard: `rate [easy/good/hard]`
This command rates the flashcard, depending on how well you answered the question i.e. easy, good, hard.

`rate [rating]`, e.g. `rate hard`

==== End test
==== Skip question: `skip`
If you would like to manually filter and skip questions, the `skip` command helps you to skip FlashCards,
saving you extra time.

==== End test: `end`
You can stop the test any time simply by typing `end`.

//@@author LeowWB
Expand Down
Binary file added docs/images/StartEmptyParam.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 added docs/images/StartWithTagParam.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
13 changes: 12 additions & 1 deletion src/main/java/seedu/address/logic/commands/EndTestCommand.java
Original file line number Diff line number Diff line change
Expand Up @@ -2,28 +2,39 @@

import static java.util.Objects.requireNonNull;

import java.util.logging.Level;
import java.util.logging.Logger;

import seedu.address.logic.parser.KeyboardFlashCardsParser;
import seedu.address.model.Model;

//@@author keiteo
/**
* Ends the current flashcard test.
* Instantiates an EndTestcommand that allows users to end the current flashcard test.
*/
public class EndTestCommand extends Command {

public static final String COMMAND_WORD = "end";

private static Logger logger = Logger.getLogger("Foo");
private KeyboardFlashCardsParser keyboardFlashCardsParser;

public EndTestCommand(KeyboardFlashCardsParser keyboardFlashCardsParser) {
requireNonNull(keyboardFlashCardsParser);

this.keyboardFlashCardsParser = keyboardFlashCardsParser;
}

@Override
public CommandResult execute(Model model) {
requireNonNull(model);

model.updatePerformance(model);
logger.log(Level.INFO, "Updating performance");

keyboardFlashCardsParser.endTestMode();
logger.log(Level.INFO, "Enabling KeyboardFlashCardsParser to accept normal commands");

CommandResult result = new CommandResult("Test ended");
result.setTestMode(false, true);
return result;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,17 +2,21 @@

import static java.util.Objects.requireNonNull;

import java.util.logging.Level;
import java.util.logging.Logger;

import seedu.address.logic.parser.KeyboardFlashCardsParser;
import seedu.address.model.Model;

//@@author keiteo
/**
* Represents a NextQuestionCommand to skip questions.
* This class provides a skeletal implementation for commands that fetch the next FlashCard from the test model.
*/
abstract class NextQuestionCommand extends Command {

private static final String MESSAGE_SUCCESS_END_OF_TEST = "End of test!";
public static final String MESSAGE_SUCCESS_END_OF_TEST = "End of test!";

private static Logger logger = Logger.getLogger("Foo");
private final KeyboardFlashCardsParser keyboardFlashCardsParser;
private final String messageSuccess;

Expand All @@ -24,17 +28,25 @@ abstract class NextQuestionCommand extends Command {
@Override
public CommandResult execute(Model model) {
requireNonNull(model);

if (!model.hasTestFlashCard()) {
logger.log(Level.INFO, "No more flashcards left to test!");

keyboardFlashCardsParser.endTestMode();
logger.log(Level.INFO, "Enabling KeyboardFlashCardsParser to accept normal commands");

model.updatePerformance(model);
logger.log(Level.INFO, "Updating performance");

CommandResult result = new CommandResult(MESSAGE_SUCCESS_END_OF_TEST);
result.setTestMode(false, true);
return result;
}

//String nextQuestion = model.getTestQuestion();
model.setTestFlashCard();
keyboardFlashCardsParser.setAwaitingAnswer(true);
logger.log(Level.INFO, "Getting the next flashcard");

return new CommandResult(
messageSuccess,
model.getTestFlashCardPanel());
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,14 +25,17 @@ public class RateQuestionCommand extends NextQuestionCommand {

public RateQuestionCommand(KeyboardFlashCardsParser keyboardFlashCardsParser, Rating rating) {
super(keyboardFlashCardsParser, MESSAGE_SUCCESS);

requireNonNull(rating);

this.keyboardFlashCardsParser = keyboardFlashCardsParser;
this.rating = rating;
}

@Override
public CommandResult execute(Model model) {
requireNonNull(model);

updateModelStatistics(model);
updateFlashCardRating(model);
return super.execute(model);
Expand All @@ -50,28 +53,39 @@ public boolean equals(Object other) {
/** Updates statistics in the model. */
private void updateModelStatistics(Model model) {
assert model != null;

String rating = this.rating.toString();
assert rating.equals("good") || rating.equals("hard") || rating.equals("easy");
if (rating.equals("good")) {

switch (rating) {
case "good":
model.editStats(0);
} else if (rating.equals("hard")) {
break;
case "hard":
model.editStats(1);
} else { // rating.equals("easy")
break;
case "easy":
model.editStats(2);
break;
default:
// should not reach this stage
}
}

/** Updates the rating of a flashcard. */
private void updateFlashCardRating(Model model) {
assert model != null;

FlashCard flashCardToUpdate = model.getCurrentTestFlashCard();
assert flashCardToUpdate != null;

model.setFlashCard(flashCardToUpdate, createUpdatedFlashCard(flashCardToUpdate));
}

/** Creates a new immutable flashcard with the updated rating. */
private FlashCard createUpdatedFlashCard(FlashCard flashCardToUpdate) {
assert flashCardToUpdate != null;

return new FlashCard(flashCardToUpdate.getQuestion(),
flashCardToUpdate.getAnswer(),
rating, flashCardToUpdate.getCategories());
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,21 +14,24 @@ public class ShowAnswerCommand extends Command {
public static final String COMMAND_WORD = "ans";
public static final String ERROR_MESSAGE = "Answer has already been displayed!\n"
+ "Next available command: rate, end";
private static final String MESSAGE_SHOW_ANSWER_SUCCESS = "Answer displayed! "
+ "Please rate the FlashCard easy/good/hard.";

private final KeyboardFlashCardsParser keyboardFlashCardsParser;

public ShowAnswerCommand(KeyboardFlashCardsParser keyboardFlashCardsParser) {
requireNonNull(keyboardFlashCardsParser);

this.keyboardFlashCardsParser = keyboardFlashCardsParser;
}

@Override
public CommandResult execute(Model model) {
requireNonNull(model);
model.showAnswer();

model.showAnswer();
keyboardFlashCardsParser.setAwaitingAnswer(false);
return new CommandResult("To be change: better feedback message");
return new CommandResult(MESSAGE_SHOW_ANSWER_SUCCESS);
}

@Override
Expand Down
29 changes: 21 additions & 8 deletions src/main/java/seedu/address/logic/commands/StartCommand.java
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,8 @@
import java.util.Arrays;
import java.util.LinkedList;
import java.util.List;
import java.util.logging.Level;
import java.util.logging.Logger;

import seedu.address.logic.parser.KeyboardFlashCardsParser;
import seedu.address.model.Model;
Expand All @@ -13,21 +15,24 @@

//@@author keiteo
/**
* Starts the flashcard test by going through the cards in the specified deck.
* If no deck name is supplied, a random deck will be chosen.
* Instantiates a StartCommand to allow users to start the flashcard test
* by going through the cards in the specified tag(s).
* If no tags are supplied, all FlashCards will be used.
*/
public class StartCommand extends Command {

public static final String COMMAND_WORD = "start";

public static final String MESSAGE_USAGE = COMMAND_WORD
+ ": Starts the FlashCard test by going through the cards in the specified deck.\n"
+ "Parameters: DECK NAME. If no argument is supplied, a random deck will be chosen.\n"
+ "Parameters: tag(s). If no argument is supplied, all FlashCards will be used.\n"
+ "Example: " + COMMAND_WORD + " physics";

public static final String MESSAGE_NO_FLASHCARDS = "No FlashCard to test!";
public static final String MESSAGE_NO_FLASHCARDS = "No FlashCards to test!";

public static final String MESSAGE_START_TEST_SUCCESS = "Starting test...\n";
private static final String MESSAGE_START_TEST_SUCCESS = "Starting test...";

private static Logger logger = Logger.getLogger("Foo");

private final KeyboardFlashCardsParser keyboardFlashCardsParser;

Expand All @@ -37,25 +42,31 @@ public StartCommand(KeyboardFlashCardsParser keyboardFlashCardsParser, String ta
requireNonNull(keyboardFlashCardsParser);
this.keyboardFlashCardsParser = keyboardFlashCardsParser;
this.tagName = tagName;
logger.log(Level.INFO, String.format("StartCommand created with the following tags: %s", tagName));
}

@Override
public CommandResult execute(Model model) {
requireNonNull(model);

List<FlashCard> testList = searchTag(model);
model.initializeTestModel(testList);

if (!model.hasTestFlashCard()) {
logger.log(Level.WARNING, String.format("No flashcards found with the following tag(s):\n%s", tagName));
return new CommandResult(MESSAGE_NO_FLASHCARDS);
}

keyboardFlashCardsParser.startTestMode();
model.setTestFlashCard();
//String question = model.getTestQuestion();
keyboardFlashCardsParser.setAwaitingAnswer(true);
logger.log(Level.INFO, "Initialising test mode in ModelManager and KeyboardFlashCardParser");

CommandResult result = new CommandResult(
MESSAGE_START_TEST_SUCCESS,
model.getTestFlashCardPanel());
result.setTestMode(true, false);

return result;

}
Expand All @@ -71,12 +82,14 @@ public boolean equals(Object other) {
/** Searches the list of flashcard to fetch the relevant tags. */
private List<FlashCard> searchTag(Model model) {
assert model != null;

if (tagName.isEmpty()) {
return new LinkedList<>(model.getFlashCardList());
}

CategoryContainsAnyKeywordsPredicate predicate = getSearchTermPredicate();
model.updateFilteredFlashCardList(predicate);
return new LinkedList<>(model.getFilteredFlashCardList());
logger.log(Level.INFO, "Getting a list of flashcards to test");
return new LinkedList<>(model.getFilteredFlashCardListNoCommit(predicate));
}

/** Converts tagName to a CategoryContainsAnyKeywordsPredicate for searchTag(). */
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,8 @@
import static seedu.address.commons.core.Messages.MESSAGE_UNKNOWN_COMMAND;
import static seedu.address.commons.core.Messages.MESSAGE_UNKNOWN_TEST_COMMAND;

import java.util.logging.Level;
import java.util.logging.Logger;
import java.util.regex.Matcher;
import java.util.regex.Pattern;

Expand Down Expand Up @@ -47,6 +49,8 @@ public class KeyboardFlashCardsParser {
private static final Pattern BASIC_COMMAND_FORMAT = Pattern.compile("(?<commandWord>\\S+)(?<arguments>.*)");

//@@author keiteo
private static Logger logger = Logger.getLogger("Foo");

private boolean isRunningFlashcardTest = false;

private boolean isAwaitingAnswer = false;
Expand All @@ -71,20 +75,33 @@ public Command parseCommand(String userInput) throws ParseException {
}

//@@author keiteo

/**
* Sets test mode to be true to disable parsing of non-test commands.
*/
public void startTestMode() {
isRunningFlashcardTest = true;
}

/**
* Sets test mode to be false to enable parsing of non-test commands.
*/
public void endTestMode() {
isRunningFlashcardTest = false;
}

/**
* Sets the answer status in test mode to further restrict inappropriate test commands.
*
* @param isAwaitingAnswer True if the program is waiting for user input to show answer, otherwise false.
*/
public void setAwaitingAnswer(boolean isAwaitingAnswer) {
this.isAwaitingAnswer = isAwaitingAnswer;
}

/** Parses test specific commands. */
private Command parseTestCommand(Matcher matcher) throws ParseException {
logger.log(Level.INFO, "Parsing test command");
final String commandWord = matcher.group("commandWord");
final String arguments = matcher.group("arguments");
switch (commandWord) {
Expand All @@ -110,9 +127,10 @@ private Command parseTestCommand(Matcher matcher) throws ParseException {
}
}

//@@author
//@@author keiteo-reused
/** Parses commands outside test mode i.e. list, add etc. */
private Command parseNormalCommand(Matcher matcher) throws ParseException {
logger.log(Level.INFO, "Parsing normal command");
final String commandWord = matcher.group("commandWord");
final String arguments = matcher.group("arguments");
switch (commandWord) {
Expand Down
Loading

0 comments on commit bf29a7a

Please sign in to comment.