Skip to content

Commit

Permalink
Implement graded component commands and GUI representation (#142)
Browse files Browse the repository at this point in the history
* Incorporate GradedComponents into AddCommand

* Add remove and update grades commands

* Add scoring for gradedComponents

* Implement score command and GUI representation
  • Loading branch information
rssujay authored Oct 31, 2019
1 parent 84a689d commit 34dcb08
Show file tree
Hide file tree
Showing 15 changed files with 282 additions and 11 deletions.
2 changes: 1 addition & 1 deletion src/main/Resources/view/itemBoxes/FileBox.fxml
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@

<fx:root maxHeight="-Infinity" maxWidth="1.7976931348623157E308" prefHeight="110.0" prefWidth="403.0" type="javafx.scene.layout.VBox" xmlns="http://javafx.com/javafx/11.0.1" xmlns:fx="http://javafx.com/fxml/1">
<children>
<Label fx:id="fileDetails" layoutX="16.0" layoutY="70.0" prefHeight="34.0" prefWidth="73.0" textAlignment="CENTER" wrapText="true" />
<Label fx:id="fileDetails" layoutX="16.0" layoutY="70.0" prefHeight="34.0" prefWidth="200.0" textAlignment="CENTER" wrapText="true" />
<Line endX="302.0" layoutX="101.0" layoutY="110.0" startX="-100.0" />
</children>
</fx:root>
11 changes: 11 additions & 0 deletions src/main/Resources/view/itemBoxes/GradedComponentBox.fxml
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
<?xml version="1.0" encoding="UTF-8"?>

<?import javafx.scene.control.Label?>
<?import javafx.scene.shape.Line?>

<fx:root maxHeight="-Infinity" maxWidth="1.7976931348623157E308" prefHeight="110.0" prefWidth="403.0" type="javafx.scene.layout.VBox" xmlns="http://javafx.com/javafx/11.0.1" xmlns:fx="http://javafx.com/fxml/1">
<children>
<Label fx:id="gradedComponentDetails" layoutX="16.0" layoutY="70.0" prefHeight="34.0" prefWidth="200.0" textAlignment="CENTER" wrapText="true" />
<Line endX="302.0" layoutX="101.0" layoutY="110.0" startX="-100.0" />
</children>
</fx:root>
4 changes: 4 additions & 0 deletions src/main/java/spinbox/Parser.java
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
import spinbox.commands.RemoveCommand;
import spinbox.commands.RemoveMultipleCommand;
import spinbox.commands.SetDateCommand;
import spinbox.commands.ScoreCommand;
import spinbox.commands.SetNameCommand;
import spinbox.commands.UpdateCommand;
import spinbox.commands.UpdateMultipleCommand;
Expand Down Expand Up @@ -138,6 +139,9 @@ public static Command parse(String input) throws SpinBoxException {
case "update-*":
command = new UpdateMultipleCommand(pageDataComponents, content);
break;
case "score":
command = new ScoreCommand(pageDataComponents, content);
break;
case "find":
command = new FindCommand(pageDataComponents, content);
break;
Expand Down
39 changes: 39 additions & 0 deletions src/main/java/spinbox/commands/AddCommand.java
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,10 @@
import spinbox.containers.ModuleContainer;
import spinbox.containers.lists.FileList;
import spinbox.containers.Notepad;
import spinbox.containers.lists.GradeList;
import spinbox.entities.items.File;
import spinbox.entities.Module;
import spinbox.entities.items.GradedComponent;
import spinbox.exceptions.SpinBoxException;
import spinbox.exceptions.InputException;
import spinbox.Ui;
Expand Down Expand Up @@ -37,6 +39,8 @@ public class AddCommand extends Command {
+ "the full command for adding notes:\n";
private static final String TODO_ERROR_MESSAGE = "Please ensure that you enter "
+ "the full command for adding todo:\n";
private static final String GRADED_COMPONENT_ERROR_MESSAGE = "Please ensure that you enter "
+ "the full command for adding graded components:\n";
private static final String DEADLINE_ERROR_MESSAGE = "Please ensure that you enter "
+ "the full command for adding deadlines:\n";
private static final String EVENT_ERROR_MESSAGE = "Please ensure that you enter "
Expand All @@ -45,13 +49,15 @@ public class AddCommand extends Command {
+ "the full command for adding modules:\n";
private static final String FILE_FORMAT = "add <moduleCode> / file <fileName>";
private static final String NOTE_FORMAT = "add <moduleCode> / note <fileName>";
private static final String GRADED_COMP_FORMAT = "add <moduleCode> / grade <componentName> weightage: <weightage>%";
private static final String TODO_FORMAT = "add <moduleCode> / todo <fileName>";
private static final String DEADLINE_FORMAT = "add <moduleCode> / deadline <taskName> by: <MM/DD/YYYY HH:MM>";
private static final String EVENT_FORMAT = "add <moduleCode> / <eventType> <taskName> at: "
+ "<start as MM/DD/YYYY HH:MM> to <end as MM/DD/YYYY HH:MM>";
private static final String MODULE_FORMAT = "add / module <moduleCode> <moduleName>";
private static final String EMPTY_TODO_DESCRIPTION = "☹ OOPS!!! The description of a task cannot be empty.";
private static final String EMPTY_DEADLINE_DESCRIPTION = "☹ OOPS!!! The description of a deadline cannot be empty.";
private static final String EMPTY_GRADE_DESCRIPTION = "☹ OOPS!!! The description of a component cannot be empty.";
private static final String EMPTY_EVENT_DESCRIPTION = "☹ OOPS!!! The description of an event cannot be empty.";
private static final String EMPTY_EXAM_DESCRIPTION = "☹ OOPS!!! The description of an exam cannot be empty.";
private static final String EMPTY_LAB_DESCRIPTION = "☹ OOPS!!! The description of a lab session cannot be empty.";
Expand Down Expand Up @@ -80,6 +86,7 @@ public AddCommand(String[] pageDataComponents, String content) throws InputExcep
public String execute(ModuleContainer moduleContainer, ArrayDeque<String> pageTrace, Ui ui, boolean guiMode) throws
SpinBoxException {
File fileAdded;
GradedComponent gradedComponentAdded;
Task taskAdded;
DateTime start;
DateTime end;
Expand Down Expand Up @@ -121,6 +128,38 @@ public String execute(ModuleContainer moduleContainer, ArrayDeque<String> pageTr
throw new InputException(NOTE_ERROR_MESSAGE + NOTE_FORMAT);
}

case "grade":
try {
checkIfOnModulePage(moduleCode);
if (moduleContainer.checkModuleExists(moduleCode)) {
HashMap<String, Module> modules = moduleContainer.getModules();
Module module = modules.get(moduleCode);
GradeList gradeList = module.getGrades();
String gradedComponentDetails = content.replace(type, "").trim();
gradedComponentDetails = gradedComponentDetails.replace("%", "");

String gradedComponentName = gradedComponentDetails.substring(0,
gradedComponentDetails.lastIndexOf(" weightage:"));

double weightage = Double.parseDouble(gradedComponentDetails.split("weightage: ")[1]);

if (gradedComponentDetails.split(" ")[0].equals("weightage:")) {
throw new InputException(EMPTY_GRADE_DESCRIPTION);
}

gradedComponentAdded = gradeList.add(new GradedComponent(gradedComponentName, weightage));

return HORIZONTAL_LINE + "\nAdded into " + module.toString() + " grades: "
+ gradedComponentAdded.toString() + "\n You currently have " + gradeList.size()
+ ((gradeList.size() == 1) ? " graded component in the list." : " graded components"
+ " in the list.") + "\n" + HORIZONTAL_LINE;
} else {
return NON_EXISTENT_MODULE;
}
} catch (IndexOutOfBoundsException e) {
throw new InputException(GRADED_COMPONENT_ERROR_MESSAGE + GRADED_COMP_FORMAT);
}

case "todo":
try {
checkIfOnModulePage(moduleCode);
Expand Down
27 changes: 27 additions & 0 deletions src/main/java/spinbox/commands/RemoveCommand.java
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,12 @@

import spinbox.containers.ModuleContainer;
import spinbox.containers.lists.FileList;
import spinbox.containers.lists.GradeList;
import spinbox.containers.lists.TaskList;
import spinbox.containers.Notepad;
import spinbox.entities.items.File;
import spinbox.entities.Module;
import spinbox.entities.items.GradedComponent;
import spinbox.entities.items.tasks.Task;
import spinbox.exceptions.SpinBoxException;
import spinbox.exceptions.InputException;
Expand Down Expand Up @@ -86,6 +88,31 @@ public String execute(ModuleContainer moduleContainer, ArrayDeque<String> pageTr
return NON_EXISTENT_MODULE;
}

case "grade":
checkIfOnModulePage(moduleCode);
if (moduleContainer.checkModuleExists(moduleCode)) {
try {
HashMap<String, Module> modules = moduleContainer.getModules();
Module module = modules.get(moduleCode);
GradeList gradeList = module.getGrades();
int index = Integer.parseInt(content.split(" ")[1]) - 1;
GradedComponent removedComponent = gradeList.get(index);
gradeList.remove(index);

return HORIZONTAL_LINE + "\nRemoved task: " + removedComponent.toString() + "\n"
+ "You currently have " + gradeList.size()
+ ((gradeList.size() == 1) ? " graded component in the list."
: " graded components in the list.") + "\n"
+ HORIZONTAL_LINE;
} catch (NumberFormatException e) {
throw new InputException(INVALID_INDEX);
} catch (IndexOutOfBoundsException e) {
throw new InputException(PROVIDE_INDEX);
}
} else {
return NON_EXISTENT_MODULE;
}

case "task":
checkIfOnModulePage(moduleCode);
if (moduleContainer.checkModuleExists(moduleCode)) {
Expand Down
76 changes: 76 additions & 0 deletions src/main/java/spinbox/commands/ScoreCommand.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,76 @@
package spinbox.commands;

import spinbox.Ui;
import spinbox.containers.ModuleContainer;
import spinbox.containers.lists.GradeList;
import spinbox.entities.Module;
import spinbox.entities.items.GradedComponent;
import spinbox.exceptions.InputException;
import spinbox.exceptions.SpinBoxException;

import java.util.ArrayDeque;
import java.util.HashMap;

public class ScoreCommand extends Command {
private static final String HORIZONTAL_LINE = "____________________________________________________________";
private static final String NON_EXISTENT_MODULE = "This module does not exist.";
private static final String INVALID_FORMAT = "Please use the valid score format:\n"
+ "Absolute percentage: [score <moduleCode> / <index> marks:<attained>%]" + "\n"
+ "Relative percentage: [score <moduleCode> / <index> marks: <attained>/<maximum>";
private static final String INVALID_VALUE = "PLease enter valid numerical value(s).";
private static final String PROVIDE_INDEX = "Please provide a valid index of the graded component to be scored.";
private static final String COMPONENT_SCORED = "The following component has been scored: ";

private String moduleCode;
private String content;

/**
* Constructor for initialization of variables to support scoring of graded components.
* @param pageDataComponents page data components to provide context based input completion.
* @param content A string containing the content of the processed user input.
*/
public ScoreCommand(String[] pageDataComponents, String content) {
if (pageDataComponents.length > 1) {
this.moduleCode = pageDataComponents[1];
}
this.content = content;
}


@Override
public String execute(ModuleContainer moduleContainer, ArrayDeque<String> pageTrace, Ui ui, boolean guiMode)
throws SpinBoxException {
checkIfOnModulePage(moduleCode);
if (moduleContainer.checkModuleExists(moduleCode)) {
try {
HashMap<String, Module> modules = moduleContainer.getModules();
Module module = modules.get(moduleCode);
GradeList gradeList = module.getGrades();

String[] scoreComponents = this.content.split(" marks:");
int index = Integer.parseInt(content.split(" ")[0]) - 1;
String[] scores = scoreComponents[1].split("/");

if (scoreComponents[1].contains("%")) {
scoreComponents[1] = scoreComponents[1].replace("%", "");
double attainedPercentage = Double.parseDouble(scoreComponents[1]);
gradeList.updateGradeWeightedScore(index, attainedPercentage);
} else if (scores.length == 2) {
double attainedScore = Double.parseDouble(scores[0]);
double maximumScore = Double.parseDouble(scores[1]);
gradeList.updateGradeWeightedScore(index, attainedScore, maximumScore);
} else {
throw new InputException(INVALID_FORMAT);
}
return HORIZONTAL_LINE + "\n" + COMPONENT_SCORED + "\n"
+ gradeList.get(index).toString() + "\n" + HORIZONTAL_LINE;
} catch (NumberFormatException e) {
throw new InputException(INVALID_VALUE);
} catch (IndexOutOfBoundsException e) {
throw new InputException(INVALID_FORMAT);
}
} else {
return NON_EXISTENT_MODULE;
}
}
}
31 changes: 31 additions & 0 deletions src/main/java/spinbox/commands/UpdateCommand.java
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,11 @@

import spinbox.containers.ModuleContainer;
import spinbox.containers.lists.FileList;
import spinbox.containers.lists.GradeList;
import spinbox.containers.lists.TaskList;
import spinbox.entities.items.File;
import spinbox.entities.Module;
import spinbox.entities.items.GradedComponent;
import spinbox.entities.items.tasks.Task;
import spinbox.exceptions.SpinBoxException;
import spinbox.exceptions.InputException;
Expand All @@ -17,6 +19,7 @@ public class UpdateCommand extends Command {
private static final String HORIZONTAL_LINE = "____________________________________________________________";
private static final String NON_EXISTENT_MODULE = "This module does not exist.";
private static final String FILE_MARKED = "Updated file: ";
private static final String GRADE_MARKED = "Updated graded component: ";
private static final String TASK_MARKED = "Updated task: ";
private static final String PROVIDE_INDEX = "Please provide an index of item to be updated.";
private static final String INVALID_MARK_FORMAT = "Please use the valid update format:\n"
Expand Down Expand Up @@ -73,6 +76,34 @@ public String execute(ModuleContainer moduleContainer, ArrayDeque<String> pageTr
return NON_EXISTENT_MODULE;
}

case "grade":
checkIfOnModulePage(moduleCode);
if (moduleContainer.checkModuleExists(moduleCode)) {
try {
HashMap<String, Module> modules = moduleContainer.getModules();
Module module = modules.get(moduleCode);
GradeList gradeList = module.getGrades();

int index = Integer.parseInt(content.split(" ")[1]) - 1;
GradedComponent gradeMarked = gradeList.get(index);
String[] contentComponents = content.split(" ");
if (contentComponents[2].toLowerCase().equals("true")) {
gradeList.update(index, true);
} else if (contentComponents[2].toLowerCase().equals("false")) {
gradeList.update(index, false);
} else {
throw new InputException(INVALID_VALUE);
}
return HORIZONTAL_LINE + "\n" + GRADE_MARKED + gradeMarked.toString() + "\n" + HORIZONTAL_LINE;
} catch (NumberFormatException e) {
throw new InputException(INVALID_INDEX);
} catch (IndexOutOfBoundsException e) {
throw new InputException(PROVIDE_INDEX);
}
} else {
return NON_EXISTENT_MODULE;
}

case "task":
checkIfOnModulePage(moduleCode);
if (moduleContainer.checkModuleExists(moduleCode)) {
Expand Down
12 changes: 12 additions & 0 deletions src/main/java/spinbox/containers/lists/GradeList.java
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
package spinbox.containers.lists;

import spinbox.exceptions.InputException;
import spinbox.storage.Storage;
import spinbox.exceptions.CorruptedDataException;
import spinbox.exceptions.DataReadWriteException;
Expand Down Expand Up @@ -80,4 +81,15 @@ public List<String> containsKeyword(String keyword) {

return output;
}

public void updateGradeWeightedScore(int index, double yourScore, double maximumScore) throws InputException,
DataReadWriteException {
list.get(index).updateWeightedScore(yourScore, maximumScore);
this.saveData();
}

public void updateGradeWeightedScore(int index, double weightedScore) throws DataReadWriteException {
list.get(index).updateWeightedScore(weightedScore);
this.saveData();
}
}
4 changes: 2 additions & 2 deletions src/main/java/spinbox/containers/lists/HelpList.java
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ public class HelpList {
+ "\t* Adding an item for a specific module (omit module code if current page is the specific module "
+ "page) *\n"
+ "\t2. Add a new file under module CG1111: add CG1111 / file quiz 2 2018\n"
+ "\t3. Add a new grade component under CG1111: add CG1111 / grade Report : 12.5%\n"
+ "\t3. Add a new grade component under CG1111: add CG1111 / grade Report weightage: 12.5%\n"
+ "\t4. Add a new note under CG1111: add CG1111 / note bring textbook\n"
+ "\t5. Add a new todo task under module CG1111: add CG1111 / todo finish assignment\n"
+ "\t -List of task type includes:\n"
Expand Down Expand Up @@ -109,7 +109,7 @@ public class HelpList {
+ "Example:\n"
+ "\t* Note: omit module code if current page is the specific module *\n"
+ "\t1. Update a file to downloaded under module CG1111: update CG1111 / file 1 true\n"
+ "\t2. Update a grade component under CG1111: TBC\n"
+ "\t2. Update a grade component under CG1111: update CG1111 / grade 1 false\n"
+ "\t3. Update a task to done under module CG1111: update CG1111 / task 1 true\n" + horizontalLine);

public final String updateMultiple = helpOutput.concat(horizontalLine + "\n" + "Command: update-*\n"
Expand Down
11 changes: 10 additions & 1 deletion src/main/java/spinbox/entities/items/File.java
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,12 @@
import spinbox.exceptions.CorruptedDataException;

public class File extends Item {
private static final String BRACKET_OPEN = "[";
private static final String BRACKET_CLOSE = "] ";
private static final String CORRUPTED_FILES_DATA = "Corrupted files data.";
private static final String DELIMITER_FILTER = " \\| ";
private static final String DOWNLOADED = "DOWNLOADED";
private static final String NOT_DOWNLOADED = "NOT DOWNLOADED";

/**
* This constructor is used for recreation of SpinBox.Tasks.FileTask from storage.
Expand Down Expand Up @@ -32,9 +36,14 @@ public File(String fromStorage) throws CorruptedDataException {
}
}

@Override
public String getStatusText() {
return (this.getDone() ? DOWNLOADED : NOT_DOWNLOADED);
}

@Override
public String toString() {
return super.toString();
return BRACKET_OPEN + this.getStatusText() + BRACKET_CLOSE + this.getName();
}

@Override
Expand Down
Loading

0 comments on commit 34dcb08

Please sign in to comment.