Skip to content

Commit

Permalink
Merge pull request #54 from raydenlim/branch-AddGradedTest
Browse files Browse the repository at this point in the history
branch-AddGradedTest
  • Loading branch information
Respirayson authored Oct 20, 2023
2 parents ff26a6c + 110cb7d commit 4ebe186
Show file tree
Hide file tree
Showing 78 changed files with 3,336 additions and 117 deletions.
28 changes: 26 additions & 2 deletions src/main/java/seedu/address/MainApp.java
Original file line number Diff line number Diff line change
Expand Up @@ -17,10 +17,12 @@
import seedu.address.logic.LogicManager;
import seedu.address.model.AddressBook;
import seedu.address.model.ConsultationListBook;
import seedu.address.model.GradedTestListBook;
import seedu.address.model.Model;
import seedu.address.model.ModelManager;
import seedu.address.model.ReadOnlyAddressBook;
import seedu.address.model.ReadOnlyConsultationList;
import seedu.address.model.ReadOnlyGradedTestList;
import seedu.address.model.ReadOnlySessionList;
import seedu.address.model.ReadOnlyTaskList;
import seedu.address.model.ReadOnlyUserPrefs;
Expand All @@ -30,8 +32,10 @@
import seedu.address.model.util.SampleDataUtil;
import seedu.address.storage.AddressBookStorage;
import seedu.address.storage.ConsultationListStorage;
import seedu.address.storage.GradedTestListStorage;
import seedu.address.storage.JsonAddressBookStorage;
import seedu.address.storage.JsonConsultationListStorage;
import seedu.address.storage.JsonGradedTestListStorage;
import seedu.address.storage.JsonSessionListStorage;
import seedu.address.storage.JsonTaskListStorage;
import seedu.address.storage.JsonUserPrefsStorage;
Expand Down Expand Up @@ -74,8 +78,10 @@ public void init() throws Exception {
SessionListStorage sessionListStorage = new JsonSessionListStorage(userPrefs.getSessionListFilePath());
ConsultationListStorage consultationListStorage = new JsonConsultationListStorage(userPrefs
.getConsultationListFilePath());
GradedTestListStorage gradedTestListStorage =
new JsonGradedTestListStorage(userPrefs.getGradedTestListFilePath());
storage = new StorageManager(addressBookStorage, userPrefsStorage, taskListStorage,
sessionListStorage, consultationListStorage);
sessionListStorage, consultationListStorage, gradedTestListStorage);

model = initModelManager(storage, userPrefs);

Expand All @@ -101,6 +107,10 @@ private Model initModelManager(Storage storage, ReadOnlyUserPrefs userPrefs) {
Optional<ReadOnlyTaskList> taskListOptional;
ReadOnlyTaskList initialTaskList;


Optional<ReadOnlyGradedTestList> gradedTestListOptional;
ReadOnlyGradedTestList initialGradedTestList;

Optional<ReadOnlyConsultationList> consultationListOptional;
ReadOnlyConsultationList initialConsultationList;

Expand Down Expand Up @@ -133,6 +143,19 @@ private Model initModelManager(Storage storage, ReadOnlyUserPrefs userPrefs) {
initialTaskList = new TaskListBook();
}

try {
gradedTestListOptional = storage.readGradedTestList();
if (!gradedTestListOptional.isPresent()) {
logger.info("Creating a new data file " + storage.getTaskListFilePath()
+ " populated with a sample GradedTest.");
}
initialGradedTestList = gradedTestListOptional.orElseGet(SampleDataUtil::getSampleGradedTestList);
} catch (DataLoadingException e) {
logger.warning("Data file at " + storage.getAddressBookFilePath() + " could not be loaded."
+ " Will be starting with an empty AddressBook.");
initialGradedTestList = new GradedTestListBook();
}

try {
consultationListOptional = storage.readConsultationList();
if (!consultationListOptional.isPresent()) {
Expand All @@ -159,7 +182,8 @@ private Model initModelManager(Storage storage, ReadOnlyUserPrefs userPrefs) {
initialSessionList = new SessionListBook();
}

return new ModelManager(initialData, userPrefs, initialTaskList, initialSessionList, initialConsultationList);
return new ModelManager(initialData, userPrefs, initialTaskList, initialSessionList, initialConsultationList,
initialGradedTestList);
}

private void initLogging(Config config) {
Expand Down
17 changes: 16 additions & 1 deletion src/main/java/seedu/address/logic/Messages.java
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@

import seedu.address.logic.parser.Prefix;
import seedu.address.model.consultation.Consultation;
import seedu.address.model.gradedtest.GradedTest;
import seedu.address.model.person.Person;
import seedu.address.model.session.Session;
import seedu.address.model.task.Task;
Expand Down Expand Up @@ -52,6 +53,8 @@ public static String format(Person person) {
.append(person.getAddress())
.append("; Tags: ");
person.getTags().forEach(builder::append);
builder.append("; Graded Tests: ");
person.getGradedTest().forEach(gradedTest -> builder.append(person.getGradedTest()).append(", "));
return builder.toString();
}

Expand Down Expand Up @@ -94,5 +97,17 @@ public static String format(Task task) {
+ task.getPriority();
}


/**
* Formats the {@code gradedTest} for display to the user.
*/
public static String format(GradedTest gradedTest) {
final StringBuilder builder = new StringBuilder();
builder.append("Graded Test:")
.append("; Reading Assessment 1: ").append(gradedTest.getRA1())
.append("; Reading Assessment 2: ").append(gradedTest.getRA2())
.append("; MidTerms: ").append(gradedTest.getMidTerms())
.append("; Final: ").append(gradedTest.getFinals())
.append("; Practical Exam: ").append(gradedTest.getPracticalExam());
return builder.toString();
}
}
5 changes: 4 additions & 1 deletion src/main/java/seedu/address/logic/commands/AddCommand.java
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
import static java.util.Objects.requireNonNull;
import static seedu.address.logic.parser.CliSyntax.PREFIX_ADDRESS;
import static seedu.address.logic.parser.CliSyntax.PREFIX_EMAIL;
import static seedu.address.logic.parser.CliSyntax.PREFIX_GRADED_TEST;
import static seedu.address.logic.parser.CliSyntax.PREFIX_NAME;
import static seedu.address.logic.parser.CliSyntax.PREFIX_PHONE;
import static seedu.address.logic.parser.CliSyntax.PREFIX_TAG;
Expand Down Expand Up @@ -33,7 +34,9 @@ public class AddCommand extends Command {
+ PREFIX_EMAIL + "johnd@example.com "
+ PREFIX_ADDRESS + "311, Clementi Ave 2, #02-25 "
+ PREFIX_TAG + "friends "
+ PREFIX_TAG + "owesMoney";
+ PREFIX_TAG + "owesMoney"
+ PREFIX_GRADED_TEST + "Reading Assessment 1: 0" + "Reading Assessment 2: 0"
+ "MidTerms: 0" + "Finals: 0" + "Practical Exam: 0";

public static final String MESSAGE_SUCCESS = "New person added: %1$s";
public static final String MESSAGE_DUPLICATE_PERSON = "This person already exists in the address book";
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@
import seedu.address.logic.Messages;
import seedu.address.logic.commands.exceptions.CommandException;
import seedu.address.model.Model;
import seedu.address.model.gradedtest.GradedTest;
import seedu.address.model.person.Address;
import seedu.address.model.person.Email;
import seedu.address.model.person.Name;
Expand Down Expand Up @@ -92,9 +93,10 @@ public Person createGradedPerson(Person reference, Grade newGrade) {
Email email = reference.getEmail();
Address address = reference.getAddress();
Set<Tag> tags = reference.getTags();
Set<GradedTest> gradedTest = reference.getGradedTest();
AssignmentMap updatedAssignmentMap =
reference.getAllAssignments().createUpdatedMap(this.assignmentName, newGrade);
return new Person(name, phone, email, address, tags, updatedAssignmentMap);
return new Person(name, phone, email, address, tags, updatedAssignmentMap, gradedTest);
}

@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,6 @@ public AddTaskCommand(Task task) {
this.task = task;
}


@Override
public CommandResult execute(Model model) throws CommandException {
requireNonNull(model);
Expand Down
59 changes: 56 additions & 3 deletions src/main/java/seedu/address/logic/commands/EditCommand.java
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
import static java.util.Objects.requireNonNull;
import static seedu.address.logic.parser.CliSyntax.PREFIX_ADDRESS;
import static seedu.address.logic.parser.CliSyntax.PREFIX_EMAIL;
import static seedu.address.logic.parser.CliSyntax.PREFIX_GRADED_TEST;
import static seedu.address.logic.parser.CliSyntax.PREFIX_NAME;
import static seedu.address.logic.parser.CliSyntax.PREFIX_PHONE;
import static seedu.address.logic.parser.CliSyntax.PREFIX_TAG;
Expand All @@ -21,6 +22,11 @@
import seedu.address.logic.Messages;
import seedu.address.logic.commands.exceptions.CommandException;
import seedu.address.model.Model;
import seedu.address.model.gradedtest.Finals;
import seedu.address.model.gradedtest.GradedTest;
import seedu.address.model.gradedtest.MidTerms;
import seedu.address.model.gradedtest.PracticalExam;
import seedu.address.model.gradedtest.ReadingAssessment;
import seedu.address.model.person.Address;
import seedu.address.model.person.Email;
import seedu.address.model.person.Name;
Expand All @@ -44,6 +50,7 @@ public class EditCommand extends Command {
+ "[" + PREFIX_EMAIL + "EMAIL] "
+ "[" + PREFIX_ADDRESS + "ADDRESS] "
+ "[" + PREFIX_TAG + "TAG]...\n"
+ "[" + PREFIX_GRADED_TEST + "GRADED TEST]...\n"
+ "Example: " + COMMAND_WORD + " 1 "
+ PREFIX_PHONE + "91234567 "
+ PREFIX_EMAIL + "johndoe@example.com";
Expand Down Expand Up @@ -100,8 +107,9 @@ private static Person createEditedPerson(Person personToEdit, EditPersonDescript
Email updatedEmail = editPersonDescriptor.getEmail().orElse(personToEdit.getEmail());
Address updatedAddress = editPersonDescriptor.getAddress().orElse(personToEdit.getAddress());
Set<Tag> updatedTags = editPersonDescriptor.getTags().orElse(personToEdit.getTags());
Set<GradedTest> updatedGrades = editPersonDescriptor.getGradedTests().orElse(personToEdit.getGradedTest());

return new Person(updatedName, updatedPhone, updatedEmail, updatedAddress, updatedTags);
return new Person(updatedName, updatedPhone, updatedEmail, updatedAddress, updatedTags, updatedGrades);
}

@Override
Expand Down Expand Up @@ -137,7 +145,13 @@ public static class EditPersonDescriptor {
private Phone phone;
private Email email;
private Address address;
private ReadingAssessment ra1;
private ReadingAssessment ra2;
private MidTerms midTerms;
private Finals finals;
private PracticalExam pe;
private Set<Tag> tags;
private Set<GradedTest> gradedTests;

public EditPersonDescriptor() {}

Expand All @@ -151,13 +165,14 @@ public EditPersonDescriptor(EditPersonDescriptor toCopy) {
setEmail(toCopy.email);
setAddress(toCopy.address);
setTags(toCopy.tags);
setGradedTest(toCopy.gradedTests);
}

/**
* Returns true if at least one field is edited.
*/
public boolean isAnyFieldEdited() {
return CollectionUtil.isAnyNonNull(name, phone, email, address, tags);
return CollectionUtil.isAnyNonNull(name, phone, email, address, tags, gradedTests);
}

public void setName(Name name) {
Expand Down Expand Up @@ -192,6 +207,25 @@ public Optional<Address> getAddress() {
return Optional.ofNullable(address);
}

public void setReadingAssessment1(ReadingAssessment ra1) {
this.ra1 = ra1;
}

public void setReadingAssessment2(ReadingAssessment ra2) {
this.ra2 = ra2;
}

public void setMidTerms(MidTerms midTerms) {
this.midTerms = midTerms;
}

public void setFinals(Finals finals) {
this.finals = finals;
}
public void setPracticalExam(PracticalExam pe) {
this.pe = pe;
}

/**
* Sets {@code tags} to this object's {@code tags}.
* A defensive copy of {@code tags} is used internally.
Expand All @@ -209,6 +243,23 @@ public Optional<Set<Tag>> getTags() {
return (tags != null) ? Optional.of(Collections.unmodifiableSet(tags)) : Optional.empty();
}

/**
* Sets {@code gradedTests} to this object's {@code gradedTests}.
* A defensive copy of {@code gradedTests} is used internally.
*/
public void setGradedTest(Set<GradedTest> gradedTests) {
this.gradedTests = (gradedTests != null) ? new HashSet<>(gradedTests) : null;
}

/**
* Returns an unmodifiable gradedTest set, which throws {@code UnsupportedOperationException}
* if modification is attempted.
* Returns {@code Optional#empty()} if {@code gradedTest} is null.
*/
public Optional<Set<GradedTest>> getGradedTests() {
return (gradedTests != null) ? Optional.of(Collections.unmodifiableSet(gradedTests)) : Optional.empty();
}

@Override
public boolean equals(Object other) {
if (other == this) {
Expand All @@ -225,7 +276,8 @@ public boolean equals(Object other) {
&& Objects.equals(phone, otherEditPersonDescriptor.phone)
&& Objects.equals(email, otherEditPersonDescriptor.email)
&& Objects.equals(address, otherEditPersonDescriptor.address)
&& Objects.equals(tags, otherEditPersonDescriptor.tags);
&& Objects.equals(tags, otherEditPersonDescriptor.tags)
&& Objects.equals(gradedTests, otherEditPersonDescriptor.gradedTests);
}

@Override
Expand All @@ -236,6 +288,7 @@ public String toString() {
.add("email", email)
.add("address", address)
.add("tags", tags)
.add("gradedTests", gradedTests)
.toString();
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
import static seedu.address.logic.Messages.MESSAGE_INVALID_COMMAND_FORMAT;
import static seedu.address.logic.parser.CliSyntax.PREFIX_ADDRESS;
import static seedu.address.logic.parser.CliSyntax.PREFIX_EMAIL;
import static seedu.address.logic.parser.CliSyntax.PREFIX_GRADED_TEST;
import static seedu.address.logic.parser.CliSyntax.PREFIX_NAME;
import static seedu.address.logic.parser.CliSyntax.PREFIX_PHONE;
import static seedu.address.logic.parser.CliSyntax.PREFIX_TAG;
Expand All @@ -13,6 +14,7 @@

import seedu.address.logic.commands.AddCommand;
import seedu.address.logic.parser.exceptions.ParseException;
import seedu.address.model.gradedtest.GradedTest;
import seedu.address.model.person.Address;
import seedu.address.model.person.Email;
import seedu.address.model.person.Name;
Expand All @@ -33,7 +35,8 @@ public class AddCommandParser implements Parser<AddCommand> {
*/
public AddCommand parse(String args) throws ParseException {
ArgumentMultimap argMultimap =
ArgumentTokenizer.tokenize(args, PREFIX_NAME, PREFIX_PHONE, PREFIX_EMAIL, PREFIX_ADDRESS, PREFIX_TAG);
ArgumentTokenizer.tokenize(args, PREFIX_NAME, PREFIX_PHONE, PREFIX_EMAIL,
PREFIX_ADDRESS, PREFIX_TAG, PREFIX_GRADED_TEST);

if (!arePrefixesPresent(argMultimap, PREFIX_NAME, PREFIX_ADDRESS, PREFIX_PHONE, PREFIX_EMAIL)
|| !argMultimap.getPreamble().isEmpty()) {
Expand All @@ -47,7 +50,9 @@ public AddCommand parse(String args) throws ParseException {
Address address = ParserUtil.parseAddress(argMultimap.getValue(PREFIX_ADDRESS).get());
Set<Tag> tagList = ParserUtil.parseTags(argMultimap.getAllValues(PREFIX_TAG));
Set<Session> sessionList = new HashSet<>();
Person person = new Person(name, phone, email, address, tagList);
Set<GradedTest> gradedTestList = ParserUtil.parseGradedTests(argMultimap.getAllValues(PREFIX_GRADED_TEST));

Person person = new Person(name, phone, email, address, tagList, gradedTestList);

return new AddCommand(person);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -82,6 +82,7 @@ public Command parseCommand(String userInput) throws ParseException {
case AddTaskCommand.COMMAND_WORD:
return new AddTaskCommandParser().parse(arguments);


case DeleteTaskCommand.COMMAND_WORD:
return new DeleteTaskCommandParser().parse(arguments);

Expand Down
5 changes: 5 additions & 0 deletions src/main/java/seedu/address/logic/parser/CliSyntax.java
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,11 @@ public class CliSyntax {
public static final Prefix PREFIX_EMAIL = new Prefix("e/");
public static final Prefix PREFIX_ADDRESS = new Prefix("a/");
public static final Prefix PREFIX_TAG = new Prefix("t/");
public static final Prefix PREFIX_GRADED_TEST = new Prefix("gt/");
public static final Prefix PREFIX_READING_ASSESSMENT = new Prefix("gt/ra/");
public static final Prefix PREFIX_MIDTERMS = new Prefix("gt/m/");
public static final Prefix PREFIX_FINALS = new Prefix("gt/f/");
public static final Prefix PREFIX_PRACTICAL_EXAM = new Prefix("gt/pe/");
public static final Prefix PREFIX_ASSIGNMENT = new Prefix("as/");
public static final Prefix PREFIX_GRADE = new Prefix("g/");
public static final Prefix PREFIX_DATE = new Prefix("d/");
Expand Down
Loading

0 comments on commit 4ebe186

Please sign in to comment.