Skip to content

Commit

Permalink
fix: use persisted event stream for data display
Browse files Browse the repository at this point in the history
serialized ClientData properties do not display the correct data, use
client movement token count maps to properly compute collected tokens
and movements

summary.txt is really a rehash of -player-resource-summary, see what we
can do eventually to dedupe these
  • Loading branch information
alee committed Aug 5, 2021
1 parent cd31172 commit c6dc96c
Showing 1 changed file with 18 additions and 6 deletions.
24 changes: 18 additions & 6 deletions src/main/java/edu/asu/commons/foraging/data/SummaryProcessor.java
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@
import edu.asu.commons.experiment.SaveFileProcessor;
import edu.asu.commons.experiment.SavedRoundData;
import edu.asu.commons.foraging.conf.RoundConfiguration;
import edu.asu.commons.foraging.event.MovementEvent;
import edu.asu.commons.foraging.event.StrategySelectedUpdateEvent;
import edu.asu.commons.foraging.event.StrategyVoteRequest;
import edu.asu.commons.foraging.event.SanctionAppliedEvent;
Expand All @@ -33,10 +34,11 @@ public void process(SavedRoundData savedRoundData, PrintWriter writer) {
ServerDataModel serverDataModel = (ServerDataModel) savedRoundData.getDataModel();
serverDataModel.reinitialize((RoundConfiguration) savedRoundData.getRoundParameters());
List<GroupDataModel> groups = serverDataModel.getOrderedGroups();
Map<Identifier, ClientMovementTokenCount> clientMovementTokenCounts = ClientMovementTokenCount.createMap(serverDataModel);
for (PersistableEvent event: savedRoundData.getActions()) {
// no need to apply() events to the ServerDataModel and replay them if we only want summary statistics
// from the ServerDataModel and GroupDataModel as they existed at the end of the round and
// serialized
// are serialized
if (event instanceof SanctionAppliedEvent) {
SanctionAppliedEvent sanctionEvent = (SanctionAppliedEvent) event;
Identifier id = sanctionEvent.getId();
Expand All @@ -48,25 +50,35 @@ public void process(SavedRoundData savedRoundData, PrintWriter writer) {
target.addSanctionPenalties(sanctionEvent.getSanctionPenalty());
System.err.println("penalties on client data are now " + target.getSanctionPenalties());
}
else if (event instanceof MovementEvent) {
ClientMovementTokenCount client = clientMovementTokenCounts.get(event.getId());
client.moves++;
}
else if (event instanceof TokenCollectedEvent) {
ClientMovementTokenCount client = clientMovementTokenCounts.get(event.getId());
client.tokens++;
}
}

writer.println("Group ID, Participant UUID, Assigned Number, Total Cumulative Tokens, Sanction costs, Sanction penalties");
writer.println("Group ID, Participant UUID, Assigned Number, Tokens Collected, Moves, Sanction costs, Sanction penalties");
for (GroupDataModel group: groups) {
int totalTokensHarvested = 0;
ArrayList<ClientData> clientDataList = new ArrayList<>(group.getClientDataMap().values());
clientDataList.sort(Comparator.comparingInt(ClientData::getAssignedNumber));
String groupId = group.toString();
for (ClientData data : clientDataList) {
writer.println(String.format("%s, %s, %s, %s, %s, %s",
ClientMovementTokenCount cmt = clientMovementTokenCounts.get(data.getId());
writer.println(String.format("%s, %s, %s, %s, %s, %s, %s",
groupId,
data.getId().getUUID(),
cmt.tokens,
cmt.moves,
data.getAssignedNumber(),
data.getTotalTokens(),
data.getSanctionCosts(),
data.getSanctionPenalties()));
totalTokensHarvested += data.getTotalTokens();
totalTokensHarvested += cmt.tokens;
}
writer.println(String.format("%s, %s, %s", groupId, group.getResourceDistributionSize(), totalTokensHarvested));
writer.println(String.format("%s, resources left: %s, total resources harvested: %s", groupId, group.getResourceDistributionSize(), totalTokensHarvested));
}
Map<GroupDataModel, SortedSet<ChatRequest>> chatRequestMap = new HashMap<>();
SortedSet<ChatRequest> allChatRequests = savedRoundData.getChatRequests();
Expand Down

0 comments on commit c6dc96c

Please sign in to comment.