diff --git a/experimentresources/stimuli/rorschachset01/multiplesetlist.txt b/experimentresources/stimuli/rorschachset01/multiplesetlist.txt new file mode 100644 index 0000000..2414199 --- /dev/null +++ b/experimentresources/stimuli/rorschachset01/multiplesetlist.txt @@ -0,0 +1,5 @@ +rorschachlongersequence.txt +rorschachlongersequence.txt +rorschachlongersequence.txt +rorschachlongersequence.txt +rorschachshortsequence.txt \ No newline at end of file diff --git a/src/main/java/diet/server/Conversation.java b/src/main/java/diet/server/Conversation.java index a9560bc..a8e537d 100644 --- a/src/main/java/diet/server/Conversation.java +++ b/src/main/java/diet/server/Conversation.java @@ -2522,6 +2522,9 @@ public void printWln(String windowName, String text){ if(em!=null){ em.println(windowName, text); } + else{ + System.err.println("PRINTWLN EM IS NULL"+windowName+" "+text); + } convIO.saveWindowTextToLog(windowName, text); } diff --git a/src/main/java/diet/server/ConversationController/Telegram_Dyadic_Customizable_ReferentialTask.java b/src/main/java/diet/server/ConversationController/Telegram_Dyadic_Customizable_ReferentialTask.java index 40abf8c..926050f 100644 --- a/src/main/java/diet/server/ConversationController/Telegram_Dyadic_Customizable_ReferentialTask.java +++ b/src/main/java/diet/server/ConversationController/Telegram_Dyadic_Customizable_ReferentialTask.java @@ -11,6 +11,7 @@ import diet.server.Participant; import diet.task.CustomizableReferentialTask.CustomizableReferentialTask; import diet.task.CustomizableReferentialTask.CustomizableReferentialTaskSettings; +import diet.task.CustomizableReferentialTask.CustomizableReferentialTaskSettingsFactory; import diet.tg.TelegramMessageFromClient; import diet.tg.TelegramParticipant; import org.telegram.telegrambots.meta.api.objects.CallbackQuery; @@ -22,8 +23,8 @@ */ public class Telegram_Dyadic_Customizable_ReferentialTask extends TelegramController{ - - CustomizableReferentialTaskSettings crts = new CustomizableReferentialTaskSettings(this,true, null, null ); + CustomizableReferentialTaskSettingsFactory crtsf = new CustomizableReferentialTaskSettingsFactory(this,true); + CustomizableReferentialTaskSettings crts=crtsf.getNextCustomizableReferentialTaskSettings(); CustomizableReferentialTask crt = new CustomizableReferentialTask(this, crts); // CustomizableReferentialTask crt = new CustomizableReferentialTask(this, 5000,true); // Participant pDirector; @@ -32,10 +33,15 @@ public class Telegram_Dyadic_Customizable_ReferentialTask extends TelegramContro public Telegram_Dyadic_Customizable_ReferentialTask(Conversation c) { super(c); + + } public Telegram_Dyadic_Customizable_ReferentialTask(Conversation c, long istypingtimeout) { super(c, istypingtimeout); + + + } diff --git a/src/main/java/diet/server/ConversationController/Telegram_Dyadic_Customizable_ReferentialTask_Automatic_Start.java b/src/main/java/diet/server/ConversationController/Telegram_Dyadic_Customizable_ReferentialTask_Automatic_Start.java index e917dfc..810abff 100644 --- a/src/main/java/diet/server/ConversationController/Telegram_Dyadic_Customizable_ReferentialTask_Automatic_Start.java +++ b/src/main/java/diet/server/ConversationController/Telegram_Dyadic_Customizable_ReferentialTask_Automatic_Start.java @@ -6,10 +6,9 @@ package diet.server.ConversationController; import diet.server.Conversation; -import diet.server.ConversationController.ui.CustomDialog; -import diet.server.Participant; import diet.task.CustomizableReferentialTask.CustomizableReferentialTask; import diet.task.CustomizableReferentialTask.CustomizableReferentialTaskSettings; +import diet.task.CustomizableReferentialTask.CustomizableReferentialTaskSettingsFactory; import diet.tg.TelegramMessageFromClient; import diet.tg.TelegramParticipant; import java.util.Hashtable; @@ -24,7 +23,9 @@ public class Telegram_Dyadic_Customizable_ReferentialTask_Automatic_Start extends TelegramController{ - CustomizableReferentialTaskSettings crts = new CustomizableReferentialTaskSettings(this,true, null, null ); + + CustomizableReferentialTaskSettingsFactory crtsf = new CustomizableReferentialTaskSettingsFactory(this, true); + CustomizableReferentialTaskSettings crts = crtsf.getNextCustomizableReferentialTaskSettings(); //CustomizableReferentialTask crt = new CustomizableReferentialTask(this, crts); // CustomizableReferentialTask crt = new CustomizableReferentialTask(this, 5000,true); // Participant pDirector; @@ -33,10 +34,13 @@ public class Telegram_Dyadic_Customizable_ReferentialTask_Automatic_Start extend public Telegram_Dyadic_Customizable_ReferentialTask_Automatic_Start(Conversation c) { super(c); + } public Telegram_Dyadic_Customizable_ReferentialTask_Automatic_Start(Conversation c, long istypingtimeout) { super(c, istypingtimeout); + + } diff --git a/src/main/java/diet/server/ConversationController/Telegram_Dyadic_DeepfakeBotOrNot.java b/src/main/java/diet/server/ConversationController/Telegram_Dyadic_DeepfakeBotOrNot.java index 0a97ce4..1c3f0e9 100644 --- a/src/main/java/diet/server/ConversationController/Telegram_Dyadic_DeepfakeBotOrNot.java +++ b/src/main/java/diet/server/ConversationController/Telegram_Dyadic_DeepfakeBotOrNot.java @@ -11,6 +11,7 @@ import diet.server.Participant; import diet.task.CustomizableReferentialTask.CustomizableReferentialTask; import diet.task.CustomizableReferentialTask.CustomizableReferentialTaskSettings; +import diet.task.CustomizableReferentialTask.CustomizableReferentialTaskSettingsFactory; import diet.tg.TelegramMessageFromClient; import diet.tg.TelegramParticipant; import org.telegram.telegrambots.meta.api.objects.CallbackQuery; @@ -23,7 +24,9 @@ public class Telegram_Dyadic_DeepfakeBotOrNot extends TelegramController{ - CustomizableReferentialTaskSettings crts = new CustomizableReferentialTaskSettings(this,true, "facerealornot" ,"facefakeorreal.txt"); + CustomizableReferentialTaskSettingsFactory crtsf = new CustomizableReferentialTaskSettingsFactory(this, true, "facerealornot" ,"facefakeorreal.txt"); + CustomizableReferentialTaskSettings crts = crtsf.getNextCustomizableReferentialTaskSettings(); + //CustomizableReferentialTaskSettings crts = new CustomizableReferentialTaskSettings(this,true, "facerealornot" ,"facefakeorreal.txt"); CustomizableReferentialTask crt = new CustomizableReferentialTask(this, crts); // CustomizableReferentialTask crt = new CustomizableReferentialTask(this, 5000,true); // Participant pDirector; diff --git a/src/main/java/diet/server/ConversationController/Telegram_Dyadic_Rorschach.java b/src/main/java/diet/server/ConversationController/Telegram_Dyadic_Rorschach.java index 6304e32..cc91f42 100644 --- a/src/main/java/diet/server/ConversationController/Telegram_Dyadic_Rorschach.java +++ b/src/main/java/diet/server/ConversationController/Telegram_Dyadic_Rorschach.java @@ -11,6 +11,7 @@ import diet.server.Participant; import diet.task.CustomizableReferentialTask.CustomizableReferentialTask; import diet.task.CustomizableReferentialTask.CustomizableReferentialTaskSettings; +import diet.task.CustomizableReferentialTask.CustomizableReferentialTaskSettingsFactory; import diet.tg.TelegramMessageFromClient; import diet.tg.TelegramParticipant; import org.telegram.telegrambots.meta.api.objects.CallbackQuery; @@ -23,7 +24,12 @@ public class Telegram_Dyadic_Rorschach extends TelegramController{ - CustomizableReferentialTaskSettings crts = new CustomizableReferentialTaskSettings(this,true, "rorschachset02" ,"rorschachsequence01.txt"); + + CustomizableReferentialTaskSettingsFactory crtsf = new CustomizableReferentialTaskSettingsFactory(this, true, "rorschachset02" ,"rorschachsequence01.txt"); + CustomizableReferentialTaskSettings crts = crtsf.getNextCustomizableReferentialTaskSettings(); + + + //CustomizableReferentialTaskSettings crts = new CustomizableReferentialTaskSettings(this,true, "rorschachset02" ,"rorschachsequence01.txt"); CustomizableReferentialTask crt = new CustomizableReferentialTask(this, crts); // CustomizableReferentialTask crt = new CustomizableReferentialTask(this, 5000,true); // Participant pDirector; diff --git a/src/main/java/diet/server/ConversationController/Telegram_Dyadic_TangramTask.java b/src/main/java/diet/server/ConversationController/Telegram_Dyadic_TangramTask.java index a4a5aa2..4c6f421 100644 --- a/src/main/java/diet/server/ConversationController/Telegram_Dyadic_TangramTask.java +++ b/src/main/java/diet/server/ConversationController/Telegram_Dyadic_TangramTask.java @@ -12,6 +12,7 @@ import diet.server.ParticipantGroups.ParticipantGroup; import diet.task.CustomizableReferentialTask.CustomizableReferentialTask; import diet.task.CustomizableReferentialTask.CustomizableReferentialTaskSettings; +import diet.task.CustomizableReferentialTask.CustomizableReferentialTaskSettingsFactory; import diet.tg.TelegramMessageFromClient; import diet.tg.TelegramParticipant; import java.util.Hashtable; @@ -26,7 +27,12 @@ public class Telegram_Dyadic_TangramTask extends TelegramController{ - CustomizableReferentialTaskSettings crts = new CustomizableReferentialTaskSettings(this,true, "tangramset01", "tangramsequence.txt" ); + + CustomizableReferentialTaskSettingsFactory crtsf = new CustomizableReferentialTaskSettingsFactory(this, true, "tangramset01" ,"tangramsequence.txt"); + CustomizableReferentialTaskSettings crts = crtsf.getNextCustomizableReferentialTaskSettings(); + + + //CustomizableReferentialTaskSettings crts = new CustomizableReferentialTaskSettings(this,true, "tangramset01", "tangramsequence.txt" ); Hashtable ht_pg_crt = new Hashtable(); Hashtable ht_p_crt = new Hashtable(); diff --git a/src/main/java/diet/server/ConversationController/Telegram_dyadic_AskFor_Language_NL_EN_FILTEROK_RORSCHACH.java b/src/main/java/diet/server/ConversationController/Telegram_dyadic_AskFor_Language_NL_EN_FILTEROK_RORSCHACH.java index 88493c9..ab4c753 100644 --- a/src/main/java/diet/server/ConversationController/Telegram_dyadic_AskFor_Language_NL_EN_FILTEROK_RORSCHACH.java +++ b/src/main/java/diet/server/ConversationController/Telegram_dyadic_AskFor_Language_NL_EN_FILTEROK_RORSCHACH.java @@ -18,6 +18,7 @@ import diet.server.Participant; import diet.task.CustomizableReferentialTask.CustomizableReferentialTask; import diet.task.CustomizableReferentialTask.CustomizableReferentialTaskSettings; +import diet.task.CustomizableReferentialTask.CustomizableReferentialTaskSettingsFactory; import diet.tg.TelegramMessageFromClient; import diet.tg.TelegramParticipant; import java.util.Hashtable; @@ -37,7 +38,11 @@ public class Telegram_dyadic_AskFor_Language_NL_EN_FILTEROK_RORSCHACH extends Te // CustomizableReferentialTask crt = new CustomizableReferentialTask(this, 5000,true); - CustomizableReferentialTaskSettings crts = new CustomizableReferentialTaskSettings(this,true, "rorschachset01", "rorschachlongersequence.txt" ); + CustomizableReferentialTaskSettingsFactory crtsf = new CustomizableReferentialTaskSettingsFactory(this, true, "rorschachset01", "rorschachlongersequence.txt"); + CustomizableReferentialTaskSettings crts = crtsf.getNextCustomizableReferentialTaskSettings(); + + + // CustomizableReferentialTaskSettings crts = new CustomizableReferentialTaskSettings(this,true, ); // CustomizableReferentialTask crt = new CustomizableReferentialTask(this, 5000,true); // Participant pDirector; diff --git a/src/main/java/diet/server/ConversationController/TurnByTurn_Dyadic_Customizable_ReferentialTask.java b/src/main/java/diet/server/ConversationController/TurnByTurn_Dyadic_Customizable_ReferentialTask.java index 57e6d12..4a977ca 100644 --- a/src/main/java/diet/server/ConversationController/TurnByTurn_Dyadic_Customizable_ReferentialTask.java +++ b/src/main/java/diet/server/ConversationController/TurnByTurn_Dyadic_Customizable_ReferentialTask.java @@ -12,6 +12,7 @@ import diet.server.Participant; import diet.task.CustomizableReferentialTask.CustomizableReferentialTask; import diet.task.CustomizableReferentialTask.CustomizableReferentialTaskSettings; +import diet.task.CustomizableReferentialTask.CustomizableReferentialTaskSettingsFactory; /** * @@ -20,8 +21,13 @@ public class TurnByTurn_Dyadic_Customizable_ReferentialTask extends TurnByTurn_Dyadic{ - CustomizableReferentialTaskSettings crts = new CustomizableReferentialTaskSettings(this, false, null, null ); + CustomizableReferentialTaskSettingsFactory crtsf = new CustomizableReferentialTaskSettingsFactory(this,false); + CustomizableReferentialTaskSettings crts;// = new CustomizableReferentialTaskSettings(this,true, null, null ); CustomizableReferentialTask crt = new CustomizableReferentialTask(this, crts); + + + //CustomizableReferentialTaskSettings crts = new CustomizableReferentialTaskSettings(this, false, null, null ); + //CustomizableReferentialTask crt = new CustomizableReferentialTask(this, crts); // Participant pDirector; // Participant pMatcher; diff --git a/src/main/java/diet/server/io/IntelligentIO.java b/src/main/java/diet/server/io/IntelligentIO.java index fce0723..b774a31 100644 --- a/src/main/java/diet/server/io/IntelligentIO.java +++ b/src/main/java/diet/server/io/IntelligentIO.java @@ -134,7 +134,8 @@ public void writeToThrowableFileCreatingIfNecessary(String filename, Throwable t public void saveWindowTextToLog(String windowName, String s){ - this.writeToTextFileCreatingIfNecessary("window_"+windowName+".txt", s+"\n"); + long t = new Date().getTime(); + this.writeToTextFileCreatingIfNecessary("window_"+windowName+".txt", t+": "+ s+"\n"); System.err.println("Saving window message:"+s); } diff --git a/src/main/java/diet/task/CustomizableReferentialTask/CustomizableReferentialTask.java b/src/main/java/diet/task/CustomizableReferentialTask/CustomizableReferentialTask.java index 6f75f6f..03f7836 100644 --- a/src/main/java/diet/task/CustomizableReferentialTask/CustomizableReferentialTask.java +++ b/src/main/java/diet/task/CustomizableReferentialTask/CustomizableReferentialTask.java @@ -114,6 +114,8 @@ public class CustomizableReferentialTask implements JTrialTimerActionRecipientIn boolean showScoreOnEachGame = false; boolean showIfSelectionWasCorrrectOrIncorrect = false; boolean advanceToNextManually = false; + + String filename =""; @@ -126,6 +128,7 @@ public CustomizableReferentialTask(DefaultConversationController cC, Customizabl this.correctscoreinrement = crts.correctscoreinrement; this.deleteStimulusAfterEachTrial = crts.deleteStimulusAfterEachTrial; this.directoryname = crts.directoryname; + this.filename = crts.filename; this.durationOfGame = crts.durationOfGame; this.durationOfStimulus= crts.durationOfStimulus; this.htIMAGE= crts.htIMAGE; @@ -136,10 +139,15 @@ public CustomizableReferentialTask(DefaultConversationController cC, Customizabl this.stimuluswidth=crts.stimuluswidth; this.telegram=crts.telegram; - Vector[] vstimuli = crts.getVstimuli(); + if(!telegram)CustomDialog.showDialog("This code has been mainly tested with the Telegram interface.\nT" + + "There might be some bugs that need ironing out if running this code with the java interface.\n" + + "Please let the developers know if you encounter anything that needs to be fixed!" + + ""); + + //Vector[] vstimuli = crts.getVstimuli(); - this.vstimuli=vstimuli[0]; - this.vstimuliFULL=vstimuli[1]; + this.vstimuli=crts.getVstimuli(); + this.vstimuliFULL=CustomizableReferentialTaskSettings.duplicateVectorOfStringArray(vstimuli); this. showScoreOnEachGame = crts.showScoreOnEachGame; @@ -1228,6 +1236,7 @@ public Vector getAdditionalValues(Participant p){ String stimulusself =""; String stimulusother =""; Vector avs = new Vector(); + AttribVal av = new AttribVal("setname",""+this.filename); if(pA==p){ stimulusself=directoryname+"/"+this.currentTrial[0]; stimulusother=directoryname+"/"+this.currentTrial[1]; @@ -1244,6 +1253,7 @@ public Vector getAdditionalValues(Participant p){ else { av6 = new AttribVal("haslooped","NO"); } + avs.addElement(av); avs.addElement(av0);avs.addElement(av1); avs.addElement(av2); avs.addElement(av3); avs.addElement(av4); avs.addElement(av5);avs.addElement(av6); } if(pB==p){ @@ -1261,6 +1271,7 @@ public Vector getAdditionalValues(Participant p){ }else { av6 = new AttribVal("haslooped","NO"); } + avs.addElement(av); avs.addElement(av0);avs.addElement(av1); avs.addElement(av2); avs.addElement(av3); avs.addElement(av4);avs.addElement(av5);avs.addElement(av6); } diff --git a/src/main/java/diet/task/CustomizableReferentialTask/CustomizableReferentialTaskSettings.java b/src/main/java/diet/task/CustomizableReferentialTask/CustomizableReferentialTaskSettings.java index 8a900e8..e226720 100644 --- a/src/main/java/diet/task/CustomizableReferentialTask/CustomizableReferentialTaskSettings.java +++ b/src/main/java/diet/task/CustomizableReferentialTask/CustomizableReferentialTaskSettings.java @@ -60,15 +60,18 @@ public class CustomizableReferentialTaskSettings { - public String directoryname = "tangramset01";//"tangramset02directortraining"; + public String directoryname = ""; public int stimuluswidth = -1; public int stimulusheight=-1; public boolean isinphysicalfolder = true; - private Vector vstimuli = new Vector(); - private Vector vstimuliFULL = new Vector(); + + public Vector vs= new Vector(); + + //public Vector vstimuli = new Vector(); + // public Vector vstimuliFULL = new Vector(); public Hashtable htIMAGE = new Hashtable(); @@ -80,188 +83,31 @@ public class CustomizableReferentialTaskSettings { public boolean showScoreOnEachGame = true; public boolean showIfSelectionWasCorrrectOrIncorrect = true; public boolean advanceToNextManually = true; - - public boolean randomizeSequence = false; + public String filename; + // option of looping around when done - public CustomizableReferentialTaskSettings(DefaultConversationController cC, boolean telegram, String stimulisubfolderCANBENULL, String sequencefilenameCANBENULL){ - //this.durationOfStimulus=durationOfStimulus; - //if(2<5)System.exit() - + public CustomizableReferentialTaskSettings(DefaultConversationController cC, Vector vs , String foldername, String filename){ + this.cC=cC; - - if(stimulisubfolderCANBENULL!=null && sequencefilenameCANBENULL!=null){ - String fn = System.getProperty("user.dir") + File.separator + "experimentresources"+File.separator+"stimuli" + File.separator+stimulisubfolderCANBENULL + File.separator+ sequencefilenameCANBENULL; - File seqF = new File(fn); - if(seqF.exists()){ - loadFromFile(seqF); - } - else{ - CustomDialog.showDialog("Can't find the file:\n\n" - + sequencefilenameCANBENULL+"\n\n" - + "in the folder:\n\n" - + stimulisubfolderCANBENULL +"\n\n" - + "The system is looking in: \n\n"+fn+ "\n\n\n" - + "You might be able to find it manually:"); - - loadFromFile(null); - } - } - else{ - loadFromFile(null); - } - - - - randomizeSequence = CustomDialog.getBoolean("Do you want to randomize the order of the stimuli?", "randomize", "keep order"); - - - - - - - if(randomizeSequence){ - Random r = new Random(); - - Vector vRandomized = new Vector(); - for(int i=0;i)vRandomized.clone(); - - - } - - - - - durationOfGame = CustomDialog.getLong("How long is a game?", 60000); - durationOfStimulus = CustomDialog.getLong("How long should the stimuli be displayed for?", 600000); - showButtons = CustomDialog.getBoolean("Do you want to show buttons underneath the stimuli on the clients?", "Buttons", "No Buttons"); - - - - - this.telegram=telegram; - - //loadStimuliList(); + this.vs = vs; + + this.directoryname=foldername; + this.filename=filename; + Dimension d = getImageHeights(); if(d.width==-1||d.height==-1) { - CustomDialog.showDialog("The server can't find the images in the JAR file\nTry recompiling the project!"); + CustomDialog.showDialog("The server can't find the images...\nTry recompiling the project!"); } stimuluswidth=d.width; stimulusheight=d.height; - - final CustomizableReferentialTaskSettings crtthis = this; - - if(telegram) this.deleteStimulusAfterEachTrial = CustomDialog.getBoolean("Do you want to delete the stimuli from the telegram window after each trial?", "Delete", "Keep"); - - - - - showScoreOnEachGame = CustomDialog.getBoolean("Do you want to show the score after each trial?", "Show", "Don`t show"); - showIfSelectionWasCorrrectOrIncorrect = CustomDialog.getBoolean("Do you want to show if the previous trial was correct / incorrect?", "Show", "Don`t show"); - - advanceToNextManually = !CustomDialog.getBoolean("Do you want participants to advance automatically\n or do participants have to type /NEXT to advance to next stimuli?", "Automatic advancement", "Manual advancement by typing /NEXT"); - - + } - - - private void loadFromFile(File stimulisequence){ - - if(stimulisequence==null || !stimulisequence.exists()){ - String userdir = System.getProperty("user.dir"); - String directory = (userdir+File.separator+"experimentresources"+ File.separator+ "stimuli"); - - CustomDialog.showDialog("Important:\n\n(1) The stimuli must be in a subdirectory of /experimentresources/stimuli.\n" - + "(2) The file containing the stimuli sequence must be in the same subdirectory as the stimuli.\n" - + "\n(See usermanual for more details!)"); - stimulisequence = CustomDialog.loadFileWithExtension(directory, "Choose the text file containing the sequences of stimuli. \nIt must be in the same directory as the stimuli", "txt", "Text file containing the list of stimuli and correct answers"); - } - - String foldername = stimulisequence.getParentFile().getName(); - this.directoryname=foldername; - System.err.println("Looking in "+directoryname); - if(stimulisequence==null)CustomDialog.showDialog("Couldn't find the file!"); - Vector data = new Vector(); - try{ - - BufferedReader br = new BufferedReader(new InputStreamReader(new FileInputStream(stimulisequence), "UTF-8")); - //BufferedReader br = new BufferedReader(new FileReader(stimulisequence)); - String st; - String header = br.readLine(); - while ((st = br.readLine()) != null){ - System.out.println(st); - - //st= st.replace(" ", ""); - String[] row = st.split("¦"); - data.addElement(row); - System.out.println("Split to:"); - for(int i =0;i)data.clone(); - this.vstimuliFULL=(Vector)data.clone(); - try{ - this.checkStimuliFilesExist(); - }catch(Exception e){ - e.printStackTrace(); - Conversation.saveErr(e); - CustomDialog.showDialog("Error loading the stimuli - it could be that there is empty space at the end of the script containing the stimuli names! Please check and restart!"); - } - } - - - private void checkStimuliFilesExist(){ - String userdir = System.getProperty("user.dir"); - String dir = (userdir+File.separator+"experimentresources"+ File.separator+ "stimuli"+ File.separator+directoryname); - - - for(int i=0;i[] getVstimuli() { + public Vector getVstimuli() { // returns two vectors containing the stimuli Vector v1 = new Vector(); - Vector v2 = new Vector(); - - if(this.randomizeSequence){ - Vector vrnd = randomizeSequence(vstimuli); - v1 = duplicateVectorOfStringArray(vrnd); - v2 = duplicateVectorOfStringArray(vrnd); - return new Vector[]{v1,v2}; - } - else{ - v1 = duplicateVectorOfStringArray(vstimuli); - v2 = duplicateVectorOfStringArray(vstimuli); - return new Vector[]{v1,v2}; - } + //Vector v2 = new Vector(); + + v1 = duplicateVectorOfStringArray(vs); + //v2 = duplicateVectorOfStringArray(vs); + //return new Vector[]{v1,v2}; + return v1; } @@ -390,7 +191,29 @@ static public Vector duplicateVectorOfStringArray(Vector vSA - + + + + + + + private Dimension getImageHeightsJARDEPRECATED(){ + String firstfilename = directoryname+"/"+vs.elementAt(0)[0]; + System.err.println("Trying to get image heights for: "+firstfilename); + BufferedImage bimg =null ; + try { + ClassLoader cldr = CustomizableReferentialTaskSettings.class.getClassLoader(); + URL url = cldr.getResource(firstfilename); + bimg = ImageIO.read(url); + int width = bimg.getWidth(); + int height = bimg.getHeight(); + return (new Dimension(width,height)); + } catch (IOException ex) { + // handle exception... + ex.printStackTrace(); + } + return new Dimension(-1,-1); + } diff --git a/src/main/java/diet/task/CustomizableReferentialTask/CustomizableReferentialTaskSettingsBACKUP.java b/src/main/java/diet/task/CustomizableReferentialTask/CustomizableReferentialTaskSettingsBACKUP.java new file mode 100644 index 0000000..d8d3c0b --- /dev/null +++ b/src/main/java/diet/task/CustomizableReferentialTask/CustomizableReferentialTaskSettingsBACKUP.java @@ -0,0 +1,375 @@ +/* + * To change this license header, choose License Headers in Project Properties. + * To change this template file, choose Tools | Templates + * and open the template in the editor. + */ + +package diet.task.CustomizableReferentialTask; + +import diet.attribval.AttribVal; +import diet.message.MessageTask; +import diet.server.Conversation; +import diet.server.ConversationController.DefaultConversationController; +import diet.server.ConversationController.ui.CustomDialog; +import diet.server.Participant; +import diet.task.ProceduralComms.JTrialTimerActionRecipientInterface; +import diet.task.TaskControllerInterface; +import diet.tg.TelegramParticipant; +import diet.utils.HashtableWithDefaultvalue; +import java.awt.Color; +import java.awt.Dimension; +import java.awt.image.BufferedImage; +import java.io.BufferedReader; +import java.io.File; +import java.io.FileInputStream; +import java.io.IOException; +import java.io.InputStream; +import java.io.InputStreamReader; +import java.net.URL; +import java.text.DecimalFormat; +import java.util.Date; +import java.util.Hashtable; +import java.util.Random; +import java.util.Vector; +import javax.imageio.ImageIO; +import javax.swing.JFrame; +import javax.swing.JPanel; +import javax.swing.SwingUtilities; +import org.telegram.telegrambots.meta.api.objects.CallbackQuery; +import org.telegram.telegrambots.meta.api.objects.Message; +import org.telegram.telegrambots.meta.api.objects.Update; + +/** + * + * @author gj + */ +public class CustomizableReferentialTaskSettingsBACKUP { + + + DefaultConversationController cC; + + + public long durationOfStimulus;// = CustomDialog.getLong("How long should the stimuli be displayed for?", 600000); + public long durationOfGame;// = CustomDialog.getLong("How long is a game?", 60000); + public boolean showButtons;// = CustomDialog.getBoolean("Do you want to show buttons underneath the stimuli on the clients?", "Buttons", "No Buttons"); + + + + public double correctscoreinrement = 10;//CustomDialog.getDouble("What is the score increment for correct guesses?", 10); + public double incorrectpenalty = 5;//CustomDialog.getDouble("What is the point penalty for incorrect guesses?", 5); + + + + public String directoryname = "tangramset01";//"tangramset02directortraining"; + + public int stimuluswidth = -1; + public int stimulusheight=-1; + + public boolean isinphysicalfolder = true; + + public Vector vstimuli = new Vector(); + public Vector vstimuliFULL = new Vector(); + + public Hashtable htIMAGE = new Hashtable(); + + + public boolean telegram = false; + public boolean deleteStimulusAfterEachTrial =true; + + + public boolean showScoreOnEachGame = true; + public boolean showIfSelectionWasCorrrectOrIncorrect = true; + public boolean advanceToNextManually = true; + + public boolean randomizeSequence = false; + + // option of looping around when done + + + public CustomizableReferentialTaskSettingsBACKUP(DefaultConversationController cC, boolean telegram, String stimulisubfolderCANBENULL, String sequencefilenameCANBENULL){ + //this.durationOfStimulus=durationOfStimulus; + //if(2<5)System.exit() + + this.cC=cC; + + if(stimulisubfolderCANBENULL!=null && sequencefilenameCANBENULL!=null){ + String fn = System.getProperty("user.dir") + File.separator + "experimentresources"+File.separator+"stimuli" + File.separator+stimulisubfolderCANBENULL + File.separator+ sequencefilenameCANBENULL; + File seqF = new File(fn); + if(seqF.exists()){ + loadFromFile(seqF); + } + else{ + CustomDialog.showDialog("Can't find the file:\n\n" + + sequencefilenameCANBENULL+"\n\n" + + "in the folder:\n\n" + + stimulisubfolderCANBENULL +"\n\n" + + "The system is looking in: \n\n"+fn+ "\n\n\n" + + "You might be able to find it manually:"); + + loadFromFile(null); + } + } + else{ + loadFromFile(null); + } + + + + + + + + + + randomizeSequence = CustomDialog.getBoolean("Do you want to randomize the order of the stimuli?", "randomize", "keep order"); + if(randomizeSequence){ + Random r = new Random(); + + Vector vRandomized = new Vector(); + for(int i=0;i)vRandomized.clone(); + + + } + + + + + durationOfGame = CustomDialog.getLong("How long is a game?", 60000); + durationOfStimulus = CustomDialog.getLong("How long should the stimuli be displayed for?", 600000); + showButtons = CustomDialog.getBoolean("Do you want to show buttons underneath the stimuli on the clients?", "Buttons", "No Buttons"); + + + + + this.telegram=telegram; + + //loadStimuliList(); + Dimension d = getImageHeights(); + if(d.width==-1||d.height==-1) { + CustomDialog.showDialog("The server can't find the images in the JAR file\nTry recompiling the project!"); + } + stimuluswidth=d.width; + stimulusheight=d.height; + + final CustomizableReferentialTaskSettingsBACKUP crtthis = this; + + if(telegram) this.deleteStimulusAfterEachTrial = CustomDialog.getBoolean("Do you want to delete the stimuli from the telegram window after each trial?", "Delete", "Keep"); + + + + + showScoreOnEachGame = CustomDialog.getBoolean("Do you want to show the score after each trial?", "Show", "Don`t show"); + showIfSelectionWasCorrrectOrIncorrect = CustomDialog.getBoolean("Do you want to show if the previous trial was correct / incorrect?", "Show", "Don`t show"); + + advanceToNextManually = !CustomDialog.getBoolean("Do you want participants to advance automatically\n or do participants have to type /NEXT to advance to next stimuli?", "Automatic advancement", "Manual advancement by typing /NEXT"); + + + + } + + + + private void loadFromFile(File stimulisequence){ + + if(stimulisequence==null || !stimulisequence.exists()){ + String userdir = System.getProperty("user.dir"); + String directory = (userdir+File.separator+"experimentresources"+ File.separator+ "stimuli"); + + CustomDialog.showDialog("Important:\n\n(1) The stimuli must be in a subdirectory of /experimentresources/stimuli.\n" + + "(2) The file containing the stimuli sequence must be in the same subdirectory as the stimuli.\n" + + "\n(See usermanual for more details!)"); + stimulisequence = CustomDialog.loadFileWithExtension(directory, "Choose the text file containing the sequences of stimuli. \nIt must be in the same directory as the stimuli", "txt", "Text file containing the list of stimuli and correct answers"); + + } + + String foldername = stimulisequence.getParentFile().getName(); + this.directoryname=foldername; + System.err.println("Looking in "+directoryname); + if(stimulisequence==null)CustomDialog.showDialog("Couldn't find the file!"); + Vector data = new Vector(); + try{ + + BufferedReader br = new BufferedReader(new InputStreamReader(new FileInputStream(stimulisequence), "UTF-8")); + //BufferedReader br = new BufferedReader(new FileReader(stimulisequence)); + String st; + String header = br.readLine(); + while ((st = br.readLine()) != null){ + System.out.println(st); + + //st= st.replace(" ", ""); + String[] row = st.split("¦"); + data.addElement(row); + System.out.println("Split to:"); + for(int i =0;i)data.clone(); + this.vstimuliFULL=(Vector)data.clone(); + try{ + this.checkStimuliFilesExist(); + }catch(Exception e){ + e.printStackTrace(); + Conversation.saveErr(e); + CustomDialog.showDialog("Error loading the stimuli - it could be that there is empty space at the end of the script containing the stimuli names! Please check and restart!"); + } + } + + + private void checkStimuliFilesExist(){ + String userdir = System.getProperty("user.dir"); + String dir = (userdir+File.separator+"experimentresources"+ File.separator+ "stimuli"+ File.separator+directoryname); + + + for(int i=0;i[] getVstimuli() { + // returns two vectors containing the stimuli + Vector v1 = new Vector(); + Vector v2 = new Vector(); + + if(this.randomizeSequence){ + Vector vrnd = randomizeSequence(vstimuli); + v1 = duplicateVectorOfStringArray(vrnd); + v2 = duplicateVectorOfStringArray(vrnd); + return new Vector[]{v1,v2}; + } + else{ + v1 = duplicateVectorOfStringArray(vstimuli); + v2 = duplicateVectorOfStringArray(vstimuli); + return new Vector[]{v1,v2}; + } + + + } + + + + + public static Vector randomizeSequence(Vector v){ + Random r = new Random(); + Vector vRandomized = new Vector(); + for(int i=0;i v1 = vRandomized; + //Vector v2 = (Vector)v1.clone(); + return v1; + } + + + + + + + static public Vector duplicateVectorOfStringArray(Vector vSA){ + Vector vSANEW = new Vector(); + for(int i=0;i vstimuli = new Vector(); + //public Vector vstimuliFULL = new Vector(); + + public Hashtable htIMAGE = new Hashtable(); + + + public boolean telegram = false; + public boolean deleteStimulusAfterEachTrial =true; + + + public boolean showScoreOnEachGame = true; + public boolean showIfSelectionWasCorrrectOrIncorrect = true; + public boolean advanceToNextManually = true; + + public boolean randomizeSequence = false; + + String stimulisettingsType = "singlesorted"; // + + Vector vcrts = new Vector(); + + boolean isSingleSet = true; + boolean loopAutomaticallyWhenMultipleSetsAreAllUsed = true; + + + + public CustomizableReferentialTaskSettingsFactory(DefaultConversationController cC, boolean telegram, String folder, String filename) { + this.cC = cC; + this.telegram = telegram; + String fn = System.getProperty("user.dir") + File.separator + "experimentresources"+File.separator+"stimuli" + File.separator+folder + File.separator+ filename; + File seqF = new File(fn); + if(seqF.exists()){ + this.loadStimuli_SingleSet(seqF); + } + else{ + CustomDialog.showDialog("Can't find the file:\n\n" + + folder+"\n\n" + + "in the folder:\n\n" + + filename +"\n\n" + + "The system is looking in: \n\n"+fn+ "\n\n\n" + + "You might be able to find it manually:"); + + loadStimuli_SingleSet(null); + } + } + + + + + + + + + + + + + + + + + public CustomizableReferentialTaskSettingsFactory(DefaultConversationController cC, boolean telegram) { + this.cC = cC; + this.telegram = telegram; + String[] options = {"Single set", "Multiple sets"}; + stimulisettingsType = CustomDialog.show2OptionDialog(options, "What kind of stimuli set(s) do you want to use?", "Stimuli"); + + if(stimulisettingsType.equalsIgnoreCase(options[0])){ + this.isSingleSet=true; + this.loadStimuli_SingleSet(null); + + + } + else if (stimulisettingsType.equalsIgnoreCase(options[1])){ + this.isSingleSet=false; + this.loadStimuli_MultipleSet(); + + } + + } + + + public void loadStimuli_MultipleSet(){ + + String userdir = System.getProperty("user.dir"); + String directory = (userdir+File.separator+"experimentresources"+ File.separator+ "stimuli"); + CustomDialog.showDialog("In the next step you need to select a text file\nthat contains a list of stimuli sets"); + + File f = CustomDialog.loadFileWithExtension(directory, "Select the text file containing the list of stimuli sets", "txt", "txt"); + + Vector fileNames = new Vector(); + //String textFile = ""; + try{ + BufferedReader br = new BufferedReader(new FileReader(f)); + String line = br.readLine(); + while (line != null) { + fileNames.addElement(line); + line = br.readLine(); + } + br.close(); + } + catch(Exception e){ + e.printStackTrace(); + Conversation.saveErr(e); + CustomDialog.showDialog("There was an error loading the file containing the list of stimuli sets.\nTo prevent the experiment starting with missing stimuli, the program will exit."); + System.exit(-55); + } + + + Vector vc = new Vector(); + + for (int i=0;i vs = this.loadFromFile(fStimuli); + Conversation.printWSln("Main", "checking that the stimuli in "+s+ " exist"); + CustomizableReferentialTaskSettings crts = new CustomizableReferentialTaskSettings(cC, vs, f.getParentFile().getName(),s); + vc.add(crts); + + + + + + + + } + this.askBooleanQuestions(); + this.loopAutomaticallyWhenMultipleSetsAreAllUsed = CustomDialog.getBoolean("When all sets are used, do you want to\nloop and use them again or prompt user what to do?", "loop and use again", "prompt user what to do"); + Conversation.printWSln("Main", "Now making sure that each list has images that can be found"); + + + for(int i=0;i < vc.size() ; i++ ){ + CustomizableReferentialTaskSettings crts = vc.elementAt(i); + crts.durationOfGame = this.durationOfGame; + crts.durationOfStimulus = this.durationOfStimulus; + + crts.showButtons = this.showButtons; + crts.deleteStimulusAfterEachTrial = this.deleteStimulusAfterEachTrial; + crts.showScoreOnEachGame = this.showScoreOnEachGame; + crts.showIfSelectionWasCorrrectOrIncorrect = this.showIfSelectionWasCorrrectOrIncorrect; + crts.advanceToNextManually = this.advanceToNextManually; + crts.telegram=this.telegram; + this.vcrts.add(crts); + } + + } + + + + + + + + + + public void loadStimuli_SingleSet(File f){ + + if(f!=null && !f.exists()){ + CustomDialog.showDialog("Could not find the file containing the list of stimuli.\nPlease choose manually."); + f = this.getScriptFile(); + } + + else if (f==null){ + f = this.getScriptFile(); + } + if(f==null){ + CustomDialog.showDialog("Could not load the file containing the list of stimuli! Exiting");System.exit(-45); + } + + Vector vstimuli = this.loadFromFile(f); + + this.askBooleanQuestions(); + + if(this.randomizeSequence){ + vstimuli = CustomizableReferentialTaskSettings.randomizeSequence(vstimuli); + Conversation.printWSln("Main", "Randomizing the order of the stimuli"); + } + + + CustomizableReferentialTaskSettings crts = new CustomizableReferentialTaskSettings(cC, vstimuli, f.getParentFile().getName(),f.getName()); + //crts.directoryname = f.getParent(); + //System.err.println("The name is "+f.getName()); + //System.err.println("The path is "+f.getPath()); + //System.err.println("The parent is "+f.getParent()); + + crts.durationOfGame = this.durationOfGame; + crts.durationOfStimulus = this.durationOfStimulus; + crts.showButtons = this.showButtons; + crts.deleteStimulusAfterEachTrial = this.deleteStimulusAfterEachTrial; + crts.showScoreOnEachGame = this.showScoreOnEachGame; + crts.showIfSelectionWasCorrrectOrIncorrect = this.showIfSelectionWasCorrrectOrIncorrect; + crts.advanceToNextManually = this.advanceToNextManually; + crts.telegram=this.telegram; + this.vcrts.add(crts); + } + + + + Vector usedSets = new Vector(); + Hashtable htNames = new Hashtable(); + + int indexOfNextFree =0; + public CustomizableReferentialTaskSettings getNextCustomizableReferentialTaskSettings(){ + if(this.isSingleSet) return this.vcrts.firstElement(); + + if(indexOfNextFree>=this.vcrts.size()){ + if(this.loopAutomaticallyWhenMultipleSetsAreAllUsed){ + Conversation.printWSln("Main", "looping round and reusing stimuli sets"); + this.indexOfNextFree=0; + } + else{ + CustomDialog.showDialog("This is an alert that all the stimuli sets have been used.\n" + + "Press OK to reuse the stimuli sets."); + this.indexOfNextFree=0; + } + + + + } + + CustomizableReferentialTaskSettings crts = this.vcrts.elementAt(indexOfNextFree); + Conversation.printWSln("Main", "Returning stimuli set "+crts.filename); + indexOfNextFree++; + return crts; + } + + + + + + + + public void askBooleanQuestions(){ + durationOfGame = CustomDialog.getLong("How long is a game? (seconds)\n\nNote: To prevent games from timing out ", 600000); + if(this.isSingleSet)this.randomizeSequence = CustomDialog.getBoolean("Do you want the sequence of stimuli to be in original order or ranomized?", "original order", "randomized"); + durationOfStimulus = CustomDialog.getLong("How long should the stimuli be displayed for?", 6000000); + showButtons = CustomDialog.getBoolean("Do you want to show buttons underneath the stimuli on the clients?", "Buttons", "No Buttons"); + if(telegram) this.deleteStimulusAfterEachTrial = CustomDialog.getBoolean("Do you want to delete the stimuli from the telegram window after each trial?", "Delete", "Keep"); + + showScoreOnEachGame = CustomDialog.getBoolean("Do you want to show the score after each trial?", "Show", "Don`t show"); + showIfSelectionWasCorrrectOrIncorrect = CustomDialog.getBoolean("Do you want to show if the previous trial was correct / incorrect?", "Show", "Don`t show"); + advanceToNextManually = !CustomDialog.getBoolean("Do you want participants to advance automatically\n or do participants have to type /NEXT to advance to next stimuli?", "Automatic advancement", "Manual advancement by typing /NEXT"); + this.telegram=telegram; + + } + + + + + + + private File getScriptFile(){ + String userdir = System.getProperty("user.dir"); + String directory = (userdir+File.separator+"experimentresources"+ File.separator+ "stimuli"); + + CustomDialog.showDialog("Important:\n\n(1) The stimuli must be in a subdirectory of /experimentresources/stimuli.\n" + + "(2) The file containing the stimuli sequence must be in the same subdirectory as the stimuli.\n" + + "\n(See usermanual for more details!)"); + File stimulisequence = CustomDialog.loadFileWithExtension(directory, "Choose the text file containing the sequences of stimuli. \nIt must be in the same directory as the stimuli", "txt", "Text file containing the list of stimuli and correct answers"); + return stimulisequence; + } + + + + + private Vector loadFromFile(File stimulisequence){ + + + + String foldername = stimulisequence.getParentFile().getName(); + + // stimulisequence.get + + System.err.println("Looking in "+foldername + " for script file called "+stimulisequence); + if(stimulisequence==null)CustomDialog.showDialog("Couldn't find the file!"); + Vector data = new Vector(); + try{ + + BufferedReader br = new BufferedReader(new InputStreamReader(new FileInputStream(stimulisequence), "UTF-8")); + //BufferedReader br = new BufferedReader(new FileReader(stimulisequence)); + String st; + String header = br.readLine(); + while ((st = br.readLine()) != null){ + System.out.println(st); + + //st= st.replace(" ", ""); + String[] row = st.split("¦"); + data.addElement(row); + System.out.println("Split to:"); + for(int i =0;i)data.clone(); + //this.vstimuliFULL=(Vector)data.clone(); + try{ + boolean stimuliFilesExist = this.checkStimuliFilesExist(data,foldername); + if(!stimuliFilesExist){ + CustomDialog.showDialog("Error loading the stimuli - it could be that there is empty space at the end of the script containing the stimuli names! \n" + + "The program will exit to make sure the experiment doesn`t start with missing stimuli!"); + System.exit(-5); + } + }catch(Exception e){ + e.printStackTrace(); + Conversation.saveErr(e); + CustomDialog.showDialog("Error loading the stimuli - it could be that there is empty space at the end of the script containing the stimuli names! \n" + + "The program will exit to make sure the experiment doesn`t start with missing stimuli!"); + System.exit(-5); + + } + return data; + } + + + private boolean checkStimuliFilesExist(Vector vstimuli, String directoryname){ + String userdir = System.getProperty("user.dir"); + String dir = (userdir+File.separator+"experimentresources"+ File.separator+ "stimuli"+ File.separator+directoryname); + + + for(int i=0;i