Skip to content
This repository has been archived by the owner on Mar 29, 2024. It is now read-only.

Commit

Permalink
Removed a comparison module not needed anymore.
Browse files Browse the repository at this point in the history
Added a filter (Currently hard coded) "ms"/"markscheme" to differentiate between markschemes and papers of different exam boards.
  • Loading branch information
bluishmatt committed Aug 11, 2021
1 parent b6483ed commit 244c366
Show file tree
Hide file tree
Showing 25 changed files with 38 additions and 571 deletions.
1 change: 1 addition & 0 deletions .idea/compiler.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Binary file modified PastPaperPro.jar
Binary file not shown.
6 changes: 0 additions & 6 deletions pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,6 @@
<repositories>

</repositories>

<dependencies>
<dependency>
<groupId>org.apache.pdfbox</groupId>
Expand All @@ -24,11 +23,6 @@
<artifactId>commons-lang3</artifactId>
<version>3.11</version>
</dependency>
<dependency>
<groupId>org.bitbucket.cowwoc</groupId>
<artifactId>diff-match-patch</artifactId>
<version>1.2</version>
</dependency>
<dependency>
<groupId>com.google.code.gson</groupId>
<artifactId>gson</artifactId>
Expand Down
32 changes: 0 additions & 32 deletions src/main/java/co/uk/mattelliot/LoadingPapers.java

This file was deleted.

65 changes: 37 additions & 28 deletions src/main/java/co/uk/mattelliot/PrimaryController.java
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,7 @@
import java.awt.*;
import java.awt.datatransfer.UnsupportedFlavorException;
import java.awt.image.BufferedImage;
import java.awt.print.Paper;
import java.io.*;
import java.lang.reflect.Array;
import java.net.URI;
import java.net.URISyntaxException;
import java.nio.file.Paths;
Expand All @@ -15,7 +13,6 @@
import com.google.common.reflect.TypeToken;
import com.google.gson.Gson;
import com.google.gson.GsonBuilder;
import javafx.application.Application;
import javafx.application.Platform;
import javafx.beans.binding.Bindings;
import javafx.collections.FXCollections;
Expand All @@ -25,7 +22,6 @@
import javafx.event.EventHandler;
import javafx.fxml.FXML;
import javafx.fxml.FXMLLoader;
import javafx.scene.Group;
import javafx.scene.Parent;
import javafx.scene.Scene;
import javafx.scene.control.*;
Expand All @@ -50,6 +46,7 @@
import org.apache.pdfbox.pdmodel.PDDocument;
import org.apache.pdfbox.rendering.ImageType;
import org.apache.pdfbox.rendering.PDFRenderer;

import javax.imageio.ImageIO;


Expand All @@ -76,11 +73,12 @@ public class PrimaryController {
private static ObservableList<Question> listViewTopicQ = FXCollections.observableArrayList();
private static ObservableList<Question> listViewPaperQ = FXCollections.observableArrayList();
private static ObservableList<String> questionsTopicsList = FXCollections.observableArrayList(); //to show topics this question is in.
public ObservableList<String> MarkschemeNames = FXCollections.observableArrayList();


private ListView lastSelectedList = mpaperSelectListView;
private double xOffset = 0;
private double yOffset = 0;
public String markschemeString = "";

public void pdftoimage(String pdf){
ArrayList<BufferedImage> images = new ArrayList<>();
Expand Down Expand Up @@ -127,9 +125,6 @@ public void setImage(String paper, String markscheme){
imageViewMS.setFitWidth(markschemeImage.getWidth());
}




public void initialize() throws IOException {
initializeTopBar();
//a list of Paper names for the paper choicebox.
Expand All @@ -148,50 +143,64 @@ public void initialize() throws IOException {
Task task = new Task<Void>() {
@Override public Void call() throws IOException {

//Strings to exclude. E.g Paper 3 from IBDP CS is a case study. The paper isn't useful for revision.
ArrayList<String> exclude = new ArrayList<>();
exclude.add("paper_3"); //read from json

markschemeString = "_markscheme"; //read from json.
//String names of possible markschemes.
ArrayList<String> markschemeStrings = new ArrayList<>();
markschemeStrings.add("markscheme"); //IB name
markschemeStrings.add("ms"); //ALevel name

java.nio.file.Files.walk(
Paths.get("Papers/"))
.filter(java.nio.file.Files::isRegularFile)
.filter(name -> !name.toString().contains("paper_3")) //not paper 3
.filter(name -> name.toString().contains("pdf")) //not paper 3
.filter(name -> !name.toString().contains("png")) //not paper 3
.filter(name -> name.toString().contains("pdf")) //are pdf
.filter(name -> !name.toString().contains("png")) //not png
.forEach(file -> PaperToConvert.add(String.valueOf(file).substring(7))); //adds the found filename to list, without proceeding /Papers/ folder so it looks nicer in choicebox.

for (String s: PaperToConvert) {
ArrayList<String> tempArrayList = new ArrayList<>();
for (String p: PaperToConvert) {
for (String e: exclude) {
if(s.contains(e)){
PaperToConvert.remove(s);
if(p.contains(e)) {
tempArrayList.add(p);
}
}
}
PaperToConvert.removeAll(tempArrayList);

int complete = 0;
for (String file: PaperToConvert) {

updateProgress(complete, PaperToConvert.size());
// System.out.println("Iteration " + complete);

File f = new File(System.getProperty("user.dir") + "/Papers/" + file + ".png");
//System.out.println(f + " " + f.exists());
if (!f.exists()) {
pdftoimage(System.getProperty("user.dir") + "/Papers/" + file);
}
complete++;
}

tempArrayList.clear();
java.nio.file.Files.walk(
Paths.get("Papers/"))
.filter(java.nio.file.Files::isRegularFile)
.filter(name -> !name.toString().contains(markschemeString)) //not list markschemes
.filter(name -> name.toString().endsWith("png")) //ignore the pdfs because we will work with jpegs.
.forEach(file -> PaperNames.add(String.valueOf(file).substring(7))); //adds the found filename to list, without proceeding Papers folder so it looks nice in choicebox.
.forEach(file -> tempArrayList.add(String.valueOf(file).substring(7))); //adds the found filename to list, without proceeding Papers folder so it looks nice in choicebox.

for (String s: tempArrayList) {
int moved = 0;
for (String ms: markschemeStrings) {
if(s.contains(ms)){
MarkschemeNames.add(s);
moved++;
}
}
if (moved <1){
PaperNames.add(s);
}

}

loadingPane.setVisible(false);
//System.out.println(PaperNames);
if(PaperNames.size() == 0){
loadingPane.setVisible(true);
Label l = (Label) loadingPane.getChildren().get(0);
Expand All @@ -201,6 +210,7 @@ public void initialize() throws IOException {
"See help/guide file for more details.");
}
FXCollections.reverse(PaperNames); //newest Papers at top of list.
FXCollections.reverse(MarkschemeNames); //newest MS at top of list too. These should align.

return null;
}
Expand All @@ -210,8 +220,6 @@ public void initialize() throws IOException {
pb.setPrefWidth(200);
new Thread(task).start();



//open and read Json for any previously saved data.
readJson();

Expand Down Expand Up @@ -255,9 +263,10 @@ public void initialize() throws IOException {
mpaperChoiceBox.setOnAction(event -> {
try {
File paperFile = new File( System.getProperty("user.dir") + "/Papers/" + mpaperChoiceBox.getValue().toString());
File markschemeFile = new File( System.getProperty("user.dir") + "/Papers/" +mpaperChoiceBox.getValue().toString().substring(0,mpaperChoiceBox.getValue().toString().length()-8)+markschemeString+".pdf.png");

setImage(paperFile.toURI().toString(), markschemeFile.toURI().toString());
int msIndex = mpaperChoiceBox.getSelectionModel().getSelectedIndex();
File markschemeFile = new File(System.getProperty("user.dir") + "/Papers/" + MarkschemeNames.get(msIndex));

setImage(paperFile.toURI().toString(), markschemeFile.toURI().toString());

setPaperQuestionsList(mpaperChoiceBox.getValue().toString());

Expand Down Expand Up @@ -791,7 +800,7 @@ public void about(ActionEvent actionEvent) {
contents.getChildren().add(name);
contents.getChildren().add(new Text("as a means to organize past Papers and help improve student learning. \n\r"));
contents.getChildren().add(new Text("If this program was useful please send me a line, I would love to hear how/where this is being used. \n\r"));
contents.getChildren().add(new Text("If it is super useful, buy me a drink to show your appreciation: "));
contents.getChildren().add(new Text("If it is super useful, you can also show your appreciation via paypal: "));
contents.getChildren().add(new Hyperlink("Paypal (to be added) bluishmatt@gmail.com"));
contents.getChildren().add(new Text("\n\rPlease report any issues or feature requests on github."));

Expand Down
Loading

0 comments on commit 244c366

Please sign in to comment.