Skip to content

Commit

Permalink
Merge pull request #206 from seraphimstreets/master
Browse files Browse the repository at this point in the history
Fix some formatting issues
  • Loading branch information
marioalvaro authored Nov 14, 2023
2 parents edd36d4 + 0b99ee4 commit b8cfa33
Show file tree
Hide file tree
Showing 15 changed files with 126 additions and 24 deletions.
21 changes: 19 additions & 2 deletions docs/DeveloperGuide.md
Original file line number Diff line number Diff line change
Expand Up @@ -231,7 +231,7 @@ Below is an activity diagram that demonstrates how this command works.

### Add Graded Component

<puml src="diagrams/AddGradedComponentSequenceDiagram.puml" width="450" />
<puml src="diagrams/AddGradedComponentSequenceDiagram.puml" width="1000" />

The `addComp` command allows users to add a graded component and automaticaly create student scores associated with that component for every student in the database.
A typical program flow is as follows:
Expand Down Expand Up @@ -259,7 +259,7 @@ Alternative Implementations:

### Edit Graded Component

<puml src="diagrams/EditGradedComponent.puml" width="450" />
<puml src="diagrams/EditGradedComponent.puml" width="1000" />

The `editComp` command allows users to edit a graded component's details based on its 1-based index, which are propagated to the component's associated student scores.
A typical program flow is as follows:
Expand All @@ -285,6 +285,23 @@ Alternative Implementations:
create some inefficiency as the `Model` has to search through the entire `GradedComponent` list
for the appropriate item to replace. Therefore, this is a possible extension that future developers may consider.

### Delete Graded Component

<puml src="diagrams/DeleteGradedComponentSequenceDiagram.puml" width="1000" />

The `deleteComp` command allows users to delete a graded component alongside its associated student scores based on its 1-based index.
A typical program flow is as follows:

1. User enters a command to delete a graded component, for instance `deleteComp 2`.
2. `DeleteGradedComponentCommandParser` checks that the only argument provided is a valid index, which is an integer between 1 and the size of the displayed `GradedComponent` list.
3. Index is passed into `DeleteGradedComponentCommand`'s constructor which is then executed.
4. The graded component corresponding to the index in the currently displayed `GradedComponentBook` list is removed.
5. All associated student scores of that `GradedComponent` are also removed.

Alternative Implementations:
* We originally considered having users remove graded components based on their unique component name. Ultimately, we decided it would be faster for users to type in an index rather than a name (especially if it is quite lengthy),
although future developers may want to extend this functionality so that users can choose to remove by either index or component name.

### Sort Commands

The Sort related features allows NUS professors to sort the currently displayed students or student scores. When successfully executed, the sorted students or student scores will be shown on the Graphical User Interface. <br>
Expand Down
80 changes: 80 additions & 0 deletions docs/diagrams/DeleteGradedComponentSequenceDiagram.puml
Original file line number Diff line number Diff line change
@@ -0,0 +1,80 @@
@startuml
!include style.puml
skinparam ArrowFontStyle plain

box Logic LOGIC_COLOR_T1
participant ":LogicManager" as LogicManager LOGIC_COLOR
participant ":ModuLightParser" as ModuLightParser LOGIC_COLOR
participant ":DeleteGradedComponentCommandParser" as DeleteGradedComponentCommandParser LOGIC_COLOR
participant ":DeleteGradedComponentCommand" as DeleteGradedComponentCommand LOGIC_COLOR
participant ":CommandResult" as CommandResult LOGIC_COLOR
end box

box Model MODEL_COLOR_T1
participant ":Model" as Model MODEL_COLOR
end box

[-> LogicManager : execute("deleteComp 1")
activate LogicManager

LogicManager -> ModuLightParser : parseCommand("deleteComp 1")
activate ModuLightParser

create DeleteGradedComponentCommandParser
ModuLightParser -> DeleteGradedComponentCommandParser
activate DeleteGradedComponentCommandParser

DeleteGradedComponentCommandParser --> ModuLightParser
deactivate DeleteGradedComponentCommandParser

ModuLightParser -> DeleteGradedComponentCommandParser : parse(arguments)
activate DeleteGradedComponentCommandParser


create DeleteGradedComponentCommand
DeleteGradedComponentCommandParser -> DeleteGradedComponentCommand : new DeleteGradedComponentCommand(index)
activate DeleteGradedComponentCommand

DeleteGradedComponentCommand --> DeleteGradedComponentCommandParser
deactivate DeleteGradedComponentCommand

DeleteGradedComponentCommandParser --> ModuLightParser
deactivate DeleteGradedComponentCommandParser
'Hidden arrow to position the destroy marker below the end of the activation bar.
DeleteGradedComponentCommandParser -[hidden]-> ModuLightParser
destroy DeleteGradedComponentCommandParser

ModuLightParser --> LogicManager
deactivate ModuLightParser

LogicManager -> DeleteGradedComponentCommand : execute()
activate DeleteGradedComponentCommand

DeleteGradedComponentCommand -> Model : removeGradedComponent(gc)
activate Model

Model --> DeleteGradedComponentCommand
deactivate Model

loop for all associated studentScores of gc
DeleteGradedComponentCommand -> Model :removeStudentScore(studentScore)
activate Model

Model --> DeleteGradedComponentCommand
deactivate Model
end


create CommandResult
DeleteGradedComponentCommand -> CommandResult
activate CommandResult

CommandResult --> DeleteGradedComponentCommand
deactivate CommandResult

DeleteGradedComponentCommand --> LogicManager : result
deactivate DeleteGradedComponentCommand

[<--LogicManager
deactivate LogicManager
@enduml
1 change: 1 addition & 0 deletions docs/team/seraphimstreets.md
Original file line number Diff line number Diff line change
Expand Up @@ -81,3 +81,4 @@ Format: `deleteComp INDEX`
Examples: `deleteComp 2` deletes the second graded component in the displayed Graded Components List

### Contributions to Developer Guide

4 changes: 2 additions & 2 deletions src/main/java/seedu/modulight/logic/Messages.java
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ public static String getErrorMessageForDuplicatePrefixes(Prefix... duplicatePref
/**
* Formats the {@code student} for display to the user.
*/
public static String format(Student student) {
public static String formatStudent(Student student) {
final StringBuilder builder = new StringBuilder();
builder.append(student.getStudentId())
.append("; Name: ")
Expand Down Expand Up @@ -75,7 +75,7 @@ public static String formatGradedComponent(GradedComponent gc) {
*/
public static String formatStudentScore(StudentScore sc) {
final StringBuilder builder = new StringBuilder();
builder.append("; Student ID: ")
builder.append("Student ID: ")
.append(sc.getStudentId())
.append("; Graded component name: ")
.append(sc.getGcName())
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -73,7 +73,7 @@ public CommandResult execute(Model model) throws CommandException {
addCommandUpdateLinks(toAdd, gc, sc);
addCommandUpdateBooks(model, toAdd, gc, sc);
}
return new CommandResult(String.format(MESSAGE_SUCCESS, Messages.format(toAdd)));
return new CommandResult(String.format(MESSAGE_SUCCESS, Messages.formatStudent(toAdd)));
}

@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,7 @@ public CommandResult execute(Model model) throws CommandException {
studentScoreBook.removeStudentScore(studentScoreList.get(i));
}
}
return new CommandResult(String.format(MESSAGE_DELETE_PERSON_SUCCESS, Messages.format(studentToDelete)));
return new CommandResult(String.format(MESSAGE_DELETE_PERSON_SUCCESS, Messages.formatStudent(studentToDelete)));
}

@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -106,7 +106,7 @@ public CommandResult execute(Model model) throws CommandException {
}
}

return new CommandResult(String.format(MESSAGE_EDIT_STUDENT_SUCCESS, Messages.format(editedStudent)));
return new CommandResult(String.format(MESSAGE_EDIT_STUDENT_SUCCESS, Messages.formatStudent(editedStudent)));
}

/**
Expand Down
4 changes: 3 additions & 1 deletion src/main/java/seedu/modulight/model/student/Student.java
Original file line number Diff line number Diff line change
Expand Up @@ -120,7 +120,9 @@ private float calcTotalScore() {
GradedComponent gc = sc.getGradedComponent();
Weightage w = gc.getWeightage();
float weight = w.weightage;
totalScore += weight / totalWeightage * sc.calcRelativeScore();
if (totalWeightage != 0) {
totalScore += weight / totalWeightage * sc.calcRelativeScore();
}
}
return totalScore;
}
Expand Down
9 changes: 5 additions & 4 deletions src/main/java/seedu/modulight/ui/GradedComponentCard.java
Original file line number Diff line number Diff line change
Expand Up @@ -47,15 +47,16 @@ public GradedComponentCard(GradedComponent gradedComponent, int displayedIndex)
this.gradedComponent = gradedComponent;
id.setText(displayedIndex + ". ");
gcName.setText(gradedComponent.getName().gcName);
maxMarks.setText("Max marks: " + gradedComponent.getMaxMarks());
weightage.setText("Weightage: " + gradedComponent.getWeightage());
maxMarks.setText("Max marks: " + String.format("%.2f", gradedComponent.getMaxMarks().maxMarks));
weightage.setText("Weightage: " + String.format("%.2f", gradedComponent.getWeightage().weightage));
gradedComponent.recalculateScores();

float meanAbsoluteScore = gradedComponent.getMeanAbsoluteScore();
float meanRelativeScore = gradedComponent.getMeanRelativeScore();

Label meanScoreLabel = new Label(String.format("Mean: %.1f", meanAbsoluteScore) + "/"
+ gradedComponent.getMaxMarks() + " (" + String.format("%.1f", meanRelativeScore) + "%)");
Label meanScoreLabel = new Label(String.format("Mean: %.2f", meanAbsoluteScore) + "/"
+ String.format("%.2f", gradedComponent.getMaxMarks().maxMarks)
+ " (" + String.format("%.2f", meanRelativeScore) + "%)");
meanScoreLabel.getStyleClass().add("cell_small_label");
gradedComponentBox.getChildren().add(meanScoreLabel);

Expand Down
2 changes: 1 addition & 1 deletion src/main/java/seedu/modulight/ui/StudentCard.java
Original file line number Diff line number Diff line change
Expand Up @@ -68,7 +68,7 @@ public StudentCard(Student student, int displayedIndex) {
.forEach(tag -> tags.getChildren().add(new Label(tag.tagName)));
student.recalculateScores();
float totalScore = student.getTotalScore();
Label totalScoreLabel = new Label(String.format("Total Score: %.1f", totalScore) + "%");
Label totalScoreLabel = new Label(String.format("Total Score: %.2f", totalScore) + "%");
totalScoreLabel.getStyleClass().add("cell_small_label");
studentBox.getChildren().add(totalScoreLabel);
if (!student.getStudentGrade().toString().isEmpty()) {
Expand Down
3 changes: 2 additions & 1 deletion src/main/java/seedu/modulight/ui/StudentScoreCard.java
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,8 @@ public StudentScoreCard(StudentScore studentScore, int displayedIndex) {
this.studentScore = studentScore;
id.setText(displayedIndex + ". ");
sid.setText(studentScore.getStudentId().sid + " - " + studentScore.getGcName().gcName);
score.setText("Score: " + studentScore.getScore() + "/" + studentScore.getGradedComponent().getMaxMarks());
score.setText("Score: " + String.format("%.2f", studentScore.getScore())
+ "/" + String.format("%.2f", studentScore.getGradedComponent().getMaxMarks().maxMarks));
studentScore.getTags().stream()
.sorted(Comparator.comparing(tag -> tag.tagName))
.forEach(tag -> tags.getChildren().add(new Label(tag.tagName)));
Expand Down
4 changes: 2 additions & 2 deletions src/test/java/seedu/modulight/logic/MessagesTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -31,13 +31,13 @@ public void format_student_success() {
new StudentEmail("[email protected]"), new TutorialGroup("T01"), new ArrayList<>(),
new HashSet<>());
String expectedOutput = "A0123456U; Name: Test Stu; Email: [email protected]; Tutorial Group: T01";
assertEquals(Messages.format(testStu), expectedOutput);
assertEquals(Messages.formatStudent(testStu), expectedOutput);
}

@Test
public void format_studentScore_success() {
StudentScore testStuScore = new StudentScore(new StudentId("A0123456U"), new GcName("Midterm"), 40);
String expectedOutput = "; Student ID: A0123456U; Graded component name: Midterm; Score: 40.0";
String expectedOutput = "Student ID: A0123456U; Graded component name: Midterm; Score: 40.0";
assertEquals(Messages.formatStudentScore(testStuScore), expectedOutput);
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -31,8 +31,8 @@ public void execute_studentAcceptedByModel_addSuccessful() throws Exception {

CommandResult commandResult = new AddStudentCommand(validStudent).execute(model);
String s1 = commandResult.getFeedbackToUser();
String s2 = String.format(AddStudentCommand.MESSAGE_SUCCESS, Messages.format(validStudent));
assertEquals(String.format(AddStudentCommand.MESSAGE_SUCCESS, Messages.format(validStudent)),
String s2 = String.format(AddStudentCommand.MESSAGE_SUCCESS, Messages.formatStudent(validStudent));
assertEquals(String.format(AddStudentCommand.MESSAGE_SUCCESS, Messages.formatStudent(validStudent)),
commandResult.getFeedbackToUser());
assertEquals(Arrays.asList(validStudent), model.getStudentBook().getStudentList());
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ public void execute_validIndexUnfilteredList_success() {
DeleteStudentCommand deleteCommand = new DeleteStudentCommand(INDEX_FIRST_PERSON);

String expectedMessage = String.format(DeleteStudentCommand.MESSAGE_DELETE_PERSON_SUCCESS,
Messages.format(studentToDelete));
Messages.formatStudent(studentToDelete));

ModelManager expectedModel = new ModelManager(model.getStudentBook(), new StudentScoreBook(),
new GradedComponentBook(), new UserPrefs());
Expand Down Expand Up @@ -67,7 +67,7 @@ public void execute_validIndexFilteredList_success() throws CommandException {
Student studentToDelete = model.getFilteredStudentList().get(INDEX_FIRST_PERSON.getZeroBased());
System.out.println(studentToDelete.getName());
String expectedMessage = String.format(DeleteStudentCommand.MESSAGE_DELETE_PERSON_SUCCESS,
Messages.format(studentToDelete));
Messages.formatStudent(studentToDelete));
Model expectedModel = new ModelManager(model.getStudentBook(), new StudentScoreBook(),
new GradedComponentBook(), new UserPrefs());
expectedModel.getStudentBook().removeStudent(studentToDelete);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ public void execute_allFieldsSpecifiedUnfilteredList_success() {
EditStudentCommand editStudentCommand = new EditStudentCommand(INDEX_FIRST_PERSON, descriptor);

String expectedMessage = String.format(EditStudentCommand.MESSAGE_EDIT_STUDENT_SUCCESS,
Messages.format(editedStudent));
Messages.formatStudent(editedStudent));

Model expectedModel = new ModelManager(new StudentBook(model.getStudentBook()), new StudentScoreBook(),
new GradedComponentBook(), new UserPrefs());
Expand All @@ -66,7 +66,7 @@ public void execute_someFieldsSpecifiedUnfilteredList_success() {
EditStudentCommand editCommand = new EditStudentCommand(indexLastStudent, descriptor);

String expectedMessage = String.format(EditStudentCommand.MESSAGE_EDIT_STUDENT_SUCCESS,
Messages.format(editedStudent));
Messages.formatStudent(editedStudent));

Model expectedModel = new ModelManager(new StudentBook(model.getStudentBook()), new StudentScoreBook(),
new GradedComponentBook(), new UserPrefs());
Expand All @@ -81,7 +81,7 @@ public void execute_noFieldSpecifiedUnfilteredList_success() {
Student editedStudent = model.getFilteredStudentList().get(INDEX_FIRST_PERSON.getZeroBased());

String expectedMessage = String.format(EditStudentCommand.MESSAGE_EDIT_STUDENT_SUCCESS,
Messages.format(editedStudent));
Messages.formatStudent(editedStudent));

Model expectedModel = new ModelManager(new StudentBook(model.getStudentBook()), new StudentScoreBook(),
new GradedComponentBook(), new UserPrefs());
Expand All @@ -97,7 +97,7 @@ public void execute_filteredList_success() {
new EditStudentDescriptorBuilder().withName(VALID_NAME_JAMES).build());

String expectedMessage = String.format(EditStudentCommand.MESSAGE_EDIT_STUDENT_SUCCESS,
Messages.format(editedStudent));
Messages.formatStudent(editedStudent));

Model expectedModel = new ModelManager(new StudentBook(model.getStudentBook()), new StudentScoreBook(),
new GradedComponentBook(), new UserPrefs());
Expand Down

0 comments on commit b8cfa33

Please sign in to comment.