Skip to content

Commit

Permalink
Merge pull request #34 from Geinzit/branch-heinzhuang
Browse files Browse the repository at this point in the history
Add Record viewing feature, with multiple viewing and sorting options…
  • Loading branch information
Geinzit authored Apr 3, 2024
2 parents 4208c21 + 2dd468c commit 01f0bee
Show file tree
Hide file tree
Showing 7 changed files with 157 additions and 16 deletions.
2 changes: 1 addition & 1 deletion docs/DeveloperGuide.md
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ if user missed some parameters ,defaultOptions() function will use pre-set defau
4. The accuracy and the user's answers will be stored for UI or other class to access with the specific function.
5. The checker will also store the times that user use to caculate for the problemset.

**`Psedue code` for reference:**
**`Pseudo code` for reference:**
```
# the brief psedue code for how to check the answer
Expand Down
5 changes: 3 additions & 2 deletions src/main/java/seedu/duke/Duke.java
Original file line number Diff line number Diff line change
Expand Up @@ -11,9 +11,10 @@ public class Duke {

public static void run() {

ui.greet();

Storage.readFile();

ui.greet();
String command = ui.readCommand();

while (!command.equals("exit")) {
Expand All @@ -24,7 +25,7 @@ public static void run() {
}

public static void main(String[] args) {
assert false : "dummy assertion set to fail";
//assert false : "dummy assertion set to fail";
run();
}
}
41 changes: 40 additions & 1 deletion src/main/java/seedu/duke/Parser.java
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,41 @@

public class Parser {


public static void parseRecord(String description, Ui ui) {
String[] tokens = description.split(" ");
int spdSortOp = 0;
int dateSortOp = 0;
int accSortOp = 0;
int probSortOp = 0;
boolean probShowDetails = false;
for (String token : tokens) {
if (token.equals("-details")) {
probShowDetails = true;
} else if (token.startsWith("-s")) {
spdSortOp = 1;
if(token.length() == 3 && token.endsWith("r")){
spdSortOp = 2;
}
} else if (token.startsWith("-d")) {
dateSortOp = 1;
if(token.length() == 3 && token.endsWith("r")){
dateSortOp = 2;
}
} else if (token.startsWith("-a")) {
dateSortOp = 1;
if(token.length() == 3 && token.endsWith("r")){
dateSortOp = 2;
}
} else if(token.startsWith("-p")) {
probSortOp = 1;
if(token.length() == 3 && token.endsWith("r")){
probSortOp = 2;
}
}
}
ui.printRecords(Storage.sortRecords(dateSortOp, spdSortOp, accSortOp, probSortOp), probShowDetails);
}
public static void parse(String command, Ui ui) {

/*
Expand Down Expand Up @@ -39,9 +74,13 @@ public static void parse(String command, Ui ui) {

// Storage write to file
double speed = (double) test.getNumber() / checker.getTime();
Storage.addRecord(new Record(LocalDateTime.now(), speed, checker.getAccuracy()));
Storage.addRecord(new Record(LocalDateTime.now(), speed, checker.getAccuracy(), test.getProblem()));
Storage.writeFile();

break;
case "records":
parseRecord(description, ui);
//ui.records(command);
break;
case "help":
ui.help(command);
Expand Down
4 changes: 4 additions & 0 deletions src/main/java/seedu/duke/Problem.java
Original file line number Diff line number Diff line change
Expand Up @@ -21,4 +21,8 @@ public String unsolved() {
public double getAnswer() {
return answer;
}

public String getDescription() {
return description;
}
}
57 changes: 54 additions & 3 deletions src/main/java/seedu/duke/Record.java
Original file line number Diff line number Diff line change
Expand Up @@ -2,23 +2,74 @@

import java.time.LocalDateTime;
import java.time.format.DateTimeFormatter;
import java.util.ArrayList;

public class Record {
private static final DateTimeFormatter formatter = DateTimeFormatter.ofPattern("yyyy-MM-dd HH:mm:ss");

private LocalDateTime dateTime;

private double speed;

private double accuracy;

public Record(LocalDateTime dateTime, double speed, double accuracy) {
private ArrayList<Problem> probSet = new ArrayList<>();

private int psIndex;

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

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

public void print(boolean showProbDetails) {
System.out.println("Date Time: " + getDateTime().format(formatter));
System.out.println("ProblemSet ID: " + getPsIndex());
if(showProbDetails) {
for (Problem problem : probSet) {
System.out.println(" " + problem.getDescription());
}
}
System.out.println("Speed: " + getSpeed() + "s");
System.out.println("Accuracy: " + getAccuracy() * 100 + "%");
}

public String writeLine() {
StringBuilder probStr = new StringBuilder();
for (Problem problem : probSet) {
probStr.append(problem.getDescription()).append(",").append(problem.getAnswer());
probStr.append(" ");
}

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

public int getPsIndex() {
return psIndex;
}

public void setPsIndex(int psIndex) {
this.psIndex = psIndex;
}

public ArrayList<Problem> getProbSet() {
return probSet;
}

String writeLine() {
return getDateTime().format(formatter) + " " + getSpeed() + " " + getAccuracy();
public void setProbSet(ArrayList<Problem> probSet) {
this.probSet.addAll(probSet);
}

public double getSpeed() {
Expand Down
42 changes: 39 additions & 3 deletions src/main/java/seedu/duke/Storage.java
Original file line number Diff line number Diff line change
Expand Up @@ -9,13 +9,15 @@
import java.time.format.DateTimeFormatter;
import java.util.ArrayList;
import java.util.List;
import java.util.Collections;
import java.util.Comparator;

/**
* Class for reading & writing input/output to file
*/
public class Storage {

private static String filePath = "recordList.txt";
private static final String filePath = "recordList.txt";

private static final DateTimeFormatter formatter = DateTimeFormatter.ofPattern("yyyy-MM-dd HH:mm:ss");

Expand All @@ -29,6 +31,31 @@ public static void clearRecords() {
records.clear();
}

public static ArrayList<Record> sortRecords(int dateSortOp, int spdSortOp, int accSortOp, int probSortOp) {
ArrayList<Record> sortedRecords = new ArrayList<>(records);
if (dateSortOp != 0) {
sortedRecords.sort(Comparator.comparing(Record::getDateTime));
if(dateSortOp == 2) {
Collections.reverse(sortedRecords);
}
} else if(spdSortOp != 0) {
sortedRecords.sort(Comparator.comparing(Record::getSpeed));
if(spdSortOp == 2) {
Collections.reverse(sortedRecords);
}
} else if(accSortOp != 0) {
sortedRecords.sort(Comparator.comparing(Record::getDateTime));
if(accSortOp == 2) {
Collections.reverse(sortedRecords);
}
} else if(probSortOp != 0) {
sortedRecords.sort(Comparator.comparing(Record::getPsIndex));
if(probSortOp == 2) {
Collections.reverse(sortedRecords);
}
}
return sortedRecords;
}

/**
* Method for processing a line of input
Expand All @@ -38,15 +65,24 @@ public static void clearRecords() {
public static void processLine(String line) throws Exception {
String[] words = line.split(" ");

if (words.length != 4 ) {
if (words.length < 4 ) {
throw new Exception();
}

LocalDateTime dateTime = LocalDateTime.parse(words[0] + " " + words[1], formatter);
double speed = Double.parseDouble(words[2]);
double accuracy = Double.parseDouble(words[3]);

Record record = new Record(dateTime, speed, accuracy);
int psIndex = Integer.parseInt(words[4]);

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

for (int i = 5; 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);
addRecord(record);
}

Expand Down
22 changes: 16 additions & 6 deletions src/main/java/seedu/duke/Ui.java
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
package seedu.duke;

import java.util.Scanner;

import java.util.ArrayList;
/**
* Represents the user interface for interacting with the chatbot.
*/
Expand Down Expand Up @@ -43,13 +43,14 @@ static void missingMessage(String parameters){
/**
* Displays a greeting message.
*/

public void greet() {
this.showLine();
String logo = " ____ _ \n" +
"| _ \\ _ _| | _____\n" +
"| | | | | | | |/ / _ \\\n" +
"| |_| | |_| | < __/\n" +
"|____/ \\__,_|_|\\_\\___|\n";
String logo = "__ __ _ _ ____ _\n" +
"| \\/ | __ _| |_| |__ / ___| ___ _ __ (_)_ _ ___\n" +
"| |\\/| |/ _` | __| '_ \\| | _ / _ \\ '_ \\| | | | / __|\n" +
"| | | | (_| | |_| | | | |_| | __/ | | | | |_| \\__ \\\n" +
"|_| |_|\\__,_|\\__|_| |_|\\____|\\___|_| |_|_|\\__,_|___/\n";
System.out.println(logo);
System.out.println("Hello! I'm " + name);
System.out.println("Type 'help' to see the instructions. \n");
Expand Down Expand Up @@ -85,6 +86,15 @@ public void help(String helpType) {
this.showLine();
}

// records input
public void printRecords(ArrayList<Record> records, boolean showProbDetails) {
for (Record record : records) {
showLine();
record.print(showProbDetails);
}
showLine();
}

// invalid input

/**
Expand Down

0 comments on commit 01f0bee

Please sign in to comment.