[virtualcommons-svn] SF.net SVN: virtualcommons:[335] irrigation/trunk/src/main/java/edu/asu/ commo
Status: Beta
Brought to you by:
alllee
From: <al...@us...> - 2009-10-27 02:20:14
|
Revision: 335 http://virtualcommons.svn.sourceforge.net/virtualcommons/?rev=335&view=rev Author: alllee Date: 2009-10-27 02:20:01 +0000 (Tue, 27 Oct 2009) Log Message: ----------- refactoring code in an attempt to clearly disambiguate between the irrigation capacity (theoretical maximum) and water supply (actual amount of water available to flow through the irrigation canal). Fixed bug where chat logs were not being persisted properly. Modified Paths: -------------- irrigation/trunk/src/main/java/edu/asu/commons/irrigation/client/CanalPanel.java irrigation/trunk/src/main/java/edu/asu/commons/irrigation/client/ClientDataModel.java irrigation/trunk/src/main/java/edu/asu/commons/irrigation/client/ExperimentGameWindow.java irrigation/trunk/src/main/java/edu/asu/commons/irrigation/client/InfrastructureEfficiencyChartPanel.java irrigation/trunk/src/main/java/edu/asu/commons/irrigation/client/IrrigationGamePanel.java irrigation/trunk/src/main/java/edu/asu/commons/irrigation/client/MainIrrigationGameWindow.java irrigation/trunk/src/main/java/edu/asu/commons/irrigation/server/GroupDataModel.java irrigation/trunk/src/main/java/edu/asu/commons/irrigation/server/IrrigationServer.java Modified: irrigation/trunk/src/main/java/edu/asu/commons/irrigation/client/CanalPanel.java =================================================================== --- irrigation/trunk/src/main/java/edu/asu/commons/irrigation/client/CanalPanel.java 2009-10-26 21:07:55 UTC (rev 334) +++ irrigation/trunk/src/main/java/edu/asu/commons/irrigation/client/CanalPanel.java 2009-10-27 02:20:01 UTC (rev 335) @@ -68,7 +68,7 @@ if (timer != null) { timer.stop(); } - this.maximumIrrigationCapacity = clientDataModel.getGroupDataModel().getMaximumAvailableFlowCapacity(); + this.maximumIrrigationCapacity = clientDataModel.getGroupDataModel().getMaximumAvailableWaterFlow(); this.clientDataModel = clientDataModel; initialize(); } Modified: irrigation/trunk/src/main/java/edu/asu/commons/irrigation/client/ClientDataModel.java =================================================================== --- irrigation/trunk/src/main/java/edu/asu/commons/irrigation/client/ClientDataModel.java 2009-10-26 21:07:55 UTC (rev 334) +++ irrigation/trunk/src/main/java/edu/asu/commons/irrigation/client/ClientDataModel.java 2009-10-27 02:20:01 UTC (rev 335) @@ -117,5 +117,13 @@ return clientDataList; } + public int getWaterSupplyCapacity() { + return roundConfiguration.getWaterSupplyCapacity(); + } + public int getIrrigationCapacity() { + return groupDataModel.getIrrigationCapacity(); + } + + } Modified: irrigation/trunk/src/main/java/edu/asu/commons/irrigation/client/ExperimentGameWindow.java =================================================================== --- irrigation/trunk/src/main/java/edu/asu/commons/irrigation/client/ExperimentGameWindow.java 2009-10-26 21:07:55 UTC (rev 334) +++ irrigation/trunk/src/main/java/edu/asu/commons/irrigation/client/ExperimentGameWindow.java 2009-10-27 02:20:01 UTC (rev 335) @@ -507,20 +507,21 @@ int totalContributedTokens = groupDataModel.getTotalContributedTokens(); final StringBuilder builder = new StringBuilder(); builder.append("Infrastructure efficiency before investment: ") - .append(groupDataModel.getInitialInfrastructureEfficiency()) + .append(groupDataModel.getInfrastructureEfficiencyBeforeInvestment()) .append("%\n"); - builder.append("Irrigation capacity before investment: ").append(groupDataModel.getInitialFlowCapacity()).append(" cubic feet per second\n\n"); + builder.append("Irrigation capacity before investment: ").append(groupDataModel.getIrrigationCapacityBeforeInvestment()).append(" cubic feet per second\n\n"); builder.append( String.format( "Your group invested a total of %d tokens, increasing the infrastructure efficiency to %d%%.\n", totalContributedTokens, groupDataModel.getInfrastructureEfficiency())); - if (groupDataModel.getFlowCapacity() > groupDataModel.getInitialFlowCapacity()) { + if (groupDataModel.getIrrigationCapacity() > groupDataModel.getIrrigationCapacityBeforeInvestment()) { builder.append("Your group's investment has increased the irrigation capacity to "); } else { builder.append("Your group's investment was not enough to increase the irrigation capacity. Your group's irrigation capacity is still "); } - builder.append(groupDataModel.getFlowCapacity()).append(" cubic feet of water per second."); + builder.append(groupDataModel.getIrrigationCapacity()).append(" cubic feet of water per second. The amount of water available to pass through your irrigation canal is ") + .append(groupDataModel.getActualFlowCapacity()); SwingUtilities.invokeLater(new Runnable() { public void run() { contributionInformationTextArea.setText(builder.toString()); @@ -601,7 +602,7 @@ else { instructionsBuilder.append(roundConfiguration.getInstructions()); instructionsBuilder.append("<hr/>"); - int irrigationCapacity = clientDataModel.getGroupDataModel().getFlowCapacity(); + int irrigationCapacity = clientDataModel.getGroupDataModel().getIrrigationCapacity(); int clientCapacity = roundConfiguration.getMaximumClientFlowCapacity(); if (roundConfiguration.shouldResetInfrastructureEfficiency()) { instructionsBuilder.append("The irrigation infrastructure efficiency is currently 75%."); Modified: irrigation/trunk/src/main/java/edu/asu/commons/irrigation/client/InfrastructureEfficiencyChartPanel.java =================================================================== --- irrigation/trunk/src/main/java/edu/asu/commons/irrigation/client/InfrastructureEfficiencyChartPanel.java 2009-10-26 21:07:55 UTC (rev 334) +++ irrigation/trunk/src/main/java/edu/asu/commons/irrigation/client/InfrastructureEfficiencyChartPanel.java 2009-10-27 02:20:01 UTC (rev 335) @@ -54,7 +54,7 @@ int x,y; GroupDataModel group = client.getClientDataModel().getGroupDataModel(); final int infrastructureEfficiency = group.getInfrastructureEfficiency(); - final int actualFlowCapacity = group.getFlowCapacity(); + final int actualFlowCapacity = group.getIrrigationCapacity(); for (y = 0; y <= actualFlowCapacity; y++) { actualFlowCapacitySeries.add(infrastructureEfficiency, y); } @@ -62,10 +62,10 @@ y = group.calculateFlowCapacity(x); potentialFlowCapacitySeries.add(x,y); } - final int initialInfrastructureEfficiency = group.getInitialInfrastructureEfficiency(); - final int initialFlowCapacity = group.calculateFlowCapacity(initialInfrastructureEfficiency); - for (y = 0; y <= initialFlowCapacity; y++) { - initialInfrastructureEfficiencySeries.add(initialInfrastructureEfficiency, y); + final int infrastructureEfficiencyBeforeInvestment = group.getInfrastructureEfficiencyBeforeInvestment(); + final int irrigationCapacityBeforeInvestment = group.getIrrigationCapacityBeforeInvestment(); + for (y = 0; y <= irrigationCapacityBeforeInvestment; y++) { + initialInfrastructureEfficiencySeries.add(infrastructureEfficiencyBeforeInvestment, y); } final XYSeriesCollection data = new XYSeriesCollection(); Modified: irrigation/trunk/src/main/java/edu/asu/commons/irrigation/client/IrrigationGamePanel.java =================================================================== --- irrigation/trunk/src/main/java/edu/asu/commons/irrigation/client/IrrigationGamePanel.java 2009-10-26 21:07:55 UTC (rev 334) +++ irrigation/trunk/src/main/java/edu/asu/commons/irrigation/client/IrrigationGamePanel.java 2009-10-27 02:20:01 UTC (rev 335) @@ -443,7 +443,7 @@ // getWaterCollectedToTokensTable().setText(clientDataModel.getServerConfiguration().getWaterCollectedToTokensTable()); // getScoreBoxPanel().initialize(clientDataModel); getMiddleWindowPanel().initialize(clientDataModel); - int irrigationCapacity = clientDataModel.getGroupDataModel().getMaximumAvailableFlowCapacity(); + int irrigationCapacity = clientDataModel.getGroupDataModel().getMaximumAvailableWaterFlow(); irrigationCapacityLabel.setText( String.format("Irrigation capacity: %d cubic feet per second (cfps)", irrigationCapacity)); Modified: irrigation/trunk/src/main/java/edu/asu/commons/irrigation/client/MainIrrigationGameWindow.java =================================================================== --- irrigation/trunk/src/main/java/edu/asu/commons/irrigation/client/MainIrrigationGameWindow.java 2009-10-26 21:07:55 UTC (rev 334) +++ irrigation/trunk/src/main/java/edu/asu/commons/irrigation/client/MainIrrigationGameWindow.java 2009-10-27 02:20:01 UTC (rev 335) @@ -8,6 +8,7 @@ import java.awt.event.ActionEvent; import java.awt.event.ActionListener; +import javax.swing.BoxLayout; import javax.swing.GroupLayout; import javax.swing.JButton; import javax.swing.JLabel; @@ -22,21 +23,22 @@ import edu.asu.commons.irrigation.server.ClientData; import edu.asu.commons.util.HtmlEditorPane; - - - +/** + * $Id$ + * + * Primary game interface window for the irrigation game. + * + * @author <a href='mailto:All...@as...'>Allen Lee</a>, Sanket Joshi + * @version $Rev$ + */ public class MainIrrigationGameWindow extends JPanel { - //public ChartWindowPanelTokenBandwidth xySeriesDemo; + private static final long serialVersionUID = 5900368694556557132L; - public IrrigationGameWindow controlPanel; + public IrrigationGameWindow controlPanel; - //public ActivitySummaryPanel activitySummaryWindow; + private CanalPanel canalPanel; - public CanalPanel canalPanel; - - private static final long serialVersionUID = 1L; - private JPanel jPanelMain = null; //this contains the CanalPanel private JPanel centerPanel = null; @@ -88,8 +90,10 @@ private JLabel totalTokensEarnedLabel; private JLabel irrigationCapacityLabel; + private JLabel waterSupplyLabel; private JTextField irrigationCapacityTextField; + private JTextField waterSupplyTextField; private HtmlEditorPane waterCollectedToTokensTable; @@ -135,7 +139,11 @@ jPanelMain.setLayout(new BorderLayout(4,4)); jPanelMain.setBackground(Color.WHITE); jPanelMain.setForeground(Color.BLACK); - jPanelMain.add(getIrrigationCapacityLabel(), BorderLayout.NORTH); + JPanel upperPanel = new JPanel(); + upperPanel.setLayout(new BoxLayout(upperPanel, BoxLayout.X_AXIS)); + upperPanel.add(getIrrigationCapacityLabel()); + upperPanel.add(getWaterSupplyLabel()); + jPanelMain.add(upperPanel, BorderLayout.NORTH); jPanelMain.add(getDownloadScreenPanel(), BorderLayout.CENTER); return jPanelMain; } @@ -345,7 +353,7 @@ } return totalTokensEarnedLabel; } - + private JLabel getIrrigationCapacityLabel() { if (irrigationCapacityLabel == null) { irrigationCapacityLabel = new JLabel(); @@ -361,6 +369,21 @@ } return irrigationCapacityTextField; } + + private JLabel getWaterSupplyLabel() { + if (waterSupplyLabel == null) { + waterSupplyLabel = new JLabel("Water supply: "); + waterSupplyLabel.setLabelFor(getWaterSupplyTextField()); + waterSupplyLabel.setFont(new Font("sansserif", Font.BOLD, 16)); + } + return waterSupplyLabel; + } + private JTextField getWaterSupplyTextField() { + if (waterSupplyTextField == null) { + waterSupplyTextField = createTextField(); + } + return waterSupplyTextField; + } /** * This method initializes jPanel3 * summary scoreboard @@ -388,16 +411,6 @@ return waterCollectedToTokensScrollPane; } - private void setProgressBarColor(int timeLeft) { - if (timeLeft < 10) { -// timeLeftProgressBar.setForeground( Color.RED ); -// timeLeftProgressBar.setBackground( Color.RED ); -// return Color.RED; - } - else { -// timeLeftProgressBar.setBackground( Color.GREEN ); - } - } /** * Should be invoked every second throughout the experiment, from a ClientUpdateEvent sent by the server. */ @@ -408,6 +421,7 @@ String timeLeftString = String.format("%d sec", timeLeft); timeLeftProgressBar.setValue( timeLeft ); timeLeftProgressBar.setString(timeLeftString); + // FIXME: figure out how to reliably set the progress bar colors regardless of OS. // setProgressBarColor(timeLeft); for (final ClientData clientData : clientDataModel.getClientDataMap().values()) { if (clientData.isGateOpen()) { @@ -520,10 +534,14 @@ public void startRound() { open = false; getMiddleWindowPanel().initialize(clientDataModel); - int irrigationCapacity = clientDataModel.getGroupDataModel().getMaximumAvailableFlowCapacity(); + int irrigationCapacity = clientDataModel.getIrrigationCapacity(); + int waterSupply = clientDataModel.getWaterSupplyCapacity(); irrigationCapacityLabel.setText( String.format("Irrigation capacity: %d cubic feet per second (cfps)", irrigationCapacity)); + waterSupplyLabel.setText( + String.format("Water supply: %d cubic feet per second (cfps)", + waterSupply)); revalidate(); // mainIrrigationPanel.add(getJPanelUpStreamWindow(),null); Modified: irrigation/trunk/src/main/java/edu/asu/commons/irrigation/server/GroupDataModel.java =================================================================== --- irrigation/trunk/src/main/java/edu/asu/commons/irrigation/server/GroupDataModel.java 2009-10-26 21:07:55 UTC (rev 334) +++ irrigation/trunk/src/main/java/edu/asu/commons/irrigation/server/GroupDataModel.java 2009-10-27 02:20:01 UTC (rev 335) @@ -30,11 +30,11 @@ private transient Logger logger = Logger.getLogger(GroupDataModel.class.getName()); private int currentlyAvailableFlowCapacity = 0; - private int maximumAvailableFlowCapacity = 0; + private int maximumAvailableWaterFlow = 0; private int infrastructureEfficiency; // infrastructure efficiency before investment (but post decline) - private int initialInfrastructureEfficiency; + private int infrastructureEfficiencyBeforeInvestment; private int totalContributedTokens = 0; @@ -87,7 +87,7 @@ return totalContributedTokens; } - public void calculateTotalFlowCapacity() { + public void initializeInfrastructure() { // for practice round and first round, initialize to initial infrastructure efficiency //setting the total contributed Bandwidth = 0 , so that for every round, // fresh totalContributed tokens are calculated @@ -96,7 +96,7 @@ totalContributedTokens += clientData.getInvestedTokens(); } updateInfrastructureEfficiency(totalContributedTokens); - currentlyAvailableFlowCapacity = maximumAvailableFlowCapacity = getFlowCapacity(); + currentlyAvailableFlowCapacity = maximumAvailableWaterFlow = getActualFlowCapacity(); } private void updateInfrastructureEfficiency(int totalContributedTokens) { @@ -111,7 +111,7 @@ } // set original infrastructure efficiency before token contributions getLogger().info("initial infrastructure efficiency: " + infrastructureEfficiency); - initialInfrastructureEfficiency = infrastructureEfficiency; + infrastructureEfficiencyBeforeInvestment = infrastructureEfficiency; // add total invested tokens to infrastructure efficiency, clamp at // 100 infrastructureEfficiency = Math.min(100, totalContributedTokens + infrastructureEfficiency); @@ -155,19 +155,34 @@ return 40; } - public int getInitialFlowCapacity() { - return Math.min(calculateFlowCapacity(initialInfrastructureEfficiency), getRoundConfiguration().getWaterSupplyCapacity()); + public int getIrrigationCapacityBeforeInvestment() { +// return Math.min(calculateFlowCapacity(initialInfrastructureEfficiency), getRoundConfiguration().getWaterSupplyCapacity()); + return calculateFlowCapacity(infrastructureEfficiencyBeforeInvestment); } - public int getFlowCapacity() { - return Math.min(calculateFlowCapacity(infrastructureEfficiency), getRoundConfiguration().getWaterSupplyCapacity()); + /** + * Returns the theoretical maximum amount of water that the infrastructure can handle. + * This is independent of the actual water supply. + */ + public int getIrrigationCapacity() { + return calculateFlowCapacity(infrastructureEfficiency); +// return Math.min(calculateFlowCapacity(infrastructureEfficiency), getRoundConfiguration().getWaterSupplyCapacity()); } + + /** + * Returns the actual maximum amount of water that can pass through the canal, which is the minimum + * of the irrigation capacity and the water supply. + * @return + */ + public int getActualFlowCapacity() { + return Math.min(getIrrigationCapacity(), getRoundConfiguration().getWaterSupplyCapacity()); + } public void resetCurrentlyAvailableFlowCapacity() { - currentlyAvailableFlowCapacity = maximumAvailableFlowCapacity; + currentlyAvailableFlowCapacity = maximumAvailableWaterFlow; } - public void allocateFlowCapacity(ClientData clientData) { + public void allocateWater(ClientData clientData) { int maximumClientFlowCapacity = getRoundConfiguration().getMaximumClientFlowCapacity(); if (currentlyAvailableFlowCapacity >= maximumClientFlowCapacity) { currentlyAvailableFlowCapacity -= maximumClientFlowCapacity; @@ -180,17 +195,16 @@ clientData.collectWater(); } - - public int getMaximumAvailableFlowCapacity() { - return maximumAvailableFlowCapacity; + public int getMaximumAvailableWaterFlow() { + return maximumAvailableWaterFlow; } public int getInfrastructureEfficiency() { return infrastructureEfficiency; } - public int getInitialInfrastructureEfficiency() { - return initialInfrastructureEfficiency; + public int getInfrastructureEfficiencyBeforeInvestment() { + return infrastructureEfficiencyBeforeInvestment; } public Logger getLogger() { Modified: irrigation/trunk/src/main/java/edu/asu/commons/irrigation/server/IrrigationServer.java =================================================================== --- irrigation/trunk/src/main/java/edu/asu/commons/irrigation/server/IrrigationServer.java 2009-10-26 21:07:55 UTC (rev 334) +++ irrigation/trunk/src/main/java/edu/asu/commons/irrigation/server/IrrigationServer.java 2009-10-27 02:20:01 UTC (rev 335) @@ -138,6 +138,7 @@ addEventProcessor(new EventTypeProcessor<BeginChatRoundRequest>(BeginChatRoundRequest.class) { @Override public void handle(BeginChatRoundRequest request) { + persister.clearChatData(); // pass it on to all the clients synchronized (clients) { for (Identifier id: clients.keySet()) { @@ -222,6 +223,7 @@ ChatEvent chatEvent = new ChatEvent(request.getTarget(), request.toString(), request.getSource()); transmit(chatEvent); } + persister.store(request); } }); addEventProcessor(new EventTypeProcessor<InvestedTokensEvent>(InvestedTokensEvent.class) { @@ -274,7 +276,7 @@ // post round cleanup ///////////////////////////////////////////////////////////////////////////////// for(GroupDataModel group : serverDataModel.getAllGroupDataModels()){ - group.calculateTotalFlowCapacity(); + group.initializeInfrastructure(); // iterate through all groups and send back their contribution status for (Identifier id : group.getClientDataMap().keySet()) { InfrastructureUpdateEvent infrastructureUpdateEvent = new InfrastructureUpdateEvent(id, group); @@ -309,7 +311,7 @@ // clientData.init(group.getCurrentlyAvailableFlowCapacity()); // } if (clientData.isGateOpen()) { - group.allocateFlowCapacity(clientData); + group.allocateWater(clientData); } else if (clientData.isGateClosed()) { clientData.init(group.getAvailableClientFlowCapacity()); This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |