data.add("Groups final score (food reserve)");
data.add("------------------------------------------------");
data.add(
"Group Name | Current reserve \t| Amount given \t| Amount borrowed \t| Average Happiness \t| Greediness");
SortedSet<String> active_agent_ids = sim.getactiveParticipantIdSet("group");
PublicEnvironmentConnection ec = PublicEnvironmentConnection.getInstance();
//get rid of special group
String SpecialID = "";
for(String group : active_agent_ids)
if(ec.getGroupById(group).getName().equals("Group #2"))
SpecialID = group;
active_agent_ids.remove(SpecialID);
Iterator<String> iter = active_agent_ids.iterator();
while (iter.hasNext())
{
String groupID = iter.next();
PublicGroupDataModel dm = ec.getGroupById(groupID);
Map<String, List<Tuple<Double, Double>>> loansGiven = LoansGroup.getLoansGiven(
dm);
double totalAmountGiven = 0;
if (loansGiven != null)
{
for (String debtors : loansGiven.keySet())
{
//if (ec.getGroupById(debtors) == null) break;
double amountBorrowed = 0;
for (Tuple<Double, Double> t : loansGiven.get(debtors))
{
amountBorrowed += t.getKey() * (1 + t.getValue());
}
totalAmountGiven += amountBorrowed;
}
}
Map<String, List<Tuple<Double, Double>>> loansTaken = LoansGroup.getLoansTaken(
dm);
double totalAmountTaken = 0;
if (loansTaken != null)
{
for (String creditors : loansTaken.keySet())
{
//if (ec.getGroupById(creditors) == null) break;
double amountBorrowed = 0;
for (Tuple<Double, Double> t : loansTaken.get(creditors))
{
amountBorrowed += t.getKey() * (1 + t.getValue());
}
totalAmountTaken += amountBorrowed;
}
}
double averageHappiness = 0;
for (String member : dm.getMemberList())
{
averageHappiness += ec.getAgentById(member).getCurrentHappiness();
}
averageHappiness = averageHappiness / dm.getMemberList().size();
String spaces = " ";
data.add(dm.getName()
+ spaces + Math.round(dm.getCurrentReservedFood())