Skip to content

Commit

Permalink
Merge d27539b into d92d544
Browse files Browse the repository at this point in the history
  • Loading branch information
ValentinMgt authored Apr 23, 2023
2 parents d92d544 + d27539b commit bec5bee
Show file tree
Hide file tree
Showing 20 changed files with 669 additions and 3 deletions.
4 changes: 4 additions & 0 deletions src/main/java/application/Main.java
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,10 @@
package application;

import java.io.IOException;

import components.comparison.ComparisonTable;
import components.comparison.ComparisonView;
import components.comparison.controllers.ComparisonTableController;
import javafx.application.Application;
import javafx.stage.Stage;

Expand Down
2 changes: 2 additions & 0 deletions src/main/java/application/UPMTApp.java
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@
import javafx.scene.Scene;
import javafx.stage.Stage;
import models.Project;
import utils.GlobalVariables;

import java.io.IOException;
import java.util.UUID;
Expand Down Expand Up @@ -69,6 +70,7 @@ public Stage getPrimaryStage() {
public void setCurrentProject(Project project, String path) {
currentProject = project;
currentProjectPath = path;
GlobalVariables.setCurrentProjectPath(currentProjectPath);
rootLayoutController.setProject(project);
}
public Project getCurrentProject() {
Expand Down
114 changes: 114 additions & 0 deletions src/main/java/components/comparison/ComparisonParser.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,114 @@
package components.comparison;


import javafx.collections.ObservableList;
import javafx.util.Pair;
import models.SchemaCategory;
import models.SchemaFolder;
import org.json.JSONObject;
import persistency.newSaveSystem.SConcreteCategory;
import persistency.newSaveSystem.SInterview;
import persistency.newSaveSystem.SMoment;
import persistency.newSaveSystem.SProject;
import persistency.newSaveSystem.serialization.SerializationPool;
import persistency.newSaveSystem.serialization.json.JSONReadPool;
import persistency.newSaveSystem.serialization.json.JSONSerializer;

import java.io.File;
import java.io.FileInputStream;
import java.io.IOException;
import java.nio.charset.StandardCharsets;
import java.util.ArrayList;
import java.util.LinkedHashMap;
import java.util.Objects;

public class ComparisonParser {

private LinkedHashMap<SInterview, LinkedHashMap<SMoment, ArrayList<Pair<SchemaFolder, SConcreteCategory>>>> datas;

private LinkedHashMap<SchemaFolder, ArrayList<String>> dimensions; //hashMap of the dimensions, and their categories
public ComparisonParser(String path) throws IOException {
parse(path);
}

public void parse(String path) throws IOException {
//load a project to get the datas we need (moments and categories)

File fileToRead = new File(path);
String fileContents;
FileInputStream file_input = new FileInputStream(fileToRead);
byte[] content = new byte[(int) fileToRead.length()];
file_input.read(content);
file_input.close();
fileContents = new String(content, StandardCharsets.UTF_8);

JSONObject obj = new JSONObject(fileContents);
JSONReadPool pool = new JSONReadPool();
SerializationPool<Integer, Object> modelsPool = new SerializationPool<>();
JSONSerializer serializer = new JSONSerializer(obj, pool, modelsPool);

SProject sp = new SProject(serializer);
sp.initReading();

ObservableList<SchemaFolder> folders = sp.schemaTreeRoot.convertToModel().foldersProperty(); //folders from the treeRoot
ArrayList<SInterview> interviews = sp.interviews; //list of the interviews

setDimensionsToHM(folders);
setDatas(interviews);
}

//fill the dimension hashmap with what we found in the folders
public void setDimensionsToHM(ObservableList<SchemaFolder> folders){
LinkedHashMap<SchemaFolder, ArrayList<String>> dimensions = new LinkedHashMap<>();
for (SchemaFolder f : folders) { //fill the dimension hashmap with what we found in the folders
ArrayList<String> cctmp = new ArrayList<>();
if(!Objects.equals(f.getName(), "moments")) { //avoid the momentType folder
for (SchemaCategory cc : f.categoriesProperty()){
cctmp.add(cc.getName());
}
dimensions.put(f, cctmp);
}
}
this.dimensions = dimensions;
}
public LinkedHashMap<SchemaFolder, ArrayList<String>> getDimensions(){
return dimensions;
}

public void setDatas(ArrayList<SInterview> interviews) {
LinkedHashMap<SInterview, LinkedHashMap<SMoment, ArrayList<Pair<SchemaFolder, SConcreteCategory>>>> datas = new LinkedHashMap<>();
for (SInterview i : interviews){
LinkedHashMap<SMoment, ArrayList<Pair<SchemaFolder, SConcreteCategory>>> hmTmp = new LinkedHashMap<>();
ArrayList<SMoment> moments = i.rootMoment.submoments;

for (SMoment m : moments){
ArrayList<Pair<SchemaFolder, SConcreteCategory>> lTmp = new ArrayList<>();
for (SConcreteCategory cc : m.categories){ //check each category from a moment
for (SchemaFolder key : dimensions.keySet()) { //we fuse the categories with their dimension
if (dimensions.get(key).contains(cc.schemaCategory.name)) { //if it matchs we add the dimension key
lTmp.add(new Pair<>(key, cc));
break; // break the loop if the category is found in any of the arraylists
}
}
}
hmTmp.put(m, lTmp);
}
datas.put(i, hmTmp);
}
this.datas = datas;
}

public LinkedHashMap<SInterview, LinkedHashMap<SMoment, ArrayList<Pair<SchemaFolder, SConcreteCategory>>>> getDatas(){ return datas; }

public void readDatas(){
for (SInterview i : datas.keySet()){
System.out.println("Interview : " + i.getName());
for (SMoment m : datas.get(i).keySet()){
System.out.println("Moment : " + m.getName());
for (Pair<SchemaFolder, SConcreteCategory> cc : datas.get(i).get(m)){
System.out.println("Category : " + cc.getValue().getName());
}
}
}
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
package components.comparison;

import application.configuration.Configuration;
import components.comparison.controllers.ComparisonSelectionInterviewsControler;
import javafx.application.Application;
import javafx.fxml.FXMLLoader;
import javafx.scene.Parent;
import javafx.scene.Scene;
import javafx.stage.Stage;

import java.io.IOException;

public class ComparisonSelectionInterviewsView extends Application {
@Override
public void start(Stage stage) throws IOException {
FXMLLoader fxmlLoader = new FXMLLoader(getClass().getResource("/views/Project/ComparisonSelectionInterviewsView.fxml"));
ComparisonSelectionInterviewsControler cc = new ComparisonSelectionInterviewsControler();
fxmlLoader.setController(cc);
fxmlLoader.setResources(Configuration.langBundle);
Parent root = fxmlLoader.load();
Scene scene = new Scene(root);
stage.setScene(scene);

stage.show();
}
}
113 changes: 113 additions & 0 deletions src/main/java/components/comparison/ComparisonTable.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,113 @@
package components.comparison;

import javafx.collections.ObservableList;
import javafx.util.Pair;
import models.Interview;
import models.SchemaFolder;
import persistency.newSaveSystem.SConcreteCategory;
import persistency.newSaveSystem.SInterview;
import persistency.newSaveSystem.SMoment;
import utils.GlobalVariables;

import java.io.IOException;
import java.util.ArrayList;
import java.util.HashMap;

public class ComparisonTable {
private ArrayList<block> blocks; //the table is made from the blocks (1 block = 1 interview)
private ComparisonParser rawDatas; //datas to fill the table

public ComparisonTable (ObservableList<String> selectionInterviews) throws IOException {
this.blocks = new ArrayList<>();
this.rawDatas = new ComparisonParser(GlobalVariables.getGlobalVariables().getCurrentProjectPath());
createTable(selectionInterviews);
}

public int getMaxTableLength(){
int length = 0;
for(HashMap<SMoment, ArrayList<Pair<SchemaFolder, SConcreteCategory>>> listM : rawDatas.getDatas().values()){
int momentsLength = listM.size();
if (length < momentsLength){ length = momentsLength; }
}
return length;
}
private line<SMoment> createFirstLine(SInterview interview){
int size = getMaxTableLength();
String title = "Moments";
ArrayList<SMoment> values = new ArrayList<>(interview.rootMoment.submoments);
return new line<>(title, size, values);
}
private line<ArrayList<SConcreteCategory>> createDimensionLine(SInterview interview, SchemaFolder dimension){
HashMap<SMoment, ArrayList<Pair<SchemaFolder, SConcreteCategory>>> datas = rawDatas.getDatas().get(interview);
int size = getMaxTableLength();
String title = dimension.getName();
ArrayList<ArrayList<SConcreteCategory>> values = new ArrayList<>(size);
for(ArrayList<Pair<SchemaFolder, SConcreteCategory>> pairList : datas.values()){
ArrayList<SConcreteCategory> tmpList = new ArrayList<>();
for(Pair<SchemaFolder, SConcreteCategory> pair: pairList){
if(pair.getKey() == dimension){
tmpList.add(pair.getValue());
}
}
values.add(tmpList);
}
return new line<>(title, size, values);
}

private block createBlock(SInterview interview){
String title = interview.convertToModel().getTitle();
line<SMoment> firstLine = createFirstLine(interview);
ArrayList<line<ArrayList<SConcreteCategory>>> dimensionLines = new ArrayList<>();
ArrayList<SchemaFolder> dimensions = new ArrayList<>(rawDatas.getDimensions().keySet());

for (SchemaFolder d : dimensions){
dimensionLines.add(createDimensionLine(interview, d));
}
return new block(title, firstLine, dimensionLines);
}

private void createTable(ObservableList<String> selectionInterviews){
ArrayList<block> blocks = new ArrayList<>();
for (SInterview interview : rawDatas.getDatas().keySet()){
if (selectionInterviews.contains(interview.convertToModel().getTitle())) {
blocks.add(createBlock(interview));
}
}
this.blocks = blocks;
}

//display the content of the table on the terminal
public void readTable(){
for(block b: blocks){
System.out.println(b.getTitle()+ " -> ");
line<SMoment> firstLine = b.getFirstLine();
System.out.print(firstLine.getTitle() + " : ");
for (SMoment m : firstLine.getValues()){
System.out.print(" | "+m.name);
}
ArrayList<line<ArrayList<SConcreteCategory>>> dimensionLines = b.getDimensionLines();
for (line<ArrayList<SConcreteCategory>> line : dimensionLines){
System.out.println();
System.out.print(line.getTitle() + " : ");
for (ArrayList<SConcreteCategory> ccList : line.getValues()){
System.out.print(" | ");
for (SConcreteCategory cc : ccList){
//test si c'est le dernier de la liste
if (ccList.indexOf(cc) == ccList.size()-1){
System.out.print(cc.schemaCategory.name);
}else {
System.out.print(cc.schemaCategory.name+"; ");
}
}
}
}
System.out.println();
}
}

public ArrayList<block> getBlocks() {
return blocks;
}

}

33 changes: 33 additions & 0 deletions src/main/java/components/comparison/ComparisonView.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
package components.comparison;

import application.configuration.Configuration;
import components.comparison.controllers.ComparisonTableController;
import javafx.application.Application;
import javafx.collections.ObservableList;
import javafx.fxml.FXMLLoader;
import javafx.scene.Parent;
import javafx.scene.Scene;
import javafx.stage.Stage;

import java.io.IOException;

public class ComparisonView extends Application {

private ObservableList<String> selectionInterviews;

public ComparisonView(ObservableList<String> selectionInterviews){
this.selectionInterviews = selectionInterviews;
}
@Override
public void start(Stage stage) throws IOException {
FXMLLoader fxmlLoader = new FXMLLoader(getClass().getResource("/views/Comparison/ComparisonView.fxml"));
ComparisonTableController controller = new ComparisonTableController(this.selectionInterviews);
fxmlLoader.setController(controller);
fxmlLoader.setResources(Configuration.langBundle);
Parent root = fxmlLoader.load();
Scene scene = new Scene(root);
stage.setScene(scene);

stage.show();
}
}
36 changes: 36 additions & 0 deletions src/main/java/components/comparison/block.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
package components.comparison;

import persistency.newSaveSystem.SConcreteCategory;
import persistency.newSaveSystem.SMoment;

import java.util.ArrayList;

public class block {
private final String title;
private line<SMoment> firstLine;
private ArrayList<line<ArrayList<SConcreteCategory>>> dimensionLines;

public block(String title, line<SMoment> firstLine, ArrayList<line<ArrayList<SConcreteCategory>>> dimensionLines) {
this.title = title;
this.firstLine = firstLine;
this.dimensionLines = dimensionLines;
}

public block() {
this.title = "unNamed";
this.firstLine = new line<>();
this.dimensionLines = new ArrayList<>();
}

public String getTitle() {
return title;
}

public line<SMoment> getFirstLine() {
return firstLine;
}

public ArrayList<line<ArrayList<SConcreteCategory>>> getDimensionLines() {
return dimensionLines;
}
}
Loading

0 comments on commit bec5bee

Please sign in to comment.