Skip to content

Commit

Permalink
Add class DIYProblemSet and ProblemSetType, modify Storage, Record, U…
Browse files Browse the repository at this point in the history
…i and Test to show the ProblemSetType, add PPP draft and modify the UG and DG.
  • Loading branch information
Celineyaa committed Apr 11, 2024
1 parent 0903df5 commit 0f7bb8f
Show file tree
Hide file tree
Showing 11 changed files with 208 additions and 26 deletions.
53 changes: 51 additions & 2 deletions docs/DeveloperGuide.md
Original file line number Diff line number Diff line change
Expand Up @@ -104,7 +104,7 @@ Each `Record` object stores an ArrayList of `Problem` objects for storing specif
When a problem set solving is saved to a record **for the first time**, the corresponding `Record` object will create a unique ID for the problem set using Java's built-in `hashCode` method. When loading this record in the future and re-saving the data, the same ID will be used and no new IDs will be generated. This is achieved by using two different constructors for these two different situations.

**Code Snippet**
```java
```
// the two different constructors
public Record(LocalDateTime dateTime, double speed, double accuracy, ArrayList<Problem> probSet) {
setSpeed(speed);
Expand All @@ -121,7 +121,7 @@ public Record(LocalDateTime dateTime, double speed, double accuracy, ArrayList<P
setProbSet(probSet);
setPsIndex(psIndex);
}

```
### Storage Component - Design

API: [Storage.java](../src/main/java/seedu/duke/Storage.java)
Expand All @@ -140,6 +140,55 @@ The Storage Component:
- Uses Java's built-in BufferedReader, FileReader, BufferedWriter, FileWriter to write / read properly all information of all problem sets
- sortRecords method sorts the Record list based on 4 different parameters(each representing sort by datetime, speed, accuracy, problemSet ID). each parameter have 3 different values: 0, 1, 2. 0 means to not sort by this parameter, 1 means to sort(decreasing order), 2 means to sort in reverse(increasing order). These 4 parameters are determined by the user input, and interpreted by the Parser component.

### DIYProblemSet Component

The DIYProblemSet class is responsible for creating and managing a user-defined problem set. It allows users to input custom problems and their correct answers, and saves the problem set for future reference.
## Class Signature
```
public class DIYProblemSet {
ArrayList<Problem> problemSet;
public DIYProblemSet() {
// Constructor logic
}
public void addDIYProblemSet(Ui ui) {
// Method logic
}
}
```
## Class Variables

problemSet: An ArrayList of type Problem to store the user-defined problems.

## Class Methods

```
public DIYProblemSet()
```
The constructor initializes the problemSet as a new ArrayList of Problem objects.

```
public void addDIYProblemSet(Ui ui)
```
This method allows users to input their DIY problem set. It prompts for the problem description and correct answer, validates the input, and adds the problem to the problemSet. Once the user finishes adding problems, it creates a new Record object with the current timestamp, total correct answers set to 0, total time taken set to 0, the problemSet, and the problem set type as USER_DIY. It then saves the record using the Storage.addRecord() method and displays a success message along with the details of the saved problem set.

## Method Flow
1. Create a new Scanner object to read user input.
2. Prompt the user to input their DIY problem set.
3. Inside a loop that continues until the user indicates they have finished adding problems:
- Prompt the user to input the problem description.
- Prompt the user to input the correct answer for the problem.
- Validate the input by attempting to parse the correct answer as a double. If it fails, display an error message.
- Create a new Problem object with the description and parsed answer, and add it to the problemSet.
- Prompt the user to indicate if they have finished adding problems (y for yes, n for no).
- Validate the input to ensure it is either y or n. If it is invalid, display an error message and prompt again.
4. Create a new Record object with the current timestamp, total correct answers set to 0, total time taken set to 0, the problemSet, and the problem set type as USER_DIY.
5. Save the record using the Storage.addRecord() method.
6. Display a success message indicating that the DIY problem set has been successfully saved.
7. Print the details of the saved problem set using the record.print(true) method.
8. Display a new line for formatting purposes.

### Testcase Component

# Proposed Implementation
Expand Down
19 changes: 12 additions & 7 deletions docs/UserGuide.md
Original file line number Diff line number Diff line change
Expand Up @@ -78,6 +78,9 @@ type the answer in the terminal and press ENTER/RETURN

After finishing all the problem sets, the program will automate judged the correctness and output the accuracy and speed.

### DIY: `DIY`
Add user DIY problem sets into our problem set datasets. The DIY problem set can also be saved and retried.

### Exit: `exit`

User can use this to exit the program.
Expand All @@ -92,18 +95,20 @@ Here are some example commands you can try:
2. Pressing `Enter/Return`: Submits your answer to a problem.
3. `exit`: Exits the program.
4. `records`: Displays your past problem-solving sessions, including the date you finished the set, your speed, accuracy, and the details of the problems.
5. `DIY`: Add user DIY problem sets into our problem set datasets. The DIY problem set can also be saved and retried.

Remember, practice makes perfect. Happy learning with **MathGenius**!

### Command summary:

| Command | Description | Format | Example |
|---------|-------------|--------|---------|
| `help` | Show the message about the command you can use and the standard input format | `help COMMAND_NAME` | `help generate` |
| `gen / generate` | Generate the problem based on series of parameters | `generate -t OPERATOR -n NUMBER_OF_PROBLEMS -d MAXIMUM_DIGITS` | `generate -t + -n 1 -d 1` |
| `records` | View the records of your past problem solving sessions | `records -sortByDate -sortBySpeed -sortByAccuracy -sortByProblemID -showProblemDetails` | `records -d -s -a -p -details` |
| `ENTER/RETURN` | Submit the answer in the terminal | NA | NA |
| `exit` | Exit the program | `exit` | `exit` |
| Command | Description | Format | Example |
|------------------|-------------|-----------------------------------------------------------------------------------------|--------------------------------|
| `help` | Show the message about the command you can use and the standard input format | `help COMMAND_NAME` | `help generate` |
| `gen / generate` | Generate the problem based on series of parameters | `generate -t OPERATOR -n NUMBER_OF_PROBLEMS -d MAXIMUM_DIGITS` | `generate -t + -n 1 -d 1` |
| `records` | View the records of your past problem solving sessions | `records -sortByDate -sortBySpeed -sortByAccuracy -sortByProblemID -showProblemDetails` | `records -d -s -a -p -details` |
| `ENTER/RETURN` | Submit the answer in the terminal | NA | NA |
| `DIY` | Add user DIY problem sets into our problem set datasets. | `DIY` | `DIY` |
| `exit` | Exit the program | `exit`| `exit` |

## Interaction Guide

Expand Down
35 changes: 35 additions & 0 deletions docs/team/celineyaa.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
# Yuhao ZHANG

## Overview of `MathGenius`
**`MathGenius`** is a user-friendly application that provides a platform to enhance your equation-solving abilities. Whether you're a student learning calculation, a math enthusiast looking to sharpen your skills, or a teacher preparing for exams/lessons, this application is here to support you.

## Summary of Contribution
[**link to the code**](https://nus-cs2113-ay2324s2.github.io/tp-dashboard/?search=celineyaa&breakdown=true&sort=groupTitle%20dsc&sortWithin=title&since=2024-02-23&timeframe=commit&mergegroup=&groupSelect=groupByRepos&checkedFileTypes=docs~functional-code~test-code~other)
In the project `MathGenius`, I am in conduct of implement the `DIYProblemSet` part and test cases part. For the `DIYProblemSet` which is to add user-DIY problem sets into our problem sets database. And for the testcases part, they are used to test the functionality of classes.
In the `UserGuide`,I am in conduct of writing the corresponding parts of the guidance.
In the `Development Guide`, I am in conduct of writing the `testcases` part, `DIYProblemSet`part and `Instructions for manual testing`part.
Of the team base tasks, I attend weekly meeting most of the time and do the allocated tasks as soon as possible.
I also help to check the correctness of others part and provide advices on the improvements.

## Project management:
Managed release `v1.0` on GitHub

## Challenges:
During the refinement process, I faced a few challenges, including:
- Dealing with unexpected errors and exceptions: Throughout the refinement process, unexpected errors and exceptions were encountered. These issues required thorough debugging and error handling to identify the root causes and implement appropriate solutions to prevent or handle such errors gracefully.
- Optimizing performance and scalability: Another challenge was optimizing the software's performance and ensuring scalability to handle increasing user loads. This involved identifying and resolving bottlenecks, implementing efficient algorithms, and conducting performance testing to ensure the system could handle large-scale usage.
- Collaborating with team members and managing project coordination: If the project involved a team, effective collaboration and project coordination were essential challenges. This included communicating and coordinating tasks with team members, resolving conflicts or differences in opinions, and ensuring everyone was aligned with the project goals and timeline.

## Community:
- Contributions to test code and text-ui-test for Gradle.
- Promoting coding style consistency.
- Sharing knowledge and expertise.

## Next Steps:
- Organize usability testing sessions with users to gather feedback on the existing documentation. This will help identify any areas that might be confusing or require further clarification. Incorporate the feedback received into the documentation refinement process.
- Analyze common user issues and questions that have been raised during the project's development and deployment. Use this information to expand the troubleshooting section of the User Guide, providing step-by-step solutions to common problems. Additionally, create a comprehensive FAQs section to address frequently asked questions and provide quick answers to users.
- Enhance the documentation by including relevant diagrams, flowcharts, and visuals where appropriate. These visual aids can help users and developers better understand complex concepts, system architecture, and workflows.

## Tools:
- IntelliJ

46 changes: 46 additions & 0 deletions src/main/java/seedu/duke/DIYProblemSet.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
package seedu.duke;

import java.time.LocalDateTime;
import java.util.ArrayList;
import java.util.Scanner;

public class DIYProblemSet {
ArrayList<Problem> problemSet;
public DIYProblemSet() {
problemSet = new ArrayList<>();
}
public void addDIYProblemSet(Ui ui) {
Scanner scanner = new Scanner(System.in);
ui.print("Please input your DIY problemSet: ");
String description;
String correctAnswer;
double answer = 0.0;
String quit = "";
while (!quit.equals("y")) {
ui.print("input the description of the problem (e.g. 1+2*3): ");
description = scanner.nextLine();
ui.print("input the correct answer of the problem (e.g. 7): ");
correctAnswer = scanner.nextLine();
try {
answer = Double.parseDouble(correctAnswer);
} catch (NumberFormatException e) {
ui.print("Invalid answer! Please input a number.");
}
Problem problem = new Problem(description,answer);
problemSet.add(problem);
ui.print("Do you finish adding problems? y/n: ");
quit = scanner.nextLine();
while (!quit.equals("y") && !quit.equals("n")) {
ui.print("input is invalid! Please input 'y' or 'n': ");
quit = scanner.nextLine();
}
}
Record record = new Record(LocalDateTime.now(),0.0, 0.0,problemSet,ProblemSetType.USER_DIY.getValue());
Storage.addRecord(record);
ui.print("\nSuccessfully save the DIY problem set!");
record.print(true);
ui.print("\n");
}


}
7 changes: 5 additions & 2 deletions src/main/java/seedu/duke/Parser.java
Original file line number Diff line number Diff line change
Expand Up @@ -91,9 +91,9 @@ public static void solveProbSet(Test test, Ui ui, boolean retry, int id) {
// Storage write to file
double speed = (double) test.getNumber() / checker.getTime() * 60;
if (retry) {
Storage.addRecord(new Record(LocalDateTime.now(), speed, checker.getAccuracy(), test.getProblem(), id));
Storage.addRecord(new Record(LocalDateTime.now(), speed, checker.getAccuracy(), test.getProblem(), id, test.getProblemSetType()));
} else {
Storage.addRecord(new Record(LocalDateTime.now(), speed, checker.getAccuracy(), test.getProblem()));
Storage.addRecord(new Record(LocalDateTime.now(), speed, checker.getAccuracy(), test.getProblem(), test.getProblemSetType()));
}
Storage.writeFile();
}
Expand Down Expand Up @@ -132,6 +132,9 @@ public static void parse(String command, Ui ui) {
case "retry":
parseRetry(description, ui);
break;
case "DIY":
DIYProblemSet DIY = new DIYProblemSet();
DIY.addDIYProblemSet(ui);
case "help":
ui.help(description);
break;
Expand Down
16 changes: 16 additions & 0 deletions src/main/java/seedu/duke/ProblemSetType.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
package seedu.duke;

public enum ProblemSetType {
USER_DIY("user-DIY"),
AUTO_GENERATED("auto-generated");

private String value;

private ProblemSetType(String value) {
this.value = value;
}

public String getValue() {
return value;
}
}
17 changes: 14 additions & 3 deletions src/main/java/seedu/duke/Record.java
Original file line number Diff line number Diff line change
Expand Up @@ -16,23 +16,28 @@ public class Record {
private final ArrayList<Problem> probSet = new ArrayList<>();

private int psIndex;
private String problemSetType;

public Record(LocalDateTime dateTime, double speed, double accuracy, ArrayList<Problem> probSet) {
public Record(LocalDateTime dateTime, double speed, double accuracy, ArrayList<Problem> probSet, String problemSetType) {
setSpeed(speed);
setAccuracy(accuracy);
setDateTime(dateTime);
setProbSet(probSet);
setProblemSetType(problemSetType);
psIndex = probSet.hashCode();

}

public Record(LocalDateTime dateTime, double speed, double accuracy, ArrayList<Problem> probSet, int psIndex) {
public Record(LocalDateTime dateTime, double speed, double accuracy, ArrayList<Problem> probSet, int psIndex, String problemSetType) {
setSpeed(speed);
setAccuracy(accuracy);
setDateTime(dateTime);
setProbSet(probSet);
setPsIndex(psIndex);
setProblemSetType(problemSetType);
}


public void print(boolean showProbDetails) {
// ui.printRecords(showProbDetails, this);

Expand All @@ -45,6 +50,7 @@ public void print(boolean showProbDetails) {
}
System.out.println("Speed: " + getSpeed() + " problems per minute");
System.out.println("Accuracy: " + getAccuracy() * 100 + "%");
System.out.println("Problem Set type: " + getProblemSetType());
}

public String writeLine() {
Expand All @@ -55,7 +61,7 @@ public String writeLine() {
}

return getDateTime().format(formatter) + " " + getSpeed() + " " +
getAccuracy() + " " + getPsIndex() + " " + probStr;
getAccuracy() + " " + getPsIndex() + " " + getProblemSetType() + " " + probStr;
}

public int getPsIndex() {
Expand Down Expand Up @@ -97,4 +103,9 @@ public LocalDateTime getDateTime() {
public void setDateTime(LocalDateTime dateTime) {
this.dateTime = dateTime;
}

public void setProblemSetType(String problemSetType) { this.problemSetType = problemSetType; }

public String getProblemSetType() { return problemSetType; }

}
10 changes: 7 additions & 3 deletions src/main/java/seedu/duke/Storage.java
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ public static void clearRecords() {
public static Test problemSetByID(int id) {
for (Record record : records) {
if (record.getPsIndex() == id) {
return new Test(record.getProbSet());
return new Test(record.getProbSet(),record.getProblemSetType());
}
}
return null;
Expand Down Expand Up @@ -76,7 +76,7 @@ public static ArrayList<Record> sortRecords(int dateSortOp, int spdSortOp, int a
* @throws Exception exception is thrown whenever the input format is corrupt.
*/
public static void processLine(String line) throws Exception {
int minimumLength = 4;
int minimumLength = 5;

String[] words = line.split(" ");

Expand All @@ -90,14 +90,18 @@ public static void processLine(String line) throws Exception {

int psIndex = Integer.parseInt(words[4]);

String problemSetType = words[5];

ArrayList<Problem> probSet = new ArrayList<>();

for (int i = minimumLength + 1; i < words.length; i++) {
String[] term = words[i].split(",");
probSet.add(new Problem(term[0], Double.parseDouble(term[1])));
}

Record record = new Record(dateTime, speed, accuracy, probSet, psIndex);


Record record = new Record(dateTime, speed, accuracy, probSet, psIndex,problemSetType);
addRecord(record);
}

Expand Down
8 changes: 7 additions & 1 deletion src/main/java/seedu/duke/Test.java
Original file line number Diff line number Diff line change
Expand Up @@ -10,18 +10,22 @@ public class Test {

int length;
ArrayList<Problem> problemList = new ArrayList<>();
String problemSetType;

public Test(String operators, int maxDigits, int number, int length) {
this.operators = operators;
this.maxDigits = maxDigits;
this.number = number;
this.length = length;
this.problemSetType = ProblemSetType.AUTO_GENERATED.getValue();
}

public Test(ArrayList<Problem> problemList) {
public Test(ArrayList<Problem> problemList, String problemSetType) {
this.operators = "";
this.maxDigits = 0;
this.number = problemList.size();
this.problemList = new ArrayList<>(problemList);
this.problemSetType = problemSetType;
}

public void addToTest(Problem p) {
Expand All @@ -36,4 +40,6 @@ public ArrayList<Problem> getProblem() {
return problemList;
}

public String getProblemSetType() { return problemSetType; }

}
9 changes: 8 additions & 1 deletion src/main/java/seedu/duke/Ui.java
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,8 @@ public class Ui {
"1. 'generate' or 'gen': Generate a problem set based on a series of parameters.\n" +
"2. 'records': View the records of your past problem solving sessions.\n" +
"3. 'retry': Retry a problem set you have solved before.\n" +
"4. 'exit': Exit the program.\n" +
"4. 'DIY': add user-DIY problem set to the problem set database.\n" +
"5. 'exit': Exit the program.\n" +
"For example, 'help generate' will show you how to use the generate command.";
private static final String RECORDS_COMMAND =
"View past records(in-brackets parameters are optional): \t" + "records [-d] [-s] [-a] [-p] [-details]\n" +
Expand All @@ -45,8 +46,12 @@ public class Ui {
private static final String RETRY_COMMAND =
"Retry a problem set you have solved before in the past: \t" + "retry PROBLEM_SET_ID\n" +
"PROBLEM_SET_ID is an integer, and can be found by using the 'records' command.\n";

private static final String DIY_COMMAND =
"Add user defined problem sets in to the problem database: \t" + "DIY\n";
private static final String EXIT_COMMAND = "Exit program: exit\n";


private final String name;
private final Scanner scanner = new Scanner(System.in);

Expand Down Expand Up @@ -104,6 +109,8 @@ public void help(String helpType) {
case "exit":
System.out.println(EXIT_COMMAND);
break;
case "DIY":
System.out.println(DIY_COMMAND);
default:// by default, user asks Help Instruction
System.out.println(HELP_COMMAND);
break;
Expand Down
Loading

0 comments on commit 0f7bb8f

Please sign in to comment.