[virtualcommons-svn] commit/foraging: alllee: foraging rule processor is now working, but needs to
Status: Beta
Brought to you by:
alllee
From: Bitbucket <com...@bi...> - 2012-09-18 00:47:43
|
1 new commit in foraging: https://bitbucket.org/virtualcommons/foraging/changeset/ba39f4118da8/ changeset: ba39f4118da8 branch: asu-foraging-2012 user: alllee date: 2012-09-18 02:47:35 summary: foraging rule processor is now working, but needs to be verified against the actual data and is also generating NaNs in certain cases affected #: 2 files diff -r a91c53f62f5d207e76060b15b78c31f2a4fbdd5e -r ba39f4118da8d9cfbdf2f217e290e48a2137429b src/main/java/edu/asu/commons/foraging/data/ForagingRuleProcessor.java --- a/src/main/java/edu/asu/commons/foraging/data/ForagingRuleProcessor.java +++ b/src/main/java/edu/asu/commons/foraging/data/ForagingRuleProcessor.java @@ -9,7 +9,6 @@ import edu.asu.commons.event.PersistableEvent; import edu.asu.commons.experiment.SaveFileProcessor.Base; import edu.asu.commons.experiment.SavedRoundData; -import edu.asu.commons.foraging.conf.RoundConfiguration; import edu.asu.commons.foraging.event.TokenCollectedEvent; import edu.asu.commons.foraging.model.ClientData; import edu.asu.commons.foraging.model.ServerDataModel; @@ -23,21 +22,23 @@ // rule 3: wait 60 seconds // rule 4: collect 40 tokens then wait 30 seconds private static class RuleData { - private int illegalRuleOneTokens; - private int illegalRuleFourTokens; - private int totalTokensCollected; - private int q1Tokens; - private int q2Tokens; - private int q3Tokens; - private int q4Tokens; - private int ruleFourTimestamp = -1; + private int illegalRuleOneTokens = 0; + private int illegalRuleThreeTokens = 0; + private int illegalRuleFourTokens = 0; + private int totalTokensCollected = 0; + private int q1Tokens = 0; + private int q2Tokens = 0; + private int q3Tokens = 0; + private int q4Tokens = 0; + private int nextLegalCollectionTime = -1; + private int ruleFourTokenInterval = 1; public void addTokenCollected(Point location, int elapsedTimeInSeconds) { if (isIllegalTokenCollectionForRuleOne(elapsedTimeInSeconds)) { illegalRuleOneTokens++; } if (isIllegalTokenCollectionForRuleThree(elapsedTimeInSeconds)) { - + illegalRuleThreeTokens++; } totalTokensCollected++; addRuleTwoTokens(location); @@ -45,20 +46,30 @@ } private void checkRuleFourTokens(int elapsedTimeInSeconds) { + if (isIllegalRuleFourInterval(elapsedTimeInSeconds)) { + illegalRuleFourTokens++; + } + } + + private boolean isIllegalRuleFourInterval(int elapsedTimeInSeconds) { if (totalTokensCollected < 40) { - return; + return false; } - if (totalTokensCollected < 80 && ruleFourTimestamp == -1) { - // 40 tokens have been collected, from now on each token collected is illegal until 30 seconds from ruleFourTimestamp have passed. - ruleFourTimestamp = elapsedTimeInSeconds; - return; + int allowedTokens = ruleFourTokenInterval * 40; + // first check if we've reached our token goal + if (totalTokensCollected == allowedTokens) { + // next allowable time is 30 seconds from now. + nextLegalCollectionTime = elapsedTimeInSeconds + 30; + // the next number of allowable tokens is N * 40 + ruleFourTokenInterval++; } - if (elapsedTimeInSeconds < ruleFourTimestamp + 30) { - illegalRuleFourTokens++; - return; - } - // FIXME: need to finish implementing rule four logic - +// System.err.println(String.format("allowed tokens: %d, total tokens collected: %d, next legal collection time: %d, token interval %d, legal collection? %s", +// allowedTokens, +// totalTokensCollected, +// nextLegalCollectionTime, +// ruleFourTokenInterval, +// (elapsedTimeInSeconds < nextLegalCollectionTime))); + return elapsedTimeInSeconds < nextLegalCollectionTime; } private void addRuleTwoTokens(Point location) { @@ -84,12 +95,6 @@ return elapsedTimeInSeconds <= 60; } - @Override - public String toString() { - return String.format("illegal R1 tokens: %d, illegal R2 tokens: %d, total tokens: %d, [%d, %d, %d, %d]", - illegalRuleOneTokens, illegalRuleFourTokens, totalTokensCollected, q1Tokens, q2Tokens, q3Tokens, q4Tokens); - } - /** * Returns true if the elapsed time is in the following interval ranges: * 0-10, 20-30, 40-50, 60-70, and so on. @@ -102,6 +107,23 @@ int intervalModTwo = interval % 2; return intervalModTwo == 0; } + + public double getRuleOneBreaking() { + return (double) illegalRuleOneTokens / (double) totalTokensCollected; + } + public double getRuleThreeBreaking() { + return (double) illegalRuleThreeTokens / (double) totalTokensCollected; + } + public double getRuleFourBreaking() { + return (double) illegalRuleFourTokens / (double) totalTokensCollected; + } + + @Override + public String toString() { + return String.format("illegal R1 tokens: %d, illegal R2 tokens: %d, total tokens: %d, [%d, %d, %d, %d]", + illegalRuleOneTokens, illegalRuleFourTokens, totalTokensCollected, q1Tokens, q2Tokens, q3Tokens, q4Tokens); + } + } @Override @@ -127,6 +149,22 @@ dataMap.get(clientData).addTokenCollected(location, (int) elapsedTimeInSeconds); } } + writer.println("Participant, 10 Second Rule, 60 Second Rule, 40 Second Rule, Q1 Tokens, Q2 Tokens, Q3 Tokens, Q4 Tokens"); + for (Map.Entry<ClientData, RuleData> entry: dataMap.entrySet()) { + RuleData data = entry.getValue(); + String line = String.format("%s, %3.2f, %3.2f, %3.2f, %d, %d, %d, %d", + entry.getKey(), + data.getRuleOneBreaking(), + data.getRuleThreeBreaking(), + data.getRuleFourBreaking(), + data.q1Tokens, + data.q2Tokens, + data.q3Tokens, + data.q4Tokens + ); + System.err.println(line); + writer.println(line); + } } } diff -r a91c53f62f5d207e76060b15b78c31f2a4fbdd5e -r ba39f4118da8d9cfbdf2f217e290e48a2137429b src/main/java/edu/asu/commons/foraging/data/ForagingSaveFileConverter.java --- a/src/main/java/edu/asu/commons/foraging/data/ForagingSaveFileConverter.java +++ b/src/main/java/edu/asu/commons/foraging/data/ForagingSaveFileConverter.java @@ -32,6 +32,7 @@ new CollectedTokenSpatialDistributionProcessor(), new MovementStatisticsProcessor(), // new MovieCreatorProcessor(), + new ForagingRuleProcessor(), new AggregateCollectedTokenNeighborProcessor() )); Persister.processSaveFiles(allSaveFilesDirectory, processors); 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. |