diff --git a/.classpath b/.classpath
index 894f51d..f4072d6 100644
--- a/.classpath
+++ b/.classpath
@@ -20,5 +20,25 @@
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
diff --git a/.idea/workspace.xml b/.idea/workspace.xml
index ff01b5d..d3077ba 100644
--- a/.idea/workspace.xml
+++ b/.idea/workspace.xml
@@ -2,82 +2,43 @@
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
+
+
+
+
+
-
+
-
-
+
+
+
+
+
+
-
-
-
+
-
-
-
-
+
+
+
+
+
-
+
+
+
+
+
+
+
+
-
-
-
+
-
-
-
@@ -93,9 +54,9 @@
@@ -128,20 +89,23 @@
-
+
+
-
+
+
+
-
+
-
-
+
+
@@ -215,8 +179,8 @@
-
+
@@ -243,7 +207,8 @@
-
+
+
@@ -273,11 +238,15 @@
-
+
+
+
+
+
-
+
@@ -287,46 +256,46 @@
-
+
-
-
+
+
-
-
+
+
-
-
+
+
-
-
+
+
-
-
+
+
-
-
+
+
-
-
+
+
-
+
@@ -340,16 +309,16 @@
-
+
-
-
+
+
-
+
@@ -359,10 +328,10 @@
-
+
-
+
\ No newline at end of file
diff --git a/Project Team Formation Mileston1.eml b/Project Team Formation Mileston1.eml
index 80ff6f7..15b7e70 100644
--- a/Project Team Formation Mileston1.eml
+++ b/Project Team Formation Mileston1.eml
@@ -31,5 +31,25 @@
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
diff --git a/README.md b/README.md
index 5447b16..b8ca3e0 100644
--- a/README.md
+++ b/README.md
@@ -38,3 +38,8 @@ Database - MySQL (8.0.21)
2. OSX - `MySQL is installed but is not starting.`
Use MySQL Preference Pane (`https://dev.mysql.com/doc/mysql-osx-excerpt/5.7/en/osx-installation-prefpane.html`) to Start MySQL server.
+
+3. MySQL commands:
+ Create Schema: `create schema milestone4;`
+ Drop Schema: `drop schema milestone4;`
+ Use Schema: `use milestone4;`
diff --git a/rmit.userlibraries b/rmit.userlibraries
index 6534bf2..46b6c49 100644
--- a/rmit.userlibraries
+++ b/rmit.userlibraries
@@ -45,6 +45,66 @@
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
diff --git a/src/main/java/controllers/OrmFxController.java b/src/main/java/controllers/OrmFxController.java
index ed4a130..a23ddb2 100644
--- a/src/main/java/controllers/OrmFxController.java
+++ b/src/main/java/controllers/OrmFxController.java
@@ -1,5 +1,6 @@
package controllers;
+import enums.SuggestionMode;
import hibernate.OrmStudents;
import hibernate.OrmTeams;
import hibernate.dao.StudentsDao;
@@ -8,16 +9,10 @@
import interfaces.ITeams;
import javafx.event.ActionEvent;
import javafx.fxml.FXML;
-import javafx.scene.control.Alert;
-import javafx.scene.control.CheckBox;
-import javafx.scene.control.TextField;
-import javafx.scene.control.TextFormatter;
+import javafx.scene.control.*;
import javafx.scene.layout.HBox;
import models.TeamSelection;
-import services.ChartsService;
-import services.FxCrudService;
-import services.OrmChartsService;
-import services.TeamBoxService;
+import services.*;
import sources.DatafileIOclass;
import sources.Teams;
import utils.FileNames;
@@ -41,11 +36,20 @@ public class OrmFxController {
@FXML
public TextField studentInput;
@FXML
+ public Button addBtn;
+ @FXML
+ public Button swapBtn;
+ @FXML
+ public Button suggestionBtn;
+ @FXML
+ public Button undoSuggestionBtn;
+ @FXML
Alert alert = new Alert(Alert.AlertType.ERROR);
@FXML
Alert success = new Alert(Alert.AlertType.INFORMATION);
@FXML
public Map selection = new HashMap<>();
+
private TeamBoxService teamBoxesService;
private OrmChartsService ormChartsService;
StudentsDao studentsDao = new StudentsDao();
@@ -71,8 +75,8 @@ public void addMemberToTeam(ActionEvent actionEvent) {
} else {
// actual member addition to teams table in database
OrmTeamsService.addMemberToTeam(this.selection, student, teamsDao);
- updateTextFields(FxErrorMessages.STUDENT_ADDED);
- drawCharts();
+ updateTextFields(FxErrorMessages.STUDENT_ADDED, SuggestionMode.DISABLED);
+ drawCharts(SuggestionMode.DISABLED);
}
}
}
@@ -88,8 +92,8 @@ public void swapMembers(ActionEvent actionEvent) {
List ormTeams = teamsDao.getAllTeamsById(selectedTeamIds);
if (ormStudents != null && ormStudents.size() == 2) {
teamsDao.swapMembersInTeams(this.selection, selectedStudentIds, ormTeams);
- drawCharts();
- updateTextFields(FxErrorMessages.STUDENTS_SWAPPED);
+ drawCharts(SuggestionMode.DISABLED);
+ updateTextFields(FxErrorMessages.STUDENTS_SWAPPED, SuggestionMode.DISABLED);
} else {
alert.setContentText(FxErrorMessages.INVALID_STUDENTS_SELECTED);
alert.show();
@@ -97,6 +101,20 @@ public void swapMembers(ActionEvent actionEvent) {
}
}
+ public void suggestTeams(ActionEvent actionEvent) {
+ toggleButtons(SuggestionMode.ENABLED);
+ SuggestionService.suggestTeams(teamsDao, 5);
+ updateTextFields(FxErrorMessages.TEAMS_SUGGESTED, SuggestionMode.ENABLED);
+ drawCharts(SuggestionMode.ENABLED);
+ }
+
+ public void undoSuggestion(ActionEvent actionEvent) {
+ toggleButtons(SuggestionMode.DISABLED);
+ SuggestionService.suggestTeams(teamsDao, 5);
+ updateTextFields(FxErrorMessages.UNDO_SUGGESTION, SuggestionMode.DISABLED);
+ drawCharts(SuggestionMode.DISABLED);
+ }
+
public void updateSelection(ActionEvent actionEvent) {
boolean isSelected = ((CheckBox) actionEvent.getTarget()).isSelected();
String sourceId = ((CheckBox) actionEvent.getSource()).getId();
@@ -116,7 +134,8 @@ public void initialize() {
return change;
}));
createTeamBoxes();
- drawCharts();
+ toggleButtons(SuggestionMode.DISABLED);
+ drawCharts(SuggestionMode.DISABLED);
}
private void createTeamBoxes() {
@@ -126,14 +145,28 @@ private void createTeamBoxes() {
teamBoxesService = teamBoxService;
}
- private void drawCharts() {
+ private void drawCharts(SuggestionMode suggestionMode) {
ormChartsService = new OrmChartsService(teamsDao);
- chartsContainer.getChildren().setAll(ormChartsService.drawCharts());
+ chartsContainer.getChildren().setAll(ormChartsService.drawCharts(suggestionMode));
}
- private void updateTextFields(String successMessage) {
- teamBoxesService.populateMemberIdsWithOrm(5, false);
+ private void updateTextFields(String successMessage, SuggestionMode suggestionMode) {
+ teamBoxesService.populateMemberIdsWithOrm(5, false, suggestionMode);
success.setContentText(successMessage);
success.show();
}
+
+ private void toggleButtons(SuggestionMode suggestionMode) {
+ if (suggestionMode == SuggestionMode.ENABLED) {
+ this.addBtn.setDisable(true);
+ this.swapBtn.setDisable(true);
+ this.suggestionBtn.setDisable(true);
+ this.undoSuggestionBtn.setDisable(false);
+ } else {
+ this.addBtn.setDisable(false);
+ this.swapBtn.setDisable(false);
+ this.suggestionBtn.setDisable(false);
+ this.undoSuggestionBtn.setDisable(true);
+ }
+ }
}
diff --git a/src/main/java/enums/SuggestionMode.java b/src/main/java/enums/SuggestionMode.java
new file mode 100644
index 0000000..cc097f9
--- /dev/null
+++ b/src/main/java/enums/SuggestionMode.java
@@ -0,0 +1,6 @@
+package enums;
+
+public enum SuggestionMode {
+ ENABLED,
+ DISABLED
+}
diff --git a/src/main/java/hibernate/OrmSuggestedTeams.java b/src/main/java/hibernate/OrmSuggestedTeams.java
new file mode 100644
index 0000000..d6f50f2
--- /dev/null
+++ b/src/main/java/hibernate/OrmSuggestedTeams.java
@@ -0,0 +1,99 @@
+package hibernate;
+
+import interfaces.ITeams;
+
+import javax.persistence.*;
+import java.util.ArrayList;
+import java.util.List;
+
+@Entity
+@Table(name = "suggested_teams")
+public class OrmSuggestedTeams implements ITeams {
+
+ public static List fromOrmTeams(List ormTeamsList) {
+ List suggestedTeams = new ArrayList<>();
+ for(OrmTeams ormTeam: ormTeamsList) {
+ OrmSuggestedTeams ormSuggestedTeam = new OrmSuggestedTeams();
+ ormSuggestedTeam.setId(ormTeam.getId());
+ ormSuggestedTeam.setProject(ormTeam.getProject());
+ ormSuggestedTeam.setStudent1(ormTeam.getStudent1());
+ ormSuggestedTeam.setStudent2(ormTeam.getStudent2());
+ ormSuggestedTeam.setStudent3(ormTeam.getStudent3());
+ ormSuggestedTeam.setStudent4(ormTeam.getStudent4());
+ suggestedTeams.add(ormSuggestedTeam);
+ }
+ return suggestedTeams;
+ }
+
+ @Id
+ @Column(name = "id")
+ private int id;
+
+ @OneToOne(targetEntity = OrmProjects.class)
+ @JoinColumn(name="project_id", unique = true)
+ private OrmProjects project;
+
+ @OneToOne(targetEntity = OrmStudents.class)
+ @JoinColumn(name="student_id_1")
+ private OrmStudents student1;
+
+ @OneToOne(targetEntity = OrmStudents.class)
+ @JoinColumn(name="student_id_2")
+ private OrmStudents student2;
+
+ @OneToOne(targetEntity = OrmStudents.class)
+ @JoinColumn(name="student_id_3")
+ private OrmStudents student3;
+
+ @OneToOne(targetEntity = OrmStudents.class)
+ @JoinColumn(name="student_id_4")
+ private OrmStudents student4;
+
+ public int getId() {
+ return id;
+ }
+
+ public void setId(int id) {
+ this.id = id;
+ }
+
+ public OrmProjects getProject() {
+ return project;
+ }
+
+ public void setProject(OrmProjects project) {
+ this.project = project;
+ }
+
+ public OrmStudents getStudent1() {
+ return student1;
+ }
+
+ public void setStudent1(OrmStudents student1) {
+ this.student1 = student1;
+ }
+
+ public OrmStudents getStudent2() {
+ return student2;
+ }
+
+ public void setStudent2(OrmStudents student2) {
+ this.student2 = student2;
+ }
+
+ public OrmStudents getStudent3() {
+ return student3;
+ }
+
+ public void setStudent3(OrmStudents student3) {
+ this.student3 = student3;
+ }
+
+ public OrmStudents getStudent4() {
+ return student4;
+ }
+
+ public void setStudent4(OrmStudents student4) {
+ this.student4 = student4;
+ }
+}
diff --git a/src/main/java/hibernate/OrmTeams.java b/src/main/java/hibernate/OrmTeams.java
index 0730112..e784531 100644
--- a/src/main/java/hibernate/OrmTeams.java
+++ b/src/main/java/hibernate/OrmTeams.java
@@ -4,10 +4,28 @@
import utils.Validators;
import javax.persistence.*;
+import java.util.ArrayList;
+import java.util.List;
@Entity
@Table(name = "teams")
public class OrmTeams implements ITeams {
+
+ public static List fromSuggestedTeams(List ormSuggestedTeamsList) {
+ List ormTeams = new ArrayList<>();
+ for(OrmSuggestedTeams ormSuggestedTeam: ormSuggestedTeamsList) {
+ OrmTeams ormTeam = new OrmTeams();
+ ormTeam.setId(ormSuggestedTeam.getId());
+ ormTeam.setProject(ormSuggestedTeam.getProject());
+ ormTeam.setStudent1(ormSuggestedTeam.getStudent1());
+ ormTeam.setStudent2(ormSuggestedTeam.getStudent2());
+ ormTeam.setStudent3(ormSuggestedTeam.getStudent3());
+ ormTeam.setStudent4(ormSuggestedTeam.getStudent4());
+ ormTeams.add(ormTeam);
+ }
+ return ormTeams;
+ }
+
@Id
@GeneratedValue(strategy = GenerationType.IDENTITY)
private int id;
diff --git a/src/main/java/hibernate/dao/PreferenceDao.java b/src/main/java/hibernate/dao/PreferenceDao.java
index 274c652..093e2f1 100644
--- a/src/main/java/hibernate/dao/PreferenceDao.java
+++ b/src/main/java/hibernate/dao/PreferenceDao.java
@@ -2,7 +2,6 @@
import hibernate.HibernateUtil;
import hibernate.OrmPreference;
-import hibernate.OrmStudentInfo;
import org.hibernate.Session;
import org.hibernate.query.Query;
import utils.Validators;
@@ -29,4 +28,15 @@ public OrmPreference getPreference(String studentId) {
session.close();
}
}
+
+ public List getPreferenceListFromStudentIds(List studentIds) {
+ Session session = HibernateUtil.getSessionFactory().openSession();
+ try {
+ Query query = session.createQuery("FROM OrmPreference s where s.studentId in :studentIds");
+ query.setParameter("studentIds", studentIds);
+ return query.list();
+ } finally {
+ session.close();
+ }
+ }
}
diff --git a/src/main/java/hibernate/dao/SuggestedTeamsDao.java b/src/main/java/hibernate/dao/SuggestedTeamsDao.java
new file mode 100644
index 0000000..00fe29a
--- /dev/null
+++ b/src/main/java/hibernate/dao/SuggestedTeamsDao.java
@@ -0,0 +1,44 @@
+package hibernate.dao;
+
+import hibernate.*;
+import hibernate.services.OrmTeamsService;
+import models.TeamSelection;
+import org.hibernate.Session;
+import org.hibernate.query.Query;
+
+import java.util.ArrayList;
+import java.util.List;
+import java.util.Map;
+import java.util.stream.Collectors;
+
+public class SuggestedTeamsDao {
+
+ public List getAllTeams() {
+ Session session = HibernateUtil.getSessionFactory().openSession();
+ try {
+ List teamsList = (List) session.createQuery(
+ "FROM OrmTeams s ORDER BY s.id ASC").list();
+ return teamsList;
+ } finally {
+ session.close();
+ }
+ }
+
+ public void insertTeams(List ormTeams) {
+ Session localSession = HibernateUtil.getSessionFactory().openSession();
+ try {
+ // clear previous suggestions
+ localSession.beginTransaction();
+ Query deleteQuery = localSession.createQuery("DELETE FROM OrmSuggestedTeams");
+ deleteQuery.executeUpdate();
+ // set new suggestions
+ List ormSuggestedTeams = OrmSuggestedTeams.fromOrmTeams(ormTeams);
+ for(OrmSuggestedTeams ormSuggestedTeam: ormSuggestedTeams) {
+ localSession.save("OrmSuggestedTeams", ormSuggestedTeam);
+ }
+ localSession.getTransaction().commit();
+ } finally {
+ localSession.close();
+ }
+ }
+}
diff --git a/src/main/java/hibernate/dao/TeamsDao.java b/src/main/java/hibernate/dao/TeamsDao.java
index 3e12606..b64c134 100644
--- a/src/main/java/hibernate/dao/TeamsDao.java
+++ b/src/main/java/hibernate/dao/TeamsDao.java
@@ -1,9 +1,7 @@
package hibernate.dao;
-import hibernate.HibernateUtil;
-import hibernate.OrmStudentInfo;
-import hibernate.OrmStudents;
-import hibernate.OrmTeams;
+import enums.SuggestionMode;
+import hibernate.*;
import hibernate.services.OrmTeamsService;
import models.TeamSelection;
import org.hibernate.Session;
@@ -14,12 +12,17 @@
public class TeamsDao {
- public List getAllTeams() {
+ public List getAllTeams(SuggestionMode suggestionMode) {
Session session = HibernateUtil.getSessionFactory().openSession();
try {
- List teamsList = (List) session.createQuery(
- "FROM OrmTeams s ORDER BY s.id ASC").list();
- return teamsList;
+ if(suggestionMode == SuggestionMode.DISABLED) {
+ List teamsList = (List) session.createQuery(
+ "FROM OrmTeams s ORDER BY s.id ASC").list();
+ return teamsList;
+ } else {
+ List suggestedTeams = session.createQuery("FROM OrmSuggestedTeams s ORDER BY s.id ASC").list();
+ return OrmTeams.fromSuggestedTeams(suggestedTeams);
+ }
} finally {
session.close();
}
diff --git a/src/main/java/services/OrmChartsService.java b/src/main/java/services/OrmChartsService.java
index eec041c..26c6028 100644
--- a/src/main/java/services/OrmChartsService.java
+++ b/src/main/java/services/OrmChartsService.java
@@ -1,5 +1,6 @@
package services;
+import enums.SuggestionMode;
import hibernate.OrmTeams;
import hibernate.dao.TeamsDao;
import javafx.scene.chart.BarChart;
@@ -20,9 +21,9 @@ public class OrmChartsService {
public OrmChartsService(TeamsDao teamsDao) {
this.teamsDao = teamsDao;
}
- public List> drawCharts() {
+ public List> drawCharts(SuggestionMode suggestionMode) {
List> charts = new ArrayList<>();
- List ormTeams = teamsDao.getAllTeams().stream().limit(5).collect(Collectors.toList());
+ List ormTeams = teamsDao.getAllTeams(suggestionMode).stream().limit(5).collect(Collectors.toList());
// 1st chart
PrefPercentageChartService percentageChartService = new PrefPercentageChartService(null, ormTeams);
charts.add(percentageChartService.createChart(teamsDao));
diff --git a/src/main/java/services/SuggestionService.java b/src/main/java/services/SuggestionService.java
new file mode 100644
index 0000000..1de3399
--- /dev/null
+++ b/src/main/java/services/SuggestionService.java
@@ -0,0 +1,158 @@
+package services;
+
+import enums.SuggestionMode;
+import hibernate.OrmPreference;
+import hibernate.OrmStudents;
+import hibernate.OrmTeams;
+import hibernate.dao.PreferenceDao;
+import hibernate.dao.SuggestedTeamsDao;
+import hibernate.dao.TeamsDao;
+import hibernate.services.OrmTeamsService;
+
+import java.math.BigDecimal;
+import java.util.*;
+import java.util.stream.Collectors;
+
+public class SuggestionService {
+ /*
+ Algo for Heuristic Completion which lowers the Standard Devation of all charts
+ 1. It saves the suggestion state in `suggested_teams` table, from which we show/dont show the records depending on user's selection.
+ */
+ public static void suggestTeams(TeamsDao teamsDao, int size) {
+ List allTeams = teamsDao.getAllTeams(SuggestionMode.DISABLED).stream().limit(size).collect(Collectors.toList());
+
+ Map> teamsByPercentages = new HashMap<>();
+ for (OrmTeams team : allTeams) {
+ BigDecimal percentage = OrmTeamsService.getPercentageForTeam(team, teamsDao);
+ if (teamsByPercentages.get(percentage) != null) {
+ teamsByPercentages.get(percentage).add(team);
+ } else {
+ List percTeams = new ArrayList<>();
+ percTeams.add(team);
+ teamsByPercentages.put(percentage, percTeams);
+ }
+ }
+ Set percentages = teamsByPercentages.keySet();
+ BigDecimal minPercentage = percentages.stream().min(Comparator.naturalOrder()).orElse(BigDecimal.ZERO);
+ List minimumPercentageTeams = teamsByPercentages.get(minPercentage); // 25 percent
+ List heavyWeightTeams = new ArrayList<>(); // 75 percent
+ for(BigDecimal key: percentages) {
+ if (minPercentage.compareTo(key) != 0) {
+ heavyWeightTeams.addAll(teamsByPercentages.get(key));
+ }
+ }
+ for(OrmTeams heavyTeam: heavyWeightTeams) {
+ // diff is 75-25= 50
+ BigDecimal diff = OrmTeamsService.getPercentageForTeam(heavyTeam, teamsDao).subtract(minPercentage);
+ int numberOfSwappings = numberOfSwappings(diff);
+ List studentsAddedToLightTeam = new ArrayList<>();
+ for (int i=0; i heavyWeightStudents = getMatchingStudentIds(heavyTeam);
+ for(String heavyStudentId: heavyWeightStudents) {
+ if(!isStudentMatching(heavyStudentId, minPercTeam)) {
+ List lightWeightStudents = getNonMatchingStudentIds(minPercTeam, studentsAddedToLightTeam);
+ for(String lightStudentId: lightWeightStudents) {
+ if(!isStudentMatching(lightStudentId, heavyTeam)) {
+ Map lightStudent = findStudentNumber(minPercTeam, lightStudentId);
+ Map heavyStudent = findStudentNumber(heavyTeam, heavyStudentId);
+ setStudentWithNumber((Integer) heavyStudent.keySet().toArray()[0], (OrmStudents)lightStudent.values().toArray()[0], heavyTeam);
+ studentsAddedToLightTeam.add(((OrmStudents)heavyStudent.values().toArray()[0]).getId());
+ setStudentWithNumber((Integer) lightStudent.keySet().toArray()[0], (OrmStudents)heavyStudent.values().toArray()[0], minPercTeam);
+ break;
+ }
+ }
+ break;
+ }
+ }
+ }
+ }
+ SuggestedTeamsDao suggestedTeamsDao = new SuggestedTeamsDao();
+ suggestedTeamsDao.insertTeams(allTeams);
+ }
+
+ public static void setStudentWithNumber(Integer studentNumber, OrmStudents newStudent, OrmTeams team) {
+ switch (studentNumber) {
+ case 1:
+ team.setStudent1(newStudent);
+ break;
+ case 2:
+ team.setStudent2(newStudent);
+ break;
+ case 3:
+ team.setStudent3(newStudent);
+ break;
+ case 4:
+ team.setStudent4(newStudent);
+ }
+ }
+
+ public static Map findStudentNumber(OrmTeams team, String studentId) {
+ HashMap map = new HashMap<>();
+ if(team.getStudent1().getId().equalsIgnoreCase(studentId)) {
+ map.put(1, team.getStudent1());
+ } else if(team.getStudent2().getId().equalsIgnoreCase(studentId)) {
+ map.put(2, team.getStudent2());
+ } else if(team.getStudent3().getId().equalsIgnoreCase(studentId)) {
+ map.put(3, team.getStudent3());
+ } else if(team.getStudent4().getId().equalsIgnoreCase(studentId)) {
+ map.put(4, team.getStudent4());
+ }
+ return map;
+ }
+
+ public static int numberOfSwappings(BigDecimal diff) {
+ Integer diffInInteger = new Integer(diff.intValue());
+ switch (diffInInteger) {
+ case 25:
+ return 1;
+ case 50:
+ return 2;
+ case 75:
+ return 3;
+ default:
+ return 0;
+ }
+ }
+
+ public static List getNonMatchingStudentIds(OrmTeams team, List studentsJustAdded) {
+ List studentIds = OrmTeamsService.getAllStudentIdsFromTeam(team);
+ String projectId = team.getProject().getId();
+ PreferenceDao preferenceDao = new PreferenceDao();
+ List projectPreferenceList = preferenceDao.getPreferenceListFromStudentIds(studentIds);
+ List nonMatchedStudentIds = new ArrayList<>();
+ for(OrmPreference preference: projectPreferenceList) {
+ if(!preference.getPreference1().equalsIgnoreCase(projectId)
+ && !preference.getPreference2().equalsIgnoreCase(projectId)
+ && !(studentsJustAdded.contains(preference.getStudentId()))) {
+ nonMatchedStudentIds.add(preference.getStudentId());
+ }
+ }
+ return nonMatchedStudentIds;
+ }
+
+ public static List getMatchingStudentIds(OrmTeams team) {
+ List studentIds = OrmTeamsService.getAllStudentIdsFromTeam(team);
+ String projectId = team.getProject().getId();
+ PreferenceDao preferenceDao = new PreferenceDao();
+ List projectPreferenceList = preferenceDao.getPreferenceListFromStudentIds(studentIds);
+ List matchedStudentIds = new ArrayList<>();
+ for(OrmPreference preference: projectPreferenceList) {
+ if(preference.getPreference1().equalsIgnoreCase(projectId)
+ || preference.getPreference2().equalsIgnoreCase(projectId)) {
+ matchedStudentIds.add(preference.getStudentId());
+ }
+ }
+ return matchedStudentIds;
+ }
+
+ public static boolean isStudentMatching(String studentId, OrmTeams lightTeam) {
+ PreferenceDao preferenceDao = new PreferenceDao();
+ OrmPreference preference = preferenceDao.getPreference(studentId);
+ if(preference.getPreference1().equalsIgnoreCase(lightTeam.getProject().getId())
+ || preference.getPreference2().equalsIgnoreCase(lightTeam.getProject().getId())) {
+ return true;
+ }
+ return false;
+ }
+}
diff --git a/src/main/java/services/TeamBoxService.java b/src/main/java/services/TeamBoxService.java
index 1b09acd..61772ee 100644
--- a/src/main/java/services/TeamBoxService.java
+++ b/src/main/java/services/TeamBoxService.java
@@ -1,5 +1,6 @@
package services;
+import enums.SuggestionMode;
import hibernate.OrmTeams;
import hibernate.dao.TeamsDao;
import hibernate.services.OrmTeamsService;
@@ -24,18 +25,20 @@ public class TeamBoxService {
private FxCrudService fxCrudService;
TeamsDao teamsDao = new TeamsDao();
private List teamsFromDatabase;
+ private Integer studentsPerTeam;
public TeamBoxService(HBox teamBoxContainer, EventHandler value, FxCrudService fxCrudService) {
this.teamBoxContainer = teamBoxContainer;
this.checkboxAction = value;
this.fxCrudService = fxCrudService;
+ this.studentsPerTeam = 4;
}
public TeamBoxService() {}
public void createTeamBoxes(int size, boolean initFromDatabase) {
- this.teamsFromDatabase = teamsDao.getAllTeams().stream().limit(size).collect(Collectors.toList());
+ this.teamsFromDatabase = teamsDao.getAllTeams(SuggestionMode.DISABLED).stream().limit(size).collect(Collectors.toList());
for (Integer i=1; i<=size; i++) {
VBox teamBox = new VBox();
teamBox.setStyle("-fx-background-color: "+ Colors.boxColors[i-1] + "; -fx-text-fill: black");
@@ -47,12 +50,14 @@ public void createTeamBoxes(int size, boolean initFromDatabase) {
teamBoxContainer.getChildren().addAll(teamBox);
}
if (initFromDatabase) {
- this.populateMemberIdsWithOrm(size, true);
+ this.populateMemberIdsWithOrm(size, true, SuggestionMode.DISABLED);
}
}
- public void populateMemberIdsWithOrm(int teamsToShowOnUI, boolean useCache) {
- List allTeams = useCache ? this.teamsFromDatabase : teamsDao.getAllTeams().stream().limit(teamsToShowOnUI).collect(Collectors.toList());
+ public void populateMemberIdsWithOrm(int teamsToShowOnUI, boolean useCache, SuggestionMode suggestionMode) {
+ List allTeams = useCache
+ ? this.teamsFromDatabase
+ : teamsDao.getAllTeams(suggestionMode).stream().limit(teamsToShowOnUI).collect(Collectors.toList());
this.teamsFromDatabase = allTeams;
for (int i=0; i getSelectedStudentIds(List teamSelections) {
private List getTeamBoxFields(String teamNum) {
List fields = new ArrayList<>();
- for (Integer i=1; i<=this.teamsFromDatabase.size(); i++) {
+ for (Integer i=1; i<=this.studentsPerTeam; i++) {
HBox teamBox = new HBox();
teamBox.setPadding(new Insets(10, 10, 10, 10));
teamBox.getChildren().addAll(getTextField(), getCheckbox(teamNum, i.toString()));
diff --git a/src/main/java/sources/DatafileIOclass.java b/src/main/java/sources/DatafileIOclass.java
index 744aef1..9d4fbed 100644
--- a/src/main/java/sources/DatafileIOclass.java
+++ b/src/main/java/sources/DatafileIOclass.java
@@ -146,7 +146,7 @@ public String fetchObjectById(String filename, String objectId) {
if (object != null) {
return object;
} else {
- System.out.println("Object doesnt exist in file: " + filename);
+ //System.out.println("Object doesnt exist in file: " + filename);
return null;
}
}
diff --git a/src/main/java/sources/Teams.java b/src/main/java/sources/Teams.java
index ec93849..d83b68a 100644
--- a/src/main/java/sources/Teams.java
+++ b/src/main/java/sources/Teams.java
@@ -1,10 +1,12 @@
package sources;
+import exceptions.EmptyListException;
import exceptions.NoLeaderException;
import exceptions.PersonalityImbalanceException;
import interfaces.ITeams;
import utils.FileNames;
import utils.Personalities;
+import utils.StandardDeviationService;
import utils.Validators;
import java.io.File;
@@ -93,11 +95,11 @@ public static Teams fileRowToTeams(String row) {
return team;
}
- public static void displayTeamPreference(List teams) {
+ public static void displayTeamPreference(List teams){
int i = 1;
for (Teams team: teams) {
System.out.println("---------%AGE OF PREFERENCES FOR TEAM: " + i + "---------------");
- System.out.println("Percentage of Students in this Team who had this .Project in their first 2 preferences: " + getPercentage(team, textfileN1) + "%");
+ System.out.println("Percentage of Students in this Team who had this Project in their first 2 preferences: " + getPercentage(team, textfileN1) + "%");
System.out.println("------------------------");
i++;
}
diff --git a/src/main/java/utils/FxErrorMessages.java b/src/main/java/utils/FxErrorMessages.java
index e55aac1..beac550 100644
--- a/src/main/java/utils/FxErrorMessages.java
+++ b/src/main/java/utils/FxErrorMessages.java
@@ -10,4 +10,6 @@ public class FxErrorMessages {
public static String INVALID_STUDENTS_SELECTED = "One of the selected studentIds do not exist in database";
public static String STUDENT_ADDED = "Student was successfully added at the checked spot";
public static String STUDENTS_SWAPPED = "Selected students were successfully swapped";
+ public static String TEAMS_SUGGESTED = "Suggested teams updated, click 'Undo' to show original teams";
+ public static String UNDO_SUGGESTION = "Showing original results, click 'Suggestion' to see balanced teams";
}
diff --git a/src/main/resources/fx_samples/sample.fxml b/src/main/resources/fx_samples/sample.fxml
index 93d82cb..19c5bbe 100644
--- a/src/main/resources/fx_samples/sample.fxml
+++ b/src/main/resources/fx_samples/sample.fxml
@@ -28,8 +28,10 @@
-
-
+
+
+
+
diff --git a/src/main/resources/hibernate.cfg.xml b/src/main/resources/hibernate.cfg.xml
index 0105de1..b984e2d 100644
--- a/src/main/resources/hibernate.cfg.xml
+++ b/src/main/resources/hibernate.cfg.xml
@@ -19,6 +19,7 @@
+
diff --git a/src/main/resources/mysql_scripts/10_INSERT_TEAMS.sql b/src/main/resources/mysql_scripts/10_INSERT_TEAMS.sql
index fa7b124..b72371e 100644
--- a/src/main/resources/mysql_scripts/10_INSERT_TEAMS.sql
+++ b/src/main/resources/mysql_scripts/10_INSERT_TEAMS.sql
@@ -1,5 +1,5 @@
-INSERT INTO teams(project_id,student_id_1,student_id_2,student_id_3,student_id_4) VALUES ('pr1','S1','S6',NULL,NULL);
-INSERT INTO teams(project_id,student_id_1,student_id_2,student_id_3,student_id_4) VALUES ('pr2','S2','S7',NULL,NULL);
-INSERT INTO teams(project_id,student_id_1,student_id_2,student_id_3,student_id_4) VALUES ('pr3','S3','S8',NULL,NULL);
-INSERT INTO teams(project_id,student_id_1,student_id_2,student_id_3,student_id_4) VALUES ('pr4','S4','S9','S11',NULL);
-INSERT INTO teams(project_id,student_id_1,student_id_2,student_id_3,student_id_4) VALUES ('pr5','S5','S10',NULL,NULL);
+INSERT INTO teams (`id`,`project_id`,`student_id_1`,`student_id_2`,`student_id_3`,`student_id_4`) VALUES (1,'pr1','S1','S6','S21','S13');
+INSERT INTO teams (`id`,`project_id`,`student_id_1`,`student_id_2`,`student_id_3`,`student_id_4`) VALUES (2,'pr2','S2','S7','S20','S14');
+INSERT INTO teams (`id`,`project_id`,`student_id_1`,`student_id_2`,`student_id_3`,`student_id_4`) VALUES (3,'pr3','S3','S8','S22','S15');
+INSERT INTO teams (`id`,`project_id`,`student_id_1`,`student_id_2`,`student_id_3`,`student_id_4`) VALUES (4,'pr4','S4','S9','S11','S16');
+INSERT INTO teams (`id`,`project_id`,`student_id_1`,`student_id_2`,`student_id_3`,`student_id_4`) VALUES (5,'pr5','S5','S10','S12','S17');
diff --git a/src/main/resources/mysql_scripts/11_CONSOLIDATED_INSERTS.txt b/src/main/resources/mysql_scripts/11_CONSOLIDATED_INSERTS.txt
index 2f44a5a..424d472 100644
--- a/src/main/resources/mysql_scripts/11_CONSOLIDATED_INSERTS.txt
+++ b/src/main/resources/mysql_scripts/11_CONSOLIDATED_INSERTS.txt
@@ -124,8 +124,8 @@ INSERT INTO project_preference(student_id,preferences_string,preference1,prefere
INSERT INTO project_preference(student_id,preferences_string,preference1,preference2) VALUES ('S18','PR9 3 PR10 1 PR8 2 PR4 4','PR4','PR9');
INSERT INTO project_preference(student_id,preferences_string,preference1,preference2) VALUES ('S19','PR9 3 PR10 1 PR8 2 PR4 4','PR4','PR9');
INSERT INTO project_preference(student_id,preferences_string,preference1,preference2) VALUES ('S20','PR9 3 PR10 1 PR8 2 PR5 4','PR5','PR9');
-INSERT INTO teams(project_id,student_id_1,student_id_2,student_id_3,student_id_4) VALUES ('pr1','S1','S6',NULL,NULL);
-INSERT INTO teams(project_id,student_id_1,student_id_2,student_id_3,student_id_4) VALUES ('pr2','S2','S7',NULL,NULL);
-INSERT INTO teams(project_id,student_id_1,student_id_2,student_id_3,student_id_4) VALUES ('pr3','S3','S8',NULL,NULL);
-INSERT INTO teams(project_id,student_id_1,student_id_2,student_id_3,student_id_4) VALUES ('pr4','S4','S9','S11',NULL);
-INSERT INTO teams(project_id,student_id_1,student_id_2,student_id_3,student_id_4) VALUES ('pr5','S5','S10',NULL,NULL);
+INSERT INTO teams (`id`,`project_id`,`student_id_1`,`student_id_2`,`student_id_3`,`student_id_4`) VALUES (1,'pr1','S1','S6','S21','S13');
+INSERT INTO teams (`id`,`project_id`,`student_id_1`,`student_id_2`,`student_id_3`,`student_id_4`) VALUES (2,'pr2','S2','S7','S20','S14');
+INSERT INTO teams (`id`,`project_id`,`student_id_1`,`student_id_2`,`student_id_3`,`student_id_4`) VALUES (3,'pr3','S3','S8','S22','S15');
+INSERT INTO teams (`id`,`project_id`,`student_id_1`,`student_id_2`,`student_id_3`,`student_id_4`) VALUES (4,'pr4','S4','S9','S11','S16');
+INSERT INTO teams (`id`,`project_id`,`student_id_1`,`student_id_2`,`student_id_3`,`student_id_4`) VALUES (5,'pr5','S5','S10','S12','S17');
diff --git a/src/main/resources/mysql_scripts/1_CREATE_TABLES.sql b/src/main/resources/mysql_scripts/1_CREATE_TABLES.sql
index 0e3b7ea..39d1a62 100644
--- a/src/main/resources/mysql_scripts/1_CREATE_TABLES.sql
+++ b/src/main/resources/mysql_scripts/1_CREATE_TABLES.sql
@@ -103,3 +103,21 @@ create table teams
foreign key (student_id_4) references students(id)
);
-- TEAMS END --
+
+-- SUGGESTED_TEAMS --
+create table suggested_teams
+(
+ id int not null,
+ project_id varchar(5) unique not null,
+ student_id_1 varchar(5),
+ student_id_2 varchar(5),
+ student_id_3 varchar(5),
+ student_id_4 varchar(5),
+ foreign key (id) references teams(id),
+ foreign key (project_id) references projects(id),
+ foreign key (student_id_1) references students(id),
+ foreign key (student_id_2) references students(id),
+ foreign key (student_id_3) references students(id),
+ foreign key (student_id_4) references students(id)
+);
+-- SUGGESTED_TEAMS END --
diff --git a/target/classes/controllers/OrmFxController.class b/target/classes/controllers/OrmFxController.class
index 2b47560..3fd5a2b 100644
Binary files a/target/classes/controllers/OrmFxController.class and b/target/classes/controllers/OrmFxController.class differ
diff --git a/target/classes/enums/SuggestionMode.class b/target/classes/enums/SuggestionMode.class
new file mode 100644
index 0000000..e020535
Binary files /dev/null and b/target/classes/enums/SuggestionMode.class differ
diff --git a/target/classes/fx_samples/sample.fxml b/target/classes/fx_samples/sample.fxml
index 93d82cb..19c5bbe 100644
--- a/target/classes/fx_samples/sample.fxml
+++ b/target/classes/fx_samples/sample.fxml
@@ -28,8 +28,10 @@
-
-
+
+
+
+
diff --git a/target/classes/hibernate.cfg.xml b/target/classes/hibernate.cfg.xml
index 0105de1..b984e2d 100644
--- a/target/classes/hibernate.cfg.xml
+++ b/target/classes/hibernate.cfg.xml
@@ -19,6 +19,7 @@
+
diff --git a/target/classes/hibernate/OrmSuggestedTeams.class b/target/classes/hibernate/OrmSuggestedTeams.class
new file mode 100644
index 0000000..402f3ff
Binary files /dev/null and b/target/classes/hibernate/OrmSuggestedTeams.class differ
diff --git a/target/classes/hibernate/OrmTeams.class b/target/classes/hibernate/OrmTeams.class
index 6da28fe..046b544 100644
Binary files a/target/classes/hibernate/OrmTeams.class and b/target/classes/hibernate/OrmTeams.class differ
diff --git a/target/classes/hibernate/dao/PreferenceDao.class b/target/classes/hibernate/dao/PreferenceDao.class
index 4f31c98..c2e4c48 100644
Binary files a/target/classes/hibernate/dao/PreferenceDao.class and b/target/classes/hibernate/dao/PreferenceDao.class differ
diff --git a/target/classes/hibernate/dao/SuggestedTeamsDao.class b/target/classes/hibernate/dao/SuggestedTeamsDao.class
new file mode 100644
index 0000000..a0ef1d8
Binary files /dev/null and b/target/classes/hibernate/dao/SuggestedTeamsDao.class differ
diff --git a/target/classes/hibernate/dao/TeamsDao.class b/target/classes/hibernate/dao/TeamsDao.class
index 7db47ce..67f6712 100644
Binary files a/target/classes/hibernate/dao/TeamsDao.class and b/target/classes/hibernate/dao/TeamsDao.class differ
diff --git a/target/classes/mysql_scripts/10_INSERT_TEAMS.sql b/target/classes/mysql_scripts/10_INSERT_TEAMS.sql
index fa7b124..b72371e 100644
--- a/target/classes/mysql_scripts/10_INSERT_TEAMS.sql
+++ b/target/classes/mysql_scripts/10_INSERT_TEAMS.sql
@@ -1,5 +1,5 @@
-INSERT INTO teams(project_id,student_id_1,student_id_2,student_id_3,student_id_4) VALUES ('pr1','S1','S6',NULL,NULL);
-INSERT INTO teams(project_id,student_id_1,student_id_2,student_id_3,student_id_4) VALUES ('pr2','S2','S7',NULL,NULL);
-INSERT INTO teams(project_id,student_id_1,student_id_2,student_id_3,student_id_4) VALUES ('pr3','S3','S8',NULL,NULL);
-INSERT INTO teams(project_id,student_id_1,student_id_2,student_id_3,student_id_4) VALUES ('pr4','S4','S9','S11',NULL);
-INSERT INTO teams(project_id,student_id_1,student_id_2,student_id_3,student_id_4) VALUES ('pr5','S5','S10',NULL,NULL);
+INSERT INTO teams (`id`,`project_id`,`student_id_1`,`student_id_2`,`student_id_3`,`student_id_4`) VALUES (1,'pr1','S1','S6','S21','S13');
+INSERT INTO teams (`id`,`project_id`,`student_id_1`,`student_id_2`,`student_id_3`,`student_id_4`) VALUES (2,'pr2','S2','S7','S20','S14');
+INSERT INTO teams (`id`,`project_id`,`student_id_1`,`student_id_2`,`student_id_3`,`student_id_4`) VALUES (3,'pr3','S3','S8','S22','S15');
+INSERT INTO teams (`id`,`project_id`,`student_id_1`,`student_id_2`,`student_id_3`,`student_id_4`) VALUES (4,'pr4','S4','S9','S11','S16');
+INSERT INTO teams (`id`,`project_id`,`student_id_1`,`student_id_2`,`student_id_3`,`student_id_4`) VALUES (5,'pr5','S5','S10','S12','S17');
diff --git a/target/classes/mysql_scripts/11_CONSOLIDATED_INSERTS.txt b/target/classes/mysql_scripts/11_CONSOLIDATED_INSERTS.txt
index 2f44a5a..424d472 100644
--- a/target/classes/mysql_scripts/11_CONSOLIDATED_INSERTS.txt
+++ b/target/classes/mysql_scripts/11_CONSOLIDATED_INSERTS.txt
@@ -124,8 +124,8 @@ INSERT INTO project_preference(student_id,preferences_string,preference1,prefere
INSERT INTO project_preference(student_id,preferences_string,preference1,preference2) VALUES ('S18','PR9 3 PR10 1 PR8 2 PR4 4','PR4','PR9');
INSERT INTO project_preference(student_id,preferences_string,preference1,preference2) VALUES ('S19','PR9 3 PR10 1 PR8 2 PR4 4','PR4','PR9');
INSERT INTO project_preference(student_id,preferences_string,preference1,preference2) VALUES ('S20','PR9 3 PR10 1 PR8 2 PR5 4','PR5','PR9');
-INSERT INTO teams(project_id,student_id_1,student_id_2,student_id_3,student_id_4) VALUES ('pr1','S1','S6',NULL,NULL);
-INSERT INTO teams(project_id,student_id_1,student_id_2,student_id_3,student_id_4) VALUES ('pr2','S2','S7',NULL,NULL);
-INSERT INTO teams(project_id,student_id_1,student_id_2,student_id_3,student_id_4) VALUES ('pr3','S3','S8',NULL,NULL);
-INSERT INTO teams(project_id,student_id_1,student_id_2,student_id_3,student_id_4) VALUES ('pr4','S4','S9','S11',NULL);
-INSERT INTO teams(project_id,student_id_1,student_id_2,student_id_3,student_id_4) VALUES ('pr5','S5','S10',NULL,NULL);
+INSERT INTO teams (`id`,`project_id`,`student_id_1`,`student_id_2`,`student_id_3`,`student_id_4`) VALUES (1,'pr1','S1','S6','S21','S13');
+INSERT INTO teams (`id`,`project_id`,`student_id_1`,`student_id_2`,`student_id_3`,`student_id_4`) VALUES (2,'pr2','S2','S7','S20','S14');
+INSERT INTO teams (`id`,`project_id`,`student_id_1`,`student_id_2`,`student_id_3`,`student_id_4`) VALUES (3,'pr3','S3','S8','S22','S15');
+INSERT INTO teams (`id`,`project_id`,`student_id_1`,`student_id_2`,`student_id_3`,`student_id_4`) VALUES (4,'pr4','S4','S9','S11','S16');
+INSERT INTO teams (`id`,`project_id`,`student_id_1`,`student_id_2`,`student_id_3`,`student_id_4`) VALUES (5,'pr5','S5','S10','S12','S17');
diff --git a/target/classes/mysql_scripts/1_CREATE_TABLES.sql b/target/classes/mysql_scripts/1_CREATE_TABLES.sql
index 0e3b7ea..39d1a62 100644
--- a/target/classes/mysql_scripts/1_CREATE_TABLES.sql
+++ b/target/classes/mysql_scripts/1_CREATE_TABLES.sql
@@ -103,3 +103,21 @@ create table teams
foreign key (student_id_4) references students(id)
);
-- TEAMS END --
+
+-- SUGGESTED_TEAMS --
+create table suggested_teams
+(
+ id int not null,
+ project_id varchar(5) unique not null,
+ student_id_1 varchar(5),
+ student_id_2 varchar(5),
+ student_id_3 varchar(5),
+ student_id_4 varchar(5),
+ foreign key (id) references teams(id),
+ foreign key (project_id) references projects(id),
+ foreign key (student_id_1) references students(id),
+ foreign key (student_id_2) references students(id),
+ foreign key (student_id_3) references students(id),
+ foreign key (student_id_4) references students(id)
+);
+-- SUGGESTED_TEAMS END --
diff --git a/target/classes/services/OrmChartsService.class b/target/classes/services/OrmChartsService.class
index 389b1eb..4e35bb1 100644
Binary files a/target/classes/services/OrmChartsService.class and b/target/classes/services/OrmChartsService.class differ
diff --git a/target/classes/services/SuggestionService.class b/target/classes/services/SuggestionService.class
new file mode 100644
index 0000000..da0ca06
Binary files /dev/null and b/target/classes/services/SuggestionService.class differ
diff --git a/target/classes/services/TeamBoxService.class b/target/classes/services/TeamBoxService.class
index f20f256..96e0eeb 100644
Binary files a/target/classes/services/TeamBoxService.class and b/target/classes/services/TeamBoxService.class differ
diff --git a/target/classes/sources/DatafileIOclass.class b/target/classes/sources/DatafileIOclass.class
index 6517e02..5e21caf 100644
Binary files a/target/classes/sources/DatafileIOclass.class and b/target/classes/sources/DatafileIOclass.class differ
diff --git a/target/classes/sources/Teams.class b/target/classes/sources/Teams.class
index baad23e..4e26c64 100644
Binary files a/target/classes/sources/Teams.class and b/target/classes/sources/Teams.class differ
diff --git a/target/classes/utils/FxErrorMessages.class b/target/classes/utils/FxErrorMessages.class
index 255e929..1df7ed9 100644
Binary files a/target/classes/utils/FxErrorMessages.class and b/target/classes/utils/FxErrorMessages.class differ