[virtualcommons-svn] SF.net SVN: virtualcommons:[493] foraging/trunk/src/main/java/edu/asu/ commons
Status: Beta
Brought to you by:
alllee
From: <db...@us...> - 2010-03-25 21:21:04
|
Revision: 493 http://virtualcommons.svn.sourceforge.net/virtualcommons/?rev=493&view=rev Author: dbarge Date: 2010-03-25 21:20:57 +0000 (Thu, 25 Mar 2010) Log Message: ----------- This code version has following improvements 1) Quiz responses are more informative. After submitting the responses the players are notified about the correct and incorrect answers. 2) Added an option to the GUI to select the type of treatment from the facilitator end. This is a workaround for selecting either full-vision treatment or limited-vision treatment. Modified Paths: -------------- foraging/trunk/src/main/java/edu/asu/commons/foraging/client/ForagingClient.java foraging/trunk/src/main/java/edu/asu/commons/foraging/client/GameWindow2D.java foraging/trunk/src/main/java/edu/asu/commons/foraging/conf/RoundConfiguration.java foraging/trunk/src/main/java/edu/asu/commons/foraging/facilitator/ConfigurationDialog.java foraging/trunk/src/main/java/edu/asu/commons/foraging/facilitator/Facilitator.java foraging/trunk/src/main/java/edu/asu/commons/foraging/facilitator/FacilitatorWindow.java foraging/trunk/src/main/java/edu/asu/commons/foraging/server/ForagingServer.java Added Paths: ----------- foraging/trunk/src/main/java/edu/asu/commons/foraging/event/TreatmentTypeRequest.java foraging/trunk/src/main/java/edu/asu/commons/foraging/model/TreatmentType.java Modified: foraging/trunk/src/main/java/edu/asu/commons/foraging/client/ForagingClient.java =================================================================== --- foraging/trunk/src/main/java/edu/asu/commons/foraging/client/ForagingClient.java 2010-03-23 23:08:38 UTC (rev 492) +++ foraging/trunk/src/main/java/edu/asu/commons/foraging/client/ForagingClient.java 2010-03-25 21:20:57 UTC (rev 493) @@ -35,7 +35,9 @@ import edu.asu.commons.foraging.event.RoundStartedEvent; import edu.asu.commons.foraging.event.SanctionUpdateEvent; import edu.asu.commons.foraging.event.ShowInstructionsRequest; +import edu.asu.commons.foraging.event.TreatmentTypeRequest; import edu.asu.commons.foraging.event.SynchronizeClientEvent; +import edu.asu.commons.foraging.model.TreatmentType; import edu.asu.commons.util.Duration; import edu.asu.commons.util.Utils; @@ -69,6 +71,8 @@ private ClientDataModel dataModel; + private TreatmentType treatmentType = TreatmentType.FULLVISION; + private MessageQueue messageQueue; private JPanel clientPanel = new JPanel(); @@ -123,6 +127,14 @@ transmit(new AgentInfoRequest(getId(), color)); gameWindow3D.removeAgentDesigner(); } + + private void setTreatmentType(TreatmentType treatmentType) { + this.treatmentType = treatmentType; + } + + private TreatmentType getTreatmentType() { + return treatmentType; + } @Override @SuppressWarnings("unchecked") @@ -131,6 +143,7 @@ public void handle(SetConfigurationEvent event) { RoundConfiguration configuration = (RoundConfiguration) event.getParameters(); dataModel.setRoundConfiguration(configuration); + dataModel.getRoundConfiguration().setTreatmentType(getTreatmentType()); SwingUtilities.invokeLater(new Runnable() { public void run() { clientPanel.removeAll(); @@ -152,11 +165,20 @@ } }); + addEventProcessor(new EventTypeProcessor<ShowInstructionsRequest>(ShowInstructionsRequest.class) { public void handle(ShowInstructionsRequest request) { getGameWindow().showInstructions(); } }); + + addEventProcessor(new EventTypeProcessor<TreatmentTypeRequest>(TreatmentTypeRequest.class) { + public void handle(TreatmentTypeRequest request) { + setTreatmentType(request.getTreatmentType()); + dataModel.getRoundConfiguration().setTreatmentType(getTreatmentType()); + } + }); + addEventProcessor(new EventTypeProcessor<RoundStartedEvent>(RoundStartedEvent.class) { public void handle(RoundStartedEvent event) { System.err.println("client starting round: " + dataModel.is2dExperiment()); Modified: foraging/trunk/src/main/java/edu/asu/commons/foraging/client/GameWindow2D.java =================================================================== --- foraging/trunk/src/main/java/edu/asu/commons/foraging/client/GameWindow2D.java 2010-03-23 23:08:38 UTC (rev 492) +++ foraging/trunk/src/main/java/edu/asu/commons/foraging/client/GameWindow2D.java 2010-03-25 21:20:57 UTC (rev 493) @@ -18,6 +18,8 @@ import java.awt.event.MouseEvent; import java.lang.reflect.InvocationTargetException; import java.util.ArrayList; +import java.util.Collections; +import java.util.Iterator; import java.util.Arrays; import java.util.List; import java.util.Map; @@ -192,16 +194,22 @@ Properties actualAnswers = formEvent.getData(); // actualAnswers.list(System.err); List<String> incorrectAnswers = new ArrayList<String>(); + List<String> correctAnswers = new ArrayList<String>(); + // FIXME: always send a quiz response event. // iterate through expected answers for (Map.Entry<String, String> entry : configuration.getQuizAnswers().entrySet()) { String questionNumber = entry.getKey(); String expectedAnswer = entry.getValue(); + System.out.println(expectedAnswer); if (! expectedAnswer.equals(actualAnswers.getProperty(questionNumber)) ) { // flag the incorrect response incorrectAnswers.add(questionNumber); } + else { + correctAnswers.add(questionNumber); + } } if (incorrectAnswers.isEmpty()) { // notify the server and also notify the participant. @@ -212,8 +220,30 @@ } else { // FIXME: highlight the incorrect answers? + Collections.sort(incorrectAnswers); + Collections.sort(correctAnswers); StringBuilder builder = new StringBuilder().append(instructionsBuilder); - builder.append("<br><b><font color='red'>You have answered some questions incorrectly. Please try again and resubmit.</font></b>"); + + StringBuilder correctString = new StringBuilder(); + if (!correctAnswers.isEmpty()) { + correctString.append("<br>Correctly answered questions"); + for (Iterator<String> itr = correctAnswers.iterator(); itr.hasNext();) { + String correctSelected = itr.next(); + String correctValue = configuration.getQuizAnswers().get(correctSelected); + correctString.append("<br>"+correctSelected+": Option "+correctValue); + } + correctString.append("<br>"); + } + + StringBuilder incorrectString = new StringBuilder(); + incorrectString.append("<br>Incorrectly answered questions"); + for (Iterator<String> itr = incorrectAnswers.iterator(); itr.hasNext();) { + String incorrectSelected = itr.next(); + incorrectString.append("<br>"+incorrectSelected); + } + incorrectString.append("<br>"); + + builder.append("<br><b><font color='red'>"+correctString.toString()+incorrectString.toString()+".<br> Please select again and resubmit.</font></b>"); setInstructions(builder.toString()); } } Modified: foraging/trunk/src/main/java/edu/asu/commons/foraging/conf/RoundConfiguration.java =================================================================== --- foraging/trunk/src/main/java/edu/asu/commons/foraging/conf/RoundConfiguration.java 2010-03-23 23:08:38 UTC (rev 492) +++ foraging/trunk/src/main/java/edu/asu/commons/foraging/conf/RoundConfiguration.java 2010-03-25 21:20:57 UTC (rev 493) @@ -10,6 +10,7 @@ import edu.asu.commons.foraging.graphics.Point3D; import edu.asu.commons.foraging.model.ClientData; import edu.asu.commons.foraging.model.EnforcementMechanism; +import edu.asu.commons.foraging.model.TreatmentType; public class RoundConfiguration extends ExperimentRoundParameters.Base<ServerConfiguration> { @@ -26,6 +27,8 @@ private static final double DEFAULT_TOKEN_MOVEMENT_PROBABILITY = 0.2d; private static final double DEFAULT_TOKEN_BIRTH_PROBABILITY = 0.01d; + + private TreatmentType treatmentType; private final static Map<String, SanctionType> sanctionTypeMap = new HashMap<String, SanctionType>(3); public enum SanctionType { @@ -115,6 +118,15 @@ || getBooleanProperty("randomize-group", false); } + public void setTreatmentType (TreatmentType treatmentType) { + this.treatmentType = treatmentType; + } + + public TreatmentType getTreatmentType () { + return treatmentType; + } + + /** * Returns the number of seconds that the flashing visualization of * sanctioning should occur. @@ -134,11 +146,24 @@ } public boolean isTokensFieldOfVisionEnabled() { - return getBooleanProperty("tokens-field-of-vision", false); + if (getTreatmentType()== TreatmentType.FULLVISION){ + return false; + } + + else { + return true; + } + //return getBooleanProperty("tokens-field-of-vision", false); } public boolean isSubjectsFieldOfVisionEnabled() { - return getBooleanProperty("subjects-field-of-vision", false); + if (getTreatmentType()== TreatmentType.FULLVISION){ + return false; + } + else { + return true; + } + //return getBooleanProperty("subjects-field-of-vision", false); } public double getViewSubjectsRadius() { Added: foraging/trunk/src/main/java/edu/asu/commons/foraging/event/TreatmentTypeRequest.java =================================================================== --- foraging/trunk/src/main/java/edu/asu/commons/foraging/event/TreatmentTypeRequest.java (rev 0) +++ foraging/trunk/src/main/java/edu/asu/commons/foraging/event/TreatmentTypeRequest.java 2010-03-25 21:20:57 UTC (rev 493) @@ -0,0 +1,22 @@ +package edu.asu.commons.foraging.event; + +import edu.asu.commons.event.AbstractEvent; +import edu.asu.commons.foraging.model.TreatmentType; +import edu.asu.commons.net.Identifier; + +public class TreatmentTypeRequest extends AbstractEvent { + + private static final long serialVersionUID = 3543634624796618926L; + + private TreatmentType treatmentType; + + public TreatmentTypeRequest(Identifier id, TreatmentType treatmentType) { + super(id); + this.treatmentType = treatmentType; + } + + public TreatmentType getTreatmentType() { + return treatmentType; + } + +} Modified: foraging/trunk/src/main/java/edu/asu/commons/foraging/facilitator/ConfigurationDialog.java =================================================================== --- foraging/trunk/src/main/java/edu/asu/commons/foraging/facilitator/ConfigurationDialog.java 2010-03-23 23:08:38 UTC (rev 492) +++ foraging/trunk/src/main/java/edu/asu/commons/foraging/facilitator/ConfigurationDialog.java 2010-03-25 21:20:57 UTC (rev 493) @@ -9,13 +9,22 @@ import java.util.ArrayList; import java.util.List; +import javax.swing.BorderFactory; +import javax.swing.Box; +import javax.swing.BoxLayout; +import javax.swing.ButtonGroup; import javax.swing.JButton; import javax.swing.JFrame; +import javax.swing.JLabel; import javax.swing.JPanel; +import javax.swing.JRadioButton; +import javax.swing.JScrollPane; import javax.swing.JTabbedPane; +import javax.swing.JTextArea; import edu.asu.commons.foraging.conf.RoundConfiguration; import edu.asu.commons.foraging.conf.ServerConfiguration; +import edu.asu.commons.foraging.model.TreatmentType; @@ -27,6 +36,8 @@ private List<RoundConfigurationDialog> roundConfigurationDialogs = new ArrayList<RoundConfigurationDialog>(); private Facilitator facilitator; private boolean readOnly = false; + private TreatmentType currentTreatment; + private ButtonGroup group; /* * Constructor @@ -35,7 +46,7 @@ // this.parentFrame = parentFrame; this.facilitator = facilitator; this.readOnly = readOnly; - + group = new ButtonGroup(); tabbedPaneFrame = new JFrame("Configuration Parameters"); Container content = tabbedPaneFrame.getContentPane(); content.setLayout(new BorderLayout(7, 7)); @@ -69,11 +80,76 @@ RoundConfigurationDialog roundConfigDlg = new RoundConfigurationDialog(roundConfiguration, readOnly); roundConfigurationDialogs.add(roundConfigDlg); configurationTabPane.addTab("Round " + roundIndex, roundConfigDlg.getPanel()); - } - + } + JPanel panel = new JPanel(); + panel.setLayout(new BoxLayout(panel, BoxLayout.Y_AXIS)); + JLabel label = new JLabel("Select one of the treatments"); + panel.add(label); + panel.add(Box.createVerticalGlue()); + panel.add(createFullVisionPanel(),null); + panel.add(Box.createVerticalGlue()); + panel.add(createLimitedVisionPanel(),null); + panel.add(Box.createVerticalGlue()); + panel.add(getInstructionPanel(), null); + panel.add(Box.createVerticalGlue()); + configurationTabPane.addTab("Type of treatment", panel); return configurationTabPane; } + private JPanel createFullVisionPanel() { + JRadioButton fullVision; + fullVision = new JRadioButton("Complete field of vision"); + fullVision.setActionCommand("1"); + group.add(fullVision); + fullVision.addActionListener(new ActionListener() { + public void actionPerformed(ActionEvent event) { + updateTreatment(event.getActionCommand()); + System.out.println(" "+event.getActionCommand()); + } + }); + JPanel fullVisionPanel = new JPanel(new GridLayout(2, 2)); + fullVisionPanel.setBorder(BorderFactory.createEtchedBorder() ); + fullVisionPanel.add(new JLabel("Full"), null); + fullVisionPanel.add(new JLabel(""), null); + fullVisionPanel.add(new JLabel("Vision"), null); + fullVisionPanel.add(fullVision, null); + return fullVisionPanel; + } + + private JPanel createLimitedVisionPanel() { + JRadioButton limitedVision; + limitedVision = new JRadioButton("Limited field of vision"); + limitedVision.setActionCommand("0"); + group.add(limitedVision); + limitedVision.addActionListener(new ActionListener() { + public void actionPerformed(ActionEvent event) { + updateTreatment(event.getActionCommand()); + System.out.println(" "+event.getActionCommand()); + } + }); + JPanel limitedVisionPanel = new JPanel(new GridLayout(2, 2)); + limitedVisionPanel.setBorder(BorderFactory.createEtchedBorder() ); + limitedVisionPanel.add(new JLabel("Limited"), null); + limitedVisionPanel.add(new JLabel(""), null); + limitedVisionPanel.add(new JLabel("Vision"), null); + limitedVisionPanel.add(limitedVision, null); + return limitedVisionPanel; + } + + + private JScrollPane getInstructionPanel() { + ServerConfiguration configuration = facilitator.getServerConfiguration(); + + JPanel panel = new JPanel(); + BoxLayout boxLayout = new BoxLayout(panel, BoxLayout.Y_AXIS); + panel.setLayout(boxLayout); + + panel.add(new JLabel("Instructions"), null); + panel.add(new JTextArea(configuration.getGeneralInstructions()), null); + + return new JScrollPane(panel); + } + private JButton createStartExperimentButton() { JButton startExperimentButton = new JButton("Start Exp"); startExperimentButton.setEnabled(!readOnly); @@ -114,7 +190,7 @@ return cancelButton; } - private void updateConfiguration() { + private void updateConfiguration() {/* List<RoundConfiguration> rounds = new ArrayList<RoundConfiguration>(); ServerConfiguration configuration = facilitator.getServerConfiguration(); @@ -143,9 +219,30 @@ } ConfigurationDialog.this.facilitator.setRoundParameters(rounds); - ConfigurationDialog.this.facilitator.sendSetConfigRequest(); + ConfigurationDialog.this.facilitator.sendSetConfigRequest();*/ + ConfigurationDialog.this.facilitator.sendTreatmentTypeRequest(currentTreatment); + } + private void updateTreatment(String treatmentType) { + //List<RoundConfiguration> rounds = new ArrayList<RoundConfiguration>(); + //RoundConfiguration roundConfiguration = new RoundConfiguration(); + currentTreatment = TreatmentType.FULLVISION; + if(treatmentType.equals("0")) { + currentTreatment = TreatmentType.LIMITEDVISION; + } + else { + currentTreatment = TreatmentType.FULLVISION; + } + //roundConfiguration.setProperty("tokens-field-of-vision", Boolean.valueOf(flag).toString()); + //roundConfiguration.setProperty("subjects-field-of-vision", Boolean.valueOf(flag).toString()); + //rounds.add(roundConfiguration); + //ConfigurationDialog.this.facilitator.setRoundParameters(rounds); + //ConfigurationDialog.this.facilitator.sendSetConfigRequest(); + ConfigurationDialog.this.facilitator.sendTreatmentTypeRequest(currentTreatment); + + } + // private void centerOnParentFrame() { // Dimension parentFrameDimension = parentFrame.getSize(); // Dimension windowDimension = tabbedPaneFrame.getSize(); Modified: foraging/trunk/src/main/java/edu/asu/commons/foraging/facilitator/Facilitator.java =================================================================== --- foraging/trunk/src/main/java/edu/asu/commons/foraging/facilitator/Facilitator.java 2010-03-23 23:08:38 UTC (rev 492) +++ foraging/trunk/src/main/java/edu/asu/commons/foraging/facilitator/Facilitator.java 2010-03-25 21:20:57 UTC (rev 493) @@ -21,7 +21,9 @@ import edu.asu.commons.foraging.event.FacilitatorUpdateEvent; import edu.asu.commons.foraging.event.QuizCompletedEvent; import edu.asu.commons.foraging.event.ShowInstructionsRequest; +import edu.asu.commons.foraging.event.TreatmentTypeRequest; import edu.asu.commons.foraging.model.ServerDataModel; +import edu.asu.commons.foraging.model.TreatmentType; @@ -159,6 +161,10 @@ public void sendBeginChatRoundRequest() { transmit(new BeginChatRoundRequest(getId())); } + + public void sendTreatmentTypeRequest(TreatmentType treatmentType) { + transmit(new TreatmentTypeRequest(getId(), treatmentType)); + } public void endExperiment() { Modified: foraging/trunk/src/main/java/edu/asu/commons/foraging/facilitator/FacilitatorWindow.java =================================================================== --- foraging/trunk/src/main/java/edu/asu/commons/foraging/facilitator/FacilitatorWindow.java 2010-03-23 23:08:38 UTC (rev 492) +++ foraging/trunk/src/main/java/edu/asu/commons/foraging/facilitator/FacilitatorWindow.java 2010-03-25 21:20:57 UTC (rev 493) @@ -201,6 +201,13 @@ } }); menu.add(menuItem); + + /* JMenuItem treatment = new JMenuItem("Treatment"); + treatmnet.addActionListener(new ActionListener() { + public void actionPerformed(ActionEvent e) { + new + } + })*/ menuBar.add(menu); Added: foraging/trunk/src/main/java/edu/asu/commons/foraging/model/TreatmentType.java =================================================================== --- foraging/trunk/src/main/java/edu/asu/commons/foraging/model/TreatmentType.java (rev 0) +++ foraging/trunk/src/main/java/edu/asu/commons/foraging/model/TreatmentType.java 2010-03-25 21:20:57 UTC (rev 493) @@ -0,0 +1,29 @@ +package edu.asu.commons.foraging.model; + +public enum TreatmentType { + + LIMITEDVISION("Limited Vision"), + FULLVISION("Full Vision"); + + //We may want to add new types of treatments going ahead like + //with sanctioning and voting etc + + private final String treatmentText; + + TreatmentType(String treatmentText) { + this.treatmentText = treatmentText; + } + + public String getTreatmentText() { + return treatmentText; + } + + public static TreatmentType get(int index) { + if (index < values().length && index >= 0) { + return values()[index]; + } + System.err.println("Returning LIMITEDVISION."); + return LIMITEDVISION; +// throw new IllegalArgumentException("No enforcement mechanism for index: " + index); + } +} Modified: foraging/trunk/src/main/java/edu/asu/commons/foraging/server/ForagingServer.java =================================================================== --- foraging/trunk/src/main/java/edu/asu/commons/foraging/server/ForagingServer.java 2010-03-23 23:08:38 UTC (rev 492) +++ foraging/trunk/src/main/java/edu/asu/commons/foraging/server/ForagingServer.java 2010-03-25 21:20:57 UTC (rev 493) @@ -56,6 +56,7 @@ import edu.asu.commons.foraging.event.ShowInstructionsRequest; import edu.asu.commons.foraging.event.SubmitRegulationRequest; import edu.asu.commons.foraging.event.SynchronizeClientEvent; +import edu.asu.commons.foraging.event.TreatmentTypeRequest; import edu.asu.commons.foraging.event.UnlockResourceRequest; import edu.asu.commons.foraging.model.ClientData; import edu.asu.commons.foraging.model.Direction; @@ -65,6 +66,7 @@ import edu.asu.commons.foraging.model.ResourceDispenser; import edu.asu.commons.foraging.model.SanctionMechanism; import edu.asu.commons.foraging.model.ServerDataModel; +import edu.asu.commons.foraging.model.TreatmentType; import edu.asu.commons.foraging.util.ForagingSaveFileConverter; import edu.asu.commons.net.Dispatcher; import edu.asu.commons.net.Identifier; @@ -109,6 +111,7 @@ private volatile int numberOfCompletedAgentDesigns; private int monitorRotationInterval; + private TreatmentType treatmentType; private Duration currentRoundDuration; // private Duration chatDuration; @@ -653,6 +656,20 @@ } } }); + addEventProcessor(new EventTypeProcessor<TreatmentTypeRequest>(TreatmentTypeRequest.class) { + public void handle(TreatmentTypeRequest event) { + // FIXME: assign groups? + if (event.getId().equals(facilitatorId)) { + logger.info("New treatment selected :"+event.getTreatmentType().getTreatmentText()); + for (Identifier id: clients.keySet()) { + transmit(new TreatmentTypeRequest(id, event.getTreatmentType())); + } + } + else { + logger.warning("Ignoring new treatment request from id: " + event.getId()); + } + } + }); addEventProcessor(new EventTypeProcessor<BeginRoundRequest>(BeginRoundRequest.class) { public void handle(BeginRoundRequest event) { if (event.getId().equals(facilitatorId)) { This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |