Skip to content
Snippets Groups Projects
Commit 43353b87 authored by Julian Dehne's avatar Julian Dehne
Browse files

implementiert Algorithmus für zufällige Gruppen

parent be3ac9a3
No related branches found
No related tags found
No related merge requests found
Showing
with 165 additions and 11 deletions
......@@ -69,6 +69,13 @@
<version>5.1.6</version>
</dependency>
<!-- converting html to java pojo -->
<!-- <dependency>
<groupId>fr.whimtrip</groupId>
<artifactId>whimtrip-ext-htmltopojo</artifactId>
<version>1.0.2</version>
</dependency>-->
<dependency>
<groupId>junit</groupId>
<artifactId>junit</artifactId>
......
......@@ -7,6 +7,7 @@ import unipotsdam.gf.modules.group.GroupFormationMechanism;
import unipotsdam.gf.modules.group.GroupfindingCriteria;
import java.util.ArrayList;
import java.util.List;
public interface IGroupFinding {
......@@ -45,4 +46,6 @@ public interface IGroupFinding {
ArrayList<String> getStudentsInSameGroup(StudentIdentifier student);
int getMinNumberOfStudentsNeeded(Project project);
List<Group> createRandomGroups(Project project);
}
......@@ -180,6 +180,13 @@ public class GroupDAO {
connect.issueUpdateStatement(mysqlRequest, "", chatRoomId);
connect.close();
}
public void deleteGroups(Project project) {
String query = "DELETE * from groups where projectName= ?";
connect.connect();
connect.issueInsertOrDeleteStatement(query, project.getName());
connect.close();
}
}
......
package unipotsdam.gf.modules.group;
import java.util.ArrayList;
import java.util.List;
public class GroupData {
List<Group> groups;
public GroupData() {
}
public GroupData(List<Group> groups) {
this.groups = groups;
}
public List<Group> getGroups() {
return groups;
}
public void setGroups(ArrayList<Group> groups) {
this.groups = groups;
}
}
......@@ -30,6 +30,16 @@ public class GroupView {
@Inject
GroupFormationProcess groupFormationProcess;
@GET
@Produces(MediaType.APPLICATION_JSON)
@Path("/all/project/{projectName}")
public GroupData getGroups(@PathParam("projectName") String projectName) {
GroupData data = groupFormationProcess.getOrInitializeGroups(new Project(projectName));
return data;
}
@GET
@Produces(MediaType.APPLICATION_JSON)
@Path("/project/{projectName}/student/{userName}")
......@@ -81,14 +91,15 @@ public class GroupView {
throw new WebApplicationException(
"the groupfindingmechanism needs to be one of " + GroupFormationMechanism.values().toString());
}
}
/**
* find out if this is used by learning goal
* @param projectName
* @param groups
*/
@Deprecated
@POST
@Consumes(MediaType.APPLICATION_JSON)
@Path("/projects/{projectName}")
......@@ -97,4 +108,21 @@ public class GroupView {
groupfinding.persistGroups(Arrays.asList(groups), project);
}
@PUT
@Consumes(MediaType.APPLICATION_JSON)
@Path("/projects/{projectName}/groups")
public void persistGroups(@PathParam("projectName") String projectName, GroupData data) {
Project project = new Project(projectName);
groupfinding.persistGroups(data.getGroups(), project);
}
@POST
@Consumes(MediaType.APPLICATION_JSON)
@Path("/projects/{projectName}/groups/finalize")
public void finalizeGroups(@PathParam("projectName") String projectName) {
Project project = new Project(projectName);
groupFormationProcess.finalize(project);
}
}
......@@ -3,9 +3,12 @@ package unipotsdam.gf.modules.group;
import unipotsdam.gf.modules.project.Project;
import unipotsdam.gf.interfaces.IGroupFinding;
import unipotsdam.gf.modules.assessment.controller.model.StudentIdentifier;
import unipotsdam.gf.modules.user.User;
import unipotsdam.gf.modules.user.UserDAO;
import javax.inject.Inject;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.List;
public class GroupfindingImpl implements IGroupFinding {
......@@ -13,6 +16,9 @@ public class GroupfindingImpl implements IGroupFinding {
@Inject
private GroupDAO groupDAO;
@Inject
private UserDAO userDAO;
@Inject
public GroupfindingImpl(GroupDAO groupDAO) {
this.groupDAO = groupDAO;
......@@ -60,4 +66,50 @@ public class GroupfindingImpl implements IGroupFinding {
return participantsNeeded;
}
@Override
public List<Group> createRandomGroups(Project project) {
ArrayList<Group> result = new ArrayList<>();
groupDAO.deleteGroups(project);
List<User> usersByProjectName = userDAO.getUsersByProjectName(project.getName());
int numberOfUsers = usersByProjectName.size();
if (usersByProjectName.size()<6){
Group group = new Group();
group.getMembers().addAll(usersByProjectName);
result.add(group);
} else {
int numberOf3Groups = getNumberOf3Groups(numberOfUsers);
//int numberOf4Groups = getNumberOf4Groups(numberOfUsers);
Group group = new Group();
for (User user : usersByProjectName) {
if (numberOf3Groups > 0) {
numberOf3Groups--;
// TODO insert formula here for the correct groups
if (group.getMembers().size() == 3) {
result.add(group);
group = new Group();
}
} else {
if (group.getMembers().size() == 4) {
result.add(group);
group = new Group();
}
}
group.addMember(user);
}
result.add(group);
}
return result;
}
// (number % 3) + (Math.floor(number/3)-(number%3)) = n für alle Zahlen größer als 5
public int getNumberOf4Groups(Integer number) {
return (number % 3);
}
// every number can be divided in factors 4 and 3 as long it is greater then 5
public int getNumberOf3Groups(Integer number) {
return (number / 3) - (number % 3);
}
}
......@@ -3,6 +3,7 @@ package unipotsdam.gf.process;
import unipotsdam.gf.interfaces.IGroupFinding;
import unipotsdam.gf.interfaces.IPhases;
import unipotsdam.gf.modules.group.Group;
import unipotsdam.gf.modules.group.GroupData;
import unipotsdam.gf.modules.group.GroupFormationMechanism;
import unipotsdam.gf.modules.project.Project;
import unipotsdam.gf.modules.project.ProjectDAO;
......@@ -16,6 +17,7 @@ import unipotsdam.gf.process.tasks.TaskName;
import javax.inject.Inject;
import javax.inject.Singleton;
import java.util.Arrays;
import java.util.List;
@Singleton
public class GroupFormationProcess {
......@@ -55,9 +57,8 @@ public class GroupFormationProcess {
* and if there groups are not handled manually
* this method finalizes the groups
* @param project
* @param groups
*/
public void finish(Project project, Group ... groups) {
public void finalize(Project project) {
taskDAO.persistTeacherTask(project, TaskName.CLOSE_GROUP_FINDING_PHASE, Phase.GroupFormation);
/**
* Gruppenphase wird beendet
......@@ -74,4 +75,12 @@ public class GroupFormationProcess {
}
public GroupData getOrInitializeGroups(Project project) {
List<Group> groups = groupfinding.getGroups(project);
if (groups.isEmpty()) {
groups = groupfinding.createRandomGroups(project);
}
return new GroupData(groups);
}
}
......@@ -79,7 +79,7 @@ public class PhasesImpl implements IPhases {
// inform users about the formed groups, optionally giving them a hint on what happens next
iCommunication.sendMessageToUsers(project, Messages.GroupFormation(project));
saveState(project, changeToPhase);
groupFormationProcess.finish(project);
groupFormationProcess.finalize(project);
dossierCreationProcess.start(project);
break;
case DossierFeedback:
......
.sortableGroup {
list-style-type: none;
margin: 0;
float: left;
margin-right: 10px;
background: #eee;
padding: 5px;
min-width: 143px;
max-width: 243px;
margin-bottom: 20px;
}
.sortableGroup li {
margin: 5px;
padding: 5px;
font-size: 1.2em;
min-width: 120px;
}
th, td {
padding: 15px;
text-align: left;
}
\ No newline at end of file
......@@ -95,7 +95,7 @@ public class GroupPhaseTaskTest {
for (User student : students) {
group.addMember(student);
}
groupFormationProcess.finish(project, group);
groupFormationProcess.finalize(project);
}
......
......@@ -196,8 +196,8 @@ ALTER TABLE `groups`
ALTER TABLE `groupuser`
ADD CONSTRAINT `groupuser_ibfk_1` FOREIGN KEY (`userEmail`) REFERENCES `users` (`email`),
ADD CONSTRAINT `groupuser_ibfk_2` FOREIGN KEY (`groupId`) REFERENCES `groups` (`id`);
ADD CONSTRAINT `groupuser_ibfk_1` FOREIGN KEY (`userEmail`) REFERENCES `users` (`email`) ON DELETE CASCADE,
ADD CONSTRAINT `groupuser_ibfk_2` FOREIGN KEY (`groupId`) REFERENCES `groups` (`id`) ON DELETE CASCADE;
ALTER TABLE `projects`
ADD CONSTRAINT `projects_ibfk_1` FOREIGN KEY (`author`) REFERENCES `users` (`email`);
......@@ -212,3 +212,5 @@ CREATE UNIQUE INDEX fullsubmissions_user_projectName_uindex ON fullsubmissions (
CREATE UNIQUE INDEX tasks_userEmail_projectName_taskName_uindex ON tasks (userEmail, projectName, taskName);
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment