-
Notifications
You must be signed in to change notification settings - Fork 5
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
Bad FlashCards/ Deadline - v1.3 #150
Changes from all commits
aea8835
b91cc3b
354d800
03c3f50
a2fcbae
e4b07b7
fc05aa1
106ae54
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
This file was deleted.
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,78 @@ | ||
//@@author: dalsontws | ||
|
||
package seedu.address.logic.commands; | ||
|
||
import static java.util.Objects.requireNonNull; | ||
|
||
import java.util.List; | ||
|
||
import seedu.address.commons.core.Messages; | ||
import seedu.address.commons.core.index.Index; | ||
|
||
import seedu.address.logic.commands.exceptions.CommandException; | ||
import seedu.address.model.Model; | ||
import seedu.address.model.deadline.BadQuestions; | ||
import seedu.address.model.deadline.Deadline; | ||
import seedu.address.model.deadline.DueDate; | ||
import seedu.address.model.deadline.Task; | ||
import seedu.address.model.deadline.exceptions.DuplicateDeadlineException; | ||
import seedu.address.model.flashcard.FlashCard; | ||
import seedu.address.model.flashcard.Question; | ||
|
||
/** | ||
* Set certain FlashCards as 'Bad' | ||
* This will then add these set of flashcards into a certain Deadline | ||
*/ | ||
public class BadCommand extends Command { | ||
|
||
public static final String COMMAND_WORD = "bad"; | ||
|
||
public static final String MESSAGE_USAGE = COMMAND_WORD | ||
+ ": Sets a specific flashCard identified by the\n " | ||
+ "index number used in the displayed flashCard list.\n" | ||
+ "as a 'Bad' flashcard that will require re-test.\n" | ||
+ "Parameters: INDEX (must be a positive integer)\n" | ||
+ "Example: " + COMMAND_WORD + " 1"; | ||
|
||
public static final String MESSAGE_SUCCESS = "Flashcard has been added into Deadlines!"; | ||
public static final String DUPLICATE_DEADLINE = "Flashcard has been added into an existing deadline!"; | ||
|
||
private final Index index; | ||
|
||
public BadCommand(Index index) { | ||
requireNonNull(index); | ||
this.index = index; | ||
} | ||
|
||
@Override | ||
public CommandResult execute(Model model) throws CommandException { | ||
requireNonNull(model); | ||
List<FlashCard> lastShownList = model.getFilteredFlashCardList(); | ||
if (index.getZeroBased() >= lastShownList.size()) { | ||
throw new CommandException(Messages.MESSAGE_INVALID_FLASHCARD_DISPLAYED_INDEX); | ||
} | ||
|
||
FlashCard badFlashcard = lastShownList.get(index.getZeroBased()); | ||
|
||
Task task = new Task("To Do: Bad Questions"); | ||
DueDate d = BadQuestions.getBadDeadline(); | ||
Deadline deadline = new Deadline(task, d); | ||
|
||
//TODO: add questions and due date into filtered bad flashcards list | ||
Question q = badFlashcard.getQuestion(); | ||
|
||
BadQuestions badQuestions = new BadQuestions(); | ||
|
||
badQuestions.addBadQuestion(d, q); | ||
|
||
badQuestions.saveAsJson(badQuestions); | ||
|
||
try { | ||
model.addDeadline(deadline); | ||
} catch (DuplicateDeadlineException e) { | ||
return new CommandResult(DUPLICATE_DEADLINE); | ||
} | ||
|
||
return new CommandResult(MESSAGE_SUCCESS); | ||
} | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,31 @@ | ||
//@@author dalsontws | ||
|
||
package seedu.address.logic.parser; | ||
|
||
import static seedu.address.commons.core.Messages.MESSAGE_INVALID_COMMAND_FORMAT; | ||
|
||
import seedu.address.commons.core.index.Index; | ||
import seedu.address.logic.commands.BadCommand; | ||
import seedu.address.logic.parser.exceptions.ParseException; | ||
|
||
/** | ||
* Parses input arguments and creates a new DeleteCommand object | ||
*/ | ||
public class BadCommandParser implements Parser<BadCommand> { | ||
|
||
/** | ||
* Parses the given {@code String} of arguments in the context of the DeleteCommand | ||
* and returns a DeleteCommand object for execution. | ||
* @throws ParseException if the user input does not conform the expected format | ||
*/ | ||
public BadCommand parse(String args) throws ParseException { | ||
try { | ||
Index index = ParserUtil.parseIndex(args); | ||
return new BadCommand(index); | ||
} catch (ParseException pe) { | ||
throw new ParseException( | ||
String.format(MESSAGE_INVALID_COMMAND_FORMAT, BadCommand.MESSAGE_USAGE), pe); | ||
} | ||
} | ||
|
||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,79 @@ | ||
//@@author dalsontws | ||
|
||
package seedu.address.model.deadline; | ||
|
||
import java.io.FileNotFoundException; | ||
import java.io.FileWriter; | ||
import java.io.IOException; | ||
import java.time.LocalDate; | ||
import java.time.format.DateTimeFormatter; | ||
import java.util.HashMap; | ||
|
||
import com.google.gson.Gson; | ||
|
||
import seedu.address.model.Model; | ||
import seedu.address.model.flashcard.Question; | ||
|
||
/** | ||
* BadQuestions class. | ||
* Contains a Hashmap with questions that are rated as 'bad' | ||
* Each Question will be tagged to a specific DueDate, which will be referred to | ||
* in the list of Deadlines | ||
*/ | ||
public class BadQuestions { | ||
|
||
private HashMap<String, String> internalMap = new HashMap<String, String>(); | ||
//private JsonBadDeadlines jsonBadDeadlines; | ||
|
||
public BadQuestions() { | ||
//TODO: add initialisation of bad deadline list - load json | ||
} | ||
|
||
public HashMap<String, String> getBadQuestionsList() { | ||
return internalMap; | ||
} | ||
|
||
public void setBadQuestionsList(HashMap<String, String> map) { | ||
internalMap = map; | ||
} | ||
|
||
public void addBadQuestion(DueDate d, Question q) { | ||
internalMap.put(d.toString(), q.toString()); | ||
} | ||
|
||
public void loadBadQuestions() throws FileNotFoundException { | ||
//internalMap = jsonBadDeadlines.loadJsonBadDeadlines(); | ||
} | ||
|
||
public static DueDate getBadDeadline() { | ||
LocalDate today = LocalDate.now(); | ||
LocalDate due = today.plusDays(3); | ||
String formattedDate = due.format(DateTimeFormatter.ofPattern("dd/MM/yyyy")); | ||
DueDate d = new DueDate(formattedDate); | ||
return d; | ||
} | ||
|
||
public void setBadQuestionsAsDeadline(Model model) { | ||
Task task = new Task("Bad Questions"); | ||
Deadline deadline = new Deadline(task, getBadDeadline()); | ||
model.addDeadline(deadline); | ||
} | ||
|
||
/** | ||
* Using Google's Gson library, save HashMap as a JSON Object and store it | ||
* in BadQuestions.json. This can later be used to fetch the 'bad' questions | ||
* to test in a future date. | ||
*/ | ||
public void saveAsJson(BadQuestions badQuestions) { | ||
Gson gson = new Gson(); | ||
String json = gson.toJson(badQuestions.getBadQuestionsList()); | ||
try { | ||
//TODO: fix load and save json, json save replace file instead of appending | ||
FileWriter writer = new FileWriter("data/BadDeadlines.json", true); | ||
writer.write(json); | ||
writer.close(); | ||
} catch (IOException e) { | ||
e.printStackTrace(); | ||
} | ||
} | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -59,5 +59,4 @@ public String toString() { | |
public int hashCode() { | ||
return dateStr.hashCode(); | ||
} | ||
|
||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -30,6 +30,9 @@ public DeadlinePanel(Deadline deadline, int displayedIndex) { | |
this.deadline = deadline; | ||
id.setText(displayedIndex + ". "); | ||
task.setText(deadline.getTask().toString()); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. You can change the task from label to Textflow so that the text will not be concatenated and you can change the color of the text. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Nice, thanks! |
||
//TODO: use date to colour code each deadline | ||
//LocalDate today = LocalDate.now(); | ||
//deadline.getDueDate(); | ||
dueDate.setText("Due Date: " + deadline.getDueDate().toString()); | ||
} | ||
|
||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,63 @@ | ||
package seedu.address.logic.commands; | ||
|
||
import static org.junit.jupiter.api.Assertions.assertFalse; | ||
import static org.junit.jupiter.api.Assertions.assertTrue; | ||
import static seedu.address.testutil.Assert.assertThrows; | ||
|
||
import org.junit.jupiter.api.Test; | ||
|
||
import seedu.address.model.deadline.Deadline; | ||
import seedu.address.testutil.DeadlineBuilder; | ||
|
||
public class DeadlineCommandTest { | ||
|
||
@Test | ||
public void constructor_nullDeadline_throwsNullPointerException() { | ||
assertThrows(NullPointerException.class, () -> new DeadlineCommand(null)); | ||
} | ||
|
||
@Test | ||
public void equals() { | ||
Deadline test = new DeadlineBuilder().withTask("Test").build(); | ||
Deadline exam = new DeadlineBuilder().withTask("Exam").build(); | ||
DeadlineCommand addTestCommand = new DeadlineCommand(test); | ||
DeadlineCommand addExamCommand = new DeadlineCommand(exam); | ||
|
||
// same object -> returns true | ||
assertTrue(addTestCommand.equals(addTestCommand)); | ||
|
||
// same values -> returns true | ||
DeadlineCommand addTestCommandCopy = new DeadlineCommand(test); | ||
assertTrue(addTestCommand.equals(addTestCommandCopy)); | ||
|
||
// different types -> returns false | ||
assertFalse(addTestCommand.equals(1)); | ||
|
||
// null -> returns false | ||
assertFalse(addTestCommand.equals(null)); | ||
|
||
// different flashCard -> returns false | ||
assertFalse(addTestCommand.equals(addExamCommand)); | ||
|
||
//same question different answer | ||
Deadline testCopy = new DeadlineBuilder(test).withDueDate("22/12/2019").build(); | ||
addTestCommandCopy = new DeadlineCommand(testCopy); | ||
assertFalse(addTestCommandCopy.equals(testCopy)); | ||
} | ||
|
||
@Test | ||
public void toStringTest() { | ||
Deadline validDeadline = new DeadlineBuilder().build(); | ||
DeadlineCommand deadlineCommand = new DeadlineCommand(validDeadline); | ||
//same object | ||
assertTrue(deadlineCommand.toString().equals(deadlineCommand.toString())); | ||
|
||
//same value | ||
DeadlineCommand deadlineCommandCopy = new DeadlineCommand(validDeadline); | ||
assertTrue(deadlineCommand.toString().equals(deadlineCommandCopy.toString())); | ||
|
||
//same question diff answer | ||
deadlineCommandCopy = new DeadlineCommand(new DeadlineBuilder(validDeadline).withDueDate("10/10/2019").build()); | ||
assertFalse(deadlineCommand.toString().equals(deadlineCommandCopy.toString())); | ||
} | ||
} |
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.
Consider SLAPing it