changed task selection

This commit is contained in:
Simon
2021-02-03 12:46:43 +01:00
parent 6b85a822eb
commit c7c27c4347
+43 -49
View File
@@ -3,18 +3,24 @@ import org.apache.poi.hssf.usermodel.HSSFRow;
import org.apache.poi.hssf.usermodel.HSSFSheet;
import org.apache.poi.hssf.usermodel.HSSFWorkbook;
import org.apache.poi.poifs.filesystem.POIFSFileSystem;
import org.apache.commons.math3.util.*;
import java.awt.*;
import java.io.File;
import java.io.FileInputStream;
import java.io.IOException;
import java.util.Scanner;
public class CorrectionHelper {
final static String FILE_PATH = "./answers.xls";
final static boolean CORRECT_ALL = false;
final static String TASK_TO_CORRECT = "1.2";
final static int LAST_NAME = 0;
final static int FIRST_NAME = 1;
final static int MATRICULATION_NUMBER = 2;
public static void main(String[] args) {
// TODO
File file = new File("./answers.xls");
File file = new File(FILE_PATH);
HSSFWorkbook wb = null;
try {
@@ -24,6 +30,7 @@ public class CorrectionHelper {
e.printStackTrace();
}
assert wb != null;
HSSFSheet sheet = wb.getSheetAt(0);
HSSFRow row;
HSSFCell cell;
@@ -32,7 +39,7 @@ public class CorrectionHelper {
rows = sheet.getPhysicalNumberOfRows();
int cols = 0; // No of columns
int tmp = 0;
int tmp;
// This trick ensures that we get the data properly even if it doesn't start from first few rows
for (int i = 0; i < 10 || i < rows; i++) {
@@ -43,11 +50,6 @@ public class CorrectionHelper {
}
}
int manualCounter = 0;
int lastName = 0;
int firstName = 1;
int matricNum = 2;
for (int r = 0; r < rows; r++) {
row = sheet.getRow(r);
@@ -57,59 +59,51 @@ public class CorrectionHelper {
cell = row.getCell((short) c);
if (cell != null) {
// TODO
try {
// System.out.println(cell.getStringCellValue());
if (cell.getStringCellValue().contains("MANUAL_CORRECTION")) {
if (inRow)
System.out.println(row.getCell(firstName) + " " + row.getCell(lastName) + " " + row.getCell(matricNum));
System.out.println(row.getCell(FIRST_NAME) + " " + row.getCell(LAST_NAME) + " " + row.getCell(MATRICULATION_NUMBER));
inRow = false;
int column = row.getCell(c - 1).getColumnIndex();
String task;
String task = sheet.getRow(0).getCell(column).getStringCellValue();
// TODO: make variable!
switch (column) {
case 6:
task = "Subtask 1.1";
break;
case 10:
task = "Subtask 1.2";
break;
case 15:
task = "Subtask 2.1";
break;
default:
task = "None";
break;
}
Scanner scanner = new Scanner(System.in);
System.out.print(task + ": ");
String input = scanner.nextLine();
if (task.contains(TASK_TO_CORRECT) || CORRECT_ALL) {
if (input.equals("SAVE")) {
Scanner scanner = new Scanner(System.in);
System.out.print(task + ": ");
String input = scanner.nextLine();
if (input.equals("SAVE")) {
wb.write(file);
System.exit(0);
// FIXME: only skip one entry
} else if (input.equals("SKIP")) {
break;
}
// TODO: validate input
row.getCell(column).setCellValue(Integer.parseInt(input));
wb.write(file);
if (Integer.parseInt(input) != 100) {
System.out.print("Comment: ");
String comment = scanner.nextLine();
row.getCell(column + 3).setCellValue(comment);
wb.write(file);
}
row.getCell(c).setCellValue("CORRECTED_MANUAL");
wb.write(file);
System.exit(0);
}
row.getCell(column).setCellValue(Integer.parseInt(input));
if (Integer.parseInt(input) != 100) {
System.out.print("Comment: ");
String comment = scanner.nextLine();
row.getCell(column + 3).setCellValue(comment);
}
row.getCell(c).setCellValue("CORRECTED_MANUAL");
}
} catch (Exception e) {
// System.out.println(cell.getNumericCellValue());
} catch (Exception ignored) {
}
}
}
}
}
System.out.println("\nMANUAL COUNTER: " + manualCounter);
}
}