[virtualcommons-svn] SF.net SVN: virtualcommons:[47] foraging/trunk/src/main/java/edu/asu/ commons
Status: Beta
Brought to you by:
alllee
From: <al...@us...> - 2008-08-22 22:22:45
|
Revision: 47 http://virtualcommons.svn.sourceforge.net/virtualcommons/?rev=47&view=rev Author: alllee Date: 2008-08-22 22:22:55 +0000 (Fri, 22 Aug 2008) Log Message: ----------- updated save file converter Modified Paths: -------------- foraging/trunk/src/main/java/edu/asu/commons/foraging/util/ForagingSaveFileConverter.java Modified: foraging/trunk/src/main/java/edu/asu/commons/foraging/util/ForagingSaveFileConverter.java =================================================================== --- foraging/trunk/src/main/java/edu/asu/commons/foraging/util/ForagingSaveFileConverter.java 2008-08-21 16:56:18 UTC (rev 46) +++ foraging/trunk/src/main/java/edu/asu/commons/foraging/util/ForagingSaveFileConverter.java 2008-08-22 22:22:55 UTC (rev 47) @@ -43,9 +43,9 @@ if (allSaveFilesDirectory.exists() && allSaveFilesDirectory.isDirectory()) { List<SaveFileProcessor> processors = new ArrayList<SaveFileProcessor>(); processors.addAll(Arrays.asList( - new ForagingSaveFileProcessor(), - new SummaryStatisticsProcessor(), - new ForagingSummarySaveFileProcessor())); + new AllDataProcessor(), + new AggregateTimeIntervalProcessor(), + new SummaryProcessor())); Persister.processSaveFiles(allSaveFilesDirectory, processors); return true; } @@ -60,7 +60,7 @@ convert(args[0]); } - private static class ForagingSummarySaveFileProcessor extends SaveFileProcessor.Base { + private static class SummaryProcessor extends SaveFileProcessor.Base { @Override public void process(SavedRoundData savedRoundData, PrintWriter writer) { ServerDataModel serverDataModel = (ServerDataModel) savedRoundData.getDataModel(); @@ -76,13 +76,19 @@ } */ List<GroupDataModel> groups = new ArrayList<GroupDataModel>(serverDataModel.getGroups()); - writer.println("Group #, Members, ..., Resources Left, Final Resource Positions"); for (GroupDataModel group: groups) { + int totalConsumedGroupTokens = 0; + ArrayList<String> clientTokens = new ArrayList<String>(); + for (ClientData data : group.getClientDataMap().values()) { + clientTokens.add(String.format("%s, %s", data.getId(), data.getTotalTokens())); + totalConsumedGroupTokens += data.getTotalTokens(); + } writer.println( String.format("%s, %s, %s, %s", "Group #" + groups.indexOf(group), - Utils.join(',', new TreeSet<Identifier>(group.getClientIdentifiers())), + Utils.join(',', clientTokens), group.getResourceDistributionSize(), + totalConsumedGroupTokens, Utils.join(',', group.getResourceDistribution().keySet()) )); } @@ -94,11 +100,11 @@ } } - private static class ForagingSaveFileProcessor extends SaveFileProcessor.Base { + private static class AllDataProcessor extends SaveFileProcessor.Base { @Override public String getOutputFileExtension() { - return "-foraging_all-data.txt"; + return "-all-data.txt"; } @Override @@ -113,8 +119,7 @@ } private void processData2d(SavedRoundData savedRoundData, PrintWriter writer) { - RoundConfiguration roundConfiguration = (RoundConfiguration) savedRoundData.getRoundParameters(); - System.err.println("is chat enabled? " + roundConfiguration.isChatEnabled() + roundConfiguration.getRoundNumber()); +// RoundConfiguration roundConfiguration = (RoundConfiguration) savedRoundData.getRoundParameters(); SortedSet<PersistableEvent> actions = savedRoundData.getActions(); ServerDataModel model = (ServerDataModel) savedRoundData.getDataModel(); Map<Identifier, ClientStats> clientStats = createClientStats(model); @@ -238,7 +243,7 @@ } - public static class SummaryStatisticsProcessor extends SaveFileProcessor.Base { + public static class AggregateTimeIntervalProcessor extends SaveFileProcessor.Base { private static int secondsPerInterval = 5; public void process(SavedRoundData savedRoundData, PrintWriter writer) { // populate the ordered identifiers, try directly from the participant tokens map that @@ -251,7 +256,22 @@ RoundConfiguration roundConfiguration = (RoundConfiguration) savedRoundData.getRoundParameters(); TreeSet<Identifier> orderedIdentifiers = new TreeSet<Identifier>(serverDataModel.getClientDataMap().keySet()); List<GroupDataModel> groups = new ArrayList<GroupDataModel>(serverDataModel.getGroups()); + +// XXX: not really any better than the below, and actually more inefficient to boot. Damn. +// List<String> foo = Utils.map(orderedIdentifiers, new Utils.MapOp<Identifier, String>() { +// public String apply(Identifier id) { +// return id + " movement"; +// } +// }); + + List<String> movementHeader = new ArrayList<String>(); + List<String> collectedTokensHeader = new ArrayList<String>(); + for (Identifier id: orderedIdentifiers) { + movementHeader.add(id + " moves"); + collectedTokensHeader.add(id + " tokens collected"); + } + // headers for average probability of a token for each group // List<String> tokenProbabilityGroupNumberHeader = new ArrayList<String>(); // headers for tokens left in each group @@ -275,9 +295,9 @@ // write out the header String header = Utils.join(',', "Period", // moves taken - Utils.join(',', orderedIdentifiers), + Utils.join(',', movementHeader), // tokens - Utils.join(',', orderedIdentifiers), + Utils.join(',', collectedTokensHeader), // group token probabilities // Utils.join(',', tokenProbabilityGroupNumberHeader), // group total tokens left @@ -430,5 +450,4 @@ return clientStats; } - -} +} \ No newline at end of file This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |