Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Batch grader test #344

Merged
merged 16 commits into from
Nov 15, 2022
Prev Previous commit
Next Next commit
it is connect with the 3.0 version batch grader
  • Loading branch information
wei-jun7 committed Oct 24, 2022
commit e9ff9934db9ce0d04af98472aed11260a030f54d
136 changes: 109 additions & 27 deletions src/main/java/edu/rpi/legup/ui/HomePanel.java
Original file line number Diff line number Diff line change
@@ -1,5 1,6 @@
package edu.rpi.legup.ui;

import edu.rpi.legup.Legup;
import edu.rpi.legup.app.GameBoardFacade;
import edu.rpi.legup.app.LegupPreferences;
import edu.rpi.legup.controller.CursorController;
Expand Down Expand Up @@ -156,13 157,14 @@ public void actionPerformed(ActionEvent e) {
// ProofEditorPanel panel=new ProofEditorPanel(new FileDialog(new Frame()),new JFrame(), legupUI);
// //legupUI.setVisible(false);
// panel.checkProofAll();
checkfile();
checkfolder();
//checkallproof1();
System.out.println("finished checking the folder");

}
});
}
public void checkfile(){
public void checkfolder(){
GameBoardFacade facade = GameBoardFacade.getInstance();

/*
Expand All @@ -177,42 179,122 @@ public void checkfile(){

LegupPreferences preferences = LegupPreferences.getInstance();
File preferredDirectory = new File(preferences.getUserPref(LegupPreferences.WORK_DIRECTORY));
JFileChooser folderBrowser = new JFileChooser();
folderBrowser = new JFileChooser(preferredDirectory);
JFileChooser folderBrowser = new JFileChooser(preferredDirectory);


folderBrowser.showOpenDialog(this);
folderBrowser.setVisible(true);
folderBrowser.setCurrentDirectory(new File(LegupPreferences.WORK_DIRECTORY));
folderBrowser.setDialogTitle("Select Directory");
folderBrowser.setFileSelectionMode(JFileChooser.DIRECTORIES_ONLY);
folderBrowser.setAcceptAllFileFilterUsed(true);

int option = folderBrowser.showOpenDialog(frame);
File folder= new File(".");
if (option == JFileChooser.APPROVE_OPTION) {

folder = folderBrowser.getCurrentDirectory();
}
folderBrowser.setAcceptAllFileFilterUsed(false);
folderBrowser.showOpenDialog(this);
folderBrowser.setVisible(true);
File folder = folderBrowser.getSelectedFile();

System.out.println(folder.getAbsolutePath());
// Write csv file (Path,File-Name,Puzzle-Type,Score,Solved?)
File resultFile = new File(folder.getAbsolutePath() File.separator "result.csv");
File resultFile = new File(folder.getAbsolutePath() File.separator "result.csv");
try (BufferedWriter writer = new BufferedWriter(new FileWriter(resultFile))) {
writer.append("Name,File Name,Puzzle Type,Score,Solved?\n");

// Go through student folders
for (final File folderEntry : Objects.requireNonNull(folder.listFiles(File::isDirectory))) {
// Write path
String path = folderEntry.getName();
traverseDir1(folderEntry, writer, path);
writer.append("Name");
writer.append(",");
writer.append("File Name");
writer.append(",");
writer.append("Solved or not");
writer.append("\n");
//csvWriter.flush();
//csvWriter.close();

for (final File folderEntry : folder.listFiles(File::isDirectory)) {
writer.append(folderEntry.getName());
writer.append(",");
int count1 = 0;
for (final File fileEntry : folderEntry.listFiles()) {
if (fileEntry.getName().charAt(0) == '.'){
continue;
}
count1 ;
if (count1 > 1){
writer.append(folderEntry.getName());
writer.append(",");
}
writer.append(fileEntry.getName());
writer.append(",");
String fileName = folderEntry.getAbsolutePath() File.separator fileEntry.getName();
System.out.println("This is path " fileName);
File puzzleFile = new File(fileName);
if (puzzleFile != null && puzzleFile.exists()) {
try {
legupUI.displayPanel(1);
legupUI.getProofEditor().loadPuzzle(null, null);
GameBoardFacade.getInstance().loadPuzzle(fileName);
String puzzleName = GameBoardFacade.getInstance().getPuzzleModule().getName();
legupUI.setTitle(puzzleName " - " puzzleFile.getName());
facade = GameBoardFacade.getInstance();
Puzzle puzzle = facade.getPuzzleModule();
if (puzzle.isPuzzleComplete()) {
writer.append("Solved");
System.out.println(fileEntry.getName() " solved");
} else {
writer.append("Not solved");
System.out.println(fileEntry.getName() " not solved");
}
writer.append("\n");
} catch (InvalidFileFormatException e) {
LOGGER.error(e.getMessage());
}
}
}
if (count1 == 0){
writer.append("No file");
writer.append("\n");
}
}
}
catch (IOException ex) {
}catch (IOException ex){
LOGGER.error(ex.getMessage());
}
JOptionPane.showMessageDialog(null, "Batch grading complete.");
}

public void checkallproof1(){
GameBoardFacade facade = GameBoardFacade.getInstance();

/*
* Select dir to grade; recursively grade sub-dirs using traverseDir()
* Selected dir must have sub-dirs for each student:
* GradeThis
* |
* | -> Student 1
* | |
* | | -> Proofs
*/

LegupPreferences preferences = LegupPreferences.getInstance();
File preferredDirectory = new File(preferences.getUserPref(LegupPreferences.WORK_DIRECTORY));
JFileChooser folderBrowser = new JFileChooser(preferredDirectory);


folderBrowser.setCurrentDirectory(new File(LegupPreferences.WORK_DIRECTORY));
folderBrowser.setDialogTitle("Select Directory");
folderBrowser.setFileSelectionMode(JFileChooser.DIRECTORIES_ONLY);
folderBrowser.setAcceptAllFileFilterUsed(false);
folderBrowser.showOpenDialog(this);
folderBrowser.setVisible(true);

File folder = folderBrowser.getSelectedFile();

// Write csv file (Path,File-Name,Puzzle-Type,Score,Solved?)
File resultFile = new File(folder.getAbsolutePath() File.separator "result.csv");
try (BufferedWriter writer = new BufferedWriter(new FileWriter(resultFile))) {
writer.append("Name,File Name,Puzzle Type,Score,Solved?\n");

// Go through student folders
for (final File folderEntry : Objects.requireNonNull(folder.listFiles(File::isDirectory))) {
// Write path
String path = folderEntry.getName();
traverseDir1(folderEntry, writer, path);
}
}
catch (IOException ex) {
LOGGER.error(ex.getMessage());
}
JOptionPane.showMessageDialog(null, "Batch grading complete.");
}
public void traverseDir1(File folder, BufferedWriter writer, String path) throws IOException{
GameBoardFacade facade = GameBoardFacade.getInstance();

Expand Down