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

[feat] implemented survey project creation

parent 5f49148c
No related branches found
No related tags found
No related merge requests found
Showing
with 462 additions and 49 deletions
package unipotsdam.gf.modules.group.preferences.database;
import unipotsdam.gf.modules.group.preferences.excel.ItemSet;
import unipotsdam.gf.modules.group.preferences.survey.SurveyData;
import unipotsdam.gf.modules.project.Project;
import unipotsdam.gf.modules.project.ProjectDAO;
import unipotsdam.gf.mysql.MysqlConnect;
import unipotsdam.gf.mysql.VereinfachtesResultSet;
......@@ -13,8 +16,12 @@ public class ProfileDAO {
@Inject
private MysqlConnect connect;
@Inject
private ProjectDAO projectDAO;
/**
* helper function for persisting questions
*
* @param profileQuestion
* @return the id of the created question
*/
......@@ -25,14 +32,14 @@ public class ProfileDAO {
String germanQuestion = profileQuestion.getQuestion();
String englishQuestion = profileQuestion.getQuestion_en();
String subvariable = profileQuestion.getSubvariable();
String subvariable = profileQuestion.getSubvariable();
int scaleSize = profileQuestion.getScaleSize();
Boolean polarity = true;
if (profileQuestion instanceof ScaledProfileQuestion) {
polarity = ((ScaledProfileQuestion)profileQuestion).getPolarity();
polarity = ((ScaledProfileQuestion) profileQuestion).getPolarity();
}
String query = "INSERT INTO profilequestions (`scaleSize`, `question`, `question_en`, `subvariable`, " +
"`polarity`) values (?,?,?,?,?)";
String query =
"INSERT INTO profilequestions (`scaleSize`, `question`, `question_en`, `subvariable`, " + "`polarity`) values (?,?,?,?,?)";
result = connect.issueInsertStatementWithAutoincrement(query, scaleSize, germanQuestion, englishQuestion,
subvariable, polarity);
......@@ -43,6 +50,7 @@ public class ProfileDAO {
/**
* persist questions with enumeration
*
* @param enumeratedProfileQuestion
*/
public void persist(EnumeratedProfileQuestion enumeratedProfileQuestion) {
......@@ -58,6 +66,7 @@ public class ProfileDAO {
/**
* persist questions with scale i.e. 1 to 5
*
* @param scaledProfileQuestion
*/
public void persist(ScaledProfileQuestion scaledProfileQuestion) {
......@@ -66,13 +75,13 @@ public class ProfileDAO {
/**
* persist an answer
*
* @param profileQuestionAnswer
*/
public void persist(ProfileQuestionAnswer profileQuestionAnswer) {
connect.connect();
String query =
"INSERT INTO profilequestionanswer (`profileQuestionId`,`answerIndex`, `selectedAnswer`, " +
"`userEmail`) values (?,?,?,?)";
"INSERT INTO profilequestionanswer (`profileQuestionId`,`answerIndex`, `selectedAnswer`, " + "`userEmail`) values (?,?,?,?)";
connect.issueInsertOrDeleteStatement(query, profileQuestionAnswer.getQuestion().getId(),
profileQuestionAnswer.getAnswerIndex(), profileQuestionAnswer.getSelectedAnswer(),
profileQuestionAnswer.getUser().getEmail());
......@@ -81,16 +90,15 @@ public class ProfileDAO {
/**
* get all the questions
*
* @return
*/
public java.util.List<ProfileQuestion> getQuestions() {
ArrayList<ProfileQuestion> profileQuestions = new ArrayList<>();
connect.connect();
String query =
"SELECT (q.id,q.scaleSize, q.subvariable, q.question, q.question_en, o.name) from profilequestions q " +
"LEFT JOIN " +
"profilequestionoptions o where q.id = o" + ".profileQuestionId group by q.id";
String query = "SELECT q.id,scaleSize, subvariable, question, question_en, name from profilequestions q" +
" LEFT JOIN profilequestionoptions o on q.id = o.profileQuestionId";
VereinfachtesResultSet vereinfachtesResultSet = connect.issueSelectStatement(query);
HashMap<Integer, ArrayList<String>> optionMap = new HashMap<>();
List<ProfileQuestion> tmpList = new ArrayList<>();
......@@ -124,7 +132,7 @@ public class ProfileDAO {
enumeratedProfileQuestion.setOptions(optionMap.get(question.getId()));
enumeratedProfileQuestion.setQuestion(question.getQuestion());
profileQuestions.add(enumeratedProfileQuestion);
}else {
} else {
profileQuestions.add(question);
}
}
......@@ -134,7 +142,7 @@ public class ProfileDAO {
}
public List<ProfileQuestionRelation> getProfileRelations() {
ArrayList<ProfileQuestionRelation>questionRelations = new ArrayList<>();
ArrayList<ProfileQuestionRelation> questionRelations = new ArrayList<>();
connect.connect();
String query = "SELCT * from profilequestionrelations";
VereinfachtesResultSet vereinfachtesResultSet = connect.issueSelectStatement(query);
......@@ -146,8 +154,8 @@ public class ProfileDAO {
ProfileQuestion profileQuestion1 = new ProfileQuestion(firstQuestionId);
ProfileQuestion profileQuestion2 = new ProfileQuestion(secondQuestionId);
ProfileQuestionRelationType profileQuestionRelationType = ProfileQuestionRelationType.valueOf(relation);
questionRelations.add(new ProfileQuestionRelation(profileQuestion1, profileQuestion2,
profileQuestionRelationType));
questionRelations
.add(new ProfileQuestionRelation(profileQuestion1, profileQuestion2, profileQuestionRelationType));
}
connect.close();
......@@ -163,6 +171,7 @@ public class ProfileDAO {
/**
* persist a variable for group formation
*
* @param itemSet
*/
public void persistProfileVariable(ItemSet itemSet) {
......@@ -174,13 +183,56 @@ public class ProfileDAO {
String variableweight = "1";
connect.connect();
String query = "INSERT INTO profilevariables (`variable`, `subvariable`, `variableDefinition`, `context`, " +
"`variableweight`, `subvariableweight`) values (?,?,?,?,?,?)";
connect.issueInsertOrDeleteStatement(query, variable, subvariable, variableDefinition, context,
variableweight, subvariableweight);
String query =
"INSERT INTO profilevariables (`variable`, `subvariable`, `variableDefinition`, `context`, " + "`variableweight`, `subvariableweight`) values (?,?,?,?,?,?)";
connect.issueInsertOrDeleteStatement(query, variable, subvariable, variableDefinition, context, variableweight,
subvariableweight);
connect.close();
}
public HashMap<Project, List<ProfileQuestion>> getSelectedQuestions() {
HashMap<Project,List<ProfileQuestion>> profileQuestions = new HashMap<>();
connect.connect();
String query =
"Select p.name, pq.question, pq.question_en, pq.subvariable from projects p " +
"join surveyitemsselected sis on p.name = sis.projectname " +
"join profilequestions pq on pq.id = sis.profilequestionid";
VereinfachtesResultSet vereinfachtesResultSet = connect.issueSelectStatement(query);
while (vereinfachtesResultSet.next()) {
Project project = new Project(vereinfachtesResultSet.getString("name"));
ProfileQuestion profileQuestion = new ProfileQuestion(5, vereinfachtesResultSet.getString("question_en"),
vereinfachtesResultSet.getString("question"), vereinfachtesResultSet.getString("subvariable"));
if (profileQuestions.keySet().contains(project)) {
List<ProfileQuestion> profileQuestions1 = profileQuestions.get(project);
profileQuestions1.add(profileQuestion);
// this will overwrite the other questions
profileQuestions.put(project, profileQuestions1);
} else {
ArrayList<ProfileQuestion> profileQuestions2 = new ArrayList<>();
profileQuestions2.add(profileQuestion);
profileQuestions.put(project, profileQuestions2);
}
}
connect.close();
return profileQuestions;
}
public void addItemsToProject(Project project, List<ProfileQuestion> questions) {
ArrayList<Integer> questionids = new ArrayList<>();
// persist the questions
for (ProfileQuestion question : questions) {
int i = persistHelper(question);
questionids.add(i);
}
connect.connect();
String query = "INSERT INTO surveyitemsselected (`projectname`, `profilequestionid`) values (?,?)";
for (Integer questionid : questionids) {
connect.issueInsertOrDeleteStatement(query, project.getName(), questionid);
}
connect.close();
}
}
package unipotsdam.gf.modules.group.preferences.survey;
public class GeneralItems {
private String name;
private String email;
public GeneralItems(String name, String email) {
this.name = name;
this.email = email;
}
public String getName() {
return name;
}
public void setName(String name) {
this.name = name;
}
public String getEmail() {
return email;
}
public void setEmail(String email) {
this.email = email;
}
}
package unipotsdam.gf.modules.group.preferences.survey;
public enum GroupWorkContext {
FL,
DOTA,
OVERWATCH,
}
package unipotsdam.gf.modules.group.preferences.survey;
public class OpenQuestion extends Question {
public OpenQuestion() {
super();
this.type = "text";
}
}
package unipotsdam.gf.modules.group.preferences.survey;
import unipotsdam.gf.modules.project.Project;
import java.util.HashMap;
public class ProjectStatus {
HashMap<Project, Integer> numberOfParticipants;
public ProjectStatus() {
}
public HashMap<Project, Integer> getNumberOfParticipants() {
return numberOfParticipants;
}
public void setNumberOfParticipants(
HashMap<Project, Integer> numberOfParticipants) {
this.numberOfParticipants = numberOfParticipants;
}
}
......@@ -3,27 +3,20 @@ package unipotsdam.gf.modules.group.preferences.survey;
import org.codehaus.jackson.annotate.JsonProperty;
public class Question {
private String type;
protected String type;
private String name;
private LocalizedText title;
private LocalizedText minRateDescription;
private LocalizedText maxRateDescription;
private Boolean isRequired;
public Question() {
this.type = "rating";
this.minRateDescription = new LocalizedText("I don't agree at all", "I fully agree");
this.maxRateDescription = new LocalizedText("Ich stimme überhaupt nicht zu", "Ich stimmve voll zu");
/*minRateDescription.setDefaultText("I don't agree at all");
maxRateDescription.setDefaultText("I fully agree");
minRateDescription.setDe("Ich stimme überhaupt nicht zu");
maxRateDescription.setDe("Ich stimmve voll zu");*/
this.isRequired = true;
}
public String getType() {
return type;
}
/* public void setType(String type) {
/*public void setType(String type) {
this.type = type;
}*/
......@@ -45,23 +38,11 @@ public class Question {
this.title = title;
}
@JsonProperty("minRateDescription")
public LocalizedText getMinRateDescription() {
return minRateDescription;
@JsonProperty("isRequired")
public Boolean getRequired() {
return isRequired;
}
/* @JsonProperty("minRateDescription")
public void setMinRateDescription(LocalizedText minRateDescription) {
this.minRateDescription = minRateDescription;
}*/
@JsonProperty("maxRateDescription")
public LocalizedText getMaxRateDescription() {
return maxRateDescription;
}
/* @JsonProperty("maxRateDescription")
public void setMaxRateDescription(LocalizedText maxRateDescription) {
this.maxRateDescription = maxRateDescription;
}*/
}
package unipotsdam.gf.modules.group.preferences.survey;
import org.codehaus.jackson.annotate.JsonProperty;
public class ScaledQuestion extends Question {
private LocalizedText minRateDescription;
private LocalizedText maxRateDescription;
public ScaledQuestion(
LocalizedText minRateDescription, LocalizedText maxRateDescription) {
this.minRateDescription = minRateDescription;
this.maxRateDescription = maxRateDescription;
}
public ScaledQuestion() {
super();
this.type = "rating";
this.minRateDescription = new LocalizedText("I don't agree at all", "I fully agree");
this.maxRateDescription = new LocalizedText("Ich stimme überhaupt nicht zu", "Ich stimmve voll zu");
/*minRateDescription.setDefaultText("I don't agree at all");
maxRateDescription.setDefaultText("I fully agree");
minRateDescription.setDe("Ich stimme überhaupt nicht zu");
maxRateDescription.setDe("Ich stimmve voll zu");*/
}
@JsonProperty("minRateDescription")
public LocalizedText getMinRateDescription() {
return minRateDescription;
}
/* @JsonProperty("minRateDescription")
public void setMinRateDescription(LocalizedText minRateDescription) {
this.minRateDescription = minRateDescription;
}*/
@JsonProperty("maxRateDescription")
public LocalizedText getMaxRateDescription() {
return maxRateDescription;
}
/* @JsonProperty("maxRateDescription")
public void setMaxRateDescription(LocalizedText maxRateDescription) {
this.maxRateDescription = maxRateDescription;
}*/
}
package unipotsdam.gf.modules.group.preferences.survey;
import unipotsdam.gf.modules.group.preferences.database.ProfileDAO;
import unipotsdam.gf.modules.group.preferences.database.ProfileQuestion;
import unipotsdam.gf.modules.project.Project;
import javax.inject.Inject;
import java.util.ArrayList;
import java.util.Collections;
import java.util.HashMap;
import java.util.List;
public class SurveyMapper {
@Inject
ProfileDAO profileDAO;
/**
* generate the backing data for the survey
* @param groupWorkContext
* @param standalone is false if run within fltrail general project
* @return
*/
public SurveyData getItemsFromDB(GroupWorkContext groupWorkContext, Boolean standalone, Project project) {
SurveyData surveyData = new SurveyData(); // the result obj
// the persisted questions from the excel sheet (ITEMS for FL, based on FideS Team research)
HashMap<Project, List<ProfileQuestion>> questionMap = profileDAO.getSelectedQuestions();
List<ProfileQuestion> questions = questionMap.get(project);
if (standalone) {
// the general questions to create a profile (given that we are not running the survey as part of the normal
// FL-Trail Mode
List<LocalizedText> generalTextQuestions = new ArrayList<>();
generalTextQuestions.add(new LocalizedText("Choose a nickname!", "Wählen Sie einen Nickname aus!"));
generalTextQuestions.add(new LocalizedText("Repeat your nickname!", "Wiederholen Sie den Nickname!"));
generalTextQuestions.add(new LocalizedText("Enter a valid email!", "Enter a valid Email!"));
switch (groupWorkContext) {
case FL:
break;
case DOTA:
case OVERWATCH:
generalTextQuestions.add(new LocalizedText("" + "(optional) Enter your discord ID!",
"(optional) Geben Sie ihre Discord ID ein!"));
break;
}
// adapt title
surveyData.setTitle(new LocalizedText(
"Thank you for participating in this survey about good group formation",
"Vielen Dank für ihre Bereitschaft zur Teilnahme an dieser Befragung"));
Page generalDetails = new Page();
generalDetails.setName("general1");
for (LocalizedText generalTextQuestion : generalTextQuestions) {
OpenQuestion openQuestion = new OpenQuestion();
openQuestion.setTitle(generalTextQuestion);
generalDetails.getQuestions().add(openQuestion);
}
surveyData.getPages().add(generalDetails);
Page profileQuestionsPage = new Page();
int i = 0;
for (ProfileQuestion question : questions) {
// just those things
if (i == 5) {
surveyData.getPages().add(profileQuestionsPage);
profileQuestionsPage = new Page();
}
ScaledQuestion scaledQuestion = convertQuestion(question);
profileQuestionsPage.getQuestions().add(scaledQuestion);
}
if (!profileQuestionsPage.getQuestions().isEmpty()) {
surveyData.getPages().add(profileQuestionsPage);
}
}
return surveyData;
}
public static ScaledQuestion convertQuestion(ProfileQuestion question) {
ScaledQuestion scaledQuestion = new ScaledQuestion();
scaledQuestion.setName(question.getSubvariable() + question.getId());
scaledQuestion.setTitle(new LocalizedText(question.getQuestion_en(), question.getQuestion()));
return scaledQuestion;
}
}
package unipotsdam.gf.modules.group.preferences.survey;
import unipotsdam.gf.modules.group.preferences.database.ProfileDAO;
import unipotsdam.gf.modules.group.preferences.database.ProfileQuestion;
import unipotsdam.gf.modules.group.preferences.excel.ItemsImporter;
import unipotsdam.gf.modules.project.Project;
import javax.inject.Inject;
import java.util.ArrayList;
import java.util.Collections;
public class SurveyPreparation {
public static void main(String[] args) throws Exception {
SurveyPreparationHelper surveyPreparationHelper = new SurveyPreparationHelper();
surveyPreparationHelper.prepareSurvey();
}
}
package unipotsdam.gf.modules.group.preferences.survey;
import org.glassfish.hk2.api.ServiceLocator;
import org.glassfish.hk2.utilities.ServiceLocatorUtilities;
import unipotsdam.gf.config.GFApplicationBinder;
import unipotsdam.gf.modules.group.preferences.database.ProfileDAO;
import unipotsdam.gf.modules.group.preferences.database.ProfileQuestion;
import unipotsdam.gf.modules.group.preferences.excel.ItemsImporter;
import unipotsdam.gf.modules.project.Project;
import unipotsdam.gf.modules.project.ProjectDAO;
import unipotsdam.gf.modules.user.User;
import unipotsdam.gf.modules.user.UserDAO;
import javax.inject.Inject;
import java.util.ArrayList;
import java.util.Collections;
import java.util.List;
public class SurveyPreparationHelper {
@Inject
ProfileDAO profileDAO;
@Inject
UserDAO userDAO;
@Inject
ProjectDAO projectDAO;
public SurveyPreparationHelper() {
final ServiceLocator locator = ServiceLocatorUtilities.bind(new GFApplicationBinder());
locator.inject(this);
}
public void prepareSurvey() throws Exception {
// create dehne user
try {
User dehne = new User("julian.dehne@uni-potsdam.de");
dehne.setPassword("egal");
dehne.setRocketChatUsername("fltrailadmin");
dehne.setStudent(false);
dehne.setName("Julian Dehne");
userDAO.persist(dehne, null);
} catch (Exception e) {}
// importing items
ItemsImporter.main(new String[0]);
// creating survey projects
ArrayList<Project> surveyProjects = new ArrayList<Project>();
Project d1_test = new Project("d1_test");
d1_test.setSurvey(true);
Project o1_test = new Project("o1_test");
o1_test.setSurvey(true);
Project fl_test = new Project("fl_test");
fl_test.setSurvey(true);
surveyProjects.add(o1_test);
surveyProjects.add(d1_test);
for (Project surveyProject : surveyProjects) {
projectDAO.persist(surveyProject);
}
// the persisted questions from the excel sheet (ITEMS for FL, based on FideS Team research)
List<ProfileQuestion> questions = profileDAO.getQuestions();
// todo find out mathematically if that works, how many iterations are needed and
persistselectedItems(d1_test, questions);
persistselectedItems(o1_test, questions);
persistselectedItems(fl_test, questions);
}
private void persistselectedItems(Project d1_test, List<ProfileQuestion> questions) {
Collections.shuffle(questions);
if (questions.size() > 30) {
int toRemove = questions.size() - 30;
List<ProfileQuestion> q2 = questions.subList(questions.size() - toRemove, questions.size());
profileDAO.addItemsToProject(d1_test, q2);
}
}
}
package unipotsdam.gf.modules.group.preferences.survey;
import unipotsdam.gf.modules.project.Project;
import javax.ws.rs.GET;
import javax.ws.rs.POST;
import javax.ws.rs.Path;
@Path("/survey")
public class SurveyView {
@GET
@Path("/data")
public SurveyData getSurveyData() {
// TODO implement
// get surveyData from db
return null;
}
@GET
@Path("/projects")
public java.util.List<Project> getCurrentSurveyProjects() {
// TODO implement
return null;
}
@GET
@Path("/status")
public ProjectStatus getProjectStatus() {
// TODO implement
return new ProjectStatus();
}
}
......@@ -20,9 +20,11 @@ public class Project {
private Phase phase;
private String[] tags;
private String description;
private Boolean isSurvey;
public Project() {
tags = new String[0];
this.timecreated = System.currentTimeMillis();
}
public Project(String name, String password, Boolean active, String author, String[] tags) {
......@@ -34,6 +36,7 @@ public class Project {
// default starting at course creation if new
this.setPhase(Phase.GroupFormation);
this.tags = tags;
this.isSurvey = false;
}
public Project(
......@@ -48,6 +51,7 @@ public class Project {
this.phase = phase;
this.tags = tags;
this.description = description;
this.isSurvey = false;
}
public Project(String projectName, String authorEmail) {
......@@ -56,11 +60,15 @@ public class Project {
this.active = true;
this.timecreated = System.currentTimeMillis();
tags = new String[0];
this.isSurvey = false;
}
public Project(String projectName) {
this.name = projectName;
this.active = true;
this.isSurvey = false;
this.timecreated = System.currentTimeMillis();
tags = new String[0];
}
......@@ -150,4 +158,12 @@ public class Project {
public void setDescription(String description) {
this.description = description;
}
public Boolean getSurvey() {
return isSurvey;
}
public void setSurvey(Boolean survey) {
isSurvey = survey;
}
}
\ No newline at end of file
......@@ -47,14 +47,20 @@ public class ProjectDAO {
if (!exists(project)) {
java.sql.Timestamp timestamp = new java.sql.Timestamp(project.getTimecreated());
if (project.getPassword() == null) {
project.setPassword("");
}
if(project.getAuthorEmail() == null) {
project.setAuthorEmail("julian.dehne@uni-potsdam.de");
}
connect.connect();
String mysqlRequest =
"INSERT INTO projects (`name`, `password`, `active`, `timecreated`, `author`, `phase`, `description`) " +
"values (?,?,?,?,?,?,?)";
"INSERT INTO projects (`name`, `password`, `active`, `timecreated`, `author`, `phase`, " +
"`description`, `isSurvey`) values (?,?,?,?,?,?,?,?)";
connect.issueInsertOrDeleteStatement(mysqlRequest, project.getName(), project.getPassword(),
project.isActive(), timestamp, project.getAuthorEmail(),
project.getPhase() == null ? Phase.GroupFormation : project.getPhase(), project.getDescription());
project.getPhase() == null ? Phase.GroupFormation : project.getPhase(), project.getDescription(),
project.getSurvey());
connect.close();
connect.connect();
......
File added
......@@ -377,8 +377,16 @@ ALTER TABLE workrating COMMENT = '@Axel plz comment';
ALTER TABLE projects ADD issurvey BOOLEAN NULL;
CREATE TABLE surveyitemsselected
(
projectname varchar(100),
profilequestionid int(11)
);
ALTER TABLE `surveyitemsselected`
ADD CONSTRAINT surveyitemsselected_profilequestions_id_fk FOREIGN KEY (profilequestionid) REFERENCES
profilequestions (id);
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