[virtualcommons-svn] commit/foraging: alllee: updating focus after chat and adding private property
Status: Beta
Brought to you by:
alllee
From: Bitbucket <com...@bi...> - 2011-09-01 21:53:27
|
1 new changeset in foraging: http://bitbucket.org/virtualcommons/foraging/changeset/fa6d63ba8ae8/ changeset: fa6d63ba8ae8 user: alllee date: 2011-09-01 23:53:56 summary: updating focus after chat and adding private property chat affected #: 4 files (208 bytes) --- a/src/main/java/edu/asu/commons/foraging/client/ChatPanel.java Thu Sep 01 14:37:13 2011 -0700 +++ b/src/main/java/edu/asu/commons/foraging/client/ChatPanel.java Thu Sep 01 14:53:56 2011 -0700 @@ -113,7 +113,7 @@ } client.transmit(new ChatRequest(clientId, message, targetIdentifier)); if (inRoundChat) { - getParent().requestFocusInWindow(); + client.getGameWindow().getPanel().requestFocusInWindow(); } else { chatField.requestFocusInWindow(); --- a/src/main/java/edu/asu/commons/foraging/client/GameWindow2D.java Thu Sep 01 14:37:13 2011 -0700 +++ b/src/main/java/edu/asu/commons/foraging/client/GameWindow2D.java Thu Sep 01 14:53:56 2011 -0700 @@ -202,6 +202,7 @@ setQuestionColors(incorrectAnswers, "red"); if (incorrectAnswers.isEmpty()) { builder.append(configuration.getInstructions()); + configuration.addAllSpecialInstructions(builder); // notify the server and also notify the participant. builder.append("<br><b>Congratulations!</b> You have answered all questions correctly."); setInstructions(builder.toString()); --- a/src/main/java/edu/asu/commons/foraging/conf/RoundConfiguration.java Thu Sep 01 14:37:13 2011 -0700 +++ b/src/main/java/edu/asu/commons/foraging/conf/RoundConfiguration.java Thu Sep 01 14:53:56 2011 -0700 @@ -14,16 +14,16 @@ /** * $Id: RoundConfiguration.java 534 2011-05-08 02:02:39Z alllee $ * - * At some point this should be persistent database objects in a key-value store..? + * At some point this should be persistent database objects in a key-value store..? * * Something like: * - * Parameter name, value, type, instructions + * Parameter name, value, type, instructions * * need to deal with i18n at some point as well.. * * - * + * * @author <a href='mailto:All...@as...'>Allen Lee</a> * @version $Rev: 534 $ */ @@ -36,38 +36,39 @@ public final static int DEFAULT_ROUND_TIME = 5 * 60; private static final int DEFAULT_SANCTION_FLASH_DURATION = 3; - + private static final double DEFAULT_DOLLARS_PER_TOKEN = .02d; private static final double DEFAULT_TOKEN_MOVEMENT_PROBABILITY = 0.2d; - + private static final double DEFAULT_TOKEN_BIRTH_PROBABILITY = 0.01d; public double getTrustGamePayoffIncrement() { return getDoubleProperty("trust-game-payoff", 0.25d); } - + public enum SanctionType { REAL_TIME, POST_ROUND, NONE; public static SanctionType find(String name) { try { return valueOf(name.toUpperCase().replaceAll("-", "_")); - } - catch (Exception exception) { + } catch (Exception exception) { return NONE; } } } - + private final static Map<String, ExperimentType> experimentTypeMap = new HashMap<String, ExperimentType>(3); public enum ExperimentType { TWO_DIMENSIONAL("2d"), ABSTRACT("abstract"), FORESTRY("forestry"); private final String name; + private ExperimentType(String name) { this.name = name; experimentTypeMap.put(name, this); } + public static ExperimentType find(String name) { ExperimentType experimentType = experimentTypeMap.get(name); if (experimentType == null) { @@ -75,17 +76,18 @@ } return experimentType; } + public String toString() { return name; } } - + public enum SanctionAction { FINE() { public void applySanctionCost(ClientData clientData) { // perform sanction cost logic here for fines } - + public void applySanctionPenalty(ClientData clientData) { // perform sanction penalty logic here for fines } @@ -94,37 +96,39 @@ public void applySanctionCost(ClientData clientData) { // perform sanction cost logic here for freezing } - + public void applySanctionPenalty(ClientData clientData) { // perform sanction penalty logic here for freezing } }; - + // FIXME: do these need to be here to be able to invoke these methods on SanctionAction? - public void applySanctionCost(ClientData clientData) { } - - public void applySanctionPenalty(ClientData clientData) { } - + public void applySanctionCost(ClientData clientData) { + } + + public void applySanctionPenalty(ClientData clientData) { + } + public boolean isFine() { return this == FINE; } - + public boolean isFreeze() { return this == FREEZE; } } - + public RoundConfiguration() { super(); } - + public RoundConfiguration(String resource) { super(resource); } public boolean shouldRandomizeGroup() { - return ( isPracticeRound() && isPrivateProperty() ) - || getBooleanProperty("randomize-group", false); + return (isPracticeRound() && isPrivateProperty()) + || getBooleanProperty("randomize-group", false); } /** @@ -136,30 +140,30 @@ public int getSanctionFlashDuration() { return getIntProperty("sanction-flash-duration", DEFAULT_SANCTION_FLASH_DURATION); } - + public double getTokenBirthProbability() { return getDoubleProperty("token-birth-probability", DEFAULT_TOKEN_BIRTH_PROBABILITY); } - + public double getTokenMovementProbability() { return getDoubleProperty("token-movement-probability", DEFAULT_TOKEN_MOVEMENT_PROBABILITY); } - + public boolean isTokensFieldOfVisionEnabled() { return getBooleanProperty("tokens-field-of-vision", false); } - + public boolean isSubjectsFieldOfVisionEnabled() { return getBooleanProperty("subjects-field-of-vision", false); } - + public int getViewSubjectsRadius() { if (isSubjectsFieldOfVisionEnabled()) { return getIntProperty("view-subjects-radius", 6); } throw new UnsupportedOperationException("subject field of vision is not enabled."); } - + public double getViewTokensRadius() { if (isTokensFieldOfVisionEnabled()) { return getDoubleProperty("view-tokens-radius", 6.0d); @@ -168,16 +172,17 @@ } /** - * Returns a double between [0, 1] used as a scaling factor modifying the probability - * that a token grows in a neighboring cell. + * Returns a double between [0, 1] used as a scaling factor modifying the probability + * that a token grows in a neighboring cell. + * * @return */ public double getRegrowthRate() { return getDoubleProperty("regrowth-rate", DEFAULT_REGROWTH_RATE); } - + public int getInitialNumberOfTokens() { - return getIntProperty("starting-tokens", + return getIntProperty("starting-tokens", (int) (getInitialDistribution() * getResourceWidth() * getResourceDepth())); } @@ -211,37 +216,39 @@ } return getIntProperty("clients-per-group", Integer.MAX_VALUE); } - + /** - * Returns an int specifying how many tokens the sanctioner must pay to + * Returns an int specifying how many tokens the sanctioner must pay to * penalize another player. + * * @return */ public int getSanctionCost() { return getIntProperty("sanction-cost", 1); } - + /** - * Returns an int specifying how much we should scale the tokens used to sanction another + * Returns an int specifying how much we should scale the tokens used to sanction another * player (for a bonus or penalty). + * * @return */ public int getSanctionMultiplier() { return getIntProperty("sanction-multiplier", 2); } - + public int getSanctionPenalty() { return getSanctionCost() * getSanctionMultiplier(); } - + public SanctionType getSanctionType() { return SanctionType.find(getProperty("sanction-type", "none")); } - + public boolean isPostRoundSanctioningEnabled() { return getSanctionType().equals(SanctionType.POST_ROUND); } - + public boolean isRealTimeSanctioningEnabled() { return getSanctionType().equals(SanctionType.REAL_TIME); } @@ -249,19 +256,19 @@ public boolean isSanctioningEnabled() { return isRealTimeSanctioningEnabled() || isPostRoundSanctioningEnabled(); } - + public boolean shouldCheckOccupancy() { return getMaximumOccupancyPerCell() < getClientsPerGroup(); } - + public int getMaximumOccupancyPerCell() { return getIntProperty("max-cell-occupancy", getClientsPerGroup()); } - + public boolean isChatAnonymized() { return getBooleanProperty("anonymous-chat", false); } - + public double getDollarsPerToken() { return getDoubleProperty("dollars-per-token", DEFAULT_DOLLARS_PER_TOKEN); } @@ -272,40 +279,42 @@ public String getInstructions() { return getProperty("instructions", "<b>No instructions available for this round.</b>"); } - + public boolean shouldDisplayGroupTokens() { return getBooleanProperty("display-group-tokens"); } - + public boolean isQuizEnabled() { return getBooleanProperty("quiz"); } - public String getChatInstructions() { return getProperty("chat-instructions"); } - + public String getRegulationInstructions() { - return getProperty("regulation-instructions"); + return getProperty("regulation-instructions"); } - + public String getVotingInstructions() { - return getProperty("voting-instructions", "You may rank the options below from 1 to 5, where 1 is the most favorable and 5 is the least favorable. When you rank a given option it will be sorted automatically."); + return getProperty( + "voting-instructions", + "You may rank the options below from 1 to 5, where 1 is the most favorable and 5 is the least favorable. When you rank a given option it will be sorted automatically."); } - + public String getLastRoundDebriefing() { return getProperty("last-round-debriefing"); } - + /** * FIXME: quiz instructions and quiz enabled should be tightly coupled.. + * * @return */ public String getQuizInstructions() { return getProperty("quiz-instructions"); } - + public Map<String, String> getQuizAnswers() { Properties properties = getProperties(); if (isQuizEnabled()) { @@ -319,83 +328,84 @@ } return Collections.emptyMap(); } - + public String getQuizExplanation(String questionNumber) { return getProperty(questionNumber + "-explanation"); } - + public double getQuizCorrectAnswerReward() { return getDoubleProperty("quiz-correct-answer-reward", 0.50d); } /** * Possible values, freeze, fine? + * * @return */ public SanctionAction getSanctionAction() { return SanctionAction.valueOf(getProperty("sanction-action", "FINE")); } - + public int getNumberOfSanctionOpportunities() { return getIntProperty("sanction-opportunities", 30); } - + public int getChatDuration() { return getIntProperty("chat-duration", 240); } - + public int getSanctionVotingDuration() { return getIntProperty("sanction-voting-duration", 30); } - + public int getRegulationSubmissionDuration() { return getIntProperty("regulation-submission-duration", 60); } - + public int getRegulationDisplayDuration() { return getIntProperty("regulation-display-duration", 30); } - + public int getRegulationVotingDuration() { return getIntProperty("regulation-voting-duration", 60); } - + public int getEnforcementVotingDuration() { return getIntProperty("enforcement-voting-duration", 60); } - + public int getEnforcementDisplayDuration() { return getIntProperty("enforcement-display-duration", 30); } - + public String getSanctionInstructions() { - return getProperty("sanction-instructions","<h2>Voting instructions</h2>" + - "<ul> " + - "<li> You must make a choice within the next 30 seconds. " + - "<li>The votes of all participants in your group will determine the outcome." + - "</ul>"); + return getProperty("sanction-instructions", "<h2>Voting instructions</h2>" + + "<ul> " + + "<li> You must make a choice within the next 30 seconds. " + + "<li>The votes of all participants in your group will determine the outcome." + + "</ul>"); } - + public boolean isAlwaysInExplicitCollectionMode() { return getBooleanProperty("always-explicit", true); } - + public boolean isExplicitCollectionEnabled() { return getBooleanProperty("explicit-collection", true); } public double getTopRegrowthScalingFactor() { - return getDoubleProperty("top-rate", 0.02); + return getDoubleProperty("top-rate", 0.02); } - + public double getBottomRegrowthScalingFactor() { return getDoubleProperty("bottom-rate", 0.01); } - + public double getTopInitialResourceDistribution() { return getDoubleProperty("top-initial-distribution", 0.50); } - + public double getBottomInitialResourceDistribution() { return getDoubleProperty("bottom-initial-distribution", 0.25); } @@ -403,11 +413,11 @@ public String getResourceGeneratorType() { return getProperty("resource-generator", "density-dependent"); } - + public int getWorldWidth() { return getResourceWidth() * getResourceWorldScale(); } - + public int getWorldDepth() { return getResourceDepth() * getResourceWorldScale(); } @@ -415,54 +425,54 @@ public int getResourceWorldScale() { return getIntProperty("resource-scale", 32); } - - //Should always return true for 3d experiments + + // Should always return true for 3d experiments public boolean isChatEnabled() { - return ! isPrivateProperty() && (getBooleanProperty("chat-enabled") || isInRoundChatEnabled()); + return getBooleanProperty("chat-enabled") || isInRoundChatEnabled(); } - + public int getMaximumResourceAge() { return getIntProperty("maximum-resource-age", 10); } - + public int getChattingRadius() { return getIntProperty("chat-radius", 50); } - + public int getResourceAgingSecondsPerYear() { return getIntProperty("seconds-per-year", 10); } - + public Point3D getTopLeftCornerCoordinate() { float zExtend = getWorldWidth() / 2.0f; float xExtend = getWorldDepth() / 2.0f; return new Point3D(-xExtend, 0, -zExtend); } - + public int ageToTokens(int resourceAge) { switch (resourceAge) { - case 0: - return 0; - case 1: - return 1; - case 2: - return 2; - case 3: - return 6; - case 4: - return 9; - case 5: - return 15; - case 6: - return 20; - case 7: - return 23; - case 8: - default: - return 25; + case 0: + return 0; + case 1: + return 1; + case 2: + return 2; + case 3: + return 6; + case 4: + return 9; + case 5: + return 15; + case 6: + return 20; + case 7: + return 23; + case 8: + default: + return 25; } } - + public int getTokensPerFruits() { return getIntProperty("tokens-per-fruits", 4); } @@ -470,9 +480,9 @@ public int getFruitHarvestDelay() { return getIntProperty("fruit-harvest-delay", 20); } - + public ExperimentType getExperimentType() { - return ExperimentType.find( getStringProperty("experiment-type", "2d") ); + return ExperimentType.find(getStringProperty("experiment-type", "2d")); } public boolean is2dExperiment() { @@ -480,66 +490,66 @@ } public boolean is3dExperiment() { - return ! is2dExperiment(); + return !is2dExperiment(); } - + public String getWelcomeInstructions() { return getParentConfiguration().getWelcomeInstructions(); } - + public String getGeneralInstructions() { return getParentConfiguration().getGeneralInstructions(); } - + public String getFieldOfVisionInstructions() { return getParentConfiguration().getFieldOfVisionInstructions(); } - + public EnforcementMechanism[] getEnforcementMechanisms() { return EnforcementMechanism.values(); } - + public boolean isRotatingMonitorEnabled() { - return getBooleanProperty("rotating-monitor-enabled", false); + return getBooleanProperty("rotating-monitor-enabled", false); } - + public boolean isVotingAndRegulationEnabled() { return getBooleanProperty("voting-and-regulation-enabled", false); } - + public boolean isFieldOfVisionEnabled() { return isTokensFieldOfVisionEnabled() || isSubjectsFieldOfVisionEnabled(); } - + public boolean isCensoredChat() { return getBooleanProperty("censored-chat-enabled", false); } - + public boolean isTrustGameEnabled() { return getBooleanProperty("trust-game", true); } - + public boolean isInRoundChatEnabled() { return getBooleanProperty("in-round-chat-enabled", false); } - + public String getCensoredChatInstructions() { - return getProperty("censored-chat-instructions", + return getProperty("censored-chat-instructions", "Your messages must be approved before they will be relayed to the rest of your group."); } - + public int getNumberOfChatsPerSecond() { return getIntProperty("chats-per-second", 5); } - + public int getDelayBetweenChats() { return getIntProperty("delay-between-chats", 0); } - + public StringBuilder getCurrentRoundInstructions() { return buildInstructions(new StringBuilder()); } - + /** * The preferred method of building instructions within the foraging experiment. * @@ -547,7 +557,7 @@ * to this {@link #RoundConfiguration()}. * * For example, if the field of vision is enabled, will append the field of vision instructions, - * if censored chat is enabled, then it will aadd the censored chat instructions, if the + * if censored chat is enabled, then it will aadd the censored chat instructions, if the * chat is enabled, will append the chat instructions. * * @param instructionsBuilder @@ -558,44 +568,48 @@ instructionsBuilder.append(getGeneralInstructions()); } instructionsBuilder.append(getInstructions()); - if (isFieldOfVisionEnabled()) { - addSpecialInstructions(instructionsBuilder,getFieldOfVisionInstructions()); - } - if (isCensoredChat()) { - addSpecialInstructions(instructionsBuilder,getCensoredChatInstructions()); - } - else if (isInRoundChatEnabled()) { - addSpecialInstructions(instructionsBuilder,getInRoundChatInstructions()); - } - else if (isChatEnabled()) { - // FIXME: hard-coded, need to make instructions template-able, perhaps - // via FreeMarker or Velocity. - addSpecialInstructions(instructionsBuilder, - "Before the beginning of this round you will be able to chat with the other members of your group for " + getChatDuration() + " seconds."); - } - String resourceGeneratorType = getResourceGeneratorType(); - if (resourceGeneratorType.equals("mobile")) { - addSpecialInstructions(instructionsBuilder,getMobileResourceInstructions()); - } - else if (resourceGeneratorType.equals("top-bottom-patchy")) { - addSpecialInstructions(instructionsBuilder,getPatchyResourceInstructions()); - } - + addAllSpecialInstructions(instructionsBuilder); // and add the quiz instructions if the quiz is enabled. if (isQuizEnabled()) { instructionsBuilder.append(getQuizInstructions()); } return instructionsBuilder; } - + + public StringBuilder addAllSpecialInstructions(StringBuilder builder) { + if (isFieldOfVisionEnabled()) { + addSpecialInstructions(builder, getFieldOfVisionInstructions()); + } + if (isCensoredChat()) { + addSpecialInstructions(builder, getCensoredChatInstructions()); + } + else if (isInRoundChatEnabled()) { + addSpecialInstructions(builder, getInRoundChatInstructions()); + } + else if (isChatEnabled()) { + // FIXME: hard-coded, need to make instructions template-able, perhaps + // via FreeMarker or Velocity. + addSpecialInstructions(builder, + "Before the beginning of this round you will be able to chat with the other members of your group for " + getChatDuration() + " seconds."); + } + String resourceGeneratorType = getResourceGeneratorType(); + if (resourceGeneratorType.equals("mobile")) { + addSpecialInstructions(builder, getMobileResourceInstructions()); + } + else if (resourceGeneratorType.equals("top-bottom-patchy")) { + addSpecialInstructions(builder, getPatchyResourceInstructions()); + } + return builder; + } + private void addSpecialInstructions(StringBuilder builder, String instructions) { builder.append("<p>").append(instructions).append("</p>"); } - + private String getMobileResourceInstructions() { return getProperty("mobile-resource-instructions", "<p>The resource can move around in a semblance of free will / agency.</p>"); } - + private String getPatchyResourceInstructions() { return getProperty("patch-resource-instructiosn", "<p>The resource is not uniformly distributed. There are patches of high growth and low growth.</p>"); } --- a/src/main/java/edu/asu/commons/foraging/server/ForagingServer.java Thu Sep 01 14:37:13 2011 -0700 +++ b/src/main/java/edu/asu/commons/foraging/server/ForagingServer.java Thu Sep 01 14:53:56 2011 -0700 @@ -298,7 +298,7 @@ addEventProcessor(new EventTypeProcessor<QuizResponseEvent>(QuizResponseEvent.class) { public void handle(final QuizResponseEvent event) { - logger.debug("Received quiz response: " + event); + logger.info("Received quiz response: " + event); numberOfSubmittedQuizzes++; transmit(new QuizCompletedEvent(facilitatorId)); ClientData clientData = clients.get(event.getId()); @@ -685,6 +685,7 @@ if (iter.hasNext()) { playerTwo = iter.next(); } + logger.info(String.format("Pairing %s with %s for trust game", playerOne, playerTwo)); serverDataModel.calculateTrustGame(playerOne, playerTwo); } Repository URL: https://bitbucket.org/virtualcommons/foraging/ -- This is a commit notification from bitbucket.org. You are receiving this because you have the service enabled, addressing the recipient of this email. |