virtualcommons-svn Mailing List for Virtual Commons Experiment Software (Page 63)
Status: Beta
Brought to you by:
alllee
You can subscribe to this list here.
2008 |
Jan
|
Feb
|
Mar
|
Apr
|
May
|
Jun
(1) |
Jul
(21) |
Aug
(31) |
Sep
(6) |
Oct
(15) |
Nov
(2) |
Dec
(9) |
---|---|---|---|---|---|---|---|---|---|---|---|---|
2009 |
Jan
(4) |
Feb
(6) |
Mar
(12) |
Apr
(52) |
May
(14) |
Jun
(19) |
Jul
(81) |
Aug
(115) |
Sep
(36) |
Oct
(88) |
Nov
(46) |
Dec
(58) |
2010 |
Jan
(52) |
Feb
(55) |
Mar
(48) |
Apr
(15) |
May
(5) |
Jun
(38) |
Jul
(27) |
Aug
(24) |
Sep
(28) |
Oct
(1) |
Nov
(2) |
Dec
(29) |
2011 |
Jan
(87) |
Feb
(39) |
Mar
(63) |
Apr
(42) |
May
(26) |
Jun
(53) |
Jul
(23) |
Aug
(43) |
Sep
(37) |
Oct
(25) |
Nov
(4) |
Dec
(7) |
2012 |
Jan
(73) |
Feb
(79) |
Mar
(62) |
Apr
(28) |
May
(12) |
Jun
(2) |
Jul
(9) |
Aug
(1) |
Sep
(8) |
Oct
|
Nov
(3) |
Dec
(3) |
2013 |
Jan
(8) |
Feb
(16) |
Mar
(38) |
Apr
(74) |
May
(62) |
Jun
(15) |
Jul
(49) |
Aug
(19) |
Sep
(9) |
Oct
|
Nov
|
Dec
|
2014 |
Jan
|
Feb
|
Mar
|
Apr
(2) |
May
(25) |
Jun
|
Jul
|
Aug
|
Sep
|
Oct
|
Nov
|
Dec
|
From: Kalin J. <kj...@as...> - 2009-10-09 20:22:54
|
I'm checking in today at 13:15pm On Thu, Oct 8, 2009 at 6:06 PM, Kalin Jonas <kj...@as...> wrote: > I'm heading out now at 18:00pm. (2hr) > I can't tell how the program could be ending up in the empty game state, > unless perhaps Seema's code is sending me an empty block at some point on > accident, or if my code is broken in a similar way. > > > On Thu, Oct 8, 2009 at 4:17 PM, Kalin Jonas <kj...@as...> wrote: > >> I came in to work today at 16:00pm, and am reading over the code to try >> and see if the problem with blocks is client side or not. >> > > |
From: <al...@us...> - 2009-10-09 06:26:49
|
Revision: 291 http://virtualcommons.svn.sourceforge.net/virtualcommons/?rev=291&view=rev Author: alllee Date: 2009-10-09 06:26:41 +0000 (Fri, 09 Oct 2009) Log Message: ----------- updated configuration files, fixing build / deployment process Modified Paths: -------------- irrigation/trunk/build.xml irrigation/trunk/src/main/resources/configuration/asu-fall-2009/irrigation.xml irrigation/trunk/src/main/resources/configuration/asu-fall-2009/round0.xml irrigation/trunk/src/main/resources/configuration/asu-fall-2009/round1.xml irrigation/trunk/src/main/resources/configuration/asu-fall-2009/round10.xml irrigation/trunk/src/main/resources/configuration/asu-fall-2009/round11.xml irrigation/trunk/src/main/resources/configuration/asu-fall-2009/round12.xml irrigation/trunk/src/main/resources/configuration/asu-fall-2009/round13.xml irrigation/trunk/src/main/resources/configuration/asu-fall-2009/round14.xml irrigation/trunk/src/main/resources/configuration/asu-fall-2009/round15.xml irrigation/trunk/src/main/resources/configuration/asu-fall-2009/round16.xml irrigation/trunk/src/main/resources/configuration/asu-fall-2009/round17.xml irrigation/trunk/src/main/resources/configuration/asu-fall-2009/round18.xml irrigation/trunk/src/main/resources/configuration/asu-fall-2009/round19.xml irrigation/trunk/src/main/resources/configuration/asu-fall-2009/round2.xml irrigation/trunk/src/main/resources/configuration/asu-fall-2009/round20.xml irrigation/trunk/src/main/resources/configuration/asu-fall-2009/round21.xml irrigation/trunk/src/main/resources/configuration/asu-fall-2009/round3.xml irrigation/trunk/src/main/resources/configuration/asu-fall-2009/round4.xml irrigation/trunk/src/main/resources/configuration/asu-fall-2009/round5.xml irrigation/trunk/src/main/resources/configuration/asu-fall-2009/round6.xml irrigation/trunk/src/main/resources/configuration/asu-fall-2009/round7.xml irrigation/trunk/src/main/resources/configuration/asu-fall-2009/round8.xml irrigation/trunk/src/main/resources/configuration/asu-fall-2009/round9.xml Added Paths: ----------- irrigation/trunk/src/main/java/edu/asu/commons/irrigation/facilitator/Facilitator.java irrigation/trunk/src/main/java/edu/asu/commons/irrigation/facilitator/FacilitatorWindow.java Removed Paths: ------------- irrigation/trunk/src/main/java/edu/asu/commons/irrigation/facilitator/IrrigationFacilitator.java irrigation/trunk/src/main/java/edu/asu/commons/irrigation/facilitator/IrrigationFacilitatorWindow.java Modified: irrigation/trunk/build.xml =================================================================== --- irrigation/trunk/build.xml 2009-10-08 22:10:47 UTC (rev 290) +++ irrigation/trunk/build.xml 2009-10-09 06:26:41 UTC (rev 291) @@ -67,7 +67,6 @@ <!-- default web & deployment properties --> <property name='web.dir' value='src/main/webapp'/> <property name='server.port' value='16001'/> - <property name='server.xml' value='server.xml'/> <property name='codebase.url' value='http://${server.address}/${ant.project.name}'/> <property name='client.class' value='edu.asu.commons.irrigation.client.IrrigationClient'/> <property name='facilitator.class' value='edu.asu.commons.irrigation.facilitator.Facilitator'/> @@ -145,7 +144,7 @@ </fileset> </copy> <!-- copy images --> - <copy todir='${deploy.dir}/images' overwrite='true'> + <copy todir='${deploy.dir}/images' overwrite='true' failonerror='false'> <fileset dir='${resources.dir}/images'/> </copy> <!-- @@ -248,10 +247,7 @@ <compilerarg value='-Xlint:unchecked'/> <classpath refid="project.classpath" /> </javac> - <copy todir='${build.dir}/data'> - <fileset dir='${resources.dir}/data'/> - </copy> - <copy todir='${build.dir}/images'> + <copy todir='${build.dir}/images' failonerror='false'> <fileset dir='${resources.dir}/images'/> </copy> </target> Copied: irrigation/trunk/src/main/java/edu/asu/commons/irrigation/facilitator/Facilitator.java (from rev 290, irrigation/trunk/src/main/java/edu/asu/commons/irrigation/facilitator/IrrigationFacilitator.java) =================================================================== --- irrigation/trunk/src/main/java/edu/asu/commons/irrigation/facilitator/Facilitator.java (rev 0) +++ irrigation/trunk/src/main/java/edu/asu/commons/irrigation/facilitator/Facilitator.java 2009-10-09 06:26:41 UTC (rev 291) @@ -0,0 +1,259 @@ +package edu.asu.commons.irrigation.facilitator; + +import java.awt.Dimension; +import java.net.InetSocketAddress; + +import javax.swing.JFrame; +import javax.swing.SwingUtilities; + +import edu.asu.commons.event.BeginExperimentRequest; +import edu.asu.commons.event.BeginRoundRequest; +import edu.asu.commons.event.ConfigurationEvent; +import edu.asu.commons.event.EndRoundRequest; +import edu.asu.commons.event.Event; +import edu.asu.commons.event.EventTypeChannel; +import edu.asu.commons.event.EventTypeProcessor; +import edu.asu.commons.event.FacilitatorRegistrationRequest; +import edu.asu.commons.irrigation.conf.RoundConfiguration; +import edu.asu.commons.irrigation.conf.ServerConfiguration; +import edu.asu.commons.irrigation.events.FacilitatorEndRoundEvent; +import edu.asu.commons.irrigation.events.ServerGameStateEvent; +import edu.asu.commons.irrigation.server.ServerDataModel; +import edu.asu.commons.net.ClientDispatcher; +import edu.asu.commons.net.DispatcherFactory; +import edu.asu.commons.net.Identifier; + +/** + * @author Sanket + * + */ +public class Facilitator { + + private final static Facilitator INSTANCE = new Facilitator(); + + private Identifier id; // @jve:decl-index=0: + + private ClientDispatcher dispatcher; + + private ServerConfiguration configuration; + + private ServerDataModel serverGameState; // @jve:decl-index=0: + + private FacilitatorWindow irrigationFacilitatorWindow; + + private boolean stopExperiment = false; + + private boolean experimentRunning = false; + + private final EventTypeChannel channel = new EventTypeChannel(); + + private Facilitator() { + this(new ServerConfiguration()); + } + + public Facilitator(ServerConfiguration configuration) { + dispatcher = DispatcherFactory.getInstance().createClientDispatcher(channel); + setConfiguration(configuration); + initializeEventProcessors(); + } + + @SuppressWarnings("unchecked") + private void initializeEventProcessors() { + channel.add(new EventTypeProcessor<ConfigurationEvent>(ConfigurationEvent.class) { + public void handle(ConfigurationEvent configurationEvent) { + setConfiguration((ServerConfiguration) configurationEvent.getConfiguration()); + } + }); + channel.add(new EventTypeProcessor<FacilitatorEndRoundEvent>(FacilitatorEndRoundEvent.class) { + public void handle(FacilitatorEndRoundEvent event) { +// serverGameState = null; + irrigationFacilitatorWindow.endRound(event); + configuration.nextRound(); + } + }); + } + + public static Facilitator getInstance(){ + return INSTANCE; + } + + public void setConfiguration(ServerConfiguration configuration) { + if (configuration == null) { + System.err.println("attempt to setConfiguration with null, ignoring"); + return; + } + else { + this.configuration = configuration; + } + } + + /** + * @param args + */ + + /* + * Connects facilitator to the server and registers with the server as a facilitator. + * + * If the connection was successful, configures the FacilitatorWindow to manage experiments, + * otherwise configures the FacilitatorWindow to replay experiments and view configuration + * for those experiments. + */ + public void connect() { + connect(configuration.getServerAddress()); + } + + public void connect(InetSocketAddress address) { + id = dispatcher.connect(address); + if (id != null) { + transmit(new FacilitatorRegistrationRequest(id)); + } + + } + + void createFacilitatorWindow(Dimension dimension) { + irrigationFacilitatorWindow = new FacilitatorWindow(dimension, this); + //if (id == null) { + // configure for unconnected functionality + // facilitatorWindow.configureForReplay(); + //} + } + + /* + * Sends requests to the server + */ + public void transmit(Event event) { + dispatcher.transmit(event); + } + + public static void main(String[] args) { + + Runnable createGuiRunnable = new Runnable(){ + public void run() { + // TODO Auto-generated method stub + Dimension dimension = new Dimension(500, 600); + Facilitator facilitator = Facilitator.getInstance(); + facilitator.connect(); + JFrame frame = new JFrame(); + frame.setTitle("Facilitator window: " + facilitator.id); + frame.setSize((int) dimension.getWidth(), (int) dimension.getHeight()); + facilitator.createFacilitatorWindow(dimension); + frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); + frame.getContentPane().add(facilitator.getFacilitatorWindow()); + frame.setVisible(true); + } + }; + SwingUtilities.invokeLater(createGuiRunnable); + } + + public void accept(Identifier id, Object event) { + // TODO Auto-generated method stub + if (event instanceof ConfigurationEvent) { + ConfigurationEvent configEvent = (ConfigurationEvent) event; + setConfiguration((ServerConfiguration)configEvent.getConfiguration()); + } + else if(event instanceof ServerGameStateEvent){ + ServerGameStateEvent serverGameStateEvent = (ServerGameStateEvent)event; + if (!stopExperiment) { + if (serverGameState == null) { + System.err.println("about to display game.."); + experimentRunning = true; + // FIXME: could use configuration from this event... serverGameStateEvent.getServerGameState().getConfiguration(); + serverGameState = serverGameStateEvent.getServerGameState(); + /** + * Here I need to display Game..this goes to the facilitator window. + */ + //facilitatorWindow.displayGame(); + } + else { + // synchronous updates + serverGameState = serverGameStateEvent.getServerGameState(); + } + } + //facilitatorWindow.updateWindow(serverGameStateEvent.getTimeLeft()); + } + else if (event instanceof FacilitatorEndRoundEvent){ + FacilitatorEndRoundEvent endRoundEvent = (FacilitatorEndRoundEvent)event; + serverGameState = null; + /** + * This method goes to facilitator widow. + */ + //facilitatorWindow.endRound(endRoundEvent); + } + + } + + /* + * Send a request to server to start an experiment + */ + void sendBeginExperimentRequest(){ + System.out.println("I am in sendBeginExperiment"); + transmit(new BeginExperimentRequest(id)); + //sendBeginRoundRequest(); + stopExperiment = false; + } + + /* + * Send a request to start a round + */ + public void sendBeginRoundRequest() { + transmit(new BeginRoundRequest(id)); + } + +// /* +// * Send a request to stop an experiment +// */ +// +// public void sendStopExperimentRequest() { +// transmit(new EndExperimentRequest(id)); +// endExperiment(); +// } + +// public void endExperiment() { +// configuration.resetExperimentRoundConfiguration(); +// serverGameState = null; +// stopExperiment = true; +// experimentRunning = false; +// //facilitatorWindow.updateMenuItems(); +// } + /* + * Send a request to stop a round + */ + + public void sendEndRoundRequest() { + transmit(new EndRoundRequest(id)); + } + /* + * Send a request to set the configuration object + */ + public void sendSetConfigRequest() { + dispatcher.transmit(new ConfigurationEvent(id, getConfiguration())); + } + + public FacilitatorWindow getFacilitatorWindow() { + return irrigationFacilitatorWindow; + } + + public Identifier getIdentifier(){ + return id; + } + + public ServerDataModel getServerGameState(){ + return serverGameState; + } + + public ServerConfiguration getConfiguration(){ + return configuration; + } + + public boolean isExperimentRunning(){ + return experimentRunning; + } + + public RoundConfiguration getCurrentRoundConfiguration() { + return configuration.getCurrentParameters(); + } + + public void setServerGameState(ServerDataModel serverGameState) { + this.serverGameState = serverGameState; + } +} Copied: irrigation/trunk/src/main/java/edu/asu/commons/irrigation/facilitator/FacilitatorWindow.java (from rev 290, irrigation/trunk/src/main/java/edu/asu/commons/irrigation/facilitator/IrrigationFacilitatorWindow.java) =================================================================== --- irrigation/trunk/src/main/java/edu/asu/commons/irrigation/facilitator/FacilitatorWindow.java (rev 0) +++ irrigation/trunk/src/main/java/edu/asu/commons/irrigation/facilitator/FacilitatorWindow.java 2009-10-09 06:26:41 UTC (rev 291) @@ -0,0 +1,195 @@ +/** + * + */ +package edu.asu.commons.irrigation.facilitator; + +import java.awt.BorderLayout; +import java.awt.Dimension; +import java.awt.Rectangle; +import java.awt.event.ActionEvent; +import java.awt.event.ActionListener; +import java.util.HashMap; +import java.util.Map; +import java.util.TreeSet; + +import javax.swing.BoxLayout; +import javax.swing.JButton; +import javax.swing.JPanel; +import javax.swing.JScrollPane; + +import edu.asu.commons.irrigation.events.BeginCommunicationRequest; +import edu.asu.commons.irrigation.events.DisplaySubmitTokenRequest; +import edu.asu.commons.irrigation.events.FacilitatorEndRoundEvent; +import edu.asu.commons.irrigation.events.InstructionEnableRequest; +import edu.asu.commons.irrigation.server.ClientData; +import edu.asu.commons.irrigation.server.GroupDataModel; +import edu.asu.commons.irrigation.server.ServerDataModel; +import edu.asu.commons.net.Identifier; +import edu.asu.commons.util.HtmlEditorPane; + +/** + * @author Sanket + * + */ +public class FacilitatorWindow extends JPanel { + + private Facilitator facilitator; + + private Dimension windowDimension; + + private static final long serialVersionUID = 1L; + + + private JButton startRoundButton = null; + + private JButton beginChatButton; + + private HtmlEditorPane editorPane; + private JScrollPane scrollPane; + + private JButton enableInstructionButton; + /** + * This is the default constructor + */ + + public FacilitatorWindow(Dimension dimension, Facilitator facilitator) { + windowDimension = dimension; + this.facilitator = facilitator; + initialize(); + } + + /* + public IrrigationFacilitatorWindow(){ + super(); + initialize(); + } + */ + + /** + * This method initializes this + * + * @return void + */ + private void initialize() { + setSize(windowDimension); + setLayout(new BorderLayout()); + JPanel buttonPanel = new JPanel(); + buttonPanel.setLayout(new BoxLayout(buttonPanel, BoxLayout.X_AXIS)); + buttonPanel.add(getStartRoundButton()); + buttonPanel.add(getBeginChatButton()); + buttonPanel.add(getEnableInstructionButton()); + add(buttonPanel, BorderLayout.NORTH); + JPanel informationPanel = new JPanel(); + editorPane = new HtmlEditorPane(); + scrollPane = new JScrollPane(editorPane); + informationPanel.add(scrollPane); + add(informationPanel, BorderLayout.CENTER); + } + + private JButton getEnableInstructionButton() { + // TODO Auto-generated method stub + if (enableInstructionButton == null) { + enableInstructionButton = new JButton("Enable Instruction"); + enableInstructionButton.addActionListener(new ActionListener() { + public void actionPerformed(ActionEvent event) { + enableInstructionButton.setEnabled(false); + facilitator.transmit(new InstructionEnableRequest(facilitator.getIdentifier())); + } + }); + } + return enableInstructionButton; + } + + /** + * This method initializes Start_Facilitator_Button + * + * @return javax.swing.JButton + */ + + private JButton getBeginChatButton() { + if (beginChatButton == null) { + beginChatButton = new JButton("Begin Chat"); + beginChatButton.addActionListener(new ActionListener() { + public void actionPerformed(ActionEvent event) { + //At present default isChatEnabledBeforeRound() value isscreen false + if(facilitator.getCurrentRoundConfiguration().isChatEnabledBeforeRound()){ + facilitator.transmit(new BeginCommunicationRequest(facilitator.getIdentifier())); + } + else + facilitator.transmit(new DisplaySubmitTokenRequest(facilitator.getIdentifier())); + } + }); + } + return beginChatButton; + } + + public Facilitator getFacilitator(){ + return facilitator; + } + + /** + * This method initializes Stop + * + * @return javax.swing.JButton + */ + /** + * This method initializes Start_Round_Button + * + * @return javax.swing.JButton + */ + private JButton getStartRoundButton() { + if (startRoundButton == null) { + startRoundButton = new JButton(); + startRoundButton.setBounds(new Rectangle(180, 16, 136, 24)); + startRoundButton.setText("Start Round"); + startRoundButton.addActionListener(new java.awt.event.ActionListener() { + public void actionPerformed(java.awt.event.ActionEvent e) { + System.out.println("actionPerformed()"); // TODO Auto-generated Event stub actionPerformed() + facilitator.sendBeginRoundRequest(); + } + }); + } + return startRoundButton; + } + + /** + * This method initializes Stop_Round_Button1 + * + * @return javax.swing.JButton + */ + + + public void endRound(FacilitatorEndRoundEvent event) { + ServerDataModel model = event.getServerDataModel(); + StringBuilder builder = new StringBuilder(); + builder.append("<h3>Facilitator Debriefing:</h3>"); + builder.append("<table><thead><th>Participant</th><th>Current tokens</th><th>Current Income</th><th>Total Income</th></thead><tbody>"); + Map<Identifier, ClientData> clientDataMap = new HashMap<Identifier, ClientData>(); + for (GroupDataModel group: model.getAllGroupDataModels()) { + clientDataMap.putAll(group.getClientDataMap()); + } + TreeSet<Identifier> orderedSet = new TreeSet<Identifier>(clientDataMap.keySet()); + for (Identifier clientId : orderedSet) { + ClientData data = clientDataMap.get(clientId); + // FIXME: hack... inject the configuration into the client data so that getIncome() will return something appropriate. + // should just refactor getIncome or remove it from ClientData entirely. + builder.append(String.format( + "<tr><td>%s</td>" + + "<td align='center'>%d</td>" + + "<td align='center'>$%3.2f</td>" + + "<td align='center'>$%3.2f</td></tr>", + clientId.toString(), + data.getTotalTokensEarned(), + data.getTotalTokensEarned() * model.getCurrentConfiguration().getDollarsPerToken(), + data.getTotalTokens() * model.getCurrentConfiguration().getDollarsPerToken()+ facilitator.getConfiguration().getShowUpPayment())); + } + builder.append("</tbody></table><hr>"); + //FIXME: Could not understand how to evaluate .isLastRound(), hence using the + if (event.isLastRound()) { + builder.append("<h2><font color='blue'>The experiment is over. Please prepare payments.</font></h2>"); + } + editorPane.setText(builder.toString()); + repaint(); + } + +} // @jve:decl-index=0:visual-constraint="48,19" Deleted: irrigation/trunk/src/main/java/edu/asu/commons/irrigation/facilitator/IrrigationFacilitator.java =================================================================== --- irrigation/trunk/src/main/java/edu/asu/commons/irrigation/facilitator/IrrigationFacilitator.java 2009-10-08 22:10:47 UTC (rev 290) +++ irrigation/trunk/src/main/java/edu/asu/commons/irrigation/facilitator/IrrigationFacilitator.java 2009-10-09 06:26:41 UTC (rev 291) @@ -1,259 +0,0 @@ -package edu.asu.commons.irrigation.facilitator; - -import java.awt.Dimension; -import java.net.InetSocketAddress; - -import javax.swing.JFrame; -import javax.swing.SwingUtilities; - -import edu.asu.commons.event.BeginExperimentRequest; -import edu.asu.commons.event.BeginRoundRequest; -import edu.asu.commons.event.ConfigurationEvent; -import edu.asu.commons.event.EndRoundRequest; -import edu.asu.commons.event.Event; -import edu.asu.commons.event.EventTypeChannel; -import edu.asu.commons.event.EventTypeProcessor; -import edu.asu.commons.event.FacilitatorRegistrationRequest; -import edu.asu.commons.irrigation.conf.RoundConfiguration; -import edu.asu.commons.irrigation.conf.ServerConfiguration; -import edu.asu.commons.irrigation.events.FacilitatorEndRoundEvent; -import edu.asu.commons.irrigation.events.ServerGameStateEvent; -import edu.asu.commons.irrigation.server.ServerDataModel; -import edu.asu.commons.net.ClientDispatcher; -import edu.asu.commons.net.DispatcherFactory; -import edu.asu.commons.net.Identifier; - -/** - * @author Sanket - * - */ -public class IrrigationFacilitator { - - private final static IrrigationFacilitator INSTANCE = new IrrigationFacilitator(); - - private Identifier id; // @jve:decl-index=0: - - private ClientDispatcher dispatcher; - - private ServerConfiguration configuration; - - private ServerDataModel serverGameState; // @jve:decl-index=0: - - private IrrigationFacilitatorWindow irrigationFacilitatorWindow; - - private boolean stopExperiment = false; - - private boolean experimentRunning = false; - - private final EventTypeChannel channel = new EventTypeChannel(); - - private IrrigationFacilitator() { - this(new ServerConfiguration()); - } - - public IrrigationFacilitator(ServerConfiguration configuration) { - dispatcher = DispatcherFactory.getInstance().createClientDispatcher(channel); - setConfiguration(configuration); - initializeEventProcessors(); - } - - @SuppressWarnings("unchecked") - private void initializeEventProcessors() { - channel.add(new EventTypeProcessor<ConfigurationEvent>(ConfigurationEvent.class) { - public void handle(ConfigurationEvent configurationEvent) { - setConfiguration((ServerConfiguration) configurationEvent.getConfiguration()); - } - }); - channel.add(new EventTypeProcessor<FacilitatorEndRoundEvent>(FacilitatorEndRoundEvent.class) { - public void handle(FacilitatorEndRoundEvent event) { -// serverGameState = null; - irrigationFacilitatorWindow.endRound(event); - configuration.nextRound(); - } - }); - } - - public static IrrigationFacilitator getInstance(){ - return INSTANCE; - } - - public void setConfiguration(ServerConfiguration configuration) { - if (configuration == null) { - System.err.println("attempt to setConfiguration with null, ignoring"); - return; - } - else { - this.configuration = configuration; - } - } - - /** - * @param args - */ - - /* - * Connects facilitator to the server and registers with the server as a facilitator. - * - * If the connection was successful, configures the FacilitatorWindow to manage experiments, - * otherwise configures the FacilitatorWindow to replay experiments and view configuration - * for those experiments. - */ - public void connect() { - connect(configuration.getServerAddress()); - } - - public void connect(InetSocketAddress address) { - id = dispatcher.connect(address); - if (id != null) { - transmit(new FacilitatorRegistrationRequest(id)); - } - - } - - void createFacilitatorWindow(Dimension dimension) { - irrigationFacilitatorWindow = new IrrigationFacilitatorWindow(dimension, this); - //if (id == null) { - // configure for unconnected functionality - // facilitatorWindow.configureForReplay(); - //} - } - - /* - * Sends requests to the server - */ - public void transmit(Event event) { - dispatcher.transmit(event); - } - - public static void main(String[] args) { - - Runnable createGuiRunnable = new Runnable(){ - public void run() { - // TODO Auto-generated method stub - Dimension dimension = new Dimension(500, 600); - IrrigationFacilitator facilitator = IrrigationFacilitator.getInstance(); - facilitator.connect(); - JFrame frame = new JFrame(); - frame.setTitle("Facilitator window: " + facilitator.id); - frame.setSize((int) dimension.getWidth(), (int) dimension.getHeight()); - facilitator.createFacilitatorWindow(dimension); - frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); - frame.getContentPane().add(facilitator.getFacilitatorWindow()); - frame.setVisible(true); - } - }; - SwingUtilities.invokeLater(createGuiRunnable); - } - - public void accept(Identifier id, Object event) { - // TODO Auto-generated method stub - if (event instanceof ConfigurationEvent) { - ConfigurationEvent configEvent = (ConfigurationEvent) event; - setConfiguration((ServerConfiguration)configEvent.getConfiguration()); - } - else if(event instanceof ServerGameStateEvent){ - ServerGameStateEvent serverGameStateEvent = (ServerGameStateEvent)event; - if (!stopExperiment) { - if (serverGameState == null) { - System.err.println("about to display game.."); - experimentRunning = true; - // FIXME: could use configuration from this event... serverGameStateEvent.getServerGameState().getConfiguration(); - serverGameState = serverGameStateEvent.getServerGameState(); - /** - * Here I need to display Game..this goes to the facilitator window. - */ - //facilitatorWindow.displayGame(); - } - else { - // synchronous updates - serverGameState = serverGameStateEvent.getServerGameState(); - } - } - //facilitatorWindow.updateWindow(serverGameStateEvent.getTimeLeft()); - } - else if (event instanceof FacilitatorEndRoundEvent){ - FacilitatorEndRoundEvent endRoundEvent = (FacilitatorEndRoundEvent)event; - serverGameState = null; - /** - * This method goes to facilitator widow. - */ - //facilitatorWindow.endRound(endRoundEvent); - } - - } - - /* - * Send a request to server to start an experiment - */ - void sendBeginExperimentRequest(){ - System.out.println("I am in sendBeginExperiment"); - transmit(new BeginExperimentRequest(id)); - //sendBeginRoundRequest(); - stopExperiment = false; - } - - /* - * Send a request to start a round - */ - public void sendBeginRoundRequest() { - transmit(new BeginRoundRequest(id)); - } - -// /* -// * Send a request to stop an experiment -// */ -// -// public void sendStopExperimentRequest() { -// transmit(new EndExperimentRequest(id)); -// endExperiment(); -// } - -// public void endExperiment() { -// configuration.resetExperimentRoundConfiguration(); -// serverGameState = null; -// stopExperiment = true; -// experimentRunning = false; -// //facilitatorWindow.updateMenuItems(); -// } - /* - * Send a request to stop a round - */ - - public void sendEndRoundRequest() { - transmit(new EndRoundRequest(id)); - } - /* - * Send a request to set the configuration object - */ - public void sendSetConfigRequest() { - dispatcher.transmit(new ConfigurationEvent(id, getConfiguration())); - } - - public IrrigationFacilitatorWindow getFacilitatorWindow() { - return irrigationFacilitatorWindow; - } - - public Identifier getIdentifier(){ - return id; - } - - public ServerDataModel getServerGameState(){ - return serverGameState; - } - - public ServerConfiguration getConfiguration(){ - return configuration; - } - - public boolean isExperimentRunning(){ - return experimentRunning; - } - - public RoundConfiguration getCurrentRoundConfiguration() { - return configuration.getCurrentParameters(); - } - - public void setServerGameState(ServerDataModel serverGameState) { - this.serverGameState = serverGameState; - } -} Deleted: irrigation/trunk/src/main/java/edu/asu/commons/irrigation/facilitator/IrrigationFacilitatorWindow.java =================================================================== --- irrigation/trunk/src/main/java/edu/asu/commons/irrigation/facilitator/IrrigationFacilitatorWindow.java 2009-10-08 22:10:47 UTC (rev 290) +++ irrigation/trunk/src/main/java/edu/asu/commons/irrigation/facilitator/IrrigationFacilitatorWindow.java 2009-10-09 06:26:41 UTC (rev 291) @@ -1,195 +0,0 @@ -/** - * - */ -package edu.asu.commons.irrigation.facilitator; - -import java.awt.BorderLayout; -import java.awt.Dimension; -import java.awt.Rectangle; -import java.awt.event.ActionEvent; -import java.awt.event.ActionListener; -import java.util.HashMap; -import java.util.Map; -import java.util.TreeSet; - -import javax.swing.BoxLayout; -import javax.swing.JButton; -import javax.swing.JPanel; -import javax.swing.JScrollPane; - -import edu.asu.commons.irrigation.events.BeginCommunicationRequest; -import edu.asu.commons.irrigation.events.DisplaySubmitTokenRequest; -import edu.asu.commons.irrigation.events.FacilitatorEndRoundEvent; -import edu.asu.commons.irrigation.events.InstructionEnableRequest; -import edu.asu.commons.irrigation.server.ClientData; -import edu.asu.commons.irrigation.server.GroupDataModel; -import edu.asu.commons.irrigation.server.ServerDataModel; -import edu.asu.commons.net.Identifier; -import edu.asu.commons.util.HtmlEditorPane; - -/** - * @author Sanket - * - */ -public class IrrigationFacilitatorWindow extends JPanel { - - private IrrigationFacilitator facilitator; - - private Dimension windowDimension; - - private static final long serialVersionUID = 1L; - - - private JButton startRoundButton = null; - - private JButton beginChatButton; - - private HtmlEditorPane editorPane; - private JScrollPane scrollPane; - - private JButton enableInstructionButton; - /** - * This is the default constructor - */ - - public IrrigationFacilitatorWindow(Dimension dimension, IrrigationFacilitator facilitator) { - windowDimension = dimension; - this.facilitator = facilitator; - initialize(); - } - - /* - public IrrigationFacilitatorWindow(){ - super(); - initialize(); - } - */ - - /** - * This method initializes this - * - * @return void - */ - private void initialize() { - setSize(windowDimension); - setLayout(new BorderLayout()); - JPanel buttonPanel = new JPanel(); - buttonPanel.setLayout(new BoxLayout(buttonPanel, BoxLayout.X_AXIS)); - buttonPanel.add(getStartRoundButton()); - buttonPanel.add(getBeginChatButton()); - buttonPanel.add(getEnableInstructionButton()); - add(buttonPanel, BorderLayout.NORTH); - JPanel informationPanel = new JPanel(); - editorPane = new HtmlEditorPane(); - scrollPane = new JScrollPane(editorPane); - informationPanel.add(scrollPane); - add(informationPanel, BorderLayout.CENTER); - } - - private JButton getEnableInstructionButton() { - // TODO Auto-generated method stub - if (enableInstructionButton == null) { - enableInstructionButton = new JButton("Enable Instruction"); - enableInstructionButton.addActionListener(new ActionListener() { - public void actionPerformed(ActionEvent event) { - enableInstructionButton.setEnabled(false); - facilitator.transmit(new InstructionEnableRequest(facilitator.getIdentifier())); - } - }); - } - return enableInstructionButton; - } - - /** - * This method initializes Start_Facilitator_Button - * - * @return javax.swing.JButton - */ - - private JButton getBeginChatButton() { - if (beginChatButton == null) { - beginChatButton = new JButton("Begin Chat"); - beginChatButton.addActionListener(new ActionListener() { - public void actionPerformed(ActionEvent event) { - //At present default isChatEnabledBeforeRound() value isscreen false - if(facilitator.getCurrentRoundConfiguration().isChatEnabledBeforeRound()){ - facilitator.transmit(new BeginCommunicationRequest(facilitator.getIdentifier())); - } - else - facilitator.transmit(new DisplaySubmitTokenRequest(facilitator.getIdentifier())); - } - }); - } - return beginChatButton; - } - - public IrrigationFacilitator getFacilitator(){ - return facilitator; - } - - /** - * This method initializes Stop - * - * @return javax.swing.JButton - */ - /** - * This method initializes Start_Round_Button - * - * @return javax.swing.JButton - */ - private JButton getStartRoundButton() { - if (startRoundButton == null) { - startRoundButton = new JButton(); - startRoundButton.setBounds(new Rectangle(180, 16, 136, 24)); - startRoundButton.setText("Start Round"); - startRoundButton.addActionListener(new java.awt.event.ActionListener() { - public void actionPerformed(java.awt.event.ActionEvent e) { - System.out.println("actionPerformed()"); // TODO Auto-generated Event stub actionPerformed() - facilitator.sendBeginRoundRequest(); - } - }); - } - return startRoundButton; - } - - /** - * This method initializes Stop_Round_Button1 - * - * @return javax.swing.JButton - */ - - - public void endRound(FacilitatorEndRoundEvent event) { - ServerDataModel model = event.getServerDataModel(); - StringBuilder builder = new StringBuilder(); - builder.append("<h3>Facilitator Debriefing:</h3>"); - builder.append("<table><thead><th>Participant</th><th>Current tokens</th><th>Current Income</th><th>Total Income</th></thead><tbody>"); - Map<Identifier, ClientData> clientDataMap = new HashMap<Identifier, ClientData>(); - for (GroupDataModel group: model.getAllGroupDataModels()) { - clientDataMap.putAll(group.getClientDataMap()); - } - TreeSet<Identifier> orderedSet = new TreeSet<Identifier>(clientDataMap.keySet()); - for (Identifier clientId : orderedSet) { - ClientData data = clientDataMap.get(clientId); - // FIXME: hack... inject the configuration into the client data so that getIncome() will return something appropriate. - // should just refactor getIncome or remove it from ClientData entirely. - builder.append(String.format( - "<tr><td>%s</td>" + - "<td align='center'>%d</td>" + - "<td align='center'>$%3.2f</td>" + - "<td align='center'>$%3.2f</td></tr>", - clientId.toString(), - data.getTotalTokensEarned(), - data.getTotalTokensEarned() * model.getCurrentConfiguration().getDollarsPerToken(), - data.getTotalTokens() * model.getCurrentConfiguration().getDollarsPerToken()+ facilitator.getConfiguration().getShowUpPayment())); - } - builder.append("</tbody></table><hr>"); - //FIXME: Could not understand how to evaluate .isLastRound(), hence using the - if (event.isLastRound()) { - builder.append("<h2><font color='blue'>The experiment is over. Please prepare payments.</font></h2>"); - } - editorPane.setText(builder.toString()); - repaint(); - } - -} // @jve:decl-index=0:visual-constraint="48,19" Modified: irrigation/trunk/src/main/resources/configuration/asu-fall-2009/irrigation.xml =================================================================== --- irrigation/trunk/src/main/resources/configuration/asu-fall-2009/irrigation.xml 2009-10-08 22:10:47 UTC (rev 290) +++ irrigation/trunk/src/main/resources/configuration/asu-fall-2009/irrigation.xml 2009-10-09 06:26:41 UTC (rev 291) @@ -4,8 +4,8 @@ <comment>Irrigation XML-ized experiment round configuration</comment> <!--<entry key="hostname">localhost</entry>--> -<entry key="hostname">localhost</entry> -<entry key="port">16001</entry> +<entry key="hostname">@SERVER_ADDRESS@</entry> +<entry key="port">@PORT_NUMBER@</entry> <entry key="round0">round0.xml</entry> <entry key="round1">round1.xml</entry> <entry key="round2">round2.xml</entry> Modified: irrigation/trunk/src/main/resources/configuration/asu-fall-2009/round0.xml =================================================================== --- irrigation/trunk/src/main/resources/configuration/asu-fall-2009/round0.xml 2009-10-08 22:10:47 UTC (rev 290) +++ irrigation/trunk/src/main/resources/configuration/asu-fall-2009/round0.xml 2009-10-09 06:26:41 UTC (rev 291) @@ -1,48 +1,22 @@ <?xml version="1.0" encoding="UTF-8"?> <!DOCTYPE properties SYSTEM "http://java.sun.com/dtd/properties.dtd"> <properties> -<comment>Costly Sanctioning XML-ized experiment round configuration</comment> -<entry key="round-time">100</entry> +<comment>Irrigation experiment round configuration</comment> <entry key='max-canal-flow-capacity'>40</entry> <entry key='max-client-flow-capacity'>25</entry> -<entry key="Btmax">50</entry> -<entry key="Token-Bandwidth-Mapping">2</entry> -<entry key="FilesDownload-Award-Conversion">2</entry> - <entry key="max-total-token-contribution">50</entry> - -<entry key="TBM-alpha">40</entry> -<entry key="TBM-a">30</entry> -<entry key="TBM-b">10</entry> <entry key="practice-round">true</entry> <entry key="clients-per-group">5</entry> -<entry key="FAM-alpha">20</entry> -<entry key="FAM-a">5</entry> -<entry key="FAM-b">6</entry> -<entry key="board-width">14</entry> -<entry key="board-height">14</entry> - -<entry key="F1">100</entry> -<entry key="F2">100</entry> -<entry key="F3">100</entry> -<entry key="F4">100</entry> -<entry key="F5">100</entry> -<entry key="F6">100</entry> -<entry key="F7">100</entry> -<entry key="F8">100</entry> -<entry key="F9">100</entry> -<entry key="F10">100</entry> - <entry key="instructions"> <![CDATA[ <p> -We will now start with two practice rounds. This practice round will not contribute to your earnings – -it is intended to acquaint you with the functioning of the exercise environment.<br> -If you have any questions feel free to raise your hand and to ask your question.<br> -<b>Do you have any questions so far?</b> +We will now start with two practice rounds. This practice round will not contribute +to your earnings. If you have any questions feel free to raise your hand and to ask +your question. +<br> +<b>Do you have any questions?</b> </p> - ]]> </entry> </properties> Modified: irrigation/trunk/src/main/resources/configuration/asu-fall-2009/round1.xml =================================================================== --- irrigation/trunk/src/main/resources/configuration/asu-fall-2009/round1.xml 2009-10-08 22:10:47 UTC (rev 290) +++ irrigation/trunk/src/main/resources/configuration/asu-fall-2009/round1.xml 2009-10-09 06:26:41 UTC (rev 291) @@ -1,41 +1,10 @@ <?xml version="1.0" encoding="UTF-8"?> <!DOCTYPE properties SYSTEM "http://java.sun.com/dtd/properties.dtd"> <properties> -<comment>Costly Sanctioning XML-ized experiment round configuration</comment> -<entry key="round-time">100</entry> -<entry key="Bs">60</entry> -<entry key="Bt">40</entry> -<entry key="Btmax">50</entry> -<entry key="Token-Bandwidth-Mapping">2</entry> -<entry key="FilesDownload-Award-Conversion">2</entry> -<entry key="TBM-alpha">40</entry> -<entry key="TBM-a">30</entry> -<entry key="TBM-b">10</entry> +<comment>Irrigation experiment round configuration</comment> <entry key="max-total-token-contribution">50</entry> <entry key="practice-round">true</entry> -<entry key="clients-per-group">5</entry> -<entry key="second-practice-round">true</entry> -<entry key="FAM-alpha">20</entry> -<entry key="FAM-a">5</entry> -<entry key="FAM-b">6</entry> - -<entry key="board-width">14</entry> -<entry key="board-height">14</entry> - -<entry key="F1">100</entry> -<entry key="F2">100</entry> -<entry key="F3">100</entry> -<entry key="F4">100</entry> -<entry key="F5">100</entry> -<entry key="F6">100</entry> -<entry key="F7">100</entry> -<entry key="F8">100</entry> -<entry key="F9">100</entry> -<entry key="F10">100</entry> - - - <entry key="instructions"> <![CDATA[ <h3>Practice Round 2</h3> Modified: irrigation/trunk/src/main/resources/configuration/asu-fall-2009/round10.xml =================================================================== --- irrigation/trunk/src/main/resources/configuration/asu-fall-2009/round10.xml 2009-10-08 22:10:47 UTC (rev 290) +++ irrigation/trunk/src/main/resources/configuration/asu-fall-2009/round10.xml 2009-10-09 06:26:41 UTC (rev 291) @@ -1,39 +1,11 @@ <?xml version="1.0" encoding="UTF-8"?> <!DOCTYPE properties SYSTEM "http://java.sun.com/dtd/properties.dtd"> <properties> -<comment>Costly Sanctioning XML-ized experiment round configuration</comment> -<entry key="round-time">100</entry> -<entry key="Bs">60</entry> -<entry key="Bt">40</entry> -<entry key="Btmax">50</entry> -<entry key="Token-Bandwidth-Mapping">2</entry> -<entry key="FilesDownload-Award-Conversion">2</entry> -<entry key="TBM-alpha">40</entry> -<entry key="TBM-a">30</entry> -<entry key="TBM-b">10</entry> +<comment>Irrigation experiment round configuration</comment> <entry key="max-total-token-contribution">50</entry> <entry key="practice-round">false</entry> <entry key="clients-per-group">5</entry> -<entry key="FAM-alpha">20</entry> -<entry key="FAM-a">5</entry> -<entry key="FAM-b">6</entry> -<entry key="board-width">14</entry> -<entry key="board-height">14</entry> - -<entry key="F1">100</entry> -<entry key="F2">100</entry> -<entry key="F3">100</entry> -<entry key="F4">100</entry> -<entry key="F5">100</entry> -<entry key="F6">100</entry> -<entry key="F7">100</entry> -<entry key="F8">100</entry> -<entry key="F9">100</entry> -<entry key="F10">100</entry> - - - <entry key="instructions"> <![CDATA[ <h3>Round 9 Instructions</h3> Modified: irrigation/trunk/src/main/resources/configuration/asu-fall-2009/round11.xml =================================================================== --- irrigation/trunk/src/main/resources/configuration/asu-fall-2009/round11.xml 2009-10-08 22:10:47 UTC (rev 290) +++ irrigation/trunk/src/main/resources/configuration/asu-fall-2009/round11.xml 2009-10-09 06:26:41 UTC (rev 291) @@ -1,39 +1,9 @@ <?xml version="1.0" encoding="UTF-8"?> <!DOCTYPE properties SYSTEM "http://java.sun.com/dtd/properties.dtd"> <properties> -<comment>Costly Sanctioning XML-ized experiment round configuration</comment> -<entry key="round-time">100</entry> -<entry key="Bs">60</entry> -<entry key="Bt">40</entry> -<entry key="Btmax">50</entry> -<entry key="Token-Bandwidth-Mapping">2</entry> -<entry key="FilesDownload-Award-Conversion">2</entry> -<entry key="TBM-alpha">40</entry> -<entry key="TBM-a">30</entry> -<entry key="TBM-b">10</entry> +<comment>Irrigation experiment round configuration</comment> <entry key="max-total-token-contribution">50</entry> -<entry key="practice-round">false</entry> -<entry key="clients-per-group">5</entry> -<entry key="FAM-alpha">20</entry> -<entry key="FAM-a">5</entry> -<entry key="FAM-b">6</entry> -<entry key="board-width">14</entry> -<entry key="board-height">14</entry> - -<entry key="F1">100</entry> -<entry key="F2">100</entry> -<entry key="F3">100</entry> -<entry key="F4">100</entry> -<entry key="F5">100</entry> -<entry key="F6">100</entry> -<entry key="F7">100</entry> -<entry key="F8">100</entry> -<entry key="F9">100</entry> -<entry key="F10">100</entry> - - - <entry key="instructions"> <![CDATA[ <h3>Round 10 Instructions</h3> Modified: irrigation/trunk/src/main/resources/configuration/asu-fall-2009/round12.xml =================================================================== --- irrigation/trunk/src/main/resources/configuration/asu-fall-2009/round12.xml 2009-10-08 22:10:47 UTC (rev 290) +++ irrigation/trunk/src/main/resources/configuration/asu-fall-2009/round12.xml 2009-10-09 06:26:41 UTC (rev 291) @@ -1,39 +1,10 @@ <?xml version="1.0" encoding="UTF-8"?> <!DOCTYPE properties SYSTEM "http://java.sun.com/dtd/properties.dtd"> <properties> -<comment>Costly Sanctioning XML-ized experiment round configuration</comment> -<entry key="round-time">100</entry> -<entry key="Bs">60</entry> -<entry key="Bt">40</entry> -<entry key="Btmax">50</entry> -<entry key="Token-Bandwidth-Mapping">2</entry> -<entry key="FilesDownload-Award-Conversion">2</entry> -<entry key="TBM-alpha">40</entry> -<entry key="TBM-a">30</entry> -<entry key="TBM-b">10</entry> +<comment>Irrigation experiment round configuration</comment> <entry key='infrastructure-degradation-factor'>10</entry> -<entry key="practice-round">false</entry> -<entry key="clients-per-group">5</entry> -<entry key="FAM-alpha">20</entry> -<entry key="FAM-a">5</entry> -<entry key="FAM-b">6</entry> -<entry key="board-width">14</entry> -<entry key="board-height">14</entry> -<entry key="F1">100</entry> -<entry key="F2">100</entry> -<entry key="F3">100</entry> -<entry key="F4">100</entry> -<entry key="F5">100</entry> -<entry key="F6">100</entry> -<entry key="F7">100</entry> -<entry key="F8">100</entry> -<entry key="F9">100</entry> -<entry key="F10">100</entry> - - - <entry key="instructions"> <![CDATA[ <h3>Round 11 Instructions</h3> Modified: irrigation/trunk/src/main/resources/configuration/asu-fall-2009/round13.xml =================================================================== --- irrigation/trunk/src/main/resources/configuration/asu-fall-2009/round13.xml 2009-10-08 22:10:47 UTC (rev 290) +++ irrigation/trunk/src/main/resources/configuration/asu-fall-2009/round13.xml 2009-10-09 06:26:41 UTC (rev 291) @@ -1,40 +1,9 @@ <?xml version="1.0" encoding="UTF-8"?> <!DOCTYPE properties SYSTEM "http://java.sun.com/dtd/properties.dtd"> <properties> -<comment>Costly Sanctioning XML-ized experiment round configuration</comment> -<entry key="round-time">100</entry> -<entry key="Bs">60</entry> -<entry key="Bt">40</entry> -<entry key="Btmax">50</entry> -<entry key="Token-Bandwidth-Mapping">2</entry> -<entry key="FilesDownload-Award-Conversion">2</entry> -<entry key="TBM-alpha">40</entry> -<entry key="TBM-a">30</entry> -<entry key="TBM-b">10</entry> +<comment>Irrigation experiment round configuration</comment> <entry key="max-total-token-contribution">50</entry> <entry key='infrastructure-degradation-factor'>10</entry> -<entry key="practice-round">false</entry> -<entry key="clients-per-group">5</entry> -<entry key="FAM-alpha">20</entry> -<entry key="FAM-a">5</entry> -<entry key="FAM-b">6</entry> - -<entry key="board-width">14</entry> -<entry key="board-height">14</entry> - -<entry key="F1">100</entry> -<entry key="F2">100</entry> -<entry key="F3">100</entry> -<entry key="F4">100</entry> -<entry key="F5">100</entry> -<entry key="F6">100</entry> -<entry key="F7">100</entry> -<entry key="F8">100</entry> -<entry key="F9">100</entry> -<entry key="F10">100</entry> - - - <entry key="instructions"> <![CDATA[ <h3>Round 12 Instructions</h3> Modified: irrigation/trunk/src/main/resources/configuration/asu-fall-2009/round14.xml =================================================================== --- irrigation/trunk/src/main/resources/configuration/asu-fall-2009/round14.xml 2009-10-08 22:10:47 UTC (rev 290) +++ irrigation/trunk/src/main/resources/configuration/asu-fall-2009/round14.xml 2009-10-09 06:26:41 UTC (rev 291) @@ -1,39 +1,9 @@ <?xml version="1.0" encoding="UTF-8"?> <!DOCTYPE properties SYSTEM "http://java.sun.com/dtd/properties.dtd"> <properties> -<comment>Costly Sanctioning XML-ized experiment round configuration</comment> -<entry key="round-time">100</entry> -<entry key="Bs">60</entry> -<entry key="Bt">40</entry> -<entry key="Btmax">50</entry> -<entry key="Token-Bandwidth-Mapping">2</entry> -<entry key="FilesDownload-Award-Conversion">2</entry> -<entry key="TBM-alpha">40</entry> -<entry key="TBM-a">30</entry> -<entry key="TBM-b">10</entry> +<comment>Irrigation experiment round configuration</comment> <entry key='infrastructure-degradation-factor'>85</entry> -<entry key="practice-round">false</entry> -<entry key="clients-per-group">5</entry> -<entry key="FAM-alpha">20</entry> -<entry key="FAM-a">5</entry> -<entry key="FAM-b">6</entry> -<entry key="board-width">14</entry> -<entry key="board-height">14</entry> - -<entry key="F1">100</entry> -<entry key="F2">100</entry> -<entry key="F3">100</entry> -<entry key="F4">100</entry> -<entry key="F5">100</entry> -<entry key="F6">100</entry> -<entry key="F7">100</entry> -<entry key="F8">100</entry> -<entry key="F9">100</entry> -<entry key="F10">100</entry> - - - <entry key="instructions"> <![CDATA[ <h3>Round 13 Instructions</h3> Modified: irrigation/trunk/src/main/resources/configuration/asu-fall-2009/round15.xml =================================================================== --- irrigation/trunk/src/main/resources/configuration/asu-fall-2009/round15.xml 2009-10-08 22:10:47 UTC (rev 290) +++ irrigation/trunk/src/main/resources/configuration/asu-fall-2009/round15.xml 2009-10-09 06:26:41 UTC (rev 291) @@ -1,39 +1,9 @@ <?xml version="1.0" encoding="UTF-8"?> <!DOCTYPE properties SYSTEM "http://java.sun.com/dtd/properties.dtd"> <properties> -<comment>Costly Sanctioning XML-ized experiment round configuration</comment> -<entry key="round-time">100</entry> -<entry key="Bs">60</entry> -<entry key="Bt">40</entry> -<entry key="Btmax">50</entry> -<entry key="Token-Bandwidth-Mapping">2</entry> -<entry key="FilesDownload-Award-Conversion">2</entry> -<entry key="TBM-alpha">40</entry> -<entry key="TBM-a">30</entry> -<entry key="TBM-b">10</entry> +<comment>Irrigation experiment round configuration</comment> <entry key='infrastructure-degradation-factor'>10</entry> -<entry key="practice-round">false</entry> -<entry key="clients-per-group">5</entry> -<entry key="FAM-alpha">20</entry> -<entry key="FAM-a">5</entry> -<entry key="FAM-b">6</entry> -<entry key="board-width">14</entry> -<entry key="board-height">14</entry> - -<entry key="F1">100</entry> -<entry key="F2">100</entry> -<entry key="F3">100</entry> -<entry key="F4">100</entry> -<entry key="F5">100</entry> -<entry key="F6">100</entry> -<entry key="F7">100</entry> -<entry key="F8">100</entry> -<entry key="F9">100</entry> -<entry key="F10">100</entry> - - - <entry key="instructions"> <![CDATA[ <h3>Round 14 Instructions</h3> Modified: irrigation/trunk/src/main/resources/configuration/asu-fall-2009/round16.xml =================================================================== --- irrigation/trunk/src/main/resources/configuration/asu-fall-2009/round16.xml 2009-10-08 22:10:47 UTC (rev 290) +++ irrigation/trunk/src/main/resources/configuration/asu-fall-2009/round16.xml 2009-10-09 06:26:41 UTC (rev 291) @@ -1,39 +1,10 @@ <?xml version="1.0" encoding="UTF-8"?> <!DOCTYPE properties SYSTEM "http://java.sun.com/dtd/properties.dtd"> <properties> -<comment>Costly Sanctioning XML-ized experiment round configuration</comment> -<entry key="round-time">100</entry> -<entry key="Bs">60</entry> -<entry key="Bt">40</entry> -<entry key="Btmax">50</entry> -<entry key="Token-Bandwidth-Mapping">2</entry> -<entry key="FilesDownload-Award-Conversion">2</entry> -<entry key="TBM-alpha">40</entry> -<entry key="TBM-a">30</entry> -<entry key="TBM-b">10</entry> +<comment>Irrigation experiment round configuration</comment> <entry key='infrastructure-degradation-factor'>10</entry> -<entry key="practice-round">false</entry> -<entry key="clients-per-group">5</entry> -<entry key="FAM-alpha">20</entry> -<entry key="FAM-a">5</entry> -<entry key="FAM-b">6</entry> -<entry key="board-width">14</entry> -<entry key="board-height">14</entry> -<entry key="F1">100</entry> -<entry key="F2">100</entry> -<entry key="F3">100</entry> -<entry key="F4">100</entry> -<entry key="F5">100</entry> -<entry key="F6">100</entry> -<entry key="F7">100</entry> -<entry key="F8">100</entry> -<entry key="F9">100</entry> -<entry key="F10">100</entry> - - - <entry key="instructions"> <![CDATA[ <h3>Round 15 Instructions</h3> Modified: irrigation/trunk/src/main/resources/configuration/asu-fall-2009/round17.xml =================================================================== --- irrigation/trunk/src/main/resources/configuration/asu-fall-2009/round17.xml 2009-10-08 22:10:47 UTC (rev 290) +++ irrigation/trunk/src/main/resources/configuration/asu-fall-2009/round17.xml 2009-10-09 06:26:41 UTC (rev 291) @@ -1,39 +1,8 @@ <?xml version="1.0" encoding="UTF-8"?> <!DOCTYPE properties SYSTEM "http://java.sun.com/dtd/properties.dtd"> <properties> -<comment>Costly Sanctioning XML-ized experiment round configuration</comment> -<entry key="round-time">100</entry> -<entry key="Bs">60</entry> -<entry key="Bt">40</entry> -<entry key="Btmax">50</entry> -<entry key="Token-Bandwidth-Mapping">2</entry> -<entry key="FilesDownload-Award-Conversion">2</entry> -<entry key="TBM-alpha">40</entry> -<entry key="TBM-a">30</entry> -<entry key="TBM-b">10</entry> +<comment>Irrigation experiment round configuration</comment> <entry key='infrastructure-degradation-factor'>10</entry> -<entry key="practice-round">false</entry> -<entry key="clients-per-group">5</entry> -<entry key="FAM-alpha">20</entry> -<entry key="FAM-a">5</entry> -<entry key="FAM-b">6</entry> - -<entry key="board-width">14</entry> -<entry key="board-height">14</entry> - -<entry key="F1">100</entry> -<entry key="F2">100</entry> -<entry key="F3">100</entry> -<entry key="F4">100</entry> -<entry key="F5">100</entry> -<entry key="F6">100</entry> -<entry key="F7">100</entry> -<entry key="F8">100</entry> -<entry key="F9">100</entry> -<entry key="F10">100</entry> - - - <entry key="instructions"> <![CDATA[ <h3>Round 16 Instructions</h3> Modified: irrigation/trunk/src/main/resources/configuration/asu-fall-2009/round18.xml =================================================================== --- irrigation/trunk/src/main/resources/configuration/asu-fall-2009/round18.xml 2009-10-08 22:10:47 UTC (rev 290) +++ irrigation/trunk/src/main/resources/configuration/asu-fall-2009/round18.xml 2009-10-09 06:26:41 UTC (rev 291) @@ -1,39 +1,9 @@ <?xml version="1.0" encoding="UTF-8"?> <!DOCTYPE properties SYSTEM "http://java.sun.com/dtd/properties.dtd"> <properties> -<comment>Costly Sanctioning XML-ized experiment round configuration</comment> -<entry key="round-time">100</entry> -<entry key="Bs">60</entry> -<entry key="Bt">40</entry> -<entry key="Btmax">50</entry> -<entry key="Token-Bandwidth-Mapping">2</entry> -<entry key="FilesDownload-Award-Conversion">2</entry> -<entry key="TBM-alpha">40</entry> -<entry key="TBM-a">30</entry> -<entry key="TBM-b">10</entry> +<comment>Irrigation experiment round configuration</comment> <entry key='infrastructure-degradation-factor'>85</entry> -<entry key="practice-round">false</entry> -<entry key="clients-per-group">5</entry> -<entry key="FAM-alpha">20</entry> -<entry key="FAM-a">5</entry> -<entry key="FAM-b">6</entry> -<entry key="board-width">14</entry> -<entry key="board-height">14</entry> - -<entry key="F1">100</entry> -<entry key="F2">100</entry> -<entry key="F3">100</entry> -<entry key="F4">100</entry> -<entry key="F5">100</entry> -<entry key="F6">100</entry> -<entry key="F7">100</entry> -<entry key="F8">100</entry> -<entry key="F9">100</entry> -<entry key="F10">100</entry> - - - <entry key="instructions"> <![CDATA[ <h3>Round 17 Instructions</h3> Modified: irrigation/trunk/src/main/resources/configuration/asu-fall-2009/round19.xml =================================================================== --- irrigation/trunk/src/main/resources/configuration/asu-fall-2009/round19.xml 2009-10-08 22:10:47 UTC (rev 290) +++ irrigation/trunk/src/main/resources/configuration/asu-fall-2009/round19.xml 2009-10-09 06:26:41 UTC (rev 291) @@ -1,39 +1,10 @@ <?xml version="1.0" encoding="UTF-8"?> <!DOCTYPE properties SYSTEM "http://java.sun.com/dtd/properties.dtd"> <properties> -<comment>Costly Sanctioning XML-ized experiment round configuration</comment> -<entry key="round-time">100</entry> -<entry key="Bs">60</entry> -<entry key="Bt">40</entry> -<entry key="Btmax">50</entry> -<entry key="Token-Bandwidth-Mapping">2</entry> -<entry key="FilesDownload-Award-Conversion">2</entry> -<entry key="TBM-alpha">40</entry> -<entry key="TBM-a">30</entry> -<entry key="TBM-b">10</entry> +<comment>Irrigation experiment round configuration</comment> <entry key='infrastructure-degradation-factor'>10</entry> -<entry key="practice-round">false</entry> -<entry key="clients-per-group">5</entry> -<entry key="FAM-alpha">20</entry> -<entry key="FAM-a">5</entry> -<entry key="FAM-b">6</entry> -<entry key="board-width">14</entry> -<entry key="board-height">14</entry> -<entry key="F1">100</entry> -<entry key="F2">100</entry> -<entry key="F3">100</entry> -<entry key="F4">100</entry> -<entry key="F5">100</entry> -<entry key="F6">100</entry> -<entry key="F7">100</entry> -<entry key="F8">100</entry> -<entry key="F9">100</entry> -<entry key="F10">100</entry> - - - <entry key="instructions"> <![CDATA[ <h3>Round 18 Instructions</h3> Modified: irrigation/trunk/src/main/resources/configuration/asu-fall-2009/round2.xml =================================================================== --- irrigation/trunk/src/main/resources/configuration/asu-fall-2009/round2.xml 2009-10-08 22:10:47 UTC (rev 290) +++ irrigation/trunk/src/main/resources/configuration/asu-fall-2009/round2.xml 2009-10-09 06:26:41 UTC (rev 291) @@ -1,41 +1,8 @@ <?xml version="1.0" encoding="UTF-8"?> <!DOCTYPE properties SYSTEM "http://java.sun.com/dtd/properties.dtd"> <properties> -<comment>Costly Sanctioning XML-ized experiment round configuration</comment> -<entry key="round-time">100</entry> -<entry key="Bs">60</entry> -<entry key="Bt">40</entry> -<entry key="Btmax">50</entry> -<entry key="Token-Bandwidth-Mapping">2</entry> -<entry key="FilesDownload-Award-Conversion">2</entry> -<entry key="TBM-alpha">40</entry> -<entry key="TBM-a">30</entry> -<entry key="TBM-b">10</entry> -<entry key="max-total-token-contribution">50</entry> -<entry key="practice-round">false</entry> -<entry key="clients-per-group">5</entry> -<entry key="FAM-alpha">20</entry> -<entry key="FAM-a">5</entry> -<entry key="FAM-b">6</entry> +<comment>Irrigation experiment round configuration</comment> -<entry key='first-round'>true</entry> - -<entry key="board-width">14</entry> -<entry key="board-height">14</entry> - -<entry key="F1">100</entry> -<entry key="F2">100</entry> -<entry key="F3">100</entry> -<entry key="F4">100</entry> -<entry key="F5">100</entry> -<entry key="F6">100</entry> -<entry key="F7">100</entry> -<entry key="F8">100</entry> -<entry key="F9">100</entry> -<entry key="F10">100</entry> - - - <entry key="instructions"> <![CDATA[ <h3>Round 1 Instructions</h3> Modified: irrigation/trunk/src/main/resources/configuration/asu-fall-2009/round20.xml ===========================... [truncated message content] |
From: Kalin J. <kj...@as...> - 2009-10-09 01:07:09
|
I'm heading out now at 18:00pm. (2hr) I can't tell how the program could be ending up in the empty game state, unless perhaps Seema's code is sending me an empty block at some point on accident, or if my code is broken in a similar way. On Thu, Oct 8, 2009 at 4:17 PM, Kalin Jonas <kj...@as...> wrote: > I came in to work today at 16:00pm, and am reading over the code to try and > see if the problem with blocks is client side or not. > |
From: Kalin J. <kj...@as...> - 2009-10-08 23:17:43
|
I came in to work today at 16:00pm, and am reading over the code to try and see if the problem with blocks is client side or not. |
From: <al...@us...> - 2009-10-08 22:11:00
|
Revision: 290 http://virtualcommons.svn.sourceforge.net/virtualcommons/?rev=290&view=rev Author: alllee Date: 2009-10-08 22:10:47 +0000 (Thu, 08 Oct 2009) Log Message: ----------- More refactoring, getting rid of unused obscure equation variable names. Adding first cut at configuration files. More cleanup to come. Modified Paths: -------------- irrigation/trunk/src/main/java/edu/asu/commons/irrigation/client/ChartWindowPanel.java irrigation/trunk/src/main/java/edu/asu/commons/irrigation/client/ChartWindowPanelTokenBandwidth.java irrigation/trunk/src/main/java/edu/asu/commons/irrigation/client/ChatPanel.java irrigation/trunk/src/main/java/edu/asu/commons/irrigation/client/IrrigationClient.java irrigation/trunk/src/main/java/edu/asu/commons/irrigation/client/IrrigationGameWindow.java irrigation/trunk/src/main/java/edu/asu/commons/irrigation/client/MainIrrigationGameWindow.java irrigation/trunk/src/main/java/edu/asu/commons/irrigation/client/MiddleScorePanel.java irrigation/trunk/src/main/java/edu/asu/commons/irrigation/conf/RoundConfiguration.java irrigation/trunk/src/main/java/edu/asu/commons/irrigation/conf/ServerConfiguration.java irrigation/trunk/src/main/java/edu/asu/commons/irrigation/facilitator/IrrigationFacilitatorWindow.java irrigation/trunk/src/main/java/edu/asu/commons/irrigation/server/ClientData.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 Added Paths: ----------- irrigation/trunk/src/main/java/edu/asu/commons/irrigation/events/CloseGateEvent.java irrigation/trunk/src/main/java/edu/asu/commons/irrigation/events/OpenGateEvent.java irrigation/trunk/src/main/java/edu/asu/commons/irrigation/events/PauseEvent.java irrigation/trunk/src/main/resources/configuration/ irrigation/trunk/src/main/resources/configuration/asu-fall-2009/ irrigation/trunk/src/main/resources/configuration/asu-fall-2009/irrigation.xml irrigation/trunk/src/main/resources/configuration/asu-fall-2009/round0.xml irrigation/trunk/src/main/resources/configuration/asu-fall-2009/round1.xml irrigation/trunk/src/main/resources/configuration/asu-fall-2009/round10.xml irrigation/trunk/src/main/resources/configuration/asu-fall-2009/round11.xml irrigation/trunk/src/main/resources/configuration/asu-fall-2009/round12.xml irrigation/trunk/src/main/resources/configuration/asu-fall-2009/round13.xml irrigation/trunk/src/main/resources/configuration/asu-fall-2009/round14.xml irrigation/trunk/src/main/resources/configuration/asu-fall-2009/round15.xml irrigation/trunk/src/main/resources/configuration/asu-fall-2009/round16.xml irrigation/trunk/src/main/resources/configuration/asu-fall-2009/round17.xml irrigation/trunk/src/main/resources/configuration/asu-fall-2009/round18.xml irrigation/trunk/src/main/resources/configuration/asu-fall-2009/round19.xml irrigation/trunk/src/main/resources/configuration/asu-fall-2009/round2.xml irrigation/trunk/src/main/resources/configuration/asu-fall-2009/round20.xml irrigation/trunk/src/main/resources/configuration/asu-fall-2009/round21.xml irrigation/trunk/src/main/resources/configuration/asu-fall-2009/round3.xml irrigation/trunk/src/main/resources/configuration/asu-fall-2009/round4.xml irrigation/trunk/src/main/resources/configuration/asu-fall-2009/round5.xml irrigation/trunk/src/main/resources/configuration/asu-fall-2009/round6.xml irrigation/trunk/src/main/resources/configuration/asu-fall-2009/round7.xml irrigation/trunk/src/main/resources/configuration/asu-fall-2009/round8.xml irrigation/trunk/src/main/resources/configuration/asu-fall-2009/round9.xml Removed Paths: ------------- irrigation/trunk/src/main/java/edu/asu/commons/irrigation/events/GateOpenedEvent.java irrigation/trunk/src/main/java/edu/asu/commons/irrigation/events/StartPausedEvent.java irrigation/trunk/src/main/java/edu/asu/commons/irrigation/events/StopDownloadEvent.java Property Changed: ---------------- irrigation/trunk/src/main/java/edu/asu/commons/irrigation/client/ActivitySummaryPanel.java irrigation/trunk/src/main/java/edu/asu/commons/irrigation/client/ActivitySummaryPanelNew.java irrigation/trunk/src/main/java/edu/asu/commons/irrigation/client/Ball.java irrigation/trunk/src/main/java/edu/asu/commons/irrigation/client/CanalPanel.java irrigation/trunk/src/main/java/edu/asu/commons/irrigation/client/CanalPanelAnimation.java irrigation/trunk/src/main/java/edu/asu/commons/irrigation/client/CanalPanelAnimationNew.java irrigation/trunk/src/main/java/edu/asu/commons/irrigation/client/ChartWindowPanel.java irrigation/trunk/src/main/java/edu/asu/commons/irrigation/client/ChartWindowPanelTokenBandwidth.java irrigation/trunk/src/main/java/edu/asu/commons/irrigation/client/ChatPanel.java irrigation/trunk/src/main/java/edu/asu/commons/irrigation/client/ExperimentGameWindow.java irrigation/trunk/src/main/java/edu/asu/commons/irrigation/client/Gate.java irrigation/trunk/src/main/java/edu/asu/commons/irrigation/client/IrrigationClient.java irrigation/trunk/src/main/java/edu/asu/commons/irrigation/client/IrrigationClientGameState.java irrigation/trunk/src/main/java/edu/asu/commons/irrigation/client/IrrigationGameWindow.java irrigation/trunk/src/main/java/edu/asu/commons/irrigation/client/MainIrrigationGameWindow.java irrigation/trunk/src/main/java/edu/asu/commons/irrigation/client/MiddleScorePanel.java irrigation/trunk/src/main/java/edu/asu/commons/irrigation/client/MiddleWindowPanel.java irrigation/trunk/src/main/java/edu/asu/commons/irrigation/client/PieChart.java irrigation/trunk/src/main/java/edu/asu/commons/irrigation/client/ScoreBoxPanel.java irrigation/trunk/src/main/java/edu/asu/commons/irrigation/conf/RoundConfiguration.java irrigation/trunk/src/main/java/edu/asu/commons/irrigation/conf/ServerConfiguration.java irrigation/trunk/src/main/java/edu/asu/commons/irrigation/events/BeginCommunicationRequest.java irrigation/trunk/src/main/java/edu/asu/commons/irrigation/events/ClientUpdateEvent.java irrigation/trunk/src/main/java/edu/asu/commons/irrigation/events/DisplaySubmitTokenRequest.java irrigation/trunk/src/main/java/edu/asu/commons/irrigation/events/EndRoundEvent.java irrigation/trunk/src/main/java/edu/asu/commons/irrigation/events/ExperimentDurationEvent.java irrigation/trunk/src/main/java/edu/asu/commons/irrigation/events/FacilitatorEndRoundEvent.java irrigation/trunk/src/main/java/edu/asu/commons/irrigation/events/FileDownloadCompleteEvent.java irrigation/trunk/src/main/java/edu/asu/commons/irrigation/events/FileDownloadedEvent.java irrigation/trunk/src/main/java/edu/asu/commons/irrigation/events/InstructionEnableRequest.java irrigation/trunk/src/main/java/edu/asu/commons/irrigation/events/InvestedTokensEvent.java irrigation/trunk/src/main/java/edu/asu/commons/irrigation/events/QuizCompletedEvent.java irrigation/trunk/src/main/java/edu/asu/commons/irrigation/events/RegistrationEvent.java irrigation/trunk/src/main/java/edu/asu/commons/irrigation/events/RoundStartedEvent.java irrigation/trunk/src/main/java/edu/asu/commons/irrigation/events/SendContributionStatusEvent.java irrigation/trunk/src/main/java/edu/asu/commons/irrigation/events/SendFileProgressEvent.java irrigation/trunk/src/main/java/edu/asu/commons/irrigation/events/ServerGameStateEvent.java irrigation/trunk/src/main/java/edu/asu/commons/irrigation/events/StartDownload.java irrigation/trunk/src/main/java/edu/asu/commons/irrigation/events/TransferFileInformationEvent.java irrigation/trunk/src/main/java/edu/asu/commons/irrigation/facilitator/IrrigationFacilitator.java irrigation/trunk/src/main/java/edu/asu/commons/irrigation/facilitator/IrrigationFacilitatorWindow.java irrigation/trunk/src/main/java/edu/asu/commons/irrigation/server/ClientData.java irrigation/trunk/src/main/java/edu/asu/commons/irrigation/server/GroupDataModel.java irrigation/trunk/src/main/java/edu/asu/commons/irrigation/server/IrrigationPersister.java irrigation/trunk/src/main/java/edu/asu/commons/irrigation/server/IrrigationServer.java irrigation/trunk/src/main/java/edu/asu/commons/irrigation/server/ServerDataModel.java Property changes on: irrigation/trunk/src/main/java/edu/asu/commons/irrigation/client/ActivitySummaryPanel.java ___________________________________________________________________ Added: svn:keywords + Date Id Revision Property changes on: irrigation/trunk/src/main/java/edu/asu/commons/irrigation/client/ActivitySummaryPanelNew.java ___________________________________________________________________ Added: svn:keywords + Date Id Revision Property changes on: irrigation/trunk/src/main/java/edu/asu/commons/irrigation/client/Ball.java ___________________________________________________________________ Added: svn:keywords + Date Id Revision Property changes on: irrigation/trunk/src/main/java/edu/asu/commons/irrigation/client/CanalPanel.java ___________________________________________________________________ Added: svn:keywords + Date Id Revision Property changes on: irrigation/trunk/src/main/java/edu/asu/commons/irrigation/client/CanalPanelAnimation.java ___________________________________________________________________ Added: svn:keywords + Date Id Revision Property changes on: irrigation/trunk/src/main/java/edu/asu/commons/irrigation/client/CanalPanelAnimationNew.java ___________________________________________________________________ Added: svn:keywords + Date Id Revision Modified: irrigation/trunk/src/main/java/edu/asu/commons/irrigation/client/ChartWindowPanel.java =================================================================== --- irrigation/trunk/src/main/java/edu/asu/commons/irrigation/client/ChartWindowPanel.java 2009-10-08 18:29:40 UTC (rev 289) +++ irrigation/trunk/src/main/java/edu/asu/commons/irrigation/client/ChartWindowPanel.java 2009-10-08 22:10:47 UTC (rev 290) @@ -30,7 +30,7 @@ * Original Author: David Gilbert (for Object Refinery Limited); * Contributor(s): -; * - * $Id: ChartWindowPanel.java 127 2009-04-29 21:31:34Z alllee $ + * $Id$ * * Changes * ------- Property changes on: irrigation/trunk/src/main/java/edu/asu/commons/irrigation/client/ChartWindowPanel.java ___________________________________________________________________ Added: svn:keywords + Date Id Revision Modified: irrigation/trunk/src/main/java/edu/asu/commons/irrigation/client/ChartWindowPanelTokenBandwidth.java =================================================================== --- irrigation/trunk/src/main/java/edu/asu/commons/irrigation/client/ChartWindowPanelTokenBandwidth.java 2009-10-08 18:29:40 UTC (rev 289) +++ irrigation/trunk/src/main/java/edu/asu/commons/irrigation/client/ChartWindowPanelTokenBandwidth.java 2009-10-08 22:10:47 UTC (rev 290) @@ -30,7 +30,7 @@ * Original Author: David Gilbert (for Object Refinery Limited); * Contributor(s): -; * - * $Id: ChartWindowPanelTokenBandwidth.java 124 2009-04-23 17:56:22Z alllee $ + * $Id$ * * Changes * ------- Property changes on: irrigation/trunk/src/main/java/edu/asu/commons/irrigation/client/ChartWindowPanelTokenBandwidth.java ___________________________________________________________________ Added: svn:keywords + Date Id Revision Modified: irrigation/trunk/src/main/java/edu/asu/commons/irrigation/client/ChatPanel.java =================================================================== --- irrigation/trunk/src/main/java/edu/asu/commons/irrigation/client/ChatPanel.java 2009-10-08 18:29:40 UTC (rev 289) +++ irrigation/trunk/src/main/java/edu/asu/commons/irrigation/client/ChatPanel.java 2009-10-08 22:10:47 UTC (rev 290) @@ -46,7 +46,7 @@ * not linear. * * @author alllee - * @version $Revision: $ + * @version $Revision$ */ @SuppressWarnings("serial") Property changes on: irrigation/trunk/src/main/java/edu/asu/commons/irrigation/client/ChatPanel.java ___________________________________________________________________ Added: svn:keywords + Date Id Revision Property changes on: irrigation/trunk/src/main/java/edu/asu/commons/irrigation/client/ExperimentGameWindow.java ___________________________________________________________________ Added: svn:keywords + Date Id Revision Property changes on: irrigation/trunk/src/main/java/edu/asu/commons/irrigation/client/Gate.java ___________________________________________________________________ Added: svn:keywords + Date Id Revision Modified: irrigation/trunk/src/main/java/edu/asu/commons/irrigation/client/IrrigationClient.java =================================================================== --- irrigation/trunk/src/main/java/edu/asu/commons/irrigation/client/IrrigationClient.java 2009-10-08 18:29:40 UTC (rev 289) +++ irrigation/trunk/src/main/java/edu/asu/commons/irrigation/client/IrrigationClient.java 2009-10-08 22:10:47 UTC (rev 290) @@ -20,15 +20,15 @@ import edu.asu.commons.irrigation.events.BeginCommunicationRequest; import edu.asu.commons.irrigation.events.DisplaySubmitTokenRequest; import edu.asu.commons.irrigation.events.EndRoundEvent; -import edu.asu.commons.irrigation.events.GateOpenedEvent; +import edu.asu.commons.irrigation.events.OpenGateEvent; import edu.asu.commons.irrigation.events.InstructionEnableRequest; import edu.asu.commons.irrigation.events.InvestedTokensEvent; import edu.asu.commons.irrigation.events.RegistrationEvent; import edu.asu.commons.irrigation.events.RoundStartedEvent; import edu.asu.commons.irrigation.events.SendContributionStatusEvent; import edu.asu.commons.irrigation.events.SendFileProgressEvent; -import edu.asu.commons.irrigation.events.StartPausedEvent; -import edu.asu.commons.irrigation.events.StopDownloadEvent; +import edu.asu.commons.irrigation.events.PauseEvent; +import edu.asu.commons.irrigation.events.CloseGateEvent; import edu.asu.commons.irrigation.server.ClientData; import edu.asu.commons.net.ClientDispatcher; import edu.asu.commons.net.DispatcherFactory; @@ -143,7 +143,7 @@ public void transmitTokenContributed(int tokens) { InvestedTokensEvent transferTokenBandwidthEvent = new InvestedTokensEvent( getId(), tokens); - clientDispatcher.transmit(transferTokenBandwidthEvent); + transmit(transferTokenBandwidthEvent); } /** @@ -152,22 +152,21 @@ * * @param fileNo */ - public void startDownload(String fileNo) { - GateOpenedEvent startDownloadEvent = new GateOpenedEvent(getId()); - startDownloadEvent.setFileNumber(fileNo); - clientDispatcher.transmit(startDownloadEvent); + public void openGate(String fileNo) { + OpenGateEvent openGateEvent = new OpenGateEvent(getId()); + transmit(openGateEvent); } - public void stopDownload(String fileNo) { - StopDownloadEvent stopDownloadEvent = new StopDownloadEvent(getId()); - stopDownloadEvent.setFileNumber(fileNo); - clientDispatcher.transmit(stopDownloadEvent); + public void closeGate(String fileNo) { + CloseGateEvent closeGateEvent = new CloseGateEvent(getId()); + closeGateEvent.setFileNumber(fileNo); + transmit(closeGateEvent); } public void startPause(String fileNo) { - StartPausedEvent startPausedEvent = new StartPausedEvent(getId()); + PauseEvent startPausedEvent = new PauseEvent(getId()); startPausedEvent.setFileNumber(fileNo); - clientDispatcher.transmit(startPausedEvent); + transmit(startPausedEvent); } public void transmit(Event event) { Property changes on: irrigation/trunk/src/main/java/edu/asu/commons/irrigation/client/IrrigationClient.java ___________________________________________________________________ Added: svn:keywords + Date Id Revision Property changes on: irrigation/trunk/src/main/java/edu/asu/commons/irrigation/client/IrrigationClientGameState.java ___________________________________________________________________ Added: svn:keywords + Date Id Revision Modified: irrigation/trunk/src/main/java/edu/asu/commons/irrigation/client/IrrigationGameWindow.java =================================================================== --- irrigation/trunk/src/main/java/edu/asu/commons/irrigation/client/IrrigationGameWindow.java 2009-10-08 18:29:40 UTC (rev 289) +++ irrigation/trunk/src/main/java/edu/asu/commons/irrigation/client/IrrigationGameWindow.java 2009-10-08 22:10:47 UTC (rev 290) @@ -376,7 +376,7 @@ * time" + System.currentTimeMillis() / 1000); */ - client.startDownload(fileNo); + client.openGate(fileNo); disableAllFiles(); initEnable(); @@ -391,7 +391,7 @@ // TODO Auto-generated method stub int i; for (i = 0; i < TOTAL_CROPS_AVAILABLE; i++) { - if (isDownloaded[i] == false && fileClicked == false && !clientData.isDownloading()) { + if (isDownloaded[i] == false && fileClicked == false && !clientData.isGateOpen()) { (getFile(i)).setBackground(new Color(186, 226, 237)); (getFile(i)).setEnabled(true); } @@ -795,7 +795,7 @@ pauseDownload.setText("Pause"); // StopDownload.setEnabled(true); disableAllFiles(); - client.startDownload(fileNo); + client.openGate(fileNo); } } }); @@ -1072,7 +1072,7 @@ updateFileFinished(clientData.getDownloadListArray()); } else - if(clientData.isDownloading() || clientData.isPaused()){ + if(clientData.isGateOpen() || clientData.isPaused()){ disableAllFiles(); initEnable(); } Property changes on: irrigation/trunk/src/main/java/edu/asu/commons/irrigation/client/IrrigationGameWindow.java ___________________________________________________________________ Added: svn:keywords + Date Id Revision 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-08 18:29:40 UTC (rev 289) +++ irrigation/trunk/src/main/java/edu/asu/commons/irrigation/client/MainIrrigationGameWindow.java 2009-10-08 22:10:47 UTC (rev 290) @@ -257,14 +257,14 @@ else{ scoreBoxPanel.update(clientData); } - if(clientData.isDownloading() == true){ + if(clientData.isGateOpen() == true){ upperPanel.openGates(clientData.getPriority()); } else if(clientData.isPaused() == true){ upperPanel.closeGates(clientData.getPriority()); } - if(clientData.isStopped() == true){ + if(clientData.isGateClosed() == true){ upperPanel.closeGates(clientData.getPriority()); } } Property changes on: irrigation/trunk/src/main/java/edu/asu/commons/irrigation/client/MainIrrigationGameWindow.java ___________________________________________________________________ Added: svn:keywords + Date Id Revision Modified: irrigation/trunk/src/main/java/edu/asu/commons/irrigation/client/MiddleScorePanel.java =================================================================== --- irrigation/trunk/src/main/java/edu/asu/commons/irrigation/client/MiddleScorePanel.java 2009-10-08 18:29:40 UTC (rev 289) +++ irrigation/trunk/src/main/java/edu/asu/commons/irrigation/client/MiddleScorePanel.java 2009-10-08 22:10:47 UTC (rev 290) @@ -164,7 +164,7 @@ filesDownloadedText.setText(new Integer(clientData.getCropsGrown()).toString()); tokensText.setText(new Integer(clientData.getTotalTokensEarned()).toString()); - if(clientData.isDownloading() == true && clientData.getAvailableFlowCapacity() > 0) + if(clientData.isGateOpen() == true && clientData.getAvailableFlowCapacity() > 0) fileLabel.setVisible(true); else fileLabel.setVisible(false); Property changes on: irrigation/trunk/src/main/java/edu/asu/commons/irrigation/client/MiddleScorePanel.java ___________________________________________________________________ Added: svn:keywords + Date Id Revision Property changes on: irrigation/trunk/src/main/java/edu/asu/commons/irrigation/client/MiddleWindowPanel.java ___________________________________________________________________ Added: svn:keywords + Date Id Revision Property changes on: irrigation/trunk/src/main/java/edu/asu/commons/irrigation/client/PieChart.java ___________________________________________________________________ Added: svn:keywords + Date Id Revision Property changes on: irrigation/trunk/src/main/java/edu/asu/commons/irrigation/client/ScoreBoxPanel.java ___________________________________________________________________ Added: svn:keywords + Date Id Revision Modified: irrigation/trunk/src/main/java/edu/asu/commons/irrigation/conf/RoundConfiguration.java =================================================================== --- irrigation/trunk/src/main/java/edu/asu/commons/irrigation/conf/RoundConfiguration.java 2009-10-08 18:29:40 UTC (rev 289) +++ irrigation/trunk/src/main/java/edu/asu/commons/irrigation/conf/RoundConfiguration.java 2009-10-08 22:10:47 UTC (rev 290) @@ -8,6 +8,15 @@ import edu.asu.commons.conf.ExperimentRoundParameters; import edu.asu.commons.util.Duration; +/** + * $Id$ + * + * Configuration parameters for a given round in the irrigation experiment. + * Provides reward functions, etc. + * + * @author <a href='mailto:All...@as...'>Allen Lee</a> + * @version $Rev$ + */ public class RoundConfiguration extends ExperimentRoundParameters.Base<ServerConfiguration> { private static final long serialVersionUID = -5053624886508752562L; @@ -22,15 +31,6 @@ super(resource); } - /** - * used to get the file Size given the File number from the current - * configuration file - */ - public int getFileSize(String fileNumber) { - // FIXME: lift constants - return getIntProperty(fileNumber, 250); - } - public int getMaximumClientFlowCapacity() { return getIntProperty("max-client-flow-capacity", 25); } @@ -47,12 +47,6 @@ return getIntProperty("max-canal-flow-capacity", 40); } - public double getFilesDownloadAwardConversion() { - // FIXME: change String key to something more meaningful - return getDoubleProperty("FilesDownload-Award-Conversion", 1.0d); - // return (double) Integer.parseInt(properties.getProperty("FilesDownload-Award-Conversion")); - } - public int getMaximumTokenContribution() { return getIntProperty("max-token-contribution", 10); } @@ -61,28 +55,29 @@ * returns maximum number of tokens that could have been contributed * @return */ - public int getMaximumTotalTokenContribution(){ + public int getMaximumTotalTokenContribution() { return getMaximumTokenContribution() * getClientsPerGroup(); } public int getMaximumInfrastructureEfficiency() { - return getIntProperty("maximum-infrastructure-efficiency", 100); + return getIntProperty("max-infrastructure-efficiency", 100); } - public int getBtmax() { - return getIntProperty("Btmax"); + public double getMaximumIndividualFlowCapacity() { + return getDoubleProperty("max-individual-flow-capacity", 20.0d); } public boolean isPracticeRound() { return getBooleanProperty("practice-round"); } + // FIXME: horrible hack.. figure out why this is here again. public boolean isSecondPracticeRound(){ return getBooleanProperty("second-practice-round",false); } public int getClientsPerGroup() { - return getIntProperty("clients-per-group", 0); + return getIntProperty("clients-per-group", 5); } /** @@ -150,30 +145,6 @@ return getIntProperty("communication-duration", 40); } - public double getAlpha() { - return getDoubleProperty("TBM-alpha", 0.0d); - } - - public double getA() { - return getDoubleProperty("TBM-a", 0.0d); - } - - public double getB() { - return getDoubleProperty("TBM-b", 0.0d); - } - - public double getAlphaAward() { - return getDoubleProperty("FAM-alpha", 0.0d); - } - - public double getA_award() { - return getDoubleProperty("FAM-a", 0.0d); - } - - public double getB_award() { - return getDoubleProperty("FAM-b", 0.0d); - } - /** * Returns the duration of the round in seconds. Set to default of 50 seconds per round. */ Property changes on: irrigation/trunk/src/main/java/edu/asu/commons/irrigation/conf/RoundConfiguration.java ___________________________________________________________________ Added: svn:keywords + Date Id Revision Modified: irrigation/trunk/src/main/java/edu/asu/commons/irrigation/conf/ServerConfiguration.java =================================================================== --- irrigation/trunk/src/main/java/edu/asu/commons/irrigation/conf/ServerConfiguration.java 2009-10-08 18:29:40 UTC (rev 289) +++ irrigation/trunk/src/main/java/edu/asu/commons/irrigation/conf/ServerConfiguration.java 2009-10-08 22:10:47 UTC (rev 290) @@ -7,7 +7,7 @@ import edu.asu.commons.conf.ExperimentConfiguration; /** - * $Id: ServerConfiguration.java 131 2009-04-30 01:52:21Z alllee $ + * $Id$ * * Contains the know-how for parsing and programmatically accessing the forager * server's configuration file properties. The forager server's config file @@ -23,7 +23,7 @@ * @author <a href='mailto:All...@as...'>Allen Lee</a> * @see edu.asu.csid.irrigation.RoundConfiguration, * edu.asu.csid.conf.ExperimentConfiguration - * @version $Revision: 131 $ + * @version $Revision$ */ public class ServerConfiguration extends ExperimentConfiguration.Base<RoundConfiguration> { @@ -34,8 +34,6 @@ private final static String DEFAULT_LOG_FILE_DESTINATION = "irrigation.log"; - //FIXME: can move this parameter to the configuration files - public ServerConfiguration() { super(); } @@ -57,9 +55,8 @@ } @Override - protected RoundConfiguration createConfiguration( - String roundConfigurationResource) { - return new RoundConfiguration(roundConfigurationResource); + protected RoundConfiguration createConfiguration(String roundConfigurationFile) { + return new RoundConfiguration(roundConfigurationFile); } @Override @@ -70,42 +67,42 @@ /** * getting the general welcome instructions * + * FIXME: Refactor this method. + * * @param instructionNumber * @param pagesTraversed * @return */ public String getGeneralInstructions(int instructionNumber, - int pagesTraversed,int clientPriority) { + int pagesTraversed, int clientPosition) { String position = ""; String undisruptedBandwidthInstruction = ""; - //System.out.println("Instruction Nnumber :"+instructionNumber+" Pages Traversed :"+pagesTraversed); if (instructionNumber != 11) { if (instructionNumber > pagesTraversed) { if (instructionNumber == 4) { //instructionNumber = getNewInstructionNumber(clientPriority); - position = "\n YOUR POSITION : "+getPosition(clientPriority); + position = "\n Your position : "+toPriorityString(clientPosition); } if(instructionNumber == 5 && isUndisruptedBandwidth()){ undisruptedBandwidthInstruction=assistant.getStringProperty("general-instructions"+"-undisruptedBandwidth"); } - - return (position+assistant.getStringProperty("general-instructions" - + instructionNumber - )+undisruptedBandwidthInstruction+assistant - .getStringProperty("general-instructionsq" - + instructionNumber)); - } else { + return (position + + assistant.getStringProperty("general-instructions" + instructionNumber) + + undisruptedBandwidthInstruction + + assistant.getStringProperty("general-instructionsq" + instructionNumber)); + } + else { if (instructionNumber == 4) { //instructionNumber = getNewInstructionNumber(clientPriority); - position = "\n YOUR POSITION : "+getPosition(clientPriority); + position = "\n YOUR POSITION : "+toPriorityString(clientPosition); } if(instructionNumber == 5 && isUndisruptedBandwidth()){ undisruptedBandwidthInstruction=assistant.getStringProperty("general-instructions"+"-undisruptedBandwidth"); } - return position+assistant.getStringProperty("general-instructions" - + instructionNumber, - "<b>No instructions available for this round</b>")+undisruptedBandwidthInstruction; + return (position + + assistant.getStringProperty("general-instructions" + instructionNumber, "<b>No instructions available for this round</b>") + + undisruptedBandwidthInstruction); } } @@ -115,27 +112,33 @@ "<b>No instructions available for this round</b>"); } + + private final static String[] PRIORITY_STRINGS = { "A", "B", "C", "D", "E" }; - private String getPosition(int clientPriority) { - // TODO Auto-generated method stub - switch(clientPriority){ - case 0 : return "A"; - case 1 : return "B"; - case 2: return "C"; - case 3: return "D"; - case 4: return "E"; - } - return "Position not found"; + private String toPriorityString(int clientPriority) { + // bounds check + if (clientPriority >= 0 && clientPriority < PRIORITY_STRINGS.length) { + return PRIORITY_STRINGS[clientPriority]; + } +// +// switch(clientPriority){ +// case 0 : return "A"; +// case 1 : return "B"; +// case 2: return "C"; +// case 3: return "D"; +// case 4: return "E"; +// } + return "Position not found"; } //overriding method isLastRound - public boolean isLastRound(){ - System.out.println("The Current round Number is :"+getCurrentRoundNumber()); - if(getCurrentRoundNumber() == assistant.getIntProperty("number-of-rounds")-1) - return true; - else - return false; - } +// public boolean isLastRound(){ +// System.out.println("The Current round Number is :"+getCurrentRoundNumber()); +// if(getCurrentRoundNumber() == assistant.getIntProperty("number-of-rounds")-1) +// return true; +// else +// return false; +// } public boolean isUndisruptedBandwidth(){ if(assistant.getBooleanProperty("undisrupted-bandwidth")== true) @@ -143,26 +146,10 @@ return false; } - private int getNewInstructionNumber(int clientPriority) { - // TODO Auto-generated method stub - switch(clientPriority){ - case 0 : return 40; - - case 1: return 41; - - } - //FIXME: AT present just returning case 1 's case when clientPriority is 2,3,4. Need to change this. - if(clientPriority == 2 || clientPriority == 3 || clientPriority == 4){ - return 41; - } - return -1; + public double getShowUpPayment() { + return assistant.getDoubleProperty("showup-payment", 5.0d); } - public String getShowUpFees() { - // TODO Auto-generated method stub - return assistant.getStringProperty("showup-fees", "5"); - } - public Map<String, String> getQuizAnswers() { //System.out.println("I am in the beginning of getquiz"); Properties properties = assistant.getProperties(); Property changes on: irrigation/trunk/src/main/java/edu/asu/commons/irrigation/conf/ServerConfiguration.java ___________________________________________________________________ Added: svn:keywords + Date Id Revision Property changes on: irrigation/trunk/src/main/java/edu/asu/commons/irrigation/events/BeginCommunicationRequest.java ___________________________________________________________________ Added: svn:keywords + Date Id Revision Property changes on: irrigation/trunk/src/main/java/edu/asu/commons/irrigation/events/ClientUpdateEvent.java ___________________________________________________________________ Added: svn:keywords + Date Id Revision Copied: irrigation/trunk/src/main/java/edu/asu/commons/irrigation/events/CloseGateEvent.java (from rev 288, irrigation/trunk/src/main/java/edu/asu/commons/irrigation/events/StopDownloadEvent.java) =================================================================== --- irrigation/trunk/src/main/java/edu/asu/commons/irrigation/events/CloseGateEvent.java (rev 0) +++ irrigation/trunk/src/main/java/edu/asu/commons/irrigation/events/CloseGateEvent.java 2009-10-08 22:10:47 UTC (rev 290) @@ -0,0 +1,17 @@ +package edu.asu.commons.irrigation.events; + +import edu.asu.commons.net.Identifier; + +/** + * @author Sanket + * + */ +public class CloseGateEvent extends TransferFileInformationEvent { + + private static final long serialVersionUID = -6932559955912875464L; + + public CloseGateEvent(Identifier id) { + super(id); + } + +} Property changes on: irrigation/trunk/src/main/java/edu/asu/commons/irrigation/events/CloseGateEvent.java ___________________________________________________________________ Added: svn:keywords + Date Id Revision Property changes on: irrigation/trunk/src/main/java/edu/asu/commons/irrigation/events/DisplaySubmitTokenRequest.java ___________________________________________________________________ Added: svn:keywords + Date Id Revision Property changes on: irrigation/trunk/src/main/java/edu/asu/commons/irrigation/events/EndRoundEvent.java ___________________________________________________________________ Added: svn:keywords + Date Id Revision Property changes on: irrigation/trunk/src/main/java/edu/asu/commons/irrigation/events/ExperimentDurationEvent.java ___________________________________________________________________ Added: svn:keywords + Date Id Revision Property changes on: irrigation/trunk/src/main/java/edu/asu/commons/irrigation/events/FacilitatorEndRoundEvent.java ___________________________________________________________________ Added: svn:keywords + Date Id Revision Property changes on: irrigation/trunk/src/main/java/edu/asu/commons/irrigation/events/FileDownloadCompleteEvent.java ___________________________________________________________________ Added: svn:keywords + Date Id Revision Property changes on: irrigation/trunk/src/main/java/edu/asu/commons/irrigation/events/FileDownloadedEvent.java ___________________________________________________________________ Added: svn:keywords + Date Id Revision Deleted: irrigation/trunk/src/main/java/edu/asu/commons/irrigation/events/GateOpenedEvent.java =================================================================== --- irrigation/trunk/src/main/java/edu/asu/commons/irrigation/events/GateOpenedEvent.java 2009-10-08 18:29:40 UTC (rev 289) +++ irrigation/trunk/src/main/java/edu/asu/commons/irrigation/events/GateOpenedEvent.java 2009-10-08 22:10:47 UTC (rev 290) @@ -1,17 +0,0 @@ -package edu.asu.commons.irrigation.events; - -import edu.asu.commons.net.Identifier; - -/** - * @author Sanket - * - */ -public class GateOpenedEvent extends TransferFileInformationEvent { - - private static final long serialVersionUID = -4902131375099741851L; - - public GateOpenedEvent(Identifier id) { - super(id); - } - -} Property changes on: irrigation/trunk/src/main/java/edu/asu/commons/irrigation/events/InstructionEnableRequest.java ___________________________________________________________________ Added: svn:keywords + Date Id Revision Property changes on: irrigation/trunk/src/main/java/edu/asu/commons/irrigation/events/InvestedTokensEvent.java ___________________________________________________________________ Added: svn:keywords + Date Id Revision Copied: irrigation/trunk/src/main/java/edu/asu/commons/irrigation/events/OpenGateEvent.java (from rev 288, irrigation/trunk/src/main/java/edu/asu/commons/irrigation/events/GateOpenedEvent.java) =================================================================== --- irrigation/trunk/src/main/java/edu/asu/commons/irrigation/events/OpenGateEvent.java (rev 0) +++ irrigation/trunk/src/main/java/edu/asu/commons/irrigation/events/OpenGateEvent.java 2009-10-08 22:10:47 UTC (rev 290) @@ -0,0 +1,18 @@ +package edu.asu.commons.irrigation.events; + +import edu.asu.commons.event.AbstractPersistableEvent; +import edu.asu.commons.net.Identifier; + +/** + * + * + */ +public class OpenGateEvent extends AbstractPersistableEvent { + + private static final long serialVersionUID = -4902131375099741851L; + + public OpenGateEvent(Identifier id) { + super(id); + } + +} Property changes on: irrigation/trunk/src/main/java/edu/asu/commons/irrigation/events/OpenGateEvent.java ___________________________________________________________________ Added: svn:keywords + Date Id Revision Copied: irrigation/trunk/src/main/java/edu/asu/commons/irrigation/events/PauseEvent.java (from rev 288, irrigation/trunk/src/main/java/edu/asu/commons/irrigation/events/StartPausedEvent.java) =================================================================== --- irrigation/trunk/src/main/java/edu/asu/commons/irrigation/events/PauseEvent.java (rev 0) +++ irrigation/trunk/src/main/java/edu/asu/commons/irrigation/events/PauseEvent.java 2009-10-08 22:10:47 UTC (rev 290) @@ -0,0 +1,21 @@ +package edu.asu.commons.irrigation.events; + +import edu.asu.commons.net.Identifier; + + + +/** + * @author Sanket + * + */ +public class PauseEvent extends TransferFileInformationEvent { + + private static final long serialVersionUID = -6518246719469415026L; + + public PauseEvent(Identifier id) { + super(id); + } + + + +} Property changes on: irrigation/trunk/src/main/java/edu/asu/commons/irrigation/events/PauseEvent.java ___________________________________________________________________ Added: svn:keywords + Date Id Revision Property changes on: irrigation/trunk/src/main/java/edu/asu/commons/irrigation/events/QuizCompletedEvent.java ___________________________________________________________________ Added: svn:keywords + Date Id Revision Property changes on: irrigation/trunk/src/main/java/edu/asu/commons/irrigation/events/RegistrationEvent.java ___________________________________________________________________ Added: svn:keywords + Date Id Revision Property changes on: irrigation/trunk/src/main/java/edu/asu/commons/irrigation/events/RoundStartedEvent.java ___________________________________________________________________ Added: svn:keywords + Date Id Revision Property changes on: irrigation/trunk/src/main/java/edu/asu/commons/irrigation/events/SendContributionStatusEvent.java ___________________________________________________________________ Added: svn:keywords + Date Id Revision Property changes on: irrigation/trunk/src/main/java/edu/asu/commons/irrigation/events/SendFileProgressEvent.java ___________________________________________________________________ Added: svn:keywords + Date Id Revision Property changes on: irrigation/trunk/src/main/java/edu/asu/commons/irrigation/events/ServerGameStateEvent.java ___________________________________________________________________ Added: svn:keywords + Date Id Revision Property changes on: irrigation/trunk/src/main/java/edu/asu/commons/irrigation/events/StartDownload.java ___________________________________________________________________ Added: svn:keywords + Date Id Revision Deleted: irrigation/trunk/src/main/java/edu/asu/commons/irrigation/events/StartPausedEvent.java =================================================================== --- irrigation/trunk/src/main/java/edu/asu/commons/irrigation/events/StartPausedEvent.java 2009-10-08 18:29:40 UTC (rev 289) +++ irrigation/trunk/src/main/java/edu/asu/commons/irrigation/events/StartPausedEvent.java 2009-10-08 22:10:47 UTC (rev 290) @@ -1,21 +0,0 @@ -package edu.asu.commons.irrigation.events; - -import edu.asu.commons.net.Identifier; - - - -/** - * @author Sanket - * - */ -public class StartPausedEvent extends TransferFileInformationEvent { - - private static final long serialVersionUID = -6518246719469415026L; - - public StartPausedEvent(Identifier id) { - super(id); - } - - - -} Deleted: irrigation/trunk/src/main/java/edu/asu/commons/irrigation/events/StopDownloadEvent.java =================================================================== --- irrigation/trunk/src/main/java/edu/asu/commons/irrigation/events/StopDownloadEvent.java 2009-10-08 18:29:40 UTC (rev 289) +++ irrigation/trunk/src/main/java/edu/asu/commons/irrigation/events/StopDownloadEvent.java 2009-10-08 22:10:47 UTC (rev 290) @@ -1,17 +0,0 @@ -package edu.asu.commons.irrigation.events; - -import edu.asu.commons.net.Identifier; - -/** - * @author Sanket - * - */ -public class StopDownloadEvent extends TransferFileInformationEvent { - - private static final long serialVersionUID = -6932559955912875464L; - - public StopDownloadEvent(Identifier id) { - super(id); - } - -} Property changes on: irrigation/trunk/src/main/java/edu/asu/commons/irrigation/events/TransferFileInformationEvent.java ___________________________________________________________________ Added: svn:keywords + Date Id Revision Property changes on: irrigation/trunk/src/main/java/edu/asu/commons/irrigation/facilitator/IrrigationFacilitator.java ___________________________________________________________________ Added: svn:keywords + Date Id Revision Modified: irrigation/trunk/src/main/java/edu/asu/commons/irrigation/facilitator/IrrigationFacilitatorWindow.java =================================================================== --- irrigation/trunk/src/main/java/edu/asu/commons/irrigation/facilitator/IrrigationFacilitatorWindow.java 2009-10-08 18:29:40 UTC (rev 289) +++ irrigation/trunk/src/main/java/edu/asu/commons/irrigation/facilitator/IrrigationFacilitatorWindow.java 2009-10-08 22:10:47 UTC (rev 290) @@ -181,7 +181,7 @@ clientId.toString(), data.getTotalTokensEarned(), data.getTotalTokensEarned() * model.getCurrentConfiguration().getDollarsPerToken(), - data.getTotalTokens() * model.getCurrentConfiguration().getDollarsPerToken()+Double.parseDouble(facilitator.getConfiguration().getShowUpFees()))); + data.getTotalTokens() * model.getCurrentConfiguration().getDollarsPerToken()+ facilitator.getConfiguration().getShowUpPayment())); } builder.append("</tbody></table><hr>"); //FIXME: Could not understand how to evaluate .isLastRound(), hence using the Property changes on: irrigation/trunk/src/main/java/edu/asu/commons/irrigation/facilitator/IrrigationFacilitatorWindow.java ___________________________________________________________________ Added: svn:keywords + Date Id Revision Modified: irrigation/trunk/src/main/java/edu/asu/commons/irrigation/server/ClientData.java =================================================================== --- irrigation/trunk/src/main/java/edu/asu/commons/irrigation/server/ClientData.java 2009-10-08 18:29:40 UTC (rev 289) +++ irrigation/trunk/src/main/java/edu/asu/commons/irrigation/server/ClientData.java 2009-10-08 22:10:47 UTC (rev 290) @@ -20,7 +20,7 @@ * minus tokens subtracted by sanctioning others * * @author <a href='ano...@gm...'>Allen Lee</a>, Deepali Bhagvat - * @version $Revision: 131 $ + * @version $Revision$ */ public class ClientData implements Serializable { @@ -46,7 +46,7 @@ private int cropsGrown = 0; // maximum available bandwidth - private double maximumDeliveryBandwidth; + private double maximumIndividualFlowCapacity; /** * current download speed */ @@ -64,11 +64,8 @@ private boolean paused = false; - // FIXME: this is just the negation of downloading, we do not need two flags for this. - private boolean stopped = true; + private boolean gateOpen = false; - private boolean downloading = false; - public ClientData(Identifier id) { this.id = id; } @@ -77,12 +74,12 @@ return paused; } - public boolean isStopped(){ - return stopped; + public boolean isGateClosed(){ + return ! gateOpen; } - public boolean isDownloading(){ - return downloading; + public boolean isGateOpen(){ + return gateOpen; } // cap on the size of the entire stream (e.g,. 50 kbps) @@ -91,12 +88,12 @@ } // cap on the size of the stream that can be delivered to the client (e.g., 25 kbps) - public void setMaximumDeliveryBandwidth(double deliveryBandwidth){ - this.maximumDeliveryBandwidth = deliveryBandwidth; + public void setMaximumIndividualFlowCapacity(double deliveryBandwidth){ + this.maximumIndividualFlowCapacity = deliveryBandwidth; } - public double getMaximumDeliveryBandwidth(){ - return maximumDeliveryBandwidth; + public double getMaximumIndividualFlowCapacity(){ + return maximumIndividualFlowCapacity; } /** @@ -126,18 +123,6 @@ return fileNumber; } - /** - * Gets and sets the size of the file - * @param fileSize - */ - public void setFileSize(int fileSize){ - this.fileSize = fileSize; - } - - public double getFileSize(){ - return fileSize; - } - public double getPercentFileDownload(){ return percentFileDownloaded; } @@ -148,21 +133,23 @@ * that the users are allowed to do. */ - public void setStartDownload(){ - downloading = true; + public void openGate(){ + gateOpen = true; paused = false; - stopped = false; } public void setPaused(){ paused = true; - downloading = false; - stopped = false; + gateOpen = false; } + + public void unpause() { + paused = false; + gateOpen = true; + } - public void setStoppedDownloading(){ - stopped = true; - downloading = false; + public void closeGate(){ + gateOpen = false; paused = false; } @@ -197,7 +184,7 @@ */ public void reset() { resetFileInformation(); - setStoppedDownloading(); + closeGate(); contributedTokens = 0; //adding number of files to be downloaded = 0 per round cropsGrown = 0; @@ -235,7 +222,7 @@ public void init(double availableBandwidth) { resetFileInformation(); //maximumDeliveryBandwidth = getRoundConfiguration().getBtmax()/getRoundConfiguration().getClientsPerGroup(); - maximumDeliveryBandwidth = getRoundConfiguration().getBtmax()/2; + maximumIndividualFlowCapacity = getRoundConfiguration().getMaximumIndividualFlowCapacity(); //currentBandwidth = totalContributedBandwidth; this.availableFlowCapacity = availableBandwidth; } @@ -245,7 +232,7 @@ fileNumber = ""; downloadedFileSize = 0; percentFileDownloaded = 0; - setStoppedDownloading(); + closeGate(); } public void award() { @@ -310,7 +297,7 @@ *as processDownload function */ public void allocateFlowCapacity(double availableBandwidth) { - assert downloading; + assert gateOpen; fileDownloaded = false; incrementFileDownloadSize(); } Property changes on: irrigation/trunk/src/main/java/edu/asu/commons/irrigation/server/ClientData.java ___________________________________________________________________ Added: svn:keywords + Date Id Revision 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-08 18:29:40 UTC (rev 289) +++ irrigation/trunk/src/main/java/edu/asu/commons/irrigation/server/GroupDataModel.java 2009-10-08 22:10:47 UTC (rev 290) @@ -192,10 +192,10 @@ public void allocateFlowCapacity(ClientData clientData) { - if (currentlyAvailableFlowCapacity >= clientData.getMaximumDeliveryBandwidth()) { - currentlyAvailableFlowCapacity -= clientData.getMaximumDeliveryBandwidth(); + if (currentlyAvailableFlowCapacity >= clientData.getMaximumIndividualFlowCapacity()) { + currentlyAvailableFlowCapacity -= clientData.getMaximumIndividualFlowCapacity(); // setAvailableBandwidth(clientData.getTotalContributedBandwidth() - clientData.getDeliveryBandwidth()); - clientData.setAvailableFlowCapacity(clientData.getMaximumDeliveryBandwidth()); + clientData.setAvailableFlowCapacity(clientData.getMaximumIndividualFlowCapacity()); } else { clientData.setAvailableFlowCapacity(currentlyAvailableFlowCapacity); Property changes on: irrigation/trunk/src/main/java/edu/asu/commons/irrigation/server/GroupDataModel.java ___________________________________________________________________ Added: svn:keywords + Date Id Revision Property changes on: irrigation/trunk/src/main/java/edu/asu/commons/irrigation/server/IrrigationPersister.java ___________________________________________________________________ Added: svn:keywords + Date Id Revision 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-08 18:29:40 UTC (rev 289) +++ irrigation/trunk/src/main/java/edu/asu/commons/irrigation/server/IrrigationServer.java 2009-10-08 22:10:47 UTC (rev 290) @@ -22,7 +22,7 @@ import edu.asu.commons.irrigation.events.DisplaySubmitTokenRequest; import edu.asu.commons.irrigation.events.EndRoundEvent; import edu.asu.commons.irrigation.events.FacilitatorEndRoundEvent; -import edu.asu.commons.irrigation.events.GateOpenedEvent; +import edu.asu.commons.irrigation.events.OpenGateEvent; import edu.asu.commons.irrigation.events.InstructionEnableRequest; import edu.asu.commons.irrigation.events.InvestedTokensEvent; import edu.asu.commons.irrigation.events.QuizCompletedEvent; @@ -30,8 +30,8 @@ import edu.asu.commons.irrigation.events.RoundStartedEvent; import edu.asu.commons.irrigation.events.SendContributionStatusEvent; import edu.asu.commons.irrigation.events.SendFileProgressEvent; -import edu.asu.commons.irrigation.events.StartPausedEvent; -import edu.asu.commons.irrigation.events.StopDownloadEvent; +import edu.asu.commons.irrigation.events.PauseEvent; +import edu.asu.commons.irrigation.events.CloseGateEvent; import edu.asu.commons.net.Dispatcher; import edu.asu.commons.net.Identifier; import edu.asu.commons.net.event.ConnectionEvent; @@ -39,12 +39,12 @@ import edu.asu.commons.util.Duration; /** - * $Id: IrrigationServer.java 129 2009-04-29 23:38:45Z alllee $ + * $Id$ * * Main entry point for the irrigation experiment server. * * @author Sanket Joshi, <a href='All...@as...'>Allen Lee</a> - * @version $Revision: 129 $ + * @version $Revision$ */ public class IrrigationServer extends AbstractExperiment<ServerConfiguration> { @@ -220,22 +220,19 @@ } } }); - addEventProcessor(new EventTypeProcessor<GateOpenedEvent>(GateOpenedEvent.class) { - public void handle(GateOpenedEvent event) { + addEventProcessor(new EventTypeProcessor<OpenGateEvent>(OpenGateEvent.class) { + public void handle(OpenGateEvent event) { ClientData clientData = clients.get(event.getId()); - String fileNumber = event.getFileNumber(); - clientData.setFileNumber(fileNumber); - clientData.setFileSize(getRoundConfiguration().getFileSize(fileNumber)); - clientData.setStartDownload(); + clientData.openGate(); } }); - addEventProcessor(new EventTypeProcessor<StopDownloadEvent>(StopDownloadEvent.class) { - public void handle(StopDownloadEvent event) { - clients.get(event.getId()).setStoppedDownloading(); + addEventProcessor(new EventTypeProcessor<CloseGateEvent>(CloseGateEvent.class) { + public void handle(CloseGateEvent event) { + clients.get(event.getId()).closeGate(); } }); - addEventProcessor(new EventTypeProcessor<StartPausedEvent>(StartPausedEvent.class) { - public void handle(StartPausedEvent event) { + addEventProcessor(new EventTypeProcessor<PauseEvent>(PauseEvent.class) { + public void handle(PauseEvent event) { clients.get(event.getId()).setPaused(); } }); @@ -298,12 +295,12 @@ if(clientData.getAvailableFlowCapacity()<=0 && getConfiguration().isUndisruptedBandwidth()){ clientData.init(group.getCurrentlyAvailableFlowCapacity()); } - if (clientData.isDownloading()) { + if (clientData.isGateOpen()) { //System.out.println("Downloading file"+clientData.getFileNumber()+"Current time"+System.currentTimeMillis()/1000); group.allocateFlowCapacity(clientData); } - else if (clientData.isStopped()) { + else if (clientData.isGateClosed()) { clientData.init(group.getCurrentlyAvailableFlowCapacity()); } else if (clientData.isPaused()) { Property changes on: irrigation/trunk/src/main/java/edu/asu/commons/irrigation/server/IrrigationServer.java ___________________________________________________________________ Added: svn:keywords + Date Id Revision Property changes on: irrigation/trunk/src/main/java/edu/asu/commons/irrigation/server/ServerDataModel.java ___________________________________________________________________ Added: svn:keywords + Date Id Revision Added: irrigation/trunk/src/main/resources/configuration/asu-fall-2009/irrigation.xml =================================================================== --- irrigation/trunk/src/main/resources/configuration/asu-fall-2009/irrigation.xml (rev 0) +++ irrigation/trunk/src/main/resources/configuration/asu-fall-2009/irrigation.xml 2009-10-08 22:10:47 UTC (rev 290) @@ -0,0 +1,620 @@ +<?xml version="1.0" encoding="UTF-8"?> +<!DOCTYPE properties SYSTEM "http://java.sun.com/dtd/properties.dtd"> +<properties> +<comment>Irrigation XML-ized experiment round configuration</comment> + +<!--<entry key="hostname">localhost</entry>--> +<entry key="hostname">localhost</entry> +<entry key="port">16001</entry> +<entry key="round0">round0.xml</entry> +<entry key="round1">round1.xml</entry> +<entry key="round2">round2.xml</entry> +<entry key="round3">round3.xml</entry> +<entry key="round4">round4.xml</entry> +<entry key="round5">round5.xml</entry> +<entry key="round6">round6.xml</entry> +<entry key="round7">round7.xml</entry> +<entry key="round8">round8.xml</entry> +<entry key="round9">round9.xml</entry> +<entry key="round10">round10.xml</entry> +<entry key="round11">round11.xml</entry> +<entry key="round12">round12.xml</entry> +<entry key="round13">round13.xml</entry> +<entry key="round14">round14.xml</entry> +<entry key="round15">round15.xml</entry> +<entry key="round16">round16.xml</entry> +<entry key="round17">round17.xml</entry> +<entry key="round18">round18.xml</entry> +<entry key="round19">round19.xml</entry> +<entry key="round20">round20.xml</entry> +<entry key="round21">round21.xml</entry> + + +<entry key="wait-for-participants">true</entry> +<entry key="number-of-rounds">22</entry> + +<entry key="undisrupted-bandwidth">true</entry> + +<entry key="q1">4</entry> +<entry key="q2">identity</entry> +<entry key="q3">49</entry> +<entry key="q4">76</entry> +<entry key="q5">4</entry> +<entry key="q6">5</entry> +<entry key="q7">25</entry> +<entry key="q8">4</entry> +<entry key="q9">25</entry> +<entry key="q10">30</entry> +<entry key="q11">1.50</entry> + + +<entry key="facilitator-instructions"> +<![CDATA[ +<h3>Facilitator Instructions</h3> +<p> +Welcome to the facilitator interface. This interface allows you to control +the experiment. You may only modify configuration parameters <b>before</b> +you start the experiment by selecting the Configuration menu. When all the +participants are ready to begin the experiment, you can start the experiment +by selecting Experiment -> Start. After a round has been completed you +will be able to view the statistics for all of the participants. You can +begin the next round by selecting Round -> Start. +</p> +]]> +</entry> + + + +<entry key="general-instructions0"> +<![CDATA[ +<center><h3>Welcome to the experiment. Please do not close this window or open any +other applications.</h3></center> +]]> +</entry> + +<entry key="general-instructions1"> +<![CDATA[ +<h3>General Instructions</h3> +<p>Welcome. You have already earned 5 dollars by showing up for this exercise. +You can earn more, up to an extra 25 dollars, by participating in the exercise +which will last for about one hour. You will participate in this exercise as a +part of a group. Each group has five participants. Your group has been formed +by randomly assigning you to FOUR other participants in the room. The amount +of money you earn will depend on the decisions made by you and the rest of the +group. That is, your earnings will depend on your decisions as well as the +other members of your group. +</p> +<p> +This exercise mimics decisions people make in irrigation systems. In each round you +will receive 10 tokens which you can choose to keep or invest in the irrigation +infrastructure (for example canals and water diversion structures). Depending on the +state of repair of the irrigation infrastructure, it will be capable of directing +water to your field when you use your water diversion structure (called an +irrigation gate). Depending on the amount of water you can get to your field, you +can grow crops. Depending on the number of crops you grow you earn tokens. Each +token is worth 5 cents and you will be paid cash in private at the end of the +experiment based on the number of tokens you earned. +</p> +<p> +The experiment consists of a number of rounds. In each round you will first make a +decision as to how much to invest in the irrigation infrastructure. Without periodic +investment, the irrigation infrastructure will break down over time. Based on the +combined contributions of all 5 participants in your group in each round, as +explained below, your group can maintain the performance of the irrigation +infrastructure. The condition of the irrigation infrastructure determines +its capacity to deliver water which you can use to grow crops. +</p> +]]> +</entry> + +<entry key="general-instructionsq1"> +<![CDATA[ +<br><br> +To continue to the next page, please answer the following question:<br> +<form> +How many OTHER people in the room will be in your group?<br> +<input type="radio" name="q1" value="0">0<br> +<input type="radio" name="q1" value="1">1<br> +<input type="radio" name="q1" value="4">4<br> +<input type="radio" name="q1" value="Everybody">Everybody<br> +<br><br> +<input type="submit" name="submit" value="Submit"> +</form> +]]> +</entry> + +<entry key="general-instructions2"> +<![CDATA[ +<h3>Chat</h3> +<p>Each round will start with a chat period of 40 seconds where you can send text +messages to the other participants. You may discuss any aspect of the exercise. +<b>However</b>, you are <b>not allowed</b> to promise the other participants +side-payments or threaten them with any consequence after the experiment is +finished. You are also <b>not allowed</b> to reveal your real identity. We will be +monitoring the chat traffic. If we see any member of a group violating the rules, +we will have to remove that <b>entire group</b> from the experiment room. That +group will have to wait until the entire experiment is finished to receive +their payment.<br><br> + +You will see a text box appear on your screen when a chat period starts. The amount +of time left in the chat period will be shown at the <b>top left of the screen</b>.<br> +]]> +</entry> + +<entry key="general-instructionsq2"> +<![CDATA[ +<br><br> +To continue to the next page, please answer the following question:<br> +<form> +Which of the following topics are you <b>not allowed</b> to discuss in chat?<br> +<input type="radio" name="q2" value="weather">the weather<br> +<input type="radio" name="q2"... [truncated message content] |
From: <see...@us...> - 2009-10-08 18:29:47
|
Revision: 289 http://virtualcommons.svn.sourceforge.net/virtualcommons/?rev=289&view=rev Author: seematalele Date: 2009-10-08 18:29:40 +0000 (Thu, 08 Oct 2009) Log Message: ----------- Refactrored the services. Assigngroups fucntionality is working but somehow blocks pushing is not working. Modified Paths: -------------- mentalmodels/trunk/src/main/java/edu/asu/commons/mme/entity/Group.java mentalmodels/trunk/src/main/java/edu/asu/commons/mme/service/GameService.java mentalmodels/trunk/src/main/java/edu/asu/commons/mme/service/RoundService.java mentalmodels/trunk/src/main/java/edu/asu/commons/mme/service/StartGame.java mentalmodels/trunk/src/main/java/edu/asu/commons/mme/service/StudentService.java mentalmodels/trunk/src/main/webapp/WEB-INF/applicationContext.xml mentalmodels/trunk/src/main/webapp/WEB-INF/classes/log4j.properties Added Paths: ----------- mentalmodels/trunk/src/main/java/edu/asu/commons/mme/utility/ mentalmodels/trunk/src/main/java/edu/asu/commons/mme/utility/MessageHandler.java Modified: mentalmodels/trunk/src/main/java/edu/asu/commons/mme/entity/Group.java =================================================================== --- mentalmodels/trunk/src/main/java/edu/asu/commons/mme/entity/Group.java 2009-10-08 00:29:17 UTC (rev 288) +++ mentalmodels/trunk/src/main/java/edu/asu/commons/mme/entity/Group.java 2009-10-08 18:29:40 UTC (rev 289) @@ -7,6 +7,7 @@ import javax.persistence.Entity; import javax.persistence.GeneratedValue; import javax.persistence.Id; +import javax.persistence.OrderBy; import javax.persistence.Table; @@ -26,6 +27,7 @@ private Long id; @Column(name="grp_number",nullable=false) + @OrderBy("number") private Integer number; /* @ManyToOne Modified: mentalmodels/trunk/src/main/java/edu/asu/commons/mme/service/GameService.java =================================================================== --- mentalmodels/trunk/src/main/java/edu/asu/commons/mme/service/GameService.java 2009-10-08 00:29:17 UTC (rev 288) +++ mentalmodels/trunk/src/main/java/edu/asu/commons/mme/service/GameService.java 2009-10-08 18:29:40 UTC (rev 289) @@ -1,11 +1,1118 @@ package edu.asu.commons.mme.service; +import java.util.ArrayList; +import java.util.HashMap; +import java.util.Iterator; +import java.util.List; +import java.util.Map; + +import org.hibernate.Hibernate; +import org.springframework.transaction.annotation.Transactional; + +import edu.asu.commons.mme.dao.HibernateBlockDao; +import edu.asu.commons.mme.dao.HibernateGameConfigDao; import edu.asu.commons.mme.dao.HibernateGameDao; +import edu.asu.commons.mme.dao.HibernateGameRoundDao; +import edu.asu.commons.mme.dao.HibernateGroupDao; +import edu.asu.commons.mme.dao.HibernateLocationDao; +import edu.asu.commons.mme.dao.HibernateModuleDao; +import edu.asu.commons.mme.dao.HibernateModuleRoundConfigDao; +import edu.asu.commons.mme.dao.HibernateRoundConfigDao; +import edu.asu.commons.mme.dao.HibernateStudentDao; +import edu.asu.commons.mme.entity.Block; +import edu.asu.commons.mme.entity.BlockInformationWindow; +import edu.asu.commons.mme.entity.CategoricalOption; +import edu.asu.commons.mme.entity.CategoricalQuestion; import edu.asu.commons.mme.entity.Game; +import edu.asu.commons.mme.entity.GameConfig; +import edu.asu.commons.mme.entity.GameRound; +import edu.asu.commons.mme.entity.Group; +import edu.asu.commons.mme.entity.Location; +import edu.asu.commons.mme.entity.Module; +import edu.asu.commons.mme.entity.ModuleRoundConfig; +import edu.asu.commons.mme.entity.Question; +import edu.asu.commons.mme.entity.QuestionGroup; +import edu.asu.commons.mme.entity.Round; +import edu.asu.commons.mme.entity.Student; +import edu.asu.commons.mme.utility.MessageHandler; +import flex.messaging.MessageBroker; +import flex.messaging.messages.AsyncMessage; +import flex.messaging.util.UUIDUtils; +@Transactional public class GameService extends Service.Base<Game, HibernateGameDao>{ + + private HibernateModuleDao moduleDao; + private HibernateBlockDao blockDao; + private HibernateRoundConfigDao roundConfigDao; + private HibernateModuleRoundConfigDao moduleRoundDao; + private HibernateGameRoundDao gameRoundDao; + private HibernateGameConfigDao gameConfigDao; + private HibernateGroupDao groupDao; + private HibernateStudentDao studentDao; + private HibernateLocationDao locationDao; + + private int blockSeqNo; - + private RoundService roundService; + public GameConfig createGameConfig(GameConfig gameConfig) + { + GameConfig newGameConfig = null; + try{ + newGameConfig = new GameConfig(); + newGameConfig.setImageLocation(null); + newGameConfig.setTimestamp(gameConfig.getTimestamp()); + newGameConfig.setMaxDays(gameConfig.getMaxDays()); + newGameConfig.setMaxFishHarvest(gameConfig.getMaxFishHarvest()); + newGameConfig.setNumberOfLocations(gameConfig.getNumberOfLocations()); + getGameConfigDao().save(newGameConfig); + initializeGameRounds(newGameConfig); + setAllLocations(newGameConfig); + + }catch(Exception e) + { + e.printStackTrace(); + } + return newGameConfig; + } + + + public Game createGame(Game game) + { + //getLogger().debug("game came from flex is : " + game.getGameCode()); + + Game newGame = new Game(); + //currentGame = game; + try + { + newGame.setGameCode(game.getGameCode()); + newGame.setMoney(game.getMoney()); + newGame.setTimestamp(game.getTimestamp()); + + //FIXME: Currently using default GameConfiguration whose id is 1 + GameConfig gameConfig = gameConfigDao.find(1L); + newGame.setGameConfig(gameConfig); + getDao().save(newGame); + String str = newGame.getGameCode()+newGame.getId(); + + if(getDao().findAllByProperty("gameCode", str).size() != 0) + { + //getLogger().debug("in if loop "); + newGame = null; + } + else + { + newGame.setGameCode(str); + getDao().save(newGame); + getLogger().info("Created the game: " + newGame.getId()); + setAllLocations(gameConfig); + initializeGame(newGame); + } + }catch(Exception e) + { + e.printStackTrace(); + } + getLogger().debug("current game from flex is: " + newGame.getId()); + return newGame; + } + + + /** + * 1)Initially first block will get pushed to all the clients. + * 2)get timer for that block + * 3)check if the block is day by day decision game if yes then start day by day decision service + * 4)if it is communication, start communication service + * 3)start the timer + * 4)Once the timer is over, push the next block + * + */ + public void startGame(Game game) { + + assignGroups(game); +/* getRoundService().setGame(game); + getRoundService().run(); +*/ + Game newGameState = null; + Block block = null; + boolean running = false; + getLogger().info("game start is: " + game.getId()); + newGameState = getDao().find(game.getId()); + MessageHandler msgHandler = new MessageHandler(); + msgHandler.setDestination("mme"); + msgHandler.setSubtopic(getGameCode(newGameState)); + int noOfBlocks = getNumberOfBlock(game); + + int i=0; + try { + while (i<noOfBlocks) { + + i++; + newGameState = getBlock(game); + game = newGameState; + if(newGameState == null) + { + msgHandler.send(null); + } + else + { + block = newGameState.getCurrentBlock(); + msgHandler.send(block); + } + + if(block.getDescription().equalsIgnoreCase("Day-by-day decisions game")) + { + //start day by day decision + //getDayBydayDecisionService(). + + } + else if (block.getDescription().equalsIgnoreCase("Communication")) + { + //start communication round + + } + //get the timer for the block + Integer timer = getTimerforBlock(block); + //start the timer for the block sent + + //for testing purpose 5000 is given as an argument + Thread.sleep(10000); + if(block == null) + { + running = false; + } + } + }catch (InterruptedException e) { + } + } + + private int getNumberOfBlock(Game game) { + // TODO Auto-generated method stub + + //game.getGameConfig() + return 0; + } + + + public void assignGroups(Game currentGame) + { + + List<Student> studentWithGroupsAssigned = new ArrayList<Student>(); + List<Student> students = new ArrayList<Student>(); + Game game = getDao().find(currentGame.getId()); + try{ + //getLogger().debug("In the assigngroups." + game.getId()); + + + students = getStudentDao().findAllByProperty("game", game); + + //getLogger().debug("test student object is : " + students.size()); + if(students.size() > 1) + { + //write an algorithm to form groups + int totalStudents = students.size(); + int noOfGroupsWithSize3=0; + int noOfGroupsWithSize4=0; + int noOfGroupsWithSize5=0; + int x; + + + //no of groups + noOfGroupsWithSize5=((int)(totalStudents/5)); + + + x= totalStudents%5; + + /* if(x==0) + { + totalGroups=groupSize5; + } + else*/ + if(x==1) + { + noOfGroupsWithSize5=noOfGroupsWithSize5 - 1; + noOfGroupsWithSize3=2; + // totalGroups=groupSize5 + groupSize3; + } + + else if(x==2) + { + noOfGroupsWithSize5=noOfGroupsWithSize5-1; + noOfGroupsWithSize4=1; + noOfGroupsWithSize3=1; + // totalGroups=groupSize5 + groupSize3 + groupSize4; + } + else if(x==3) + { + noOfGroupsWithSize3=1; + // totalGroups=groupSize3 + groupSize5; + } + + else if(x==4) + { + noOfGroupsWithSize4=1; + // totalGroups=groupSize4 + groupSize5; + } + + + /*getLogger().debug("size of 4 : " + noOfGroupsWithSize4); + getLogger().debug("size of 3 : " + noOfGroupsWithSize3); + getLogger().debug("size of 5 : " + noOfGroupsWithSize5); + */ + + int groupNo = 0; + + //assign every student a number and group + if(!students.isEmpty()) + { + if(noOfGroupsWithSize5 > 0) + { + + for(Student student5:assignGroupstoStudents(5,noOfGroupsWithSize5,students,groupNo)) + studentWithGroupsAssigned.add(student5); + + //getLogger().debug("student size after 5 is: " + students.size()); + getLogger().debug("student with groups assigned: " + studentWithGroupsAssigned.size()); + } + groupNo = noOfGroupsWithSize5; + if(noOfGroupsWithSize4 > 0) + { + for(Student student4:assignGroupstoStudents(4,noOfGroupsWithSize4,students,groupNo)) + studentWithGroupsAssigned.add(student4); + + //getLogger().debug("student size after 4 is: " + students.size()); + getLogger().debug("student with groups assigned: " + studentWithGroupsAssigned.size()); + } + groupNo = noOfGroupsWithSize5 + noOfGroupsWithSize4; + if(noOfGroupsWithSize3 > 0) + { + for(Student student3:assignGroupstoStudents(3,noOfGroupsWithSize3,students,groupNo)) + studentWithGroupsAssigned.add(student3); + //getLogger().debug("student size after 3 is: " + students.size()); + getLogger().debug("student with groups assigned: " + studentWithGroupsAssigned.size()); + } + } + } + getLogger().debug("Final student with groups assigned: " + studentWithGroupsAssigned.size()); + }catch(Exception e) + { + getLogger().error(e); + } + + if(students != null) + { + /*MessageBroker msgBroker = MessageBroker.getMessageBroker("_messageBroker"); + + String clientID = UUIDUtils.createUUID(); + AsyncMessage msg = new AsyncMessage(); + msg.setDestination("mme"); + String msgDestination = game.getGameCode(); + msg.setHeader("DSSubtopic", msgDestination); + msg.setClientId(clientID); + msg.setMessageId(UUIDUtils.createUUID()); + msg.setTimestamp(System.currentTimeMillis()); + for(Student student: studentWithGroupsAssigned) + { + initializeStudent(student); + } + msg.setBody(studentWithGroupsAssigned); + System.out.println("Message broker is: "+ msgBroker); + System.out.println("Students size is: " + studentWithGroupsAssigned.size()); + + msgBroker.routeMessageToService(msg, null);*/ + MessageHandler msgHandler = new MessageHandler(); + msgHandler.setDestination("mme"); + msgHandler.setSubtopic(game.getGameCode()); + /*for(Student student: studentWithGroupsAssigned) + { + initializeStudent(student); + }*/ + msgHandler.send(studentWithGroupsAssigned); + } + } + + + private List<Student> assignGroupstoStudents(int groupSize, int noOfGroups,List<Student> students,int groupNo) { + // TODO Auto-generated method stub + Student student = new Student(); + List<Student> studentWithGroupsAssigned = new ArrayList<Student>(); + getLogger().debug("group size is : "+groupSize + " and group number is : "+ groupNo); + + for(int counter = 0; counter < noOfGroups; counter++) + { + //create group + Group grp = new Group(); + + grp.setNumber(++groupNo); + groupDao.save(grp); + + getLogger().info("Group is created with id: " + grp.getId()); + int studentNo = 1; + int j = 0; + for(int i = 0; i <= groupSize-1 ; i++) + { + //get a student from a list + student = students.get(0); + getLogger().debug("i is: " + i +"student id is : "+student.getId()); + if(student.getGroup() == null) + { + //assign student no and group to each student + getLogger().debug("group assigned is : " + grp.getId()); + student.setStudentNo(studentNo); + student.setGroup(grp); + getDao().save(student); + studentNo++; + initializeStudent(student); + studentWithGroupsAssigned.add(student); + students.remove(0); + } + j++; + } + } + return studentWithGroupsAssigned; + } + + private void initializeStudent(Student student) { + Hibernate.initialize(student); + Hibernate.initialize(student.getGame()); + Hibernate.initialize(student.getGame().getGameConfig()); + Hibernate.initialize(student.getGame().getGameConfig().getLocations()); + Hibernate.initialize(student.getGroup()); + } + + public Group createGroup(int groupNo) + { + Group grp = new Group(); + grp.setNumber(groupNo); + groupDao.save(grp); + getLogger().info("Group is created with id: " + grp.getId()); + return grp; + } + + private void initializeGameRounds(GameConfig gameConfig) { + // TODO Auto-generated method stub + List<GameRound> gameRounds = new ArrayList<GameRound>(); + for(Round round:getRoundConfigDao().findAll()) + { + GameRound gameRound = new GameRound(); + gameRound.setGameConfig(gameConfig); + gameRound.setRound(round); + gameRoundDao.save(gameRound); + gameRounds.add(gameRound); + } + getGameConfigDao().save(gameConfig); + } + + private List<Location> setAllLocations(GameConfig gameConfig) + { + //FIXME: For the pilot experiment locations are set manually but in future might want to take inputs from user + List<Location> locations = new ArrayList<Location>(); + try{ + Location harbor = new Location(); + harbor.setLocationName("Harbor"); + harbor.setCurrentPopulation(0.0); + harbor.setGrowthRate(0.0); + harbor.setInitialPopulation(0.0); + harbor.setMaxCapacity(0.0); + harbor.setGameConfig(gameConfig); + getLocationDao().save(harbor); + getLogger().info("Saved Location "+harbor.getLocationName()+" with id " + harbor.getId()); + locations.add(harbor); + + Location bay1 = new Location(); + bay1.setLocationName("Bay1"); + bay1.setCurrentPopulation(5.0); + bay1.setInitialPopulation(5.0); + bay1.setGrowthRate(0.5); + bay1.setMaxCapacity(10.0); + bay1.setGameConfig(gameConfig); + getLocationDao().save(bay1); + getLogger().info("Saved Location " + bay1.getLocationName() +" with id "+ bay1.getId()); + locations.add(bay1); + + Location bay2 = new Location(); + bay2.setLocationName("Bay2"); + bay2.setCurrentPopulation(10.0); + bay2.setInitialPopulation(10.0); + bay2.setGrowthRate(0.15); + bay2.setMaxCapacity(20.0); + bay2.setGameConfig(gameConfig); + getLocationDao().save(bay2); + getLogger().info("Saved Location " + bay2.getLocationName() +" with id "+ bay2.getId()); + locations.add(bay2); + + Location bay3 = new Location(); + bay3.setLocationName("Bay3"); + bay3.setCurrentPopulation(15.0); + bay3.setInitialPopulation(15.0); + bay3.setGrowthRate(0.05); + bay3.setMaxCapacity(30.0); + bay3.setGameConfig(gameConfig); + getLocationDao().save(bay3); + getLogger().info("Saved Location " + bay3.getLocationName() +" with id "+ bay3.getId()); + locations.add(bay3); + }catch(Exception e) + { + e.printStackTrace(); + } + + return locations; + } + + public Module getNextModule(int sequenceNo) + { + return getModule(sequenceNo); + } + + public void test() + { + getLogger().debug("test to check if module service is working...." ); + } + + /* + *1) Check if the current module round config is null, this object keeps track of which round + * and which module in that round is going on + *2) Find out the current module number + *3) check if it is finished, if yes find out the current round number + *4) Find out the current block number + *5) Return the next block + */ + + public Game getBlock(Game game) + { + + ModuleRoundConfig currentModuleRoundConfig; + Block currentBlock = null; + Round currentRound = null; + + //check if it is a start of the game + if(game.getCurrentRound() == null && game.getCurrentBlock() == null ) + { + getLogger().info("Current Round is null... "); + getLogger().info("Current block is null... "); + getLogger().info("Starting of the game...." + game.getGameCode()); + + currentRound = getNextRound(game); + getLogger().info("Next Round object is "+ currentRound.getId()); + + currentModuleRoundConfig = getModuleRoundConfig(0, currentRound); + getLogger().info("Next ModuleRound Config object is "+ currentModuleRoundConfig.getId()); + + Module currentModule = getModuleForCurrentRound(currentModuleRoundConfig); + getLogger().info("Next Module object is "+ currentModule.getId()); + currentBlock = getBlock(currentModule,1); + } + else + { + getLogger().debug("Current Round is : " + game.getCurrentRound().getId()); + getLogger().debug("Current block is : " + game.getCurrentBlock().getId()); + currentBlock = game.getCurrentBlock(); + currentRound = game.getCurrentRound(); + if(isModuleFinished(game.getCurrentBlock())) + { + getLogger().debug("current module is finished"); + + //currentModuleRoundConfig = game.getCurrentRound(). + if(isCurrentRoundFinished(game)) + { + getLogger().debug("current round is finished"); + if(isGameFinished(game)) + { + getLogger().debug("Game is finished..." + game.getId()); + return null; + } + else + { + //set the next round + currentRound = getNextRound(game); + getLogger().info("Next Round object is "+ currentRound.getId()); + + currentModuleRoundConfig = getModuleRoundConfig(0, currentRound); + getLogger().info("Next ModuleRound Config object is "+ currentModuleRoundConfig.getId()); + + Module currentModule = getModuleForCurrentRound(currentModuleRoundConfig); + getLogger().info("Next Module object is "+ currentModule.getId()); + + currentBlock = getBlock(currentModule,1); + } + } + else + { + getLogger().debug("current round is not finished"); + //currentRound = getNextRound(game.getCurrentRound()); + + currentModuleRoundConfig = getModuleRoundConfig(getPreviousModuleConfigSequenceNo(game), currentRound); + getLogger().info("Next ModuleRound Config object is "+ currentModuleRoundConfig.getId()); + + Module currentModule = getModuleForCurrentRound(currentModuleRoundConfig); + getLogger().info("Next Module object is "+ currentModule.getId()); + + currentBlock = getBlock(currentModule,1); + + } + } + else + { + //get the next block in the module + //getLogger().debug("currentmodule is " + game.getCurrentBlock().getModule().getId()); + currentBlock = getNextBlock(game.getCurrentBlock()); + getLogger().debug("the next block for the game is: " + game.getCurrentBlock().getDescription()); + } + } + + Game newGame = saveGameState(currentBlock,currentRound,game); + getLogger().debug("question group sizes is : " + newGame.getCurrentBlock().getQuestionGroups().size()); + //initializeCurrentBlock(newGame.getCurrentBlock()); + initializeGame(newGame); + getLogger().debug("Module is " + newGame.getCurrentBlock().getModule().getId() + "Block sent to the server is: " + currentBlock.getDescription()); + return newGame; + } + + private int getPreviousModuleConfigSequenceNo(Game game) { + // TODO Auto-generated method stub + List<ModuleRoundConfig> moduleRoundConfigs = new ArrayList<ModuleRoundConfig> (); + ModuleRoundConfig currentModuleRoundConfig = null; + + Map<String, Object> variables = new HashMap<String, Object>(); + variables.put("module",game.getCurrentBlock().getModule()); + variables.put("round", game.getCurrentRound()); + moduleRoundConfigs = moduleRoundDao.findByEqCriteria(variables); + if(moduleRoundConfigs.size() == 1) + { + currentModuleRoundConfig = moduleRoundConfigs.get(0); + moduleRoundConfigs.clear(); + } + getLogger().debug("the prev Sequence no is : " + currentModuleRoundConfig.getSequenceNo()); + if(currentModuleRoundConfig != null) + return currentModuleRoundConfig.getSequenceNo(); + return 0; + } + + private ModuleRoundConfig getModuleRoundConfig(int prevSeqNo, Round currentRound) { + // TODO Auto-generated method stub + //int prevSeqNo = 0; + List<ModuleRoundConfig> moduleRoundConfigs = new ArrayList<ModuleRoundConfig> (); + ModuleRoundConfig currentModuleRoundConfig = null; + try + { + moduleRoundConfigs = moduleRoundDao.findAllByProperty("round",currentRound); + for(int i = 0; i < moduleRoundConfigs.size(); i++) + { + if(moduleRoundConfigs.get(i).getSequenceNo() > prevSeqNo) + { + currentModuleRoundConfig = moduleRoundConfigs.get(i); + break; + + /*setCurrentModule(moduleRoundConfigs.get(i).getModule()); + getLogger().debug("current module is: " + getCurrentModule().getDescription()); + currentBlock = null; + break;*/ + } + } + }catch(Exception e) + { + e.printStackTrace(); + } + return currentModuleRoundConfig; + + } + + private Module getModuleForCurrentRound(ModuleRoundConfig moduleRoundConfig) { + // TODO Auto-generated method stub + //getLogger().debug("current module is: " + getCurrentModule().getDescription()); + return moduleRoundConfig.getModule(); + } + + + private Round getNextRound(Game game) { + // TODO Auto-generated method stub + + Round returnRound = null; + Round currentRound = game.getCurrentRound(); + GameConfig gameConfig = game.getGameConfig(); + List<GameRound> gameRounds = new ArrayList<GameRound>(); + if(currentRound == null) + { + //get the first round + Map<String, Object> variables = new HashMap<String, Object>(); + variables.put("gameConfig",gameConfig); + variables.put("seqNo", 1); + getGameRoundDao().findByEqCriteria(variables); + gameRounds = gameRoundDao.findByEqCriteria(variables); + if(gameRounds.size() == 1) + { + returnRound = gameRounds.get(0).getRound(); + gameRounds.clear(); + } + } + else + { + Map<String, Object> variables = new HashMap<String, Object>(); + variables.put("gameConfig",gameConfig); + variables.put("round", currentRound); + gameRounds = getGameRoundDao().findByEqCriteria(variables); + if(gameRounds.size() == 1) + { + int currentSeqNo = gameRounds.get(0).getSeqNo(); + gameRounds = getGameRoundDao().findAll(); + for(int i = 0; i < gameRounds.size(); i++) + { + if(currentSeqNo < gameRounds.get(i).getSeqNo()) + { + returnRound = gameRounds.get(i).getRound(); + break; + //getLogger().debug("currentround object is "+ rounds.get(i).getId()); + } + } + } + else + { + getLogger().error("Error Occured.. Game Config is associated with multiple Rounds "); + } + } + + return returnRound; + } + + public void initializeGame(Game game) { + // TODO Auto-generated method stub + try{ + Hibernate.initialize(game); + Hibernate.initialize(game.getCurrentBlock()); + + + GameConfig gameconfig = game.getGameConfig(); + Hibernate.initialize(gameconfig); + + for(Location location:gameconfig.getLocations()) + { + Hibernate.initialize(location); + + } + + Round round = game.getCurrentRound(); + Hibernate.initialize(round); + /*for(GameRound gameRound:round.getGameRounds()) + { + getLogger().debug("gameround in initializing round is " + gameRound.getId()); + Hibernate.initialize(gameRound); + }*/ + + }catch(Exception e ) + { + e.printStackTrace(); + } + //Hibernate.initialize(gameconfig.getGameRounds()); + + + } + + private void initializeModule(Module module) + { + // TODO Auto-generated method stub + Iterator<Block> iterateBlock = module.getBlocks().iterator(); + while(iterateBlock.hasNext()) + { + Block block = iterateBlock.next(); + Hibernate.initialize(block); + List<BlockInformationWindow> infoWindow = block.getInformationWindows(); + for(int j = 0; j < infoWindow.size(); j++) + { + Hibernate.initialize(infoWindow.get(j)); + Hibernate.initialize(infoWindow.get(j).getInfoWindow()); + } + Iterator<QuestionGroup> iteratorquestionGrp = block.getQuestionGroups().iterator(); + { + while(iteratorquestionGrp.hasNext()) + { + QuestionGroup questionGroup = iteratorquestionGrp.next(); + Hibernate.initialize(questionGroup); + // getLogger().debug(questionGroup.getDescription()); + List<Question> questions = questionGroup.getQuestions(); + + for(int j = 0; j < questions.size(); j++) + { + Hibernate.initialize(questions.get(j)); + if(questions.get(j).getClass().getName().equalsIgnoreCase("edu.asu.commons.mme.entity.CategoricalQuestion")) + { + CategoricalQuestion categoricalQ = (CategoricalQuestion)questions.get(j); + Iterator<CategoricalOption> categoricalOption = categoricalQ.getCategoricalOptions().iterator(); + Hibernate.initialize(categoricalOption); + } + } + } + } + + } + } + + private void initializeCurrentBlock(Block block) { + + Hibernate.initialize(block); + Iterator<QuestionGroup> iteratorquestionGrp = block.getQuestionGroups().iterator(); + { + while(iteratorquestionGrp.hasNext()) + { + QuestionGroup questionGroup = iteratorquestionGrp.next(); + Hibernate.initialize(questionGroup); + // getLogger().debug(questionGroup.getDescription()); + List<Question> questions = questionGroup.getQuestions(); + + for(int j = 0; j < questions.size(); j++) + { + Hibernate.initialize(questions.get(j)); + if(questions.get(j).getClass().getName().equalsIgnoreCase("edu.asu.commons.mme.entity.CategoricalQuestion")) + { + CategoricalQuestion categoricalQ = (CategoricalQuestion)questions.get(j); + Iterator<CategoricalOption> categoricalOption = categoricalQ.getCategoricalOptions().iterator(); + Hibernate.initialize(categoricalOption); + } + } + } + } + + Module module = block.getModule(); + Hibernate.initialize(module); + initializeModule(module); + + } + + + private Block getNextBlock(Block currentBlock) { + // TODO Auto-generated method stub + List<Block> blocks = new ArrayList<Block>(); + blocks = currentBlock.getModule().getBlocks(); + Block returnBlock = null; + for(int i = 0; i < blocks.size(); i++) + { + if(currentBlock.getSequenceNo() < blocks.get(i).getSequenceNo()) + { + returnBlock = blocks.get(i); + break; + } + } + return returnBlock; + + } + + public Module getModule(int moduleNumber) + { + // Enter the sequence number in new Integer(Sequence number of module u want to fetch) + + Module module = moduleDao.findByProperty("sequenceNo", moduleNumber); + Hibernate.initialize(module); + getLogger().debug("Module object is " + module.getDescription()); + initializeModule(module); + + return module; + } + + public Block getBlock(Module currentModule, int seqNo) + { + //Module module = new Module(); + // module = currentModule; + Block block = new Block(); + for(int i = 0; i < currentModule.getBlocks().size(); i++) + { + block = currentModule.getBlocks().get(i); + if(block.getSequenceNo() == seqNo) + { + return block; + } + } + + return block; + } + + /* private void setRound(int roundNo) { + // TODO Auto-generated method stub + currentRound = new Round(); + + currentRound = getDao().findByProperty("roundNo", roundNo); + //Hibernate.initialize(currentRound); + getLogger().debug("currentround object is "+ currentRound.getId()); + setCurrentRound(currentRound); + + }*/ + + /*private int getCurrentRoundNo() { + // TODO Auto-generated method stub + //FIXME: Game id 1 is hard coded but needs to make it dynamic + //Game game = gameDao.find(1L); + if(getCurrentGame().getCurrentRound() == null) + return 0; + else + return getCurrentGame().getCurrentRound().getRoundNo(); + + }*/ + public boolean isGameFinished(Game game) { + GameConfig gameConfig = game.getGameConfig(); + List<GameRound> gameRounds = getGameRoundDao().findAllByProperty("gameConfig",game.getGameConfig()); + boolean flag = false; + + Map<String, Object> variables = new HashMap<String, Object>(); + variables.put("gameConfig",gameConfig); + variables.put("round", game.getCurrentRound()); + gameRounds = getGameRoundDao().findByEqCriteria(variables); + if(gameRounds.size() == 1) + { + int currentSeqNo = gameRounds.get(0).getSeqNo(); + gameRounds.clear(); + gameRounds = getGameRoundDao().findAllByProperty("gameConfig", gameConfig); + + if(currentSeqNo == gameRounds.get(gameRounds.size() - 1).getSeqNo()) + { + flag = true; + } + else + { + for(GameRound gameRound:gameRounds) + { + if(currentSeqNo < gameRound.getSeqNo()) + { + flag = false; + } + } + + } + } + return flag; + } + + private boolean isCurrentRoundFinished(Game game) { + boolean flag = false; + List<ModuleRoundConfig> moduleRoundConfigs = new ArrayList<ModuleRoundConfig> (); + Round currentRound = game.getCurrentRound(); + Module currentModule = game.getCurrentBlock().getModule(); + + ModuleRoundConfig currentModuleRoundConfig = new ModuleRoundConfig(); + + Map<String, Object> variables = new HashMap<String, Object>(); + variables.put("module",currentModule); + variables.put("round", currentRound); + moduleRoundConfigs = moduleRoundDao.findByEqCriteria(variables); + if(moduleRoundConfigs.size() == 1) + { + currentModuleRoundConfig = moduleRoundConfigs.get(0); + moduleRoundConfigs.clear(); + } + moduleRoundConfigs = moduleRoundDao.findAllByProperty("round",currentRound); + getLogger().debug("the module round configs size is: " + moduleRoundConfigs.size()); + //check if it contains only one module, if yes then round is over + if(moduleRoundConfigs.size() == 1) + { + flag = true; + } + else + { + getLogger().debug("module round config is "+ moduleRoundConfigs.get(moduleRoundConfigs.size() - 1).getSequenceNo()); + int seqNo = moduleRoundConfigs.get(moduleRoundConfigs.size() - 1).getSequenceNo(); + if((currentModuleRoundConfig.getSequenceNo()) == seqNo) + { + flag = true; + } + else + { + for(int i = 0; i < moduleRoundConfigs.size(); i++) + { + // getLogger().debug("moduleroundconfig seq no is" + moduleRoundConfigs.get(i).getSequenceNo()); + getLogger().debug("Current seq no is" + currentModuleRoundConfig.getSequenceNo() +"and the moduleroundconfig is "+ moduleRoundConfigs.get(i).getSequenceNo()); + + if(currentModuleRoundConfig.getSequenceNo() == moduleRoundConfigs.get(moduleRoundConfigs.size() - 1).getSequenceNo()) + flag = true; + if(currentModuleRoundConfig.getSequenceNo() < moduleRoundConfigs.get(i).getSequenceNo()) + { + flag = false; + } + } + } + } + return flag; + } + + + private boolean isModuleFinished(Block currentBlock) { + // TODO Auto-generated method stub + boolean flag = false; + + List<Block> blocks = new ArrayList<Block>(); + getLogger().debug("in iscurrentmodulefinished"); + if(currentBlock == null) + { + flag = true; + } + else + { + Module currentModule = currentBlock.getModule(); + //getBlocks() return blocks in order of sequence number + blocks = currentModule.getBlocks(); + //select max(b.sequence_no) from block b where b.module_id=2; + getLogger().debug("no of blocks " + blocks.size() +"for module id: " + currentModule.getId()); + //if module contains only one block + if(blocks.size() == 1) + flag = true; + else + { + for(int i = 0; i < blocks.size(); i++) + { + if(currentBlock.getSequenceNo() == blocks.get(blocks.size() - 1).getSequenceNo()) + flag = true; + if(currentBlock.getSequenceNo() < blocks.get(i).getSequenceNo()) + { + flag = false; + } + + } + } + } + return flag; + } + + private Game saveGameState(Block currentBlock, Round currentRound, Game game) { + + //FIXME: Game id 1 is hard coded but needs to make it dynamic + getLogger().info(" Game id to SAVE is: " + game.getId()); + Game newGame = null; + newGame = getDao().find(game.getId()); + getLogger().info("The current block is: " + currentBlock.getId() + " while the current Round is: " + currentRound.getId()); + if(newGame.getCurrentBlock() == null && newGame.getCurrentRound()==null) + getLogger().info("BEFORE GAME SAVE: The current block NULL while the current Round is NULL"); + else + getLogger().info("BEFORE GAME SAVE: The current block is: " + newGame.getCurrentBlock().getId() + " while the current Round is: " + newGame.getCurrentRound().getId()); + newGame.setCurrentBlock(currentBlock); + newGame.setCurrentRound(currentRound); + getRoundConfigDao().save(newGame); + getLogger().info("The game state is saved. The current block : " + newGame.getCurrentBlock().getId() + "while the current Round is: " + newGame.getCurrentRound().getId()); + return newGame; + } + + public Integer getTimerforBlock(Block block) + { + return block.getDuration(); + + } + + /*public Block getCurrentBlock() { + //FIXEME: game id 1 is hard coded, it should be dynamic + // Game game = gameDao.find(1L); + Block block = new Block(); + block = currentGame.getCurrentBlock(); + // Hibernate.initialize(block); + + return block; + }*/ + + + /*public Round getCurrentRound() { + getLogger().debug("in get current round funciton"); + Round round = currentGame.getCurrentRound(); + //Round round = getDao().find(getCurrentRound().getId()); + + initializeRound(round); + getLogger().debug("round no is " + currentRound.getRoundNo() + " " + currentRound.getId()); + return currentRound; + }*/ + + public void setBlockSeqNo(int blockSeqNo) { + this.blockSeqNo = blockSeqNo; + } + + public int getBlockSeqNo() { + return blockSeqNo; + } + public void setModuleRoundDao(HibernateModuleRoundConfigDao moduleRoundDao) { + this.moduleRoundDao = moduleRoundDao; + } + public HibernateModuleRoundConfigDao getModuleRoundDao() { + return moduleRoundDao; + } + public void setBlockDao(HibernateBlockDao blockDao) { + this.blockDao = blockDao; + } + public HibernateBlockDao getBlockDao() { + return blockDao; + } + public void setGameFinished(boolean gameFinished) { + } + + public String getGameCode(Game game) { + // TODO Auto-generated method stub + return game.getGameCode(); + } + + public void setGameRoundDao(HibernateGameRoundDao gameRoundDao) { + this.gameRoundDao = gameRoundDao; + } + + public HibernateGameRoundDao getGameRoundDao() { + return gameRoundDao; + } + + public void setGameConfigDao(HibernateGameConfigDao gameConfigDao) { + this.gameConfigDao = gameConfigDao; + } + + public HibernateGameConfigDao getGameConfigDao() { + return gameConfigDao; + } + + + public void setRoundConfigDao(HibernateRoundConfigDao roundConfigDao) { + this.roundConfigDao = roundConfigDao; + } + + + public HibernateRoundConfigDao getRoundConfigDao() { + return roundConfigDao; + } + + public HibernateModuleDao getModuleDao() { + return moduleDao; + } + + + public void setModuleDao(HibernateModuleDao moduleDao) { + this.moduleDao = moduleDao; + } + + + public void setGroupDao(HibernateGroupDao groupDao) { + this.groupDao = groupDao; + } + + + public HibernateGroupDao getGroupDao() { + return groupDao; + } + + + public void setStudentDao(HibernateStudentDao studentDao) { + this.studentDao = studentDao; + } + + + public HibernateStudentDao getStudentDao() { + return studentDao; + } + + + public void setLocationDao(HibernateLocationDao locationDao) { + this.locationDao = locationDao; + } + + + public HibernateLocationDao getLocationDao() { + return locationDao; + } + + + public void setRoundService(RoundService roundService) { + this.roundService = roundService; + } + + + public RoundService getRoundService() { + return roundService; + } } Modified: mentalmodels/trunk/src/main/java/edu/asu/commons/mme/service/RoundService.java =================================================================== --- mentalmodels/trunk/src/main/java/edu/asu/commons/mme/service/RoundService.java 2009-10-08 00:29:17 UTC (rev 288) +++ mentalmodels/trunk/src/main/java/edu/asu/commons/mme/service/RoundService.java 2009-10-08 18:29:40 UTC (rev 289) @@ -29,9 +29,10 @@ import edu.asu.commons.mme.entity.Question; import edu.asu.commons.mme.entity.QuestionGroup; import edu.asu.commons.mme.entity.Round; +import edu.asu.commons.mme.utility.MessageHandler; @Transactional -public class RoundService extends Service.Base<Round, HibernateRoundConfigDao> { +public class RoundService extends Service.Base<Round, HibernateRoundConfigDao>{ private HibernateModuleDao moduleDao; private HibernateBlockDao blockDao; @@ -43,7 +44,17 @@ private LocationService locationService; private int blockSeqNo; + + private Game game; + public Game getGame() { + return game; + } + + public void setGame(Game game) { + this.game = game; + } + public RoundService() { setBlockSeqNo(0); @@ -136,17 +147,17 @@ try{ Hibernate.initialize(game); Hibernate.initialize(game.getCurrentBlock()); - - + + GameConfig gameconfig = game.getGameConfig(); Hibernate.initialize(gameconfig); - + for(Location location:gameconfig.getLocations()) { Hibernate.initialize(location); } - + Round round = game.getCurrentRound(); Hibernate.initialize(round); /*for(GameRound gameRound:round.getGameRounds()) @@ -154,7 +165,7 @@ getLogger().debug("gameround in initializing round is " + gameRound.getId()); Hibernate.initialize(gameRound); }*/ - + }catch(Exception e ) { e.printStackTrace(); @@ -755,4 +766,63 @@ public HibernateGameConfigDao getGameConfigDao() { return gameConfigDao; } + + + public void run() { + // TODO Auto-generated method stub + Game newGameState = null; + Block block = null; + boolean running = false; + getLogger().info("game start is: " + game.getId()); + newGameState = getGameDao().find(game.getId()); + MessageHandler msgHandler = new MessageHandler(); + msgHandler.setDestination("mme"); + msgHandler.setSubtopic(getGameCode(newGameState)); + + int i=0; + try { + while (running) { + + i++; + newGameState = getBlock(game); + game = newGameState; + if(newGameState == null) + { + msgHandler.send(null); + } + else + { + block = newGameState.getCurrentBlock(); + msgHandler.send(block); + } + + /* if(block.getDescription().equalsIgnoreCase("Day-by-day decisions game")) + { + //start day by day decision + //getDayBydayDecisionService(). + + } + else if (block.getDescription().equalsIgnoreCase("Communication")) + { + //start communication round + + }*/ + //get the timer for the block + Integer timer = getTimerforBlock(block); + //start the timer for the block sent + + //for testing purpose 5000 is given as an argument + Thread.sleep(10000); + if(block == null) + { + running = false; + } + } + }catch (InterruptedException e) { + getLogger().debug(e); + } + + + + } } Modified: mentalmodels/trunk/src/main/java/edu/asu/commons/mme/service/StartGame.java =================================================================== --- mentalmodels/trunk/src/main/java/edu/asu/commons/mme/service/StartGame.java 2009-10-08 00:29:17 UTC (rev 288) +++ mentalmodels/trunk/src/main/java/edu/asu/commons/mme/service/StartGame.java 2009-10-08 18:29:40 UTC (rev 289) @@ -45,6 +45,7 @@ //System.out.println("game came from flex is: " + game.getDescription()); game = roundService.createGame(game); System.out.println("game object return from round service is: " + game); + if(game != null) { setGame(game); @@ -80,79 +81,6 @@ return students; } - /** - * 1)Initially first block will get pushed to all the clients. - * 2)get timer for that block - * 3)check if the block is day by day decision game if yes then start day by day decision service - * 4)if it is communication, start communication service - * 3)start the timer - * 4)Once the timer is over, push the next block - * - */ - public void run() { - - Game newGameState = null; - Block block = null; - //roundService.test(); - - MessageBroker msgBroker = MessageBroker.getMessageBroker("_messageBroker"); - String clientID = UUIDUtils.createUUID(); - newGameState = game; - int i=0; - while (i<17) { - - i++; - String msgDestination = roundService.getGameCode(newGameState); - - //Push the first block to the clients - AsyncMessage msg = new AsyncMessage(); - - msg.setDestination("mme"); - msg.setHeader("DSSubtopic", msgDestination); - msg.setClientId(clientID); - msg.setMessageId(UUIDUtils.createUUID()); - msg.setTimestamp(System.currentTimeMillis()); - - newGameState = roundService.getBlock(game); - setGame(newGameState); - if(newGameState == null) - { - msg.setBody(null); - } - else - { - block = newGameState.getCurrentBlock(); - msg.setBody(block); - } - msgBroker.routeMessageToService(msg, null); - logger.debug("message is sent to the client: " + msg); - - /* if(block.getDescription().equalsIgnoreCase("Day-by-day decisions game")) - { - //start day by day decision - //getDayBydayDecisionService(). - - } - else if (block.getDescription().equalsIgnoreCase("Communication")) - { - //start communication round - - }*/ - //get the timer for the block - Integer timer = roundService.getTimerforBlock(block); - //start the timer for the block sent - try { - //for testing purpose 5000 is given as an argument - Thread.sleep(10000); - if(block == null) - { - running = false; - } - } catch (InterruptedException e) { - } - } - } - private boolean isGameOver() { // TODO Auto-generated method stub return false; @@ -205,5 +133,63 @@ public Game getGame() { return game; } + + + @Override + public void run() { + + /*assignGroups(game); + Game newGameState = null; + Block block = null; + boolean running = false; + MessageBroker msgBroker = MessageBroker.getMessageBroker("_messageBroker"); + String clientID = UUIDUtils.createUUID(); + newGameState = game; + int i=0; + while (running) { + + i++; + String msgDestination = getGameCode(newGameState); + + //Push the first block to the clients + AsyncMessage msg = new AsyncMessage(); + + msg.setDestination("mme"); + msg.setHeader("DSSubtopic", msgDestination); + msg.setClientId(clientID); + msg.setMessageId(UUIDUtils.createUUID()); + msg.setTimestamp(System.currentTimeMillis()); + + newGameState = getBlock(game); + game = newGameState; + if(newGameState == null) + { + msg.setBody(null); + } + else + { + block = newGameState.getCurrentBlock(); + msg.setBody(block); + } + msgBroker.routeMessageToService(msg, null); + getLogger().debug("message is sent to the client: " + msg); + + //get the timer for the block + Integer timer = getTimerforBlock(block); + //start the timer for the block sent + try { + //for testing purpose 5000 is given as an argument + Thread.sleep(10000); + if(block == null) + { + running = false; + } + } catch (InterruptedException e) { + } + }*/ + + + + } } Modified: mentalmodels/trunk/src/main/java/edu/asu/commons/mme/service/StudentService.java =================================================================== --- mentalmodels/trunk/src/main/java/edu/asu/commons/mme/service/StudentService.java 2009-10-08 00:29:17 UTC (rev 288) +++ mentalmodels/trunk/src/main/java/edu/asu/commons/mme/service/StudentService.java 2009-10-08 18:29:40 UTC (rev 289) @@ -6,6 +6,7 @@ import org.hibernate.Hibernate; import org.springframework.transaction.annotation.Transactional; +import edu.asu.commons.mme.dao.HibernateGameDao; import edu.asu.commons.mme.dao.HibernateGroupDao; import edu.asu.commons.mme.dao.HibernateStudentDao; import edu.asu.commons.mme.entity.Game; @@ -24,37 +25,44 @@ @Transactional public class StudentService extends Service.Base<Student, HibernateStudentDao> { - HibernateGroupDao groupDao; + private HibernateGroupDao groupDao; + private HibernateGameDao gameDao; + public void setGameDao(HibernateGameDao gameDao) { + this.gameDao = gameDao; + } + public Student createStudent(Student student) { Student studentSave = null; if(!checkStudentAlreadyExists(student)) { studentSave = new Student(); - studentSave.setBirthYear(student.getBirthYear()); - studentSave.setGame(student.getGame()); - studentSave.setGameCode(student.getGameCode()); - studentSave.setGender(student.getGender()); - studentSave.setMajor(student.getMajor()); - studentSave.setSemester(student.getSemester()); - studentSave.setTimestamp(student.getTimestamp()); - - //studentSave.setTimestamp(new Timestamp(new Date().getTime())); - getDao(). - save(studentSave); - getLogger().debug("Student id is: " + studentSave.getId()); - + Game game = gameDao.findByProperty("gameCode", student.getGameCode()); + if(game !=null) + { + studentSave.setGame(game); + studentSave.setBirthYear(student.getBirthYear()); + studentSave.setGameCode(student.getGameCode()); + studentSave.setGender(student.getGender()); + studentSave.setMajor(student.getMajor()); + studentSave.setSemester(student.getSemester()); + studentSave.setTimestamp(student.getTimestamp()); + getDao().save(studentSave); + getLogger().info("Created the student..."); + getLogger().debug("Student id is: " + studentSave.getId()); + initializeStudent(studentSave); + } } - - initializeStudent(student); - return studentSave; } private void initializeStudent(Student student) { Hibernate.initialize(student); - Hibernate.initialize(student.getGame()); + Game game = student.getGame(); + Hibernate.initialize(game); + Hibernate.initialize(game.getGameConfig()); + Hibernate.initialize(game.getGameConfig().getLocations()); Hibernate.initialize(student.getGroup()); } @@ -78,87 +86,90 @@ List<Student> studentWithGroupsAssigned = new ArrayList<Student>(); List<Student> students = new ArrayList<Student>(); try{ - getLogger().debug("In the assigngroups." + game.getId()); + getLogger().debug("In the assigngroups." + game.getId()); - students = getDao().findAllByProperty("game", game); - - getLogger().debug("test student object is : " + students.size()); - if(students.size() > 1) - { - //write an algorithm to form groups - int totalStudents = students.size(); - int noOfGroupsWithSize3=0; - int noOfGroupsWithSize4=0; - int noOfGroupsWithSize5=0; - int x; + students = getDao().findAllByProperty("game", game); + //getLogger().debug("test student object is : " + students.size()); + if(students.size() > 1) + { + //write an algorithm to form groups + int totalStudents = students.size(); + int noOfGroupsWithSize3=0; + int noOfGroupsWithSize4=0; + int noOfGroupsWithSize5=0; + int x; - //no of groups - noOfGroupsWithSize5=((int)(totalStudents/5)); + //no of groups + noOfGroupsWithSize5=((int)(totalStudents/5)); - x= totalStudents%5; - /* if(x==0) + x= totalStudents%5; + + /* if(x==0) { totalGroups=groupSize5; } else*/ - if(x==1) - { - noOfGroupsWithSize5=noOfGroupsWithSize5 - 1; - noOfGroupsWithSize3=2; - // totalGroups=groupSize5 + groupSize3; - } + if(x==1) + { + noOfGroupsWithSize5=noOfGroupsWithSize5 - 1; + noOfGroupsWithSize3=2; + // totalGroups=groupSize5 + groupSize3; + } - else if(x==2) - { - noOfGroupsWithSize5=noOfGroupsWithSize5-1; - noOfGroupsWithSize4=1; - noOfGroupsWithSize3=1; - // totalGroups=groupSize5 + groupSize3 + groupSize4; - } - else if(x==3) - { - noOfGroupsWithSize3=1; - // totalGroups=groupSize3 + groupSize5; - } - - else if(x==4) - { - noOfGroupsWithSize4=1; - // totalGroups=groupSize4 + groupSize5; - } - - - getLogger().debug("size of 4 : " + noOfGroupsWithSize4); - getLogger().debug("size of 3 : " + noOfGroupsWithSize3); - getLogger().debug("size of 5 : " + noOfGroupsWithSize5); - - //assign every student a number and group - if(!students.isEmpty()) - { - if(noOfGroupsWithSize5 > 0) + else if(x==2) { - studentWithGroupsAssigned.addAll(assignGroupstoStudents(5,noOfGroupsWithSize5,students)); - getLogger().debug("student size after 5 is: " + students.size()); - getLogger().debug("student with groups assigned: " + studentWithGroupsAssigned.size()); + noOfGroupsWithSize5=noOfGroupsWithSize5-1; + noOfGroupsWithSize4=1; + noOfGroupsWithSize3=1; + // totalGroups=groupSize5 + groupSize3 + groupSize4; } - if(noOfGroupsWithSize4 > 0) + else if(x==3) { - studentWithGroupsAssigned.addAll(assignGroupstoStudents(4,noOfGroupsWithSize4,students)); - getLogger().debug("student size after 4 is: " + students.size()); - getLogger().debug("student with groups assigned: " + studentWithGroupsAssigned.size()); + noOfGroupsWithSize3=1; + // totalGroups=groupSize3 + groupSize5; } - if(noOfGroupsWithSize3 > 0) + + else if(x==4) { - studentWithGroupsAssigned.addAll(assignGroupstoStudents(3,noOfGroupsWithSize3,students)); - getLogger().debug("student size after 3 is: " + students.size()); - getLogger().debug("student with groups assigned: " + studentWithGroupsAssigned.size()); + noOfGroupsWithSize4=1; + // totalGroups=groupSize4 + groupSize5; } + + + //getLogger().debug("size of 4 : " + noOfGroupsWithSize4); + //getLogger().debug("size of 3 : " + noOfGroupsWithSize3); + //getLogger().debug("size of 5 : " + noOfGroupsWithSize5); + + int groupNo = 0; + //assign every student a number and group + if(!students.isEmpty()) + { + if(noOfGroupsWithSize5 > 0) + { + studentWithGroupsAssigned.addAll(assignGroupstoStudents(5,noOfGroupsWithSize5,students,groupNo)); + //getLogger().debug("student size after 5 is: " + students.size()); + //getLogger().debug("student with groups assigned: " + studentWithGroupsAssigned.size()); + } + groupNo = noOfGroupsWithSize5; + if(noOfGroupsWithSize4 > 0) + { + studentWithGroupsAssigned.addAll(assignGroupstoStudents(4,noOfGroupsWithSize4,students,groupNo)); + //getLogger().debug("student size after 4 is: " + students.size()); + //getLogger().debug("student with groups assigned: " + studentWithGroupsAssigned.size()); + } + groupNo = noOfGroupsWithSize5 + noOfGroupsWithSize4; + if(noOfGroupsWithSize3 > 0) + { + studentWithGroupsAssigned.addAll(assignGroupstoStudents(3,noOfGroupsWithSize3,students,groupNo)); + //getLogger().debug("student size after 3 is: " + students.size()); + //getLogger().debug("student with groups assigned: " + studentWithGroupsAssigned.size()); + } + } } - } - getLogger().debug("Final student with groups assigned: " + studentWithGroupsAssigned.size()); + getLogger().debug("Final student with groups assigned: " + studentWithGroupsAssigned.size()); }catch(Exception e) { getLogger().error(e); @@ -167,19 +178,20 @@ } - private List<Student> assignGroupstoStudents(int groupSize, int noOfGroups,List<Student> students) { + private List<Student> assignGroupstoStudents(int groupSize, int noOfGroups,List<Student> students,int groupNo) { // TODO Auto-generated method stub Student student = new Student(); List<Student> studentWithGroupsAssigned = new ArrayList<Student>(); - getLogger().debug("group size is : "+groupSize); - int k = 0; - for(int grpno = 0; grpno < noOfGroups; grpno++) + getLogger().debug("group size is : "+groupSize + " and group number is : "+ groupNo); + + for(int counter = 0; counter < noOfGroups; counter++) { //create group Group grp = new Group(); - k= grpno+1; - grp.setNumber(k); + + grp.setNumber(++groupNo); groupDao.save(grp); + getLogger().info("Group is created with id: " + grp.getId()); int studentNo = 1; int j = 0; @@ -198,7 +210,6 @@ studentNo++; initializeStudent(student); studentWithGroupsAssigned.add(student); - students.remove(0); } j++; Added: mentalmodels/trunk/src/main/java/edu/asu/commons/mme/utility/MessageHandler.java =================================================================== --- mentalmodels/trunk/src/main/java/edu/asu/commons/mme/utility/MessageHandler.java (rev 0) +++ mentalmodels/trunk/src/main/java/edu/asu/commons/mme/utility/MessageHandler.java 2009-10-08 18:29:40 UTC (rev 289) @@ -0,0 +1,78 @@ +package edu.asu.commons.mme.utility; + +import edu.asu.commons.mme.entity.Block; +import edu.asu.commons.mme.service.StartGame; +import flex.messaging.MessageBroker; +import flex.messaging.messages.AcknowledgeMessage; +import flex.messaging.messages.AsyncMessage; +import flex.messaging.util.UUIDUtils; +import org.apache.log4j.Logger; + +public class MessageHandler { + + private static Logger logger = Logger.getLogger(StartGame.class); + + private String destination; + + public String getDestination() { + return destination; + } + + public void setDestination(String destination) { + this.destination = destination; + } + + private String subtopic; + + public String getSubtopic() { + return subtopic; + } + + public void setSubtopic(String subtopic) { + this.subtopic = subtopic; + } + + public void send(Object message) + { + + MessageBroker msgBroker = MessageBroker.getMessageBroker("_messageBroker"); + + String clientID = UUIDUtils.createUUID(); + AsyncMessage msg = new AsyncMessage(); + msg.setDestination(destination); + //String msgDestination = game.getGameCode(); + msg.setHeader("DSSubtopic", subtopic); + msg.setClientId(clientID); + msg.setMessageId(UUIDUtils.createUUID()); + msg.setTimestamp(System.currentTimeMillis()); + + msg.setBody(message); + System.out.println("Message broker is: "+ msgBroker); + System.out.println("Students size is: " + message); + + AcknowledgeMessage ack = msgBroker.routeMessageToService(msg, null); + logger.info("Ack received from client for message " + msg + "is : " + ack); + } + + public void sendBlock(Block block) + { + MessageBroker msgBroker = MessageBroker.getMessageBroker("_messageBroker"); + + String clientID = UUIDUtils.createUUID(); + AsyncMessage msg = new AsyncMessage(); + msg.setDestination(destination); + //String msgDestination = game.getGameCode(); + msg.setHeader("DSSubtopic", subtopic); + msg.setClientId(clientID); + msg.setMessageId(UUIDUtils.createUUID()); + msg.setTimestamp(System.currentTimeMillis()); + + msg.setBody(block); + System.out.println("Message broker is: "+ msgBroker); + //System.out.println("Students size is: " + message); + + AcknowledgeMessage ack = msgBroker.routeMessageToService(msg, null); + logger.info("Ack received from client for message " + msg + "is : " + ack); + + } +} Modified: mentalmodels/trunk/src/main/webapp/WEB-INF/applicationContext.xml =================================================================== --- mentalmodels/trunk/src/main/webapp/WEB-INF/applicationContext.xml 2009-10-08 00:29:17 UTC (rev 288) +++ mentalmodels/trunk/src/main/webapp/WEB-INF/applicationContext.xml 2009-10-08 18:29:40 UTC (rev 289) @@ -111,7 +111,21 @@ <!-- spring managed service layer --> +<bean id='gameService' class='edu.asu.commons.mme.service.GameService'> + <property name='dao' ref='gameDao'/> + <property name='roundConfigDao' ref='roundConfigDao'/> + <property name='moduleDao' ref='moduleDao'/> + <property name='gameConfigDao' ref='gameConfigDao' /> + <property name='moduleRoundDao' ref='moduleRoundDao' /> + <property name='locationDao' ref='locationDao'/> + <property name='gameRoundDao' ref='gameRoundDao'/> + <property name='blockDao' ref='blockDao'/> + <property name='studentDao' ref='studentDao'/> + <property name='groupDao' ref='groupDao'/> + + </bean> + <bean id='dayByDayDecisionsService' class='edu.asu.commons.mme.service.DayByDayDecisionsService'> <property name='dao' ref='dayByDayDecisionsDao'/> </bean> @@ -157,6 +171,7 @@ <bean id='studentService' class='edu.asu.commons.mme.service.StudentService'> <property name='dao' ref='studentDao'/> <property name='groupDao' ref='groupDao'/> + <property name='gameDao' ref='gameDao'/> </bean> <!-- spring managed service layer --> @@ -186,10 +201,11 @@ <flex:remoting-destination ref="moduleService" /> <flex:remoting-destination ref="questionCreatorService" /> <flex:remoting-destination ref="roundService" /> - <flex:remoting-destination ref="startupService" /> + <flex:remoting-destination ref="gameService" /> <flex:remoting-destination ref="answeringService" /> <flex:remoting-destination ref="locationService" /> <flex:remoting-destination ref="feed" /> + <!-- Expose services for Flex/BlazeDS messaging --> <flex:message-destination id="chat" /> Modified: mentalmodels/trunk/src/main/webapp/WEB-INF/classes/log4j.properties =================================================================== --- mentalmodels/trunk/src/main/webapp/WEB-INF/classes/log4j.properties 2009-10-08 00:29:17 UTC (rev 288) +++ mentalmodels/trunk/src/main/webapp/WEB-INF/classes/log4j.properties 2009-10-08 18:29:40 UTC (rev 289) @@ -12,5 +12,5 @@ log4j.logger.edu.asu.commons=DEBUG #log4j.logger.org.springframework=DEBUG -log4j.logger.org.springframework=DEBUG +log4j.logger.org.springframework=ERROR log4j.logger.org.hibernate=ERROR This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <al...@us...> - 2009-10-08 00:29:29
|
Revision: 288 http://virtualcommons.svn.sourceforge.net/virtualcommons/?rev=288&view=rev Author: alllee Date: 2009-10-08 00:29:17 +0000 (Thu, 08 Oct 2009) Log Message: ----------- initial import of legacy irrigation experiment with new csidex dependency. renamed edu.asu.csid to edu.asu.commons and some minor changes. Added Paths: ----------- irrigation/trunk/src/main/java/edu/ irrigation/trunk/src/main/java/edu/asu/ irrigation/trunk/src/main/java/edu/asu/commons/ irrigation/trunk/src/main/java/edu/asu/commons/irrigation/ irrigation/trunk/src/main/java/edu/asu/commons/irrigation/client/ irrigation/trunk/src/main/java/edu/asu/commons/irrigation/client/ActivitySummaryPanel.java irrigation/trunk/src/main/java/edu/asu/commons/irrigation/client/ActivitySummaryPanelNew.java irrigation/trunk/src/main/java/edu/asu/commons/irrigation/client/Ball.java irrigation/trunk/src/main/java/edu/asu/commons/irrigation/client/CanalPanel.java irrigation/trunk/src/main/java/edu/asu/commons/irrigation/client/CanalPanelAnimation.java irrigation/trunk/src/main/java/edu/asu/commons/irrigation/client/CanalPanelAnimationNew.java irrigation/trunk/src/main/java/edu/asu/commons/irrigation/client/ChartWindowPanel.java irrigation/trunk/src/main/java/edu/asu/commons/irrigation/client/ChartWindowPanelTokenBandwidth.java irrigation/trunk/src/main/java/edu/asu/commons/irrigation/client/ChatPanel.java irrigation/trunk/src/main/java/edu/asu/commons/irrigation/client/ExperimentGameWindow.java irrigation/trunk/src/main/java/edu/asu/commons/irrigation/client/Gate.java irrigation/trunk/src/main/java/edu/asu/commons/irrigation/client/IrrigationClient.java irrigation/trunk/src/main/java/edu/asu/commons/irrigation/client/IrrigationClientGameState.java irrigation/trunk/src/main/java/edu/asu/commons/irrigation/client/IrrigationGameWindow.java irrigation/trunk/src/main/java/edu/asu/commons/irrigation/client/MainIrrigationGameWindow.java irrigation/trunk/src/main/java/edu/asu/commons/irrigation/client/MiddleScorePanel.java irrigation/trunk/src/main/java/edu/asu/commons/irrigation/client/MiddleWindowPanel.java irrigation/trunk/src/main/java/edu/asu/commons/irrigation/client/PieChart.java irrigation/trunk/src/main/java/edu/asu/commons/irrigation/client/ScoreBoxPanel.java irrigation/trunk/src/main/java/edu/asu/commons/irrigation/conf/ irrigation/trunk/src/main/java/edu/asu/commons/irrigation/conf/RoundConfiguration.java irrigation/trunk/src/main/java/edu/asu/commons/irrigation/conf/ServerConfiguration.java irrigation/trunk/src/main/java/edu/asu/commons/irrigation/events/ irrigation/trunk/src/main/java/edu/asu/commons/irrigation/events/BeginCommunicationRequest.java irrigation/trunk/src/main/java/edu/asu/commons/irrigation/events/ClientUpdateEvent.java irrigation/trunk/src/main/java/edu/asu/commons/irrigation/events/DisplaySubmitTokenRequest.java irrigation/trunk/src/main/java/edu/asu/commons/irrigation/events/EndRoundEvent.java irrigation/trunk/src/main/java/edu/asu/commons/irrigation/events/ExperimentDurationEvent.java irrigation/trunk/src/main/java/edu/asu/commons/irrigation/events/FacilitatorEndRoundEvent.java irrigation/trunk/src/main/java/edu/asu/commons/irrigation/events/FileDownloadCompleteEvent.java irrigation/trunk/src/main/java/edu/asu/commons/irrigation/events/FileDownloadedEvent.java irrigation/trunk/src/main/java/edu/asu/commons/irrigation/events/GateOpenedEvent.java irrigation/trunk/src/main/java/edu/asu/commons/irrigation/events/InstructionEnableRequest.java irrigation/trunk/src/main/java/edu/asu/commons/irrigation/events/InvestedTokensEvent.java irrigation/trunk/src/main/java/edu/asu/commons/irrigation/events/QuizCompletedEvent.java irrigation/trunk/src/main/java/edu/asu/commons/irrigation/events/RegistrationEvent.java irrigation/trunk/src/main/java/edu/asu/commons/irrigation/events/RoundStartedEvent.java irrigation/trunk/src/main/java/edu/asu/commons/irrigation/events/SendContributionStatusEvent.java irrigation/trunk/src/main/java/edu/asu/commons/irrigation/events/SendFileProgressEvent.java irrigation/trunk/src/main/java/edu/asu/commons/irrigation/events/ServerGameStateEvent.java irrigation/trunk/src/main/java/edu/asu/commons/irrigation/events/StartDownload.java irrigation/trunk/src/main/java/edu/asu/commons/irrigation/events/StartPausedEvent.java irrigation/trunk/src/main/java/edu/asu/commons/irrigation/events/StopDownloadEvent.java irrigation/trunk/src/main/java/edu/asu/commons/irrigation/events/TransferFileInformationEvent.java irrigation/trunk/src/main/java/edu/asu/commons/irrigation/facilitator/ irrigation/trunk/src/main/java/edu/asu/commons/irrigation/facilitator/IrrigationFacilitator.java irrigation/trunk/src/main/java/edu/asu/commons/irrigation/facilitator/IrrigationFacilitatorWindow.java irrigation/trunk/src/main/java/edu/asu/commons/irrigation/server/ irrigation/trunk/src/main/java/edu/asu/commons/irrigation/server/ClientData.java irrigation/trunk/src/main/java/edu/asu/commons/irrigation/server/GroupDataModel.java irrigation/trunk/src/main/java/edu/asu/commons/irrigation/server/IrrigationPersister.java irrigation/trunk/src/main/java/edu/asu/commons/irrigation/server/IrrigationServer.java irrigation/trunk/src/main/java/edu/asu/commons/irrigation/server/ServerDataModel.java Added: irrigation/trunk/src/main/java/edu/asu/commons/irrigation/client/ActivitySummaryPanel.java =================================================================== --- irrigation/trunk/src/main/java/edu/asu/commons/irrigation/client/ActivitySummaryPanel.java (rev 0) +++ irrigation/trunk/src/main/java/edu/asu/commons/irrigation/client/ActivitySummaryPanel.java 2009-10-08 00:29:17 UTC (rev 288) @@ -0,0 +1,132 @@ +/** + * + */ +package edu.asu.commons.irrigation.client; + +import java.awt.Color; +import java.awt.Dimension; +import java.awt.GridLayout; + +import javax.swing.JLabel; +import javax.swing.JPanel; +import javax.swing.SwingUtilities; + +import edu.asu.commons.irrigation.server.ClientData; + +/** + * @author Sanket + * + */ +public class ActivitySummaryPanel extends JPanel { + + /** + * + */ + private static final long serialVersionUID = -2400441194759984763L; + private JLabel currentBandwidthTextjLabel = null; + private JLabel filesDownloadedjLabel = null; + private JLabel filesDownloadedTextjLabel = null; + private JLabel tokensCollectedjLabel = null; + private JLabel currentBandwidthjLabel = null; + private JLabel tokensCollectedTextjLabel = null; + + private JLabel positionjLabel = null; + private JLabel positionTextjLabel = null; + + private ClientData clientData; // @jve:decl-index=0: + /** + * This method initializes + * + */ + public ActivitySummaryPanel(int i) { + super(); + initialize(i); + } + + /** + * This method initializes this + * + */ + private void initialize(int i) { + tokensCollectedTextjLabel = new JLabel(); + tokensCollectedTextjLabel.setText(""); + currentBandwidthjLabel = new JLabel(); + currentBandwidthjLabel.setText("Current Flow Capacity:"); + tokensCollectedjLabel = new JLabel(); + tokensCollectedjLabel.setText("Tokens Collected:"); + filesDownloadedTextjLabel = new JLabel(); + filesDownloadedTextjLabel.setText(""); + filesDownloadedjLabel = new JLabel(); + filesDownloadedjLabel.setText("Crops Grown:"); + currentBandwidthTextjLabel = new JLabel(); + currentBandwidthTextjLabel.setText(""); + + positionjLabel = new JLabel(); + positionjLabel.setText("Position :"); + + positionTextjLabel = new JLabel(); + positionTextjLabel.setText(""); + + GridLayout gridLayout = new GridLayout(); + gridLayout.setRows(4); + gridLayout.setColumns(2); + this.setLayout(gridLayout); + this.setSize(new Dimension(430,126)); + switch(i) + { + case 0: this.setBackground(Color.PINK); + break; + + case 1: this.setBackground(Color.GREEN); + break; + + case 2: this.setBackground(Color.WHITE); + break; + + case 3: this.setBackground(Color.CYAN); + break; + + case 4: this.setBackground(Color.YELLOW); + break; + } + this.add(positionjLabel, null); + this.add(positionTextjLabel, null); + this.add(currentBandwidthjLabel, null); + this.add(currentBandwidthTextjLabel, null); + this.add(filesDownloadedjLabel, null); + this.add(filesDownloadedTextjLabel, null); + this.add(tokensCollectedjLabel, null); + this.add(tokensCollectedTextjLabel, null); + } + + public void update(ClientData data) { + this.clientData = data; + // TODO Auto-generated method stub + //System.out.println("Client Data Prioriity"+clientData.getPriority()+"Avaiable bandwidth"+ + //clientData.getAvailableBandwidth()); + + Runnable createGuiRunnable = new Runnable(){ + public void run() { + //System.out.println("In the UPdate facilitator"); + positionTextjLabel.setText(new Integer(clientData.getPriority()).toString()); + tokensCollectedTextjLabel.setText(new Integer(clientData.getTotalTokensEarned()).toString()); + if(clientData.getAvailableFlowCapacity() > 25){ + currentBandwidthTextjLabel.setText(new Double(25).toString()); + } + else + currentBandwidthTextjLabel.setText(new Double(clientData.getAvailableFlowCapacity()).toString()); + filesDownloadedTextjLabel.setText(new Integer(clientData.getCropsGrown()).toString()); + } + }; + SwingUtilities.invokeLater(createGuiRunnable); + } + + public void endRound() { + // TODO Auto-generated method stub + currentBandwidthTextjLabel.setText(""); + filesDownloadedTextjLabel.setText(""); + tokensCollectedTextjLabel.setText(""); + + } + +} // @jve:decl-index=0:visual-constraint="10,10" Added: irrigation/trunk/src/main/java/edu/asu/commons/irrigation/client/ActivitySummaryPanelNew.java =================================================================== --- irrigation/trunk/src/main/java/edu/asu/commons/irrigation/client/ActivitySummaryPanelNew.java (rev 0) +++ irrigation/trunk/src/main/java/edu/asu/commons/irrigation/client/ActivitySummaryPanelNew.java 2009-10-08 00:29:17 UTC (rev 288) @@ -0,0 +1,221 @@ +/** + * + */ +package edu.asu.commons.irrigation.client; + +import java.awt.Color; +import java.awt.Font; +import java.awt.Rectangle; +import java.util.LinkedHashMap; +import java.util.Map; + +import javax.swing.JLabel; +import javax.swing.JPanel; +import javax.swing.JProgressBar; + +import edu.asu.commons.irrigation.server.ClientData; + + +/** + * @author Sanket + * + */ +public class ActivitySummaryPanelNew extends JPanel { + + /** + * + */ + private static final long serialVersionUID = 2393688647176774993L; + + //create three Maps for every parameter + Map<Integer,JProgressBar>availableBandwidthMap = new LinkedHashMap<Integer, JProgressBar>(); + Map<Integer, JLabel>filesDownLoadedMap = new LinkedHashMap<Integer, JLabel>(); + Map<Integer, JLabel>tokensCollectedMap = new LinkedHashMap<Integer, JLabel>(); + + JLabel labelA; + + JLabel labelB; + + JLabel labelC; + + JLabel labelD; + + JLabel labelE; + + JLabel titleLabel[] = new JLabel[3]; + + //private int NUMBER_OF_PARTICIPANTS_PERGROUP = 2; + + private int parameterIndex; + + IrrigationClient client; // @jve:decl-index=0: + + public ActivitySummaryPanelNew(int parameterIndex, IrrigationClient client) { + // TODO Auto-generated constructor stub + super(); + initialize(parameterIndex,client); + } + + private void initialize(int parameterIndex,IrrigationClient client) { + // TODO Auto-generated method stub + this.parameterIndex = parameterIndex; + + this.client = client; + + this.setLayout(null); + /*else{ + GridLayout gridLayout = new GridLayout(); + gridLayout.setColumns(1); + gridLayout.setRows(5); + this.setLayout(gridLayout); + }*/ + //add the parameters depending on the parameter Index + //initialize Labels + + for(int i=0;i<client.getRoundConfiguration().getClientsPerGroup();i++){ + System.out.println("I reach here"); + switch(i){ + case 0 :labelA = new JLabel(); + labelA.setBounds(new Rectangle(0,30+15*(i+i),25,15)); + if(client.getClientGameState().getPriority() == i){ + labelA.setText("YOU"); + } + else + labelA.setText("A"); + this.add(labelA); + break; + + case 1: labelB = new JLabel(); + labelB.setBounds(new Rectangle(0,30+15*(i+i),25,15)); + if(client.getClientGameState().getPriority() == i){ + labelB.setText("YOU"); + } + else + labelB.setText("B"); + this.add(labelB); + break; + + case 2: labelC = new JLabel(); + labelC.setBounds(new Rectangle(0,30+15*(i+i),25,15)); + if(client.getClientGameState().getPriority() == i){ + labelC.setText("YOU"); + } + else + labelC.setText("C"); + this.add(labelC); + break; + + case 3: labelD = new JLabel(); + labelD.setBounds(new Rectangle(0,30+15*(i+i),25,15)); + if(client.getClientGameState().getPriority() == i){ + labelD.setText("YOU"); + } + else + labelD.setText("D"); + this.add(labelD); + break; + + case 4: labelE = new JLabel(); + labelE.setBounds(new Rectangle(0,30+15*(i+i),25,15)); + if(client.getClientGameState().getPriority() == i){ + labelE.setText("YOU"); + } + else + labelE.setText("E"); + this.add(labelE); + break; + } + } + switch(parameterIndex){ + + case 0 : //add the progress Bbar + this.setBackground(Color.PINK); + titleLabel[0] = new JLabel(); + titleLabel[0].setText("Available Flow Capacity"); + titleLabel[0].setBounds(new Rectangle(60,5,200,20)); + this.add(titleLabel[0],null); + for(int i=0;i<client.getRoundConfiguration().getClientsPerGroup();i++){ + JProgressBar availableBandwidthProgressBar = new JProgressBar(); + availableBandwidthProgressBar.setMaximum(25); + availableBandwidthProgressBar.setBounds(new Rectangle(40,30+15*(i+i),150,15)); + availableBandwidthProgressBar.setStringPainted(true); + if(i == client.getClientGameState().getPriority()){ + availableBandwidthProgressBar.setForeground(Color.ORANGE); + } + else + availableBandwidthProgressBar.setForeground(new Color(51, 153, 255)); + availableBandwidthProgressBar.setBackground(Color.white); + availableBandwidthProgressBar.setValue(25); + this.add(availableBandwidthProgressBar); + availableBandwidthMap.put(new Integer(i), availableBandwidthProgressBar); + } + break; + + case 1 : //add the number of files downloaded + this.setBackground(Color.WHITE); + titleLabel[1] = new JLabel(); + titleLabel[1].setText("Crops Grown"); + titleLabel[1].setBounds(new Rectangle(60,5,200,20)); + this.add(titleLabel[1],null); + for(int i=0;i<client.getRoundConfiguration().getClientsPerGroup();i++){ + JLabel filesDownLoaded = new JLabel(); + filesDownLoaded.setFont(new Font("Serif", Font.BOLD, 14)); + if(i == client.getClientGameState().getPriority()){ + filesDownLoaded.setForeground(Color.ORANGE); + } + else + filesDownLoaded.setForeground(new Color(51,153,255)); + filesDownLoaded.setBounds(new Rectangle(132,30+15*(i+i),100,15)); + this.add(filesDownLoaded); + filesDownLoaded.setText(""); + filesDownLoadedMap.put(new Integer(i),filesDownLoaded); + } + break; + + case 2: //add the number of tokens collected + this.setBackground(Color.WHITE); + titleLabel[2] = new JLabel(); + titleLabel[2].setText("Tokens Collected"); + titleLabel[2].setBounds(new Rectangle(60,5,200,20)); + this.add(titleLabel[2],null); + for(int i=0;i<client.getRoundConfiguration().getClientsPerGroup();i++){ + JLabel tokensCollected = new JLabel(); + tokensCollected.setFont(new Font("Comic Sans MS", Font.BOLD, 14)); + if(i == client.getClientGameState().getPriority()){ + tokensCollected.setForeground(Color.ORANGE); + } + else + tokensCollected.setForeground(new Color(51,153,255)); + tokensCollected.setBounds(new Rectangle(132,30+15*(i+i),100,15)); + this.add(tokensCollected); + tokensCollected.setText(""); + tokensCollectedMap.put(new Integer(i),tokensCollected); + } + break; + } + } + + public void update(ClientData clientData) { + // TODO Auto-generated method stub + switch(parameterIndex){ + case 0 : + availableBandwidthMap.get(new Integer(clientData.getPriority())).setValue((int) clientData.getAvailableFlowCapacity()); + break; + + case 1: + filesDownLoadedMap.get(new Integer(clientData.getPriority())).setText(new Integer(clientData.getCropsGrown()).toString()); + break; + + case 2: + tokensCollectedMap.get(new Integer(clientData.getPriority())).setText(new Integer(clientData.getTotalTokensEarned()).toString()); + break; + } + } + + //implement this Later on + public void endRound() { + // TODO Auto-generated method stub + //implement this later on. + } + +} Added: irrigation/trunk/src/main/java/edu/asu/commons/irrigation/client/Ball.java =================================================================== --- irrigation/trunk/src/main/java/edu/asu/commons/irrigation/client/Ball.java (rev 0) +++ irrigation/trunk/src/main/java/edu/asu/commons/irrigation/client/Ball.java 2009-10-08 00:29:17 UTC (rev 288) @@ -0,0 +1,102 @@ +package edu.asu.commons.irrigation.client; + +import java.util.Random; + +public class Ball{ + + public boolean isInServer; + + public boolean isInFirstCanal; + + public boolean isInSecondCanal; + + private int size = 2; + + public int x; + + public int y; + + public int moveX; + public int moveY; + + public int xBOUNDSUPPER; + public int xBOUNDSLOWER; + public int yBOUNDSUPPER; + public int yBOUNDSLOWER; + + //just one global variable speciying the ten potential positions of the balls + private int position; + + public Ball(Random generator){ + + this.x = generator.nextInt(100); + this.y = generator.nextInt(100); + this.xBOUNDSUPPER = 100; + this.yBOUNDSUPPER = 100; + this.xBOUNDSLOWER = 0; + this.yBOUNDSLOWER = 0; + this.moveX = generator.nextInt(15); + this.moveY = generator.nextInt(10); + /*this.moveX = 3; + this.moveY = 3; + */ + setPosition(0); + } + + public void setPosition(int position) { + // TODO Auto-generated method stub + + //System.out.println("Setting the position :"+position); + + this.position = position; + + } + + public int getBallSize(){ + return size; + } + + public boolean getIsInServer(){ + return isInServer; + } + + public boolean getIsInFirstCanal(){ + return isInFirstCanal; + } + + public boolean getIsInSecondCanal(){ + return isInSecondCanal; + } + + public void setX(int x){ + this.x = x; + } + + public void setY(int y){ + this.y = y; + } + + public int getPosition() { + // TODO Auto-generated method stub + return position; + } + + public int getX() { + // TODO Auto-generated method stub + return x; + } + + /* + * will set the upper and the lower bounds for a ball depending on its position + */ + /*public void setBounds(int position) { + // TODO Auto-generated method stub + + }*/ + + public int getY() { + // TODO Auto-generated method stub + return y; + } + +} \ No newline at end of file Added: irrigation/trunk/src/main/java/edu/asu/commons/irrigation/client/CanalPanel.java =================================================================== --- irrigation/trunk/src/main/java/edu/asu/commons/irrigation/client/CanalPanel.java (rev 0) +++ irrigation/trunk/src/main/java/edu/asu/commons/irrigation/client/CanalPanel.java 2009-10-08 00:29:17 UTC (rev 288) @@ -0,0 +1,472 @@ +package edu.asu.commons.irrigation.client; + +import java.awt.Color; +import java.awt.Graphics; +import java.awt.Graphics2D; +import java.awt.GridBagLayout; +import java.awt.event.ActionEvent; +import java.awt.event.ActionListener; +import java.util.Random; + +import javax.swing.JPanel; +import javax.swing.Timer; + +/** + * @author Sanket + * + */ +public class CanalPanel extends JPanel { + + private static final long serialVersionUID = 1L; + + /** + * This is the default constructor + */ + private int x1UpStream; + + private int y1UpStream; + + private int x2UpStream = 420; + + private int y2UpStream = 100; + + private int y2DownStream = 100; + + private int x2DownStream = 950; + + private int y1DownStream; + + private int x1DownStream; + + private Graphics2D graphics2D; + + private boolean flagDownStream = false; + + private boolean flagUpStream = false; + + //private IrrigationClientGameState clientGameState; + + //////////////////animation logic parameters////////////////////////////// + private Timer timer; + + private final int DELAY = 20; + + private Ball balls[]; + + private int BALLCOUNT = 500; + + private Gate gate[] = new Gate[6]; + + private int gateHeight = 20; + + Random generator = new Random(); + + private boolean enableBallAnimation = true; + + private double totalContributedBandwidth; + + private IrrigationClientGameState clientGameState; + + private int numberofGates = 6; + + private int serverHeight = 100; + + private int serverWidth = 100; + + private double bandWidthCanalHeightMapping = 0.8; + + private int gateBuffer = 20; + + //////////////////////////////////////////////////////////////////////////// + + public CanalPanel(IrrigationClientGameState clientGameState) { + super(); + //when totalContributed bandwidth = 1.0, you dont see the canal line + this.totalContributedBandwidth = clientGameState.getGroupDataModel().getMaximumAvailableFlowCapacity(); + this.clientGameState = clientGameState; + if(totalContributedBandwidth == 1.0){ + totalContributedBandwidth = 2.0; + } + + initialize(); + } + + /** + * This method initializes this + * + * @return void + */ + private void initialize() { + this.setSize(1098,150); + this.setLayout(new GridBagLayout()); + this.setBackground(Color.white); + //initializing the constructor for Gates + for(int i=0;i<numberofGates ;i++){ + gate[i] = new Gate(totalContributedBandwidth,i); + //System.out.println("Gate "+i+"x : "+gate[i].getX()+"y : "+gate[i].getY()); + } + + initializexy(); + + timer = new Timer(DELAY, new Rebound()); // setup the Timer to do an action + // every DELAY times. + timer.start(); // starts the timer. + + } + + protected void paintComponent(Graphics graphics){ + updateGUI(); + super.paintComponent(graphics); // needed! + Graphics2D graphics2D = (Graphics2D)graphics; + this.graphics2D = graphics2D; + this.graphics2D.setColor(Color.BLUE); + this.graphics2D.fillRect(0,0,serverHeight,serverWidth); + //draw the other gates + for(int i=0;i<numberofGates-1;i++){ + this.graphics2D.setColor(Color.BLUE); + this.graphics2D.fillRect(gate[i].getX(), gate[i].getY(), gate[i].getWidth(),gate[i].getHeight()); + } + + int numClients = clientGameState.getAllClientIdentifiers().size(); + for(int i=0;i<numClients;i++){ + this.graphics2D.setColor(Color.BLUE); + this.graphics2D.fillRect(gate[i].getOpeningsX(), gate[i].getOpeningsY(),gate[i].getOpeningsWidth(), + gate[i].getOpeningsHeight()); + this.graphics2D.setColor(Color.BLACK); + this.graphics2D.drawLine(gate[i].getx1(),gate[i].gety1(),gate[i].getx2(),gate[i].gety2()); + } + + this.graphics2D.setColor(Color.BLUE); + this.graphics2D.fillRect(gate[5].getX(), gate[5].getY(),10,gate[5].getHeight()); + + //////////////////////Animation Logic//////////////////////////// + if(enableBallAnimation == true) + { + graphics.setColor(Color.white); +// int ballCounter = 0; + for(int i=0;i<BALLCOUNT;i++){ + if((balls[i].getPosition() == 1)||(balls[i].getPosition() == 2) || (balls[i].getPosition()==3) + || (balls[i].getPosition() == 4) || (balls[i].getPosition() == 5)){ + if(!((!gate[balls[i].getPosition()-1].isOpenGate())&& balls[i].getY() >= (gate[balls[i].getPosition()-1].getY()+gate[balls[i].getPosition()-1].getHeight()))) + graphics.fillOval(balls[i].x,balls[i].y,balls[i].getBallSize(), balls[i].getBallSize()); + } + else{ + if(balls[i].getPosition() != 0){ + if(gate[balls[i].getPosition() - 6].getHeight() != 0) + graphics.fillOval(balls[i].x,balls[i].y,balls[i].getBallSize(), balls[i].getBallSize()); + } + else{ + graphics.fillOval(balls[i].x,balls[i].y,balls[i].getBallSize(), balls[i].getBallSize()); + } + } + } + } + + } + + + + private void updateGUI() { + for(int i=1;i<6;i++){ + if(gate[i-1].isOpenGate()){ + if(!(gate[i-1].getHeight() - gateHeight < 0)){ + gate[i].setHeight(gate[i-1].getHeight() - gateHeight ); + + } + else{ + gate[i].setHeight(0); + } + } + else{ + gate[i].setHeight(gate[i-1].getHeight()); + + } + //order matters here + if(!(i == 5)){ + gate[i].setOpeningsHeight((totalContributedBandwidth*bandWidthCanalHeightMapping) + - gate[i].getHeight()); + gate[i].setOpeningsY(gate[i].getOpeningsHeight() - 50); + + //opening the lid logic + if(gate[i].isOpenGate()){ + gate[i].setx1(gate[i].getx2()); + if(!(gate[i].gety2()- gate[i].getGateWidth() < gate[i].getY())) + gate[i].sety1(gate[i].gety2()- gate[i].getGateWidth()); + else + gate[i].sety1(gate[i].getOpeningsY()); + } + else{ + gate[i].setx1(gate[i].getdefaultx1()); + gate[i].sety1(gate[i].getdefaulty1()); + } + + if(gate[0].isOpenGate()){ + gate[0].setx1(gate[0].getx2()); + if(!(gate[0].gety2()- gate[0].getGateWidth() < gate[0].getY())) + gate[0].sety1(gate[0].gety2()- gate[0].getGateWidth()); + else + gate[0].sety1(gate[0].getY()); + } + else{ + gate[0].setx1(gate[0].getdefaultx1()); + gate[0].sety1(gate[0].getdefaulty1()); + } + + } + } + } + + /* + * initialize the Balls + */ + private void initializexy() { + // TODO Auto-generated method stub + balls = new Ball[BALLCOUNT]; + if(balls == null){ + System.out.println("Ball is null"); + } + + for(int i=0;i<BALLCOUNT;i++){ + balls[i] = new Ball(generator); + + } + } + + // this is the private class the Timer will look at every DELAY seconds + private class Rebound implements ActionListener{ + Random generator = new Random(); + public void actionPerformed(ActionEvent e) { + for(int i=0;i<BALLCOUNT;i++){ + //updateGUI(); + balls[i].x += balls[i].moveX; + balls[i].y += balls[i].moveY; + process(i); + } + repaint(); + } + } + + /* + * This will process the balls according to their position + */ + private void process(int i){ + // TODO Auto-generated method stub + + switch(balls[i].getPosition()){ + + case 0: if((balls[i].x >= (serverWidth - gateBuffer ) && balls[i].x <= serverWidth) && (balls[i].y >= serverHeight-(int)(totalContributedBandwidth*bandWidthCanalHeightMapping) && + balls[i].y <= serverHeight)){ + balls[i].setPosition(1); + setBounds(i); + } + //still in server + else{ + setBounds(i); + if(balls[i].x <= balls[i].xBOUNDSLOWER || balls[i].x >= balls[i].xBOUNDSUPPER-balls[i].getBallSize()){ + balls[i].moveX = balls[i].moveX * -1; + } + if(balls[i].y <= balls[i].yBOUNDSLOWER || balls[i].y >= balls[i].yBOUNDSUPPER-balls[i].getBallSize()) + balls[i].moveY = balls[i].moveY * -1; + } + break; + + case 1: if(gate[0].isOpenGate() && (balls[i].x >= gate[0].getOpeningsX() && balls[i].x <= (gate[0].getOpeningsX()+gateBuffer)) + && (balls[i].y >= serverHeight - gateBuffer && balls[i].y <= serverHeight)){ + balls[i].setPosition(7); + //directly pass in the information + setBounds(i); + } + else{ + setBounds(i); + if(balls[i].getX() > balls[i].xBOUNDSUPPER){ + balls[i].setPosition(2); + } + if(balls[i].getY() >= balls[i].yBOUNDSUPPER - balls[i].getBallSize() || balls[i].getY() <= balls[i].yBOUNDSLOWER){ + balls[i].moveY = balls[i].moveY*-1; + } + } + + break; + + case 2: if(gate[1].isOpenGate() && (balls[i].x >= gate[1].getOpeningsX() && balls[i].x <= (gate[1].getOpeningsX()+gateBuffer)) + && (balls[i].y >= serverHeight - gateBuffer && balls[i].y <= serverHeight)){ + balls[i].setPosition(8); + //directly pass in the information + setBounds(i); + } + else{ + setBounds(i); + if(balls[i].getX() > balls[i].xBOUNDSUPPER){ + balls[i].setPosition(3); + } + if(balls[i].getY() >= balls[i].yBOUNDSUPPER - balls[i].getBallSize() || balls[i].getY() <= balls[i].yBOUNDSLOWER){ + balls[i].moveY = balls[i].moveY*-1; + } + } + break; + + + case 3: if(gate[2].isOpenGate() && (balls[i].x >= gate[2].getOpeningsX() && balls[i].x <= (gate[2].getOpeningsX()+gateBuffer)) + && (balls[i].y >= serverHeight - gateBuffer && balls[i].y <= serverHeight)){ + balls[i].setPosition(9); + //directly pass in the information + setBounds(i); + /* balls[i].xBOUNDSUPPER = 420; + balls[i].xBOUNDSLOWER = 400; + balls[i].yBOUNDSUPPER = 150; + balls[i].yBOUNDSLOWER = 80; + balls[i].moveX = 0; + balls[i].moveY = 3;*/ + } + else{ + setBounds(i); + if(balls[i].getX() > balls[i].xBOUNDSUPPER){ + balls[i].setPosition(4); + } + if(balls[i].getY() >= balls[i].yBOUNDSUPPER - balls[i].getBallSize() || balls[i].getY() <= balls[i].yBOUNDSLOWER){ + balls[i].moveY = balls[i].moveY*-1; + } + } + break; + + case 4: if(gate[3].isOpenGate() && (balls[i].x >= gate[3].getOpeningsX() && balls[i].x <= (gate[3].getOpeningsX()+gateBuffer)) + && (balls[i].y >= serverHeight - gateBuffer && balls[i].y <= serverHeight)){ + balls[i].setPosition(10); + //directly pass in the information + setBounds(i); + } + else{ + setBounds(i); + if(balls[i].getX() > balls[i].xBOUNDSUPPER){ + balls[i].setPosition(5); + } + if(balls[i].getY() >= balls[i].yBOUNDSUPPER - balls[i].getBallSize() || balls[i].getY() <= balls[i].yBOUNDSLOWER){ + balls[i].moveY = balls[i].moveY*-1; + } + } + break; + + case 5: if(gate[4].isOpenGate() && (balls[i].x >= gate[4].getOpeningsX() && balls[i].x <= (gate[4].getOpeningsX()+gateBuffer)) + && (balls[i].y >= serverHeight - gateBuffer && balls[i].y <= serverHeight)){ + balls[i].setPosition(11); + //directly pass in the information + setBounds(i); + } + else{ + setBounds(i); + if(balls[i].getX() > balls[i].xBOUNDSUPPER){ + balls[i].setPosition(6); + } + if(balls[i].getY() >= balls[i].yBOUNDSUPPER - balls[i].getBallSize() || balls[i].getY() <= balls[i].yBOUNDSLOWER){ + balls[i].moveY = balls[i].moveY*-1; + } + } + break; + + case 6: setBounds(i); + if(balls[i].getX() > balls[i].xBOUNDSUPPER){ + setBallinServer(i); + } + + if(balls[i].getY() >= balls[i].yBOUNDSUPPER - balls[i].getBallSize() || balls[i].getY() <= balls[i].yBOUNDSLOWER){ + balls[i].moveY = balls[i].moveY*-1; + } + break; + } + + //set balls back to the server when they complete their flow in the gates + if((balls[i].getPosition() == 11) || (balls[i].getPosition() == 7) || (balls[i].getPosition() == 8) + || (balls[i].getPosition() == 9) || (balls[i].getPosition() == 10)){ + if(balls[i].getY() >= 150){ + setBallinServer(i); + } + else{ + setBounds(i); + } + } + } + + + private void setBallinServer(int i) { + // TODO Auto-generated method stub + generator.setSeed(i*(i+1)); + balls[i].setX(generator.nextInt(serverWidth)); + balls[i].setY(generator.nextInt(serverHeight)); + balls[i].setPosition(0); + if(balls[i].moveX == 0) + balls[i].moveX = generator.nextInt(15); + setBounds(i); + } + + private void setBounds(int ballIndex) { + // TODO Auto-generated method stub + //ball is in the server + if(balls[ballIndex].getPosition() == 0){ + balls[ballIndex].xBOUNDSUPPER = serverWidth; + balls[ballIndex].xBOUNDSLOWER = 0; + balls[ballIndex].yBOUNDSUPPER = serverHeight; + balls[ballIndex].yBOUNDSLOWER = 0; + //balls[ballIndex].moveX = generator.nextInt(6); + //balls[ballIndex].moveY = generator.nextInt(6); + //balls[ballIndex].moveX = 3; + //balls[ballIndex].moveY = 3; + } + else{ + if((balls[ballIndex].getPosition() == 1)||(balls[ballIndex].getPosition() == 2) || (balls[ballIndex].getPosition()==3) + || (balls[ballIndex].getPosition() == 4) || (balls[ballIndex].getPosition() == 5)||(balls[ballIndex].getPosition() == 6)){ + + balls[ballIndex].xBOUNDSUPPER = gate[balls[ballIndex].getPosition() - 1].getX()+gate[balls[ballIndex].getPosition() - 1].getWidth(); + balls[ballIndex].xBOUNDSLOWER = gate[balls[ballIndex].getPosition() - 1].getX(); + balls[ballIndex].yBOUNDSUPPER = gate[balls[ballIndex].getPosition() - 1].getY()/*+gate[balls[ballIndex].getPosition() - 1].getHeight()*/; + balls[ballIndex].yBOUNDSLOWER = gate[balls[ballIndex].getPosition() - 1].getY(); + } + //the ball is in one of the openings + else{ + balls[ballIndex].xBOUNDSUPPER = gate[balls[ballIndex].getPosition() - 7].getOpeningsX()+gate[balls[ballIndex].getPosition() - 7].getGateWidth(); + balls[ballIndex].xBOUNDSLOWER = gate[balls[ballIndex].getPosition() - 7].getOpeningsX(); + balls[ballIndex].yBOUNDSUPPER = gate[balls[ballIndex].getPosition() - 7].getOpeningsY()+gate[balls[ballIndex].getPosition() - 7].getOpeningsHeight(); + balls[ballIndex].yBOUNDSLOWER = gate[balls[ballIndex].getPosition() - 7].getOpeningsY(); + //X change in motion + balls[ballIndex].moveX = 0; + //Y change in motion + balls[ballIndex].moveY = 3; + } + } + } + + public void openGates(int priority) { + // TODO Auto-generated method stub + + gate[priority].setGateOpen(true); + + //set the height of all the canal panls depending on the state of the game + paintComponent(graphics2D); + } + + public void closeGates(int priority) { + // TODO Auto-generated method stub + gate[priority].setGateOpen(false); + gate[priority].setx1(gate[priority].getdefaultx1()); + gate[priority].sety1(gate[priority].getdefaulty1()); + /*if(!(priority == 0)) + gate[priority].setHeight(gate[priority-1].getHeight());*/ + paintComponent(graphics2D); + } + + public void endRound() { + // TODO Auto-generated method stub + flagDownStream = false; + flagDownStream = false; + + x2UpStream = 420; + + y2UpStream = 100; + + y2DownStream = 100; + + x2DownStream = 950; + + initializexy(); + } +} + Added: irrigation/trunk/src/main/java/edu/asu/commons/irrigation/client/CanalPanelAnimation.java =================================================================== --- irrigation/trunk/src/main/java/edu/asu/commons/irrigation/client/CanalPanelAnimation.java (rev 0) +++ irrigation/trunk/src/main/java/edu/asu/commons/irrigation/client/CanalPanelAnimation.java 2009-10-08 00:29:17 UTC (rev 288) @@ -0,0 +1,422 @@ +/** + * + */ +package edu.asu.commons.irrigation.client; + +import java.awt.Color; +import java.awt.Graphics; +import java.awt.Graphics2D; +import java.awt.GridBagLayout; +import java.awt.event.ActionEvent; +import java.awt.event.ActionListener; +import java.util.Random; + +import javax.swing.JPanel; +import javax.swing.Timer; + + + +/** + * @author Sanket + * + */ +public class CanalPanelAnimation extends JPanel{ + + private static final long serialVersionUID = 1L; + + /** + * This is the default constructor + */ + private int x1UpStream; + + private int y1UpStream; + + private int x2UpStream = 420; + + private int y2UpStream = 100; + + private int y2DownStream = 100; + + private int x2DownStream = 950; + + private int y1DownStream; + + private int x1DownStream; + + private Graphics2D graphics2D; + + private boolean flagDownStream = false; + + private boolean flagUpStream = false; + + private double totalContributedBandwidth; + + //////////////////animation logic parameters////////////////////////////// + private Timer timer; + + private final int DELAY = 20; + + private Ball balls[]; + + private int BALLCOUNT = 500; + + private long prev_time; + + //////////////////////////////////////////////////////////////////////////// + + public CanalPanelAnimation(double totalContributedBandwidth) { + super(); + this.totalContributedBandwidth = totalContributedBandwidth; + initialize(); + } + + /** + * This method initializes this + * + * @return void + */ + private void initialize() { + this.setSize(1098,150); + this.setLayout(new GridBagLayout()); + this.setBackground(Color.white); + + initializexy(); + + timer = new Timer(DELAY, new ReboundListener()); // setup the Timer to do an action + // every DELAY times. + prev_time = System.currentTimeMillis(); + timer.start(); // starts the timer. + + } + + private void gateReboundListener(){ + + if(flagUpStream == false && flagDownStream == false){ + System.out.println("Opening gates"); + closeGates(0); + openGates(1); + } + else + if(flagUpStream == false && flagDownStream == true) + { + openGates(0); + } + else + if(flagUpStream == true && flagDownStream == true) + { + closeGates(1); + //openGates(1); + } + else + if(flagUpStream == true && flagDownStream == false){ + closeGates(0); + //closeGates(1); + } +} + + protected void paintComponent(Graphics graphics){ + super.paintComponent(graphics); // needed! + Graphics2D graphics2D = (Graphics2D)graphics; + this.graphics2D = graphics2D; + //this.graphics2D.setColor(new Color(186,226,237)); + this.graphics2D.setColor(Color.BLUE); + this.graphics2D.fillRect(0,0,100,100); + //graphics2D.fillRoundRect(5,25,100,100,10,10); + //this.graphics2D.setColor(new Color(186,226,237)); + if((int)(totalContributedBandwidth) == 1) + this.graphics2D.fillRect(0, 100 - 2,420,2); + else + /*this.graphics2D.fillRect(0, 100-(int)(totalContributedBandwidth*0.8),1093, (int)(totalContributedBandwidth*0.8)); + this.graphics2D.fillRect(400, 100, 20, 50); + this.graphics2D.fillRect(930, 100, 20, 50); + */ + + this.graphics2D.fillRect(0, 100-(int)(totalContributedBandwidth*0.8),420, (int)(totalContributedBandwidth*0.8)); + if(flagUpStream == true){ + this.graphics2D.fillRect(420, 100-(int)(totalContributedBandwidth*0.8),(950-420), (int)(totalContributedBandwidth*0.8)-20); + //here if downstream is alsoo open, dont show the remaining part + if(flagDownStream == false) + this.graphics2D.fillRect(950, 100-(int)(totalContributedBandwidth*0.8),(1093-950), (int)(totalContributedBandwidth*0.8)-20); + else + this.graphics2D.fillRect(950, 100-(int)(totalContributedBandwidth*0.8),0,0); + + this.graphics2D.fillRect(930,100 - 20, 20, 50+20); + + } + + else{ + this.graphics2D.fillRect(420, 100-(int)(totalContributedBandwidth*0.8),(950-420), (int)(totalContributedBandwidth*0.8)); + if(flagDownStream == false) + this.graphics2D.fillRect(950, 100-(int)(totalContributedBandwidth*0.8),(1093-950), (int)(totalContributedBandwidth*0.8)); + else{ + if(totalContributedBandwidth <= 25){ + this.graphics2D.fillRect(950, 100-(int)(totalContributedBandwidth*0.8),0,0); + } + else + this.graphics2D.fillRect(950, 100-(int)(totalContributedBandwidth*0.8),(1093-950), (int)(totalContributedBandwidth*0.8)-20); + } + + this.graphics2D.fillRect(930, 100, 20, 50); + } + + this.graphics2D.fillRect(400, 100, 20, 50); + + this.graphics2D.setColor(Color.BLACK); + if(flagUpStream == false){ + x1UpStream = x2UpStream - 20; + y1UpStream = y2UpStream; + //resetting the position of downstream gate + //y2DownStream = y2DownStream + 20; + if(y2DownStream == 100-20) + y2DownStream = 100; + } + if(flagDownStream == false){ + x1DownStream = x2DownStream - 20; + y1DownStream = y2DownStream; + } + drawLid(x1UpStream,y1UpStream,x2UpStream,y2UpStream); + drawLid(x1DownStream,y1DownStream,x2DownStream,y2DownStream); + + //////////////////////Animation Logic//////////////////////////// + graphics.setColor(Color.white); + int ballCounter = 0; + for(int i=0;i<BALLCOUNT;i++){ + if(!(balls[i].isInServer == false && totalContributedBandwidth == 0)){ + if(!(flagDownStream == true && flagUpStream == true && balls[i].x >= 950)) + if(!(flagUpStream == true && totalContributedBandwidth <=25 && balls[i].x >=420)){ + if(flagUpStream == true && balls[i].x >=420 && totalContributedBandwidth >=25 ){ + if(!(flagDownStream == false && balls[i].y >= 80)) + //if(ballCounter < 20){ + graphics.fillOval(balls[i].x,balls[i].y,balls[i].getBallSize(), balls[i].getBallSize()); + //ballCounter++; + //} + } + else{ + + graphics.fillOval(balls[i].x,balls[i].y,balls[i].getBallSize(), balls[i].getBallSize()); // paints a whole new circle, with changing coords + + } + + } + + } + } + } + + private void initializexy() { + // TODO Auto-generated method stub + balls = new Ball[BALLCOUNT]; + if(balls == null){ + System.out.println("Ball is null"); + } + for(int i=0;i<BALLCOUNT;i++){ + Random generator = new Random(); + balls[i] = new Ball(generator); + if(balls[i] == null){ + System.out.println("Ball i is null"); + } + } + Random generator = new Random(); + System.out.println("Here it fails"); + balls[0].x = 40; + balls[0].y = 50; + + for(int i=1;i<BALLCOUNT;i++){ + balls[i].x = generator.nextInt(100); + balls[i].y = generator.nextInt(100); + balls[i].xBOUNDSUPPER = 100; + balls[i].yBOUNDSUPPER = 100; + balls[i].xBOUNDSLOWER = 0; + balls[i].yBOUNDSLOWER = 0; + balls[i].moveX = generator.nextInt(6); + balls[i].moveY = generator.nextInt(6); + balls[i].isInServer = true; + balls[i].isInSecondCanal = false; + balls[i].isInFirstCanal = false; + } + } + + // this is the private class the Timer will look at every DELAY seconds + private class ReboundListener implements ActionListener{ + Random generator = new Random(); + public void actionPerformed(ActionEvent e) { + if((System.currentTimeMillis() - prev_time) > 5000){ + System.out.println("Change the time"); + prev_time = System.currentTimeMillis(); + gateReboundListener(); + } + for(int i=0;i<BALLCOUNT;i++){ + balls[i].x += balls[i].moveX; + balls[i].y += balls[i].moveY; + + if(balls[i].isInServer == true){ + if((balls[i].x >= (100-20) && balls[i].x <= 100) && (balls[i].y >= 100-(int)(totalContributedBandwidth*0.8) && + balls[i].y <= 100)){ + balls[i].isInServer = false; + balls[i].moveX = 3; + balls[i].moveY = 3; + balls[i].xBOUNDSUPPER = 1093; + balls[i].xBOUNDSLOWER = 0; + balls[i].yBOUNDSUPPER = 100; + balls[i].yBOUNDSLOWER = 100-(int)(totalContributedBandwidth*0.8); + } + else{ + if(balls[i].x <= balls[i].xBOUNDSLOWER || balls[i].x >= balls[i].xBOUNDSUPPER-balls[i].getBallSize()){ + balls[i].moveX = balls[i].moveX * -1; + } + if(balls[i].y <= balls[i].yBOUNDSLOWER || balls[i].y >= balls[i].yBOUNDSUPPER-balls[i].getBallSize()) + balls[i].moveY = balls[i].moveY * -1; + } + } + //within the canal + else{ + // the upstream gate is open + if(flagUpStream == true){ + if((balls[i].x >= 400 && balls[i].x <= 420) && (balls[i].y >= 80 && balls[i].y <= 100)){ + balls[i].isInFirstCanal = true; + balls[i].xBOUNDSUPPER = 420; + balls[i].xBOUNDSLOWER = 400; + balls[i].yBOUNDSUPPER = 150; + balls[i].yBOUNDSLOWER = 80; + balls[i].moveX = 0; + balls[i].moveY = 3; + } + if(balls[i].isInFirstCanal == true) + if(balls[i].y <= balls[i].yBOUNDSLOWER || balls[i].y >= balls[i].yBOUNDSUPPER){ + balls[i].x = generator.nextInt(100); + balls[i].y = generator.nextInt(100); + balls[i].isInServer = true; + balls[i].isInFirstCanal = false; + balls[i].moveX = 3; + balls[i].moveY = 3; + balls[i].xBOUNDSUPPER = 100; + balls[i].xBOUNDSLOWER = 0; + balls[i].yBOUNDSUPPER = 100; + balls[i].yBOUNDSLOWER = 0; + } + if(balls[i].x <= balls[i].xBOUNDSLOWER || balls[i].x >= balls[i].xBOUNDSUPPER-balls[i].getBallSize()) + balls[i].moveX = balls[i].moveX * -1; + } + + if(flagDownStream == true){ + int yUpperBound; + if(flagUpStream == true){ + yUpperBound = 100 - (int)((totalContributedBandwidth)*0.8); + } + else + yUpperBound = 80; + if((balls[i].x >= 930 && balls[i].x <= 950) && (balls[i].y >= yUpperBound && balls[i].y <= 100)){ + balls[i].isInSecondCanal = true; + balls[i].xBOUNDSUPPER = 950; + balls[i].xBOUNDSLOWER = 930; + balls[i].yBOUNDSUPPER = 150; + balls[i].yBOUNDSLOWER = 80; + balls[i].moveX = 0; + balls[i].moveY = 3; + } + if(balls[i].isInSecondCanal == true) + if(balls[i].y <= balls[i].yBOUNDSLOWER || balls[i].y >= balls[i].yBOUNDSUPPER){ + balls[i].x = generator.nextInt(100); + balls[i].y = generator.nextInt(100); + balls[i].isInServer = true; + balls[i].isInSecondCanal = false; + balls[i].xBOUNDSUPPER = 100; + balls[i].xBOUNDSLOWER = 0; + balls[i].yBOUNDSUPPER = 100; + balls[i].yBOUNDSLOWER = 0; + balls[i].moveX =3; + balls[i].moveY =3; + } + if(balls[i].x <= balls[i].xBOUNDSLOWER || balls[i].x >= balls[i].xBOUNDSUPPER-balls[i].getBallSize()) + balls[i].moveX = balls[i].moveX * -1; + } + + //ball goes out of the scope of the canal + if(balls[i].isInFirstCanal == false && balls[i].isInSecondCanal == false){ + if(balls[i].x <= balls[i].xBOUNDSLOWER || balls[i].x >= balls[i].xBOUNDSUPPER-balls[i].getBallSize()){ + balls[i].x = generator.nextInt(100); + balls[i].y = generator.nextInt(100); + balls[i].moveX = 3; + balls[i].isInServer = true; + balls[i].xBOUNDSUPPER = 100; + balls[i].xBOUNDSLOWER = 0; + balls[i].yBOUNDSUPPER = 100; + balls[i].yBOUNDSLOWER = 0; + } + if(balls[i].y <= balls[i].yBOUNDSLOWER || balls[i].y >= balls[i].yBOUNDSUPPER-balls[i].getBallSize()) + balls[i].moveY = balls[i].moveY * -1; + } + } + } + repaint(); + } + } + + private void drawLid(int x1, int y1, int x2, int y2) { + // TODO Auto-generated method stub + graphics2D.drawLine(x1,y1,x2,y2); + } + + public void openGates(int priority) { + // TODO Auto-generated method stub + switch(priority){ + case 0 : x1UpStream = x2UpStream; + if(totalContributedBandwidth < 25){ + y1UpStream = y2UpStream - (int)(totalContributedBandwidth*0.8); + } + else{ + y1UpStream = y2UpStream - 20; + //changing the position of downstream gate + //y2DownStream = y2DownStream - 20; + + } + if(y2DownStream == 100) + y2DownStream = y2DownStream - 20; + flagUpStream = true; + break; + + case 1 : x1DownStream = x2DownStream; + if(totalContributedBandwidth < 25){ + y1DownStream = y2DownStream - (int)(totalContributedBandwidth*0.8); + //for the new animation + //y2DownStream = y1DownStream; + } + else + y1DownStream = y2DownStream - 20; + if(y1DownStream < (100-totalContributedBandwidth*0.8)){ + y1DownStream = y2DownStream - (int)(totalContributedBandwidth*0.8 - 20); + } + flagDownStream = true; + break; + + } + paintComponent(graphics2D); + } + + public void closeGates(int priority) { + // TODO Auto-generated method stub + switch (priority){ + case 0 : flagUpStream = false; + break; + + case 1 : flagDownStream = false; + break; + } + } + + public void endRound() { + // TODO Auto-generated method stub + flagDownStream = false; + flagDownStream = false; + totalContributedBandwidth = 0; + x2UpStream = 420; + + y2UpStream = 100; + + y2DownStream = 100; + + x2DownStream = 950; + + initializexy(); + } +} Added: irrigation/trunk/src/main/java/edu/asu/commons/irrigation/client/CanalPanelAnimationNew.java =================================================================== --- irrigation/trunk/src/main/java/edu/asu/commons/irrigation/client/CanalPanelAnimationNew.java (rev 0) +++ irrigation/trunk/src/main/java/edu/asu/commons/irrigation/client/CanalPanelAnimationNew.java 2009-10-08 00:29:17 UTC (rev 288) @@ -0,0 +1,560 @@ +package edu.asu.commons.irrigation.client; + +import java.awt.Color; +import java.awt.Graphics; +import java.awt.Graphics2D; +import java.awt.GridBagLayout; +import java.awt.event.ActionEvent; +import java.awt.event.ActionListener; +import java.util.Random; + +import javax.swing.JPanel; +import javax.swing.Timer; + +/** + * @author Sanket + * + */ +public class CanalPanelAnimationNew extends JPanel { + + private static final long serialVersionUID = 1L; + + /** + * This is the default constructor + */ + private int x1UpStream; + + private int y1UpStream; + + private int x2UpStream = 420; + + private int y2UpStream = 100; + + private int y2DownStream = 100; + + private int x2DownStream = 950; + + private int y1DownStream; + + private int x1DownStream; + + private Graphics2D graphics2D; + + private boolean flagDownStream = false; + + private boolean flagUpStream = false; + + //private IrrigationClientGameState clientGameState; + + //////////////////animation logic parameters////////////////////////////// + private Timer timer; + + private final int DELAY = 20; + + private Ball balls[]; + + private int BALLCOUNT = 500; + + private Gate gate[] = new Gate[6]; + + private int gateHeight = 20; + + Random generator = new Random(); + + private boolean enableBallAnimation = true; + + private double totalContributedBandwidth; + + private long prev_time; + + private int gateCount = 0; + + //////////////////////////////////////////////////////////////////////////// + + public CanalPanelAnimationNew(double totalContributedBandwidth) { + super(); + this.totalContributedBandwidth = totalContributedBandwidth; + initialize(); + } + + /** + * This method initializes this + * + * @return void + */ + private void initialize() { + this.setSize(1098,150); + this.setLayout(new GridBagLayout()); + this.setBackground(Color.white); + //initializing the constructor for Gates + for(int i=0;i<6;i++){ + gate[i] = new Gate(totalContributedBandwidth,i); + //System.out.println("Gate "+i+"x : "+gate[i].getX()+"y : "+gate[i].getY()); + } + + initializexy(); + + timer = new Timer(DELAY, new ReboundListener()); // setup the Timer to do an action + // every DELAY times. + prev_time = System.currentTimeMillis(); + timer.start(); // starts the timer. + } + + private void gateReboundListener(){ + + openGates(gateCount ); + if(!(gateCount == 0)) + closeGates(gateCount-1); + /*if(!gate[0].isOpenGate() && flagDownStream == false){ + System.out.println("Opening gates"); + closeGates(0); + openGates(1); + } + else + if(flagUpStream == false && flagDownStream == true) + { + openGates(0); + } + else + if(flagUpStream == true && flagDownStream == true) + { + closeGates(1); + //openGates(1); + } + else + if(flagUpStream == true && flagDownStream == false){ + closeGates(0); + //closeGates(1); + } +*/} + + + + protected void paintComponent(Graphics graphics){ + updateGUI(); + super.paintComponent(graphics); // needed! + Graphics2D graphics2D = (Graphics2D)graphics; + this.graphics2D = graphics2D; + this.graphics2D.setColor(Color.BLUE); + this.graphics2D.fillRect(0,0,100,100); + //draw the other gates + for(int i=0;i<5;i++){ + this.graphics2D.setColor(Color.BLUE); + this.graphics2D.fillRect(gate[i].getX(), gate[i].getY(), gate[i].getWidth(),gate[i].getHeight()); + this.graphics2D.fillRect(gate[i].getOpeningsX(), gate[i].getOpeningsY(),gate[i].getOpeningsWidth(), + gate[i].getOpeningsHeight()); + this.graphics2D.setColor(Color.BLACK); + this.graphics2D.drawLine(gate[i].getx1(),gate[i].gety1(),gate[i].getx2(),gate[i].gety2()); + } + + this.graphics2D.setColor(Color.BLUE); + this.graphics2D.fillRect(gate[5].getX(), gate[5].getY(),10,gate[5].getHeight()); + //System.out.println("Gate :"+5+" X: "+gate[5].getX()+" Y :"+gate[5].getY()); + + //////////////////////Animation Logic//////////////////////////// + if(enableBallAnimation == true) + { + graphics.setColor(Color.white); + int ballCounter = 0; + for(int i=0;i<BALLCOUNT;i++){ + /*if(!(balls[i].isInServer == false && clientGameState.getGroupDataModel().getMaximumAvailableBandwidth() == 0)){ + if(!(flagDownStream == true && flagUpStream == true && balls[i].x >= 950)) + if(!(flagUpStream == true && clientGameState.getGroupDataModel().getMaximumAvailableBandwidth() <=25 && balls[i].x >=420)){ + if(flagUpStream == true && balls[i].x >=420 && clientGameState.getGroupDataModel().getMaximumAvailableBandwidth() >=25 ){ + if(!(flagDownStream == false && balls[i].y >= 80)) + graphics.fillOval(balls[i].x,balls[i].y,balls[i].getBallSize(), balls[i].getBallSize()); + } + else{ + + graphics.fillOval(balls[i].x,balls[i].y,balls[i].getBallSize(), balls[i].getBallSize()); // paints a whole new circle, with changing coords + + } + + } + + } + */ + //System.out.println("ball sposition x :"+balls[i].x+" y:"+balls[i].y); + //get the position information of the ball. and then recheck the condition for height. + if((balls[i].getPosition() == 1)||(balls[i].getPosition() == 2) || (balls[i].getPosition()==3) + || (balls[i].getPosition() == 4) || (balls[i].getPosition() == 5)){ + if(!((!gate[balls[i].getPosition()-1].isOpenGate())&& balls[i].getY() >= (gate[balls[i].getPosition()-1].getY()+gate[balls[i].getPosition()-1].getHeight()))) + graphics.fillOval(balls[i].x,balls[i].y,balls[i].getBallSize(), balls[i].getBallSize()); + + + } + else{ + if(balls[i].getPosition() != 0){ + if(gate[balls[i].getPosition() - 6].getHeight() != 0) + graphics.fillOval(balls[i].x,balls[i].y,balls[i].getBallSize(), balls[i].getBallSize()); + } + else{ + graphics.fillOval(balls[i].x,balls[i].y,balls[i].getBallSize(), balls[i].getBallSize()); + } + } + } + } + + } + + + + private void updateGUI() { + // TODO Auto-generated method stub + for(int i=1;i<6;i++){ + if(gate[i-1].isOpenGate()){ + if(!(gate[i-1].getHeight() - gateHeight < 0)){ + gate[i].setHeight(gate[i-1].getHeight() - gateHeight ); + + } + else{ + gate[i].setHeight(0); + } + } + else{ + gate[i].setHeight(gate[i-1].getHeight()); + + } + //order matters here + if(!(i == 5)){ + gate[i].setOpeningsHeight((totalContributedBandwidth*0.8) + - gate[i].getHeight()); + gate[i].setOpeningsY(gate[i].getOpeningsHeight() - 50); + + //opening the lid logic + if(gate[i].isOpenGate()){ + gate[i].setx1(gate[i].getx2()); + if(!(gate[i].gety2()- gate[i].getGateWidth() < gate[i].getY())) + gate[i].sety1(gate[i].gety2()- gate[i].getGateWidth()); + else + gate[i].sety1(gate[i].getOpeningsY()); + } + else{ + gate[i].setx1(gate[i].getdefaultx1()); + gate[i].sety1(gate[i].getdefaulty1()); + } + + if(gate[0].isOpenGate()){ + gate[0].setx1(gate[0].getx2()); + if(!(gate[0].gety2()- gate[0].getGateWidth() < gate[0].getY())) + gate[0].sety1(gate[0].gety2()- gate[0].getGateWidth()); + else + gate[0].sety1(gate[0].getY()); + } + else{ + gate[0].setx1(gate[0].getdefaultx1()); + gate[0].sety1(gate[0].getdefaulty1()); + } + + } + } + } + + /* + * initialize the Balls + */ + private void initializexy() { + // TODO Auto-generated method stub + balls = new Ball[BALLCOUNT]; + if(balls == null){ + System.out.println("Ball is null"); + } + + for(int i=0;i<BALLCOUNT;i++){ + balls[i] = new Ball(generator); + + } + } + + // this is the private class the Timer will look at every DELAY seconds + private class ReboundListener implements ActionListener{ + Random generator = new Random(); + public void actionPerformed(ActionEvent e) { + if((System.currentTimeMillis() - prev_time) > 5000){ + //System.out.println("Change the time"); + prev_time = System.currentTimeMillis(); + gateCount++; + if(gateCount > 4) + gateCount = 0; + gateReboundListener(); + } + for(int i=0;i<BALLCOUNT;i++){ + //updateGUI(); + balls[i].x += balls[i].moveX; + balls[i].y += balls[i].moveY; + process(i); + + } + repaint(); + } + } + + /* + * This will process the balls according to their position + */ + private void process(int i){ + // TODO Auto-generated method stub + + switch(balls[i].getPosition()){ + + case 0: if((balls[i].x >= (100 - 20) && balls[i].x <= 100) && (balls[i].y >= 100-(int)(totalContributedBandwidth*0.8) && + balls[i].y <= 100)){ + balls[i].setPosition(1); + setBounds(i); + } + //still in server + else{ + setBounds(i); + if(balls[i].x <= balls[i].xBOUNDSLOWER || balls[i].x >= balls[i].xBOUNDSUPPER-balls[i].getBallSize()){ + balls[i].moveX = balls[i].moveX * -1; + } + if(balls[i].y <= balls[i].yBOUNDSLOWER || balls[i].y >= balls[i].yBOUNDSUPPER-balls[i].getBallSize()) + balls[i].moveY = balls[i].moveY * -1; + } + break; + + case 1: /*if(gate[0].isOpenGate() && (balls[i].x >= 400 && balls[i].x <= 420) && (balls[i].y >= 80 && + balls[i].y <= 100)){ + */ if(gate[0].isOpenGate() && (balls[i].x >= gate[0].getOpeningsX() && balls[i].x <= (gate[0].getOpeningsX()+20)) + && (balls[i].y >= 80 && balls[i].y <= 100)){ + balls[i].setPosition(7); + //directly pass in the information + setBounds(i); + /*System.out.println("X upper :"+balls[i].xBOUNDSUPPER+" Y Upper :"+balls[i].yBOUNDSUPPER + +" X Lower"+balls[i].xBOUNDSLOWER+" X Upper"+balls[i].xBOUNDSUPPER);*/ + /* balls[i].xBOUNDSUPPER = 420; + balls[i].xBOUNDSLOWER = 400; + balls[i].yBOUNDSUPPER = 150; + balls[i].yBOUNDSLOWER = 80; + balls[i].moveX = 0; + balls[i].moveY = 3;*/ + } + else{ + setBounds(i); + /*System.out.println("X upper :"+balls[i].xBOUNDSUPPER+" Y Upper :"+balls[i].yBOUNDSUPPER + +" X Lower"+balls[i].xBOUNDSLOWER+" X Upper"+balls[i].xBOUNDSUPPER); + */ + if(balls[i].getX() > balls[i].xBOUNDSUPPER){ + balls[i].setPosition(2); + } + if(balls[i].getY() >= balls[i].yBOUNDSUPPER - balls[i].getBallSize() || balls[i].getY() <= balls[i].yBOUNDSLOWER){ + balls[i].moveY = balls[i].moveY*-1; + } + } + + break; + + case 2: if(gate[1].isOpenGate() && (balls[i].x >= gate[1].getOpeningsX() && balls[i].x <= (gate[1].getOpeningsX()+20)) + && (balls[i].y >= 80 && balls[i].y <= 100)){ + balls[i].setPosition(8); + //directly pass in the information + setBounds(i); + /* balls[i].xBOUNDSUPPER = 420; + balls[i].xBOUNDSLOWER = 400; + balls[i].yBOUNDSUPPER = 150; + balls[i].yBOUNDSLOWER = 80; + balls[i].moveX = 0; + balls[i].moveY = 3;*/ + } + else{ + setBounds(i); + if(balls[i].getX() > balls[i].xBOUNDSUPPER){ + balls[i].setPosition(3); + } + if(balls[i].getY() >= balls[i].yBOUNDSUPPER - balls[i].getBallSize() || balls[i].getY() <= balls[i].yBOUNDSLOWER){ + balls[i].moveY = balls[i].moveY*-1; + } + } + break; + + + case 3: if(gate[2].isOpenGate() && (balls[i].x >= gate[2].getOpeningsX() && balls[i].x <= (gate[2].getOpeningsX()+20)) + && (balls[i].y >= 80 && balls[i].y <= 100)){ + balls[i].setPosition(9); + //directly pass in the information + setBounds(i); + /* balls[i].xBOUNDSUPPER = 420; + balls[i].xBOUNDSLOWER = 400; + balls[i].yBOUNDSUPPER = 150; + balls[i].yBOUNDSLOWER = 80; + balls[i].moveX = 0; + balls[i].... [truncated message content] |
From: <al...@us...> - 2009-10-07 23:30:21
|
Revision: 287 http://virtualcommons.svn.sourceforge.net/virtualcommons/?rev=287&view=rev Author: alllee Date: 2009-10-07 23:30:13 +0000 (Wed, 07 Oct 2009) Log Message: ----------- starting to migrate irrigation experiment over to use csidex / maven / ivy Added Paths: ----------- irrigation/trunk/ irrigation/trunk/build.properties.example irrigation/trunk/build.xml irrigation/trunk/deploy.bat irrigation/trunk/ivy.xml irrigation/trunk/ivysettings.xml irrigation/trunk/jetty.bat irrigation/trunk/pom.xml irrigation/trunk/src/ irrigation/trunk/src/main/ irrigation/trunk/src/main/java/ irrigation/trunk/src/main/resources/ irrigation/trunk/src/main/resources/web/ irrigation/trunk/src/main/resources/web/client.jnlp irrigation/trunk/src/main/resources/web/facilitator.jnlp irrigation/trunk/src/main/resources/web/index.html irrigation/trunk/src/test/ irrigation/trunk/src/test/java/ Added: irrigation/trunk/build.properties.example =================================================================== --- irrigation/trunk/build.properties.example (rev 0) +++ irrigation/trunk/build.properties.example 2009-10-07 23:30:13 UTC (rev 287) @@ -0,0 +1,30 @@ +# Any configuration properties set here will override the defaults provided in +# the build.xml file. If you are using the builtin Maven Jetty webserver, you +# just need to change the server address (and the port listed in the +# codebase.url property if you are running on a port other than 8080). + +# server name, set this to the IP address or domain name that will be running +# the experiment server +# FIXME: currently, this MUST be the same as the IP address/domain name of the +# webserver you are deploying the software on. +server.address=localhost + +# the absolute path of where you would like to deploy the experiment JNLP and +# jar files +# (should be accessible / mounted by the webserver) +# NOTE: for windows, use double backslashes as a path separator +# web.dir=C:\\WebServer\\foraging +web.dir=src/main/webapp + +# The URL that maps to the path above. If you don't mind using "foraging" as +# part of the URL you can just set the server.address and leave this property +# blank since the build.xml that loads this properties file sets the codebase +# url to the ${server.address} + "/foraging" by default. +codebase.url=http://${server.address}:8080/irrigation + +# set to whatever port you want the Java experiment server to run on (this is +# *not* the webserver port, this is the experiment server port used to +# communicate with the individual experiment clients) +server.port=16001 + + Added: irrigation/trunk/build.xml =================================================================== --- irrigation/trunk/build.xml (rev 0) +++ irrigation/trunk/build.xml 2009-10-07 23:30:13 UTC (rev 287) @@ -0,0 +1,365 @@ +<!-- $Id: build.xml 330 2008-02-13 05:31:26Z alllee $ + vim:sts=2:sw=2: + Version: $Revision: 330 $ + --> +<project xmlns:ivy='antlib:org.apache.ivy.ant' name="irrigation" default="build-all" basedir="."> + + <!-- ensure ivy availability --> + <!-- + <path id='ivy.lib.path'> + <fileset dir='lib/ivy' includes='*.jar'/> + </path> + <taskdef resource='org/apache/ivy/ant/antlib.xml' + uri='antlib:org.apache.ivy.ant' + classpathref='ivy.lib.path'/> + --> + <property name="ivy.install.version" value="2.1.0-rc2" /> + <condition property="ivy.home" value="${env.IVY_HOME}"> + <isset property="env.IVY_HOME" /> + </condition> + <property name="ivy.home" value="${user.home}/.ant" /> + <property name="ivy.jar.dir" value="${ivy.home}/lib" /> + <property name="ivy.jar.file" value="${ivy.jar.dir}/ivy.jar" /> + + <target name="download-ivy" unless="offline"> + + <mkdir dir="${ivy.jar.dir}"/> + <!-- download Ivy from web site so that it can be used even without any special installation --> + <get src="http://repo2.maven.org/maven2/org/apache/ivy/ivy/${ivy.install.version}/ivy-${ivy.install.version}.jar" + dest="${ivy.jar.file}" usetimestamp="true"/> + <!-- + <get src="http://www.apache.org/dist/ant/ivy/${ivy.install.version}/ivy.jar" + dest="${ivy.jar.file}" usetimestamp="true"/> + <get src="http://www.apache.org/dist/ant/ivy/${ivy.install.version}/apache-ivy-${ivy.install.version}-bin.zip" + dest="${ivy.jar.dir}/ivy-${ivy.install.version}-bin.zip" usetimestamp="true"/> + --> + <!-- FIXME: this should be dependent on the download in the first place + <unzip src='${ivy.jar.dir}/ivy-${ivy.install.version}-bin.zip' dest='${ivy.jar.dir}' overwrite='false' /> + <move file='${ivy.jar.dir}/apache-ivy-${ivy.install.version}/ivy-${ivy.install.version}.jar' tofile='${ivy.jar.file}' overwrite='false' /> + --> + </target> + + <target name="init-ivy" depends="download-ivy"> + <!-- try to load ivy here from ivy home, in case the user has not already dropped + it into ant's lib dir (note that the latter copy will always take precedence). + We will not fail as long as local lib dir exists (it may be empty) and + ivy is in at least one of ant's lib dir or the local lib dir. --> + <path id="ivy.lib.path"> + <fileset dir="${ivy.jar.dir}" includes="*.jar"/> + </path> + <taskdef resource="org/apache/ivy/ant/antlib.xml" uri="antlib:org.apache.ivy.ant" classpathref="ivy.lib.path"/> + </target> + + <target name='resolve' depends='init-ivy' description='--> retrieve dependencies with ivy'> + <ivy:retrieve pattern='${lib.dir}/[artifact].[ext]'/> + </target> + + <!-- Load all properties from the build.properties file, + then try to define defaults for all the properties. + The property definitions in the build.properties file + will have precedence. + --> + <property file="build.properties" /> + <!-- default compilation properties --> + <property name='src.dir' value='src/main/java'/> + <property name='build.dir' value='target'/> + + <!-- default web & deployment properties --> + <property name='web.dir' value='src/main/webapp'/> + <property name='server.port' value='16001'/> + <property name='server.xml' value='server.xml'/> + <property name='codebase.url' value='http://${server.address}/${ant.project.name}'/> + <property name='client.class' value='edu.asu.commons.irrigation.client.IrrigationClient'/> + <property name='facilitator.class' value='edu.asu.commons.irrigation.facilitator.Facilitator'/> + <property name='server.class' value='edu.asu.commons.irrigation.server.IrrigationServer'/> + <property name='framework.jar' value='csidex.jar'/> + + <property name='dist.dir' value='dist' /> + + <property name='resources.dir' value='src/main/resources'/> + <property name='conf.dir' value='${resources.dir}/configuration'/> + + <!-- test properties --> + <property name="test.src.dir" value="src/test/java"/> + <property name="test.build.dir" value="target/test-classes"/> + <property name="test.results.dir" value="target/surefire-reports" /> + + <property name="javadoc.dir" value="docs/javadoc"/> + <property name="javadoc.private.dir" value="docs/private"/> + <property name='lib.dir' value='lib'/> + + <!-- Set up the CLASSPATH, includes all jars in the lib + directory and all built files for both the main project + and the tests --> + <path id="project.classpath"> + <pathelement location="." /> + <fileset dir="${lib.dir}"> + <include name="**/*.jar" /> + </fileset> + <pathelement location="${build.dir}" /> + <pathelement location="${test.build.dir}" /> + <pathelement location='${resources.dir}' /> + </path> + + <target name="help"> + <echo> + NOTE: At minimum you will need to modify the default web.dir and + server.address properties in the build.properties file before invoking deploy + or build-all. + + Currently deploying to ${web.dir} with a web address of ${codebase.url}. + + Experiment server will start on ${server.address}, listening on port ${server.port}. + + Available targets: + compile - Compile all the source code and tests. + clean - Remove all compiled source and test classes. + docs - Create JavaDoc documentation for all source code. + test - Run all JUnit in the test source tree. + build-all - builds the client, server, and facilitator jars. + deploy - invokes build-all and then copies the client and facilitator jars to ${web.dir} + </echo> + </target> + + <target name='build-all' depends='facilitator-jar, client-jar, server-jar, compile'/> + +<!-- deploys the client + facilitator + csidex jarfiles to the appropriate + webapps directory. --> + <target name='deploy-to' depends='build-all'> + <mkdir dir='${deploy.dir}'/> + <!-- + copy client jar, facilitator jar, and csidex.jar to web deployment + directory + --> + <copy todir='${deploy.dir}' overwrite='true'> + <fileset dir='${dist.dir}'> + <include name='client.jar'/> + <include name='facilitator.jar'/> + </fileset> + <fileset dir='${lib.dir}'> + <include name='${framework.jar}'/> + </fileset> + <fileset dir='${resources.dir}/web'> + <include name='index.html'/> + <include name='WEB-INF/**'/> + </fileset> + </copy> + <!-- copy images --> + <copy todir='${deploy.dir}/images' overwrite='true'> + <fileset dir='${resources.dir}/images'/> + </copy> + <!-- + copy client and facilitator JNLP descriptor files, replacing + url/main class tokens. + --> + <copy file='${resources.dir}/web/client.jnlp' todir='${deploy.dir}' overwrite='true'> + <filterset> + <filter token='CODEBASE_URL' value='${codebase.url}'/> + <filter token='MAIN_CLASS' value='${client.class}'/> + <filter token='FRAMEWORK_JAR' value='${framework.jar}'/> + </filterset> + </copy> + <copy file='${resources.dir}/web/facilitator.jnlp' todir='${deploy.dir}' overwrite='true'> + <filterset> + <filter token='CODEBASE_URL' value='${codebase.url}'/> + <filter token='MAIN_CLASS' value='${facilitator.class}'/> + <filter token='FRAMEWORK_JAR' value='${framework.jar}'/> + </filterset> + </copy> + <chmod dir='${deploy.dir}' perm='664' type='file' includes='**'/> + <chmod dir='${deploy.dir}' perm='775' type='dir' includes='**'/> + </target> + + <target name='deploy'> + <antcall target='deploy-to'> + <param name='deploy.dir' value='${web.dir}'/> + </antcall> + </target> + + <target name='client-jar' depends='server-jar'> + <antcall target='build-jar'> + <param name='main.class' value='${client.class}'/> + <param name='jar.name' value='client.jar'/> + </antcall> + </target> + + <target name='facilitator-jar' depends='client-jar'> + <antcall target='build-jar'> + <param name='main.class' value='${facilitator.class}'/> + <param name='jar.name' value='facilitator.jar'/> + </antcall> + </target> + + + <target name='server-jar' depends='compile, configure'> + <antcall target='build-jar'> + <param name='main.class' value='${server.class}'/> + <param name='jar.name' value='server.jar'/> + </antcall> + <move file='${dist.dir}/server.jar' tofile='server.jar'/> + </target> + + <target name='build-jar'> + <manifestclasspath property='manifest.classpath' jarfile='${jar.name}'> + <classpath refid='project.classpath'/> + </manifestclasspath> + <chmod dir='${build.dir}' perm='a+rx' type='dir' includes='**'/> + <chmod dir='${build.dir}' perm='a+r' type='file' includes='**'/> + <manifest file='manifest.mf'> + <attribute name="Main-Class" value="${main.class}"/> + <attribute name='Class-Path' value='${manifest.classpath}'/> + </manifest> + <jar destfile='${dist.dir}/${jar.name}' manifest='manifest.mf'> + <fileset dir='${build.dir}'> + <include name='edu/asu/commons/**'/> + <include name='data/**'/> + <include name='conf/**'/> + <include name='images/**'/> + </fileset> + </jar> + <chmod file='${dist.dir}/${jar.name}' perm='664'/> + </target> + <!-- Prepare for a build by creating appropriate directories --> + <target name="prepare" depends='resolve'> + <mkdir dir="${build.dir}"/> + <mkdir dir="${test.build.dir}"/> + <mkdir dir='${dist.dir}'/> + </target> + + <!-- Clean up build by deleting build directories --> + <target name="clean"> + <delete dir="${build.dir}"/> + <delete dir="${test.build.dir}"/> + <delete dir='${dist.dir}'/> + <delete dir='${lib.dir}'/> + <delete file='server.jar'/> + + </target> + + <!-- Compile project source files --> + <target name='compile' depends="prepare"> + <javac srcdir="${src.dir}" + destdir="${build.dir}" + debug="on" + optimize="off" + deprecation="on" + source="1.6" + > + <compilerarg value='-Xlint:unchecked'/> + <classpath refid="project.classpath" /> + </javac> + <copy todir='${build.dir}/data'> + <fileset dir='${resources.dir}/data'/> + </copy> + <copy todir='${build.dir}/images'> + <fileset dir='${resources.dir}/images'/> + </copy> + </target> + + <target name='configure'> + <copy todir='${build.dir}/conf'> + <fileset dir='${conf.dir}'/> + <filterset> + <filter token='SERVER_ADDRESS' value='${server.address}'/> + <filter token='PORT_NUMBER' value='${server.port}'/> + <filter token='CODEBASE_URL' value='${codebase.url}'/> + </filterset> + </copy> + </target> + + <target name='profile' depends='test'> + <java jar='${project.profiler}' classpathref='project.classpath' fork='true'> + <arg value='${hprof.file}'/> + </java> + <!-- do something like java -jar PerfAnal.jar <hprof.txt> --> + </target> + + <!-- Build project documentation --> + <target name="docs"> + <javadoc sourcepath="${src.dir}" + destdir="${javadoc.dir}" + packagenames="*" + source="1.6" + classpathref='project.classpath' + link='http://java.sun.com/javase/6/docs/api/ + http://commons.asu.edu/src/csidex/api' + overview="${src.dir}/overview.html" /> + </target> + + <!-- RUN TARGETS --> + <target name='client' depends='compile'> + <java classname='${client.class}' + classpathref='project.classpath' + fork='yes'/> + </target> + + <target name='fac' depends='compile'> + <java classname='${facilitator.class}' + classpathref='project.classpath' + fork='yes'/> + </target> + + <target name='deploy-server' depends='deploy, server' /> + + <target name='server' depends='compile'> + <!-- make sure we update the configuration --> + <copy todir='${build.dir}/conf' overwrite='true'> + <fileset dir='${conf.dir}'/> + <filterset> + <filter token='SERVER_ADDRESS' value='${server.address}'/> + <filter token='PORT_NUMBER' value='${server.port}'/> + <filter token='CODEBASE_URL' value='${codebase.url}'/> + </filterset> + </copy> + <java classname='${server.class}' classpathref='project.classpath' fork='yes'> + <jvmarg value="-server"/> + </java> + </target> + + + <!-- Compile Tests --> + <target name="compile-tests" depends="compile"> + <javac srcdir="${test.src.dir}" + destdir="${test.build.dir}" + source="1.6" + debug="on"> + <!-- <compilerarg value='-Xlint:unchecked'/> --> + <classpath refid="project.classpath" /> + </javac> + </target> + + <!-- Run Tests --> + <target name="test" depends="compile-tests"> + <delete dir="${test.results.dir}"/> + <mkdir dir="${test.results.dir}"/> + <junit fork="yes" haltonfailure="yes" printsummary="yes"> + <classpath refid="project.classpath" /> + <batchtest todir="${test.results.dir}" > + <formatter usefile="no" type="plain" /> + <formatter type="xml" /> + <fileset dir="${test.build.dir}"> + <include name="**/*Test.class" /> + </fileset> + </batchtest> + </junit> + </target> + + <property name='savefile.converter.class' value='edu.asu.commons.irrigation.util.SaveFileConverter'/> + <target name='convert-savefiles' depends='compile'> + <java classname='${savefile.converter.class}' classpathref='project.classpath' fork='yes'> + <arg value='raw-data'/> + </java> + </target> + + <!-- Run Test on GUI --> + <target name="guitest" depends="compile-tests"> + <java fork="yes" classname="junit.swingui.TestRunner" taskname="JUnit" failonerror="true" dir="${basedir}"> + <jvmarg value="-Djunit.test.path=${test.build.dir}" /> + <sysproperty key="basedir" value="${basedir}" /> + <classpath> + <path refid="project.classpath" /> + </classpath> + </java> + </target> + +</project> Added: irrigation/trunk/deploy.bat =================================================================== --- irrigation/trunk/deploy.bat (rev 0) +++ irrigation/trunk/deploy.bat 2009-10-07 23:30:13 UTC (rev 287) @@ -0,0 +1,7 @@ +REM set ANT_HOME to the location where you unpacked Ant. Inside this +REM directory should be bin and lib directories containing the Ant +REM executables and library dependencies. +set ANT_HOME=C:\tools\ant +set JAVA_HOME=C:\Program Files\Java\jdk1.6.0_16 +set PATH=%ANT_HOME%\bin;%JAVA_HOME%\bin;%PATH% +ant deploy Added: irrigation/trunk/ivy.xml =================================================================== --- irrigation/trunk/ivy.xml (rev 0) +++ irrigation/trunk/ivy.xml 2009-10-07 23:30:13 UTC (rev 287) @@ -0,0 +1,13 @@ +<?xml version="1.0"?> +<!-- +vim:sts=2:sw=2: +--> +<ivy-module version="2.0"> + <info organisation="edu.asu.commons" module="irrigation"/> + <dependencies> + <dependency org="junit" name="junit" rev="latest.integration"/> + <dependency org="edu.asu.commons" name="csidex" rev="latest.integration"/> + <dependency org="jfree" name="jfreechart" rev="1.0.13"/> + <dependency org="jfree" name="jcommon" rev="1.0.16"/> + </dependencies> +</ivy-module> Added: irrigation/trunk/ivysettings.xml =================================================================== --- irrigation/trunk/ivysettings.xml (rev 0) +++ irrigation/trunk/ivysettings.xml 2009-10-07 23:30:13 UTC (rev 287) @@ -0,0 +1,19 @@ +<?xml version="1.0"?> +<!-- +vim:sts=2:sw=2: +--> +<ivysettings> + <settings defaultResolver="chain-resolver" /> + <property name='local-m2-pattern' + value='${user.home}/.m2/repository/[organisation]/[module]/[revision]/[module]-[revision]'/> + <resolvers> + <chain name='chain-resolver' returnFirst='true'> + <filesystem name='m2' m2compatible='true'> + <ivy pattern='${local-m2-pattern}.pom' /> + <artifact pattern='${local-m2-pattern}.[ext]'/> + </filesystem> + <ibiblio name='commons-archiva' m2compatible='true' root='http://dev.commons.asu.edu/archiva/repository/internal'/> + <ibiblio name='tdar-archiva' m2compatible='true' root='http://dev.tdar.org/archiva/repository/internal'/> + </chain> + </resolvers> +</ivysettings> Added: irrigation/trunk/jetty.bat =================================================================== --- irrigation/trunk/jetty.bat (rev 0) +++ irrigation/trunk/jetty.bat 2009-10-07 23:30:13 UTC (rev 287) @@ -0,0 +1,11 @@ +REM set M2_HOME to the location where you unpacked Maven. Inside this +REM directory should be bin and lib directories containing the Maven +REM executables and library dependencies. +REM ******* +REM You MUST RUN deploy.bat or server.bat before this to properly compile and +REM configure this application. +set ANT_HOME=C:\tools\ant +set M2_HOME=C:\tools\maven +set JAVA_HOME=C:\Program Files\Java\jdk1.6.0_16 +set PATH=%JAVA_HOME%\bin;%ANT_HOME%\bin;%M2_HOME%\bin;%PATH% +mvn jetty:run Added: irrigation/trunk/pom.xml =================================================================== --- irrigation/trunk/pom.xml (rev 0) +++ irrigation/trunk/pom.xml 2009-10-07 23:30:13 UTC (rev 287) @@ -0,0 +1,119 @@ +<?xml version="1.0" encoding="UTF-8"?> +<!-- +vim:sts=2:sw=2 +--> +<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" + xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/maven-v4_0_0.xsd"> + <modelVersion>4.0.0</modelVersion> + <groupId>edu.asu.commons</groupId> + <artifactId>irrigation</artifactId> + <packaging>jar</packaging> + <version>1.0-SNAPSHOT</version> + <name>foraging</name> + <url>http://commons.asu.edu/irrigation</url> + <repositories> + <repository> + <id>dev.commons.asu.edu</id> + <name>dev.commons Maven2 repository</name> + <url>http://dev.commons.asu.edu/archiva/repository/internal</url> + <releases><enabled>true</enabled></releases> + <snapshots><enabled>false</enabled></snapshots> + </repository> + <repository> + <id>snapshot.dev.commons.asu.edu</id> + <name>dev.commons Maven2 snapshot repository</name> + <url>http://dev.commons.asu.edu/archiva/repository/snapshots</url> + <releases><enabled>false</enabled></releases> + <snapshots><enabled>true</enabled></snapshots> + </repository> + <repository> + <id>dev.tdar.org</id> + <name>tDAR Maven2 repository</name> + <url>http://dev.tdar.org/archiva/repository/internal</url> + <releases><enabled>true</enabled></releases> + <snapshots><enabled>false</enabled></snapshots> + </repository> + </repositories> + <dependencies> + <dependency> + <groupId>junit</groupId> + <artifactId>junit</artifactId> + <version>4.5</version> + <scope>test</scope> + </dependency> + <dependency> + <groupId>edu.asu.commons</groupId> + <artifactId>csidex</artifactId> + <version>0.2.1</version> + </dependency> + <dependency> + <groupId>jfree</groupId> + <artifactId>jcommon</artifactId> + <version>1.0.16</version> + </dependency> + <dependency> + <groupId>jfree</groupId> + <artifactId>jfreechart</artifactId> + <version>1.0.13</version> + </dependency> + </dependencies> + <build> + <finalName>irrigation</finalName> + <plugins> + <plugin> + <artifactId>maven-compiler-plugin</artifactId> + <configuration> + <source>1.6</source> + <target>1.6</target> + </configuration> + </plugin> + <plugin> + <groupId>org.mortbay.jetty</groupId> + <artifactId>jetty-maven-plugin</artifactId> + <configuration> + <scanIntervalSeconds>10</scanIntervalSeconds> + </configuration> + </plugin> + </plugins> + </build> + <profiles> + <profile> + <id>ant</id> + <build> + <defaultGoal>antrun:run</defaultGoal> + <plugins> + <plugin> + <groupId>org.apache.maven.plugins</groupId> + <artifactId>maven-antrun-plugin</artifactId> + <goals> + <goal>load</goal> + </goals> + <configuration> + <tasks> + <!-- + can be invoked via + mdeployvn -P ant -D target= + --> + <property name="compile.classpath" refid="maven.compile.classpath"/> + <property name="runtime.classpath" refid="maven.runtime.classpath"/> + <property name="test.classpath" refid="maven.test.classpath"/> + <property name="plugin.classpath" refid="maven.plugin.classpath"/> + <ant antfile="${basedir}/build.xml" inheritRefs="true" inheritAll="true"> + <target name="${target}"/> + </ant> + </tasks> + </configuration> + </plugin> + </plugins> + </build> + <dependencies> + <dependency> + <groupId>ant-contrib</groupId> + <artifactId>ant-contrib</artifactId> + <version>1.0b2</version> + </dependency> + </dependencies> + </profile> + + </profiles> +</project> Added: irrigation/trunk/src/main/resources/web/client.jnlp =================================================================== --- irrigation/trunk/src/main/resources/web/client.jnlp (rev 0) +++ irrigation/trunk/src/main/resources/web/client.jnlp 2009-10-07 23:30:13 UTC (rev 287) @@ -0,0 +1,17 @@ +<?xml version="1.0" encoding="utf-8"?> +<!-- irrigation client jnlp --> +<jnlp spec="1.6+" codebase="@CODEBASE_URL@" href="client.jnlp"> + <information> + <title>Virtual Commons Experiment</title> + <vendor>The Virtual Commons, Center for the Study of Institutional Diversity, Dr. Marco Janssen, Marty Anderies, Allen Lee, Sanket Joshi</vendor> + <homepage href="http://commons.asu.edu"/> + <description>Virtual Commons Experiment</description> + </information> + <resources> + <j2se version="1.6+"/> + <jar href="client.jar"/> + <jar href='@FRAMEWORK_JAR@'/> + </resources> + <application-desc main-class="@MAIN_CLASS@"/> +</jnlp> + Added: irrigation/trunk/src/main/resources/web/facilitator.jnlp =================================================================== --- irrigation/trunk/src/main/resources/web/facilitator.jnlp (rev 0) +++ irrigation/trunk/src/main/resources/web/facilitator.jnlp 2009-10-07 23:30:13 UTC (rev 287) @@ -0,0 +1,17 @@ +<?xml version="1.0" encoding="utf-8"?> +<!-- irrigation facilitator JNLP --> +<jnlp spec="1.6+" codebase="@CODEBASE_URL@" href="facilitator.jnlp"> + <information> + <title>Virtual Commons Experiment</title> + <vendor>The Virtual Commons, Center for the Study of Institutional Diversity, Dr. Marco Janssen, Marty Anderies, Allen Lee, Sanket Joshi</vendor> + <homepage href="http://commons.asu.edu"/> + <description>Virtual Commons Experiment</description> + </information> + <resources> + <j2se version="1.6+"/> + <jar href="facilitator.jar"/> + <jar href='@FRAMEWORK_JAR@'/> + </resources> + <application-desc main-class="@MAIN_CLASS@"/> +</jnlp> + Added: irrigation/trunk/src/main/resources/web/index.html =================================================================== --- irrigation/trunk/src/main/resources/web/index.html (rev 0) +++ irrigation/trunk/src/main/resources/web/index.html 2009-10-07 23:30:13 UTC (rev 287) @@ -0,0 +1,12 @@ +<html> +<head> +<META HTTP-EQUIV="Refresh" CONTENT="0;URL=client.jnlp"> +<title>Virtual Commons Experiment</title> +</head> +<body> +<p> +Automatically starting the client. You may close this window after the client +loads. Please <b>do not reload or refresh</b> this window. +</p> +</body> +</html> This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <al...@us...> - 2009-10-07 22:03:19
|
Revision: 286 http://virtualcommons.svn.sourceforge.net/virtualcommons/?rev=286&view=rev Author: alllee Date: 2009-10-07 22:03:10 +0000 (Wed, 07 Oct 2009) Log Message: ----------- moving irrigation trunk to tags Added Paths: ----------- irrigation/tags/irrigation.sanket.v1/ Removed Paths: ------------- irrigation/trunk/ This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <see...@us...> - 2009-10-05 21:23:02
|
Revision: 285 http://virtualcommons.svn.sourceforge.net/virtualcommons/?rev=285&view=rev Author: seematalele Date: 2009-10-05 21:22:54 +0000 (Mon, 05 Oct 2009) Log Message: ----------- added statement for setting the threshold for savingStrategy method. Modified Paths: -------------- mentalmodels/trunk/src/main/java/edu/asu/commons/mme/service/AnsweringService.java Modified: mentalmodels/trunk/src/main/java/edu/asu/commons/mme/service/AnsweringService.java =================================================================== --- mentalmodels/trunk/src/main/java/edu/asu/commons/mme/service/AnsweringService.java 2009-10-01 01:16:55 UTC (rev 284) +++ mentalmodels/trunk/src/main/java/edu/asu/commons/mme/service/AnsweringService.java 2009-10-05 21:22:54 UTC (rev 285) @@ -39,6 +39,7 @@ studentResponse.setQuestion(clientStudentResponse.getQuestion()); studentResponse.setResponse(clientStudentResponse.getResponse()); studentResponse.setStudent(clientStudentResponse.getStudent()); + getDao().save(studentResponse); } @@ -57,6 +58,7 @@ studentStrategy.setRepeatedDecisions(clientStudentStrategy.isRepeatedDecisions()); studentStrategy.setRound(clientStudentStrategy.getRound()); studentStrategy.setStudent(clientStudentStrategy.getStudent()); + studentStrategy.setThreshold(clientStudentStrategy.getThreshold()); getStudentStrategyDao().save(studentStrategy); } } This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: Kalin J. <kj...@as...> - 2009-10-05 21:13:16
|
Today I work from about 13:30-14:30pm I've been reading over the SVN updates to see how the games are kept separate |
From: <see...@us...> - 2009-10-01 01:17:03
|
Revision: 284 http://virtualcommons.svn.sourceforge.net/virtualcommons/?rev=284&view=rev Author: seematalele Date: 2009-10-01 01:16:55 +0000 (Thu, 01 Oct 2009) Log Message: ----------- 1) Created GameService.java. Need to enter into the ApplicationContext file. 2) Changed the assignGrouptoStudents method. Need to test it.Sometimes it creates groups in the database, sometimes it does not. Modified Paths: -------------- mentalmodels/trunk/src/main/java/edu/asu/commons/mme/entity/Student.java mentalmodels/trunk/src/main/java/edu/asu/commons/mme/service/StartGame.java mentalmodels/trunk/src/main/java/edu/asu/commons/mme/service/StartupService.java mentalmodels/trunk/src/main/java/edu/asu/commons/mme/service/StudentService.java Added Paths: ----------- mentalmodels/trunk/src/main/java/edu/asu/commons/mme/service/GameService.java Modified: mentalmodels/trunk/src/main/java/edu/asu/commons/mme/entity/Student.java =================================================================== --- mentalmodels/trunk/src/main/java/edu/asu/commons/mme/entity/Student.java 2009-09-28 22:57:24 UTC (rev 283) +++ mentalmodels/trunk/src/main/java/edu/asu/commons/mme/entity/Student.java 2009-10-01 01:16:55 UTC (rev 284) @@ -44,7 +44,6 @@ @Temporal(TemporalType.TIMESTAMP) private Date timestamp; - private String gender; Added: mentalmodels/trunk/src/main/java/edu/asu/commons/mme/service/GameService.java =================================================================== --- mentalmodels/trunk/src/main/java/edu/asu/commons/mme/service/GameService.java (rev 0) +++ mentalmodels/trunk/src/main/java/edu/asu/commons/mme/service/GameService.java 2009-10-01 01:16:55 UTC (rev 284) @@ -0,0 +1,11 @@ +package edu.asu.commons.mme.service; + +import edu.asu.commons.mme.dao.HibernateGameDao; +import edu.asu.commons.mme.entity.Game; + +public class GameService extends Service.Base<Game, HibernateGameDao>{ + + + + +} Modified: mentalmodels/trunk/src/main/java/edu/asu/commons/mme/service/StartGame.java =================================================================== --- mentalmodels/trunk/src/main/java/edu/asu/commons/mme/service/StartGame.java 2009-09-28 22:57:24 UTC (rev 283) +++ mentalmodels/trunk/src/main/java/edu/asu/commons/mme/service/StartGame.java 2009-10-01 01:16:55 UTC (rev 284) @@ -1,5 +1,6 @@ package edu.asu.commons.mme.service; +import java.util.ArrayList; import java.util.List; import org.apache.log4j.Logger; import edu.asu.commons.mme.entity.Block; @@ -53,9 +54,30 @@ } - public List<Student> assignGroups() + public List<Student> assignGroups(Game game) { - return studentService.assignGroups(); + List<Student> students = null; + students = studentService.assignGroups(game); + if(students != null) + { + MessageBroker msgBroker = MessageBroker.getMessageBroker("_messageBroker"); + + String clientID = UUIDUtils.createUUID(); + AsyncMessage msg = new AsyncMessage(); + msg.setDestination("mme"); + String msgDestination = game.getGameCode(); + msg.setHeader("DSSubtopic", msgDestination); + msg.setClientId(clientID); + msg.setMessageId(UUIDUtils.createUUID()); + msg.setTimestamp(System.currentTimeMillis()); + + msg.setBody(students); + System.out.println("Message broker is: "+ msgBroker); + System.out.println("Students size is: " + students.size()); + + msgBroker.routeMessageToService(msg, null); + } + return students; } /** @@ -84,7 +106,7 @@ //Push the first block to the clients AsyncMessage msg = new AsyncMessage(); - + msg.setDestination("mme"); msg.setHeader("DSSubtopic", msgDestination); msg.setClientId(clientID); Modified: mentalmodels/trunk/src/main/java/edu/asu/commons/mme/service/StartupService.java =================================================================== --- mentalmodels/trunk/src/main/java/edu/asu/commons/mme/service/StartupService.java 2009-09-28 22:57:24 UTC (rev 283) +++ mentalmodels/trunk/src/main/java/edu/asu/commons/mme/service/StartupService.java 2009-10-01 01:16:55 UTC (rev 284) @@ -1,7 +1,6 @@ package edu.asu.commons.mme.service; import java.util.ArrayList; -import java.util.List; import org.springframework.beans.BeansException; import org.springframework.context.ApplicationContext; @@ -10,9 +9,6 @@ import edu.asu.commons.mme.entity.Game; import edu.asu.commons.mme.entity.Student; -import flex.messaging.MessageBroker; -import flex.messaging.messages.AsyncMessage; -import flex.messaging.util.UUIDUtils; @Transactional @@ -22,11 +18,16 @@ private StartGame startGame; private ApplicationContext ctx; private ArrayList<StartGame> currentGames; + + private GameService gameService; + public void setGameService(GameService gameService) { + this.gameService = gameService; + } + /*public void setQuestionCreatorService(QuestionCreatorService questionCreatorService) { this.questionCreatorService = questionCreatorService; }*/ - public Student createStudent(Student student) { //Game game = student.getGame(); @@ -69,30 +70,14 @@ return newGame; } - public void assignGroups() - { - MessageBroker msgBroker = MessageBroker.getMessageBroker(null); - String clientID = UUIDUtils.createUUID(); - AsyncMessage msg = new AsyncMessage(); - msg.setDestination("DataPush"); - //msg.setHeader("DSSubtopic", "hello"); - msg.setClientId(clientID); - msg.setMessageId(UUIDUtils.createUUID()); - msg.setTimestamp(System.currentTimeMillis()); - List<Student> students = new ArrayList<Student>(); - - msg.setBody(students); - System.out.println("Message broker is: "+ msgBroker); - System.out.println("Students size is: " + students.size()); - - msgBroker.routeMessageToService(msg, null); - } - public void startGame(Game game) { //push assign groups to all the students - //assignGroups(); - + + //FIXME: get persistence entity from database rather than using the game obejct came from Flex. + + //Game gameEntity = gameDao.find(game.getId()); + //start the game System.out.println("Game came from client is to start: " + game.getId() + "size of currentGame is " + currentGames.size()); try @@ -104,6 +89,7 @@ if(currentGames.get(i).getGame().getId().equals(game.getId())) { System.out.println("Game is found"); + currentGames.get(i).assignGroups(game); currentGames.get(i).run(); } } Modified: mentalmodels/trunk/src/main/java/edu/asu/commons/mme/service/StudentService.java =================================================================== --- mentalmodels/trunk/src/main/java/edu/asu/commons/mme/service/StudentService.java 2009-09-28 22:57:24 UTC (rev 283) +++ mentalmodels/trunk/src/main/java/edu/asu/commons/mme/service/StudentService.java 2009-10-01 01:16:55 UTC (rev 284) @@ -1,8 +1,6 @@ package edu.asu.commons.mme.service; -import java.sql.Timestamp; import java.util.ArrayList; -import java.util.Date; import java.util.List; import org.hibernate.Hibernate; @@ -10,6 +8,7 @@ import edu.asu.commons.mme.dao.HibernateGroupDao; import edu.asu.commons.mme.dao.HibernateStudentDao; +import edu.asu.commons.mme.entity.Game; import edu.asu.commons.mme.entity.Group; import edu.asu.commons.mme.entity.Student; @@ -26,33 +25,31 @@ public class StudentService extends Service.Base<Student, HibernateStudentDao> { HibernateGroupDao groupDao; - private List<Student> studentWithGroupsAssigned = new ArrayList<Student>(); - private List<Student> students = new ArrayList<Student>(); - public Student createStudent(Student student) { - Student studentSave = new Student(); - studentSave.setBirthYear(student.getBirthYear()); - studentSave.setGame(student.getGame()); - studentSave.setGameCode(student.getGameCode()); - studentSave.setGender(student.getGender()); - studentSave.setMajor(student.getMajor()); - studentSave.setSemester(student.getSemester()); - studentSave.setTimestamp(student.getTimestamp()); - - //studentSave.setTimestamp(new Timestamp(new Date().getTime())); - save(studentSave); - getLogger().debug("Student id is: " + studentSave.getId()); - /*if(!checkStudentAlreadyExists(studentSave)) + Student studentSave = null; + if(!checkStudentAlreadyExists(student)) { - students.add(studentSave); + studentSave = new Student(); + studentSave.setBirthYear(student.getBirthYear()); + studentSave.setGame(student.getGame()); + studentSave.setGameCode(student.getGameCode()); + studentSave.setGender(student.getGender()); + studentSave.setMajor(student.getMajor()); + studentSave.setSemester(student.getSemester()); + studentSave.setTimestamp(student.getTimestamp()); + + //studentSave.setTimestamp(new Timestamp(new Date().getTime())); + getDao(). + save(studentSave); + getLogger().debug("Student id is: " + studentSave.getId()); + } - else - return null;*/ + initializeStudent(student); - return student; + return studentSave; } private void initializeStudent(Student student) { @@ -63,6 +60,8 @@ public boolean checkStudentAlreadyExists(Student student) { + List<Student> students = new ArrayList<Student>(); + students = getDao().findAllByProperty("game",student.getGame()); for(int i = 0; i < students.size(); i++) { if(students.get(i).equals(student)){ @@ -73,97 +72,152 @@ } - public List<Student> assignGroups() + public List<Student> assignGroups(Game game) { - //write an algorithm to form groups - int totalStudents = students.size(); - int noOfGroupsWithSize3=0; - int noOfGroupsWithSize4=0; - int noOfGroupsWithSize5=0; - int x; + //createGroup(1); + List<Student> studentWithGroupsAssigned = new ArrayList<Student>(); + List<Student> students = new ArrayList<Student>(); + try{ + getLogger().debug("In the assigngroups." + game.getId()); + students = getDao().findAllByProperty("game", game); + + getLogger().debug("test student object is : " + students.size()); + if(students.size() > 1) + { + //write an algorithm to form groups + int totalStudents = students.size(); + int noOfGroupsWithSize3=0; + int noOfGroupsWithSize4=0; + int noOfGroupsWithSize5=0; + int x; - //no of groups - noOfGroupsWithSize5=((int)(totalStudents/5)); - x= totalStudents%5; + //no of groups + noOfGroupsWithSize5=((int)(totalStudents/5)); - /* if(x==0) + + x= totalStudents%5; + + /* if(x==0) { totalGroups=groupSize5; } else*/ - if(x==1) - { - noOfGroupsWithSize5=noOfGroupsWithSize5 - 1; - noOfGroupsWithSize3=2; - // totalGroups=groupSize5 + groupSize3; - } + if(x==1) + { + noOfGroupsWithSize5=noOfGroupsWithSize5 - 1; + noOfGroupsWithSize3=2; + // totalGroups=groupSize5 + groupSize3; + } - else if(x==2) - { - noOfGroupsWithSize5=noOfGroupsWithSize5-1; - noOfGroupsWithSize4=1; - noOfGroupsWithSize3=1; - // totalGroups=groupSize5 + groupSize3 + groupSize4; - } - else if(x==3) - { - noOfGroupsWithSize3=1; - // totalGroups=groupSize3 + groupSize5; - } + else if(x==2) + { + noOfGroupsWithSize5=noOfGroupsWithSize5-1; + noOfGroupsWithSize4=1; + noOfGroupsWithSize3=1; + // totalGroups=groupSize5 + groupSize3 + groupSize4; + } + else if(x==3) + { + noOfGroupsWithSize3=1; + // totalGroups=groupSize3 + groupSize5; + } - else if(x==4) - { - noOfGroupsWithSize4=1; - // totalGroups=groupSize4 + groupSize5; - } + else if(x==4) + { + noOfGroupsWithSize4=1; + // totalGroups=groupSize4 + groupSize5; + } - //assign every student a number and group - if(!students.isEmpty()) - { - assignGroupstoStudents(5,noOfGroupsWithSize5); - assignGroupstoStudents(4,noOfGroupsWithSize4); - assignGroupstoStudents(3,noOfGroupsWithSize3); + getLogger().debug("size of 4 : " + noOfGroupsWithSize4); + getLogger().debug("size of 3 : " + noOfGroupsWithSize3); + getLogger().debug("size of 5 : " + noOfGroupsWithSize5); + + //assign every student a number and group + if(!students.isEmpty()) + { + if(noOfGroupsWithSize5 > 0) + { + studentWithGroupsAssigned.addAll(assignGroupstoStudents(5,noOfGroupsWithSize5,students)); + getLogger().debug("student size after 5 is: " + students.size()); + getLogger().debug("student with groups assigned: " + studentWithGroupsAssigned.size()); + } + if(noOfGroupsWithSize4 > 0) + { + studentWithGroupsAssigned.addAll(assignGroupstoStudents(4,noOfGroupsWithSize4,students)); + getLogger().debug("student size after 4 is: " + students.size()); + getLogger().debug("student with groups assigned: " + studentWithGroupsAssigned.size()); + } + if(noOfGroupsWithSize3 > 0) + { + studentWithGroupsAssigned.addAll(assignGroupstoStudents(3,noOfGroupsWithSize3,students)); + getLogger().debug("student size after 3 is: " + students.size()); + getLogger().debug("student with groups assigned: " + studentWithGroupsAssigned.size()); + } + } } + getLogger().debug("Final student with groups assigned: " + studentWithGroupsAssigned.size()); + }catch(Exception e) + { + getLogger().error(e); + } return studentWithGroupsAssigned; } - private void assignGroupstoStudents(int groupSize, int noOfGroups) { + private List<Student> assignGroupstoStudents(int groupSize, int noOfGroups,List<Student> students) { // TODO Auto-generated method stub Student student = new Student(); - - for(int grpno = 0,studentNo = 1; grpno < noOfGroups; grpno++,studentNo++) + List<Student> studentWithGroupsAssigned = new ArrayList<Student>(); + getLogger().debug("group size is : "+groupSize); + int k = 0; + for(int grpno = 0; grpno < noOfGroups; grpno++) { //create group Group grp = new Group(); - grp.setNumber(grpno + 1); - getGroupDao().save(grp); - for(int i = 0; i < groupSize; i++) + k= grpno+1; + grp.setNumber(k); + groupDao.save(grp); + getLogger().info("Group is created with id: " + grp.getId()); + int studentNo = 1; + int j = 0; + for(int i = 0; i <= groupSize-1 ; i++) { //get a student from a list - student = students.get(i); + student = students.get(0); + getLogger().debug("i is: " + i +"student id is : "+student.getId()); if(student.getGroup() == null) { //assign student no and group to each student + getLogger().debug("group assigned is : " + grp.getId()); student.setStudentNo(studentNo); student.setGroup(grp); - save(student); + getDao().save(student); + studentNo++; initializeStudent(student); studentWithGroupsAssigned.add(student); - students.remove(i); + + students.remove(0); } + j++; } } + return students; } - - - public HibernateGroupDao getGroupDao() { + public Group createGroup(int groupNo) + { + Group grp = new Group(); + grp.setNumber(groupNo); + groupDao.save(grp); + getLogger().info("Group is created with id: " + grp.getId()); + return grp; + } + /*public HibernateGroupDao getGroupDao() { return groupDao; - } + }*/ public void setGroupDao(HibernateGroupDao groupDao) { this.groupDao = groupDao; This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: Kalin J. <kj...@as...> - 2009-09-30 10:36:13
|
I'm sorry I have not been coming in to work recently. I've been feeling very fatigued for the last week or so, and have developed a persistant cough over the weekend. The campus' local health center has diagnosed me with acute bronchitis, and I would prefer not to share this condition with the rest of you. I'll be trying to rest a lot more, and catch up on the schoolwork I have ahead of me, and try to get back to work as soon as possible. |
From: <see...@us...> - 2009-09-28 22:57:37
|
Revision: 283 http://virtualcommons.svn.sourceforge.net/virtualcommons/?rev=283&view=rev Author: seematalele Date: 2009-09-28 22:57:24 +0000 (Mon, 28 Sep 2009) Log Message: ----------- Created GameConfig.java entity which is a meta data for game configuration. Game.java will use one of the GameConfig.java configuration for conducting the game. Changed the FisheryExperimentCore.mxml so that each participant will receive blocks for that particular game. I have manually added entries in the database in GameConfig and gameroundConfig table. Created the GameConfig.as and change the actionscript classes according to the schema (entities in the java side). Modified Paths: -------------- mentalmodels/trunk/flex/src/StartGame.mxml mentalmodels/trunk/flex/src/actionscript/Game.as mentalmodels/trunk/flex/src/actionscript/Location.as mentalmodels/trunk/flex/src/actionscript/Student.as mentalmodels/trunk/flex/src/custom/FisheryExperimentCore.mxml mentalmodels/trunk/src/main/db/init-mme.sql mentalmodels/trunk/src/main/java/edu/asu/commons/mme/entity/Game.java mentalmodels/trunk/src/main/java/edu/asu/commons/mme/entity/GameRound.java mentalmodels/trunk/src/main/java/edu/asu/commons/mme/entity/Location.java mentalmodels/trunk/src/main/java/edu/asu/commons/mme/entity/Round.java mentalmodels/trunk/src/main/java/edu/asu/commons/mme/service/LocationService.java mentalmodels/trunk/src/main/java/edu/asu/commons/mme/service/ModuleService.java mentalmodels/trunk/src/main/java/edu/asu/commons/mme/service/RoundService.java mentalmodels/trunk/src/main/java/edu/asu/commons/mme/service/StartGame.java mentalmodels/trunk/src/main/java/edu/asu/commons/mme/service/StartupService.java mentalmodels/trunk/src/main/webapp/WEB-INF/applicationContext.xml mentalmodels/trunk/src/main/webapp/WEB-INF/classes/log4j.properties mentalmodels/trunk/src/main/webapp/WEB-INF/hibernate.cfg.xml Added Paths: ----------- mentalmodels/trunk/flex/src/actionscript/GameConfig.as mentalmodels/trunk/src/main/java/edu/asu/commons/mme/dao/HibernateGameConfigDao.java mentalmodels/trunk/src/main/java/edu/asu/commons/mme/entity/GameConfig.java mentalmodels/trunk/src/main/java/edu/asu/commons/mme/entity/Instructor.java mentalmodels/trunk/src/main/java/edu/asu/commons/mme/service/GameConfigService.java Removed Paths: ------------- mentalmodels/trunk/src/main/java/edu/asu/commons/mme/entity/RoundLocation.java Modified: mentalmodels/trunk/flex/src/StartGame.mxml =================================================================== --- mentalmodels/trunk/flex/src/StartGame.mxml 2009-09-28 22:53:16 UTC (rev 282) +++ mentalmodels/trunk/flex/src/StartGame.mxml 2009-09-28 22:57:24 UTC (rev 283) @@ -109,13 +109,9 @@ var gameObject:Game = new Game(); gameObject.money = stpMoney.value; - gameObject.description = txtDescription.text; - gameObject.numberOfRounds = 2; - gameObject.maxDays = 30; - gameObject.maxFishHarvest = 100; + gameObject.gameCode = txtDescription.text; gameObject.timestamp = new Date(); - gameObject.title = "test Game Title"; - + startupService.createGame(gameObject); /* var message:AsyncMessage = new AsyncMessage(); message.body = "got gameObject" + gameObject.description; @@ -146,7 +142,7 @@ if(event.result != null) { - var description:String = (event.result as Game).description; + var description:String = (event.result as Game).gameCode; btnStartGame.enabled = true; game = event.result as Game; txtGameID.text = description; Modified: mentalmodels/trunk/flex/src/actionscript/Game.as =================================================================== --- mentalmodels/trunk/flex/src/actionscript/Game.as 2009-09-28 22:53:16 UTC (rev 282) +++ mentalmodels/trunk/flex/src/actionscript/Game.as 2009-09-28 22:57:24 UTC (rev 283) @@ -1,21 +1,15 @@ package actionscript { - import mx.collections.ArrayCollection; - [Bindable] [RemoteClass(alias="edu.asu.commons.mme.entity.Game")] public class Game { public var id:Number; - public var numberOfRounds:int; - public var numberOfLocations:int; - public var maxDays:int; - public var maxFishHarvest:int; - public var timestamp:Date; - public var title:String; - public var description:String; + public var gameConfig:GameConfig; + public var timestamp:Date; + public var gameCode:String; public var money:Number; - public var imageLocation:String; - public var rounds:ArrayCollection; + public var currentRound:Round; + public var currentBlock:Block; } } \ No newline at end of file Added: mentalmodels/trunk/flex/src/actionscript/GameConfig.as =================================================================== --- mentalmodels/trunk/flex/src/actionscript/GameConfig.as (rev 0) +++ mentalmodels/trunk/flex/src/actionscript/GameConfig.as 2009-09-28 22:57:24 UTC (rev 283) @@ -0,0 +1,19 @@ +package actionscript +{ + [Bindable] + [RemoteClass(alias="edu.asu.commons.mme.entity.GameConfig")] + public class GameConfig + { + public var id:Number; + public var numberOfRounds:int; + public var numberOfLocations:int; + public var maxDays:int; + public var maxFishHarvest:int; + public var timestamp:Date; + public var title:String; + public var description:String; + public var money:Number; + public var imageLocation:String; + + } +} \ No newline at end of file Modified: mentalmodels/trunk/flex/src/actionscript/Location.as =================================================================== --- mentalmodels/trunk/flex/src/actionscript/Location.as 2009-09-28 22:53:16 UTC (rev 282) +++ mentalmodels/trunk/flex/src/actionscript/Location.as 2009-09-28 22:57:24 UTC (rev 283) @@ -1,6 +1,5 @@ package actionscript { - import mx.collections.ArrayCollection; [Bindable] [RemoteClass(alias="edu.asu.commons.mme.entity.Location")] @@ -11,6 +10,9 @@ public var maxCapacity:int; public var growthRate:Number; public var initialPopulation:int; - public var roundLocations:ArrayCollection; + public var currentPopulation:Number; + public var fishLeaving:Number; + public var fishReturned:Number; + public var gameConfig:GameConfig; } } \ No newline at end of file Modified: mentalmodels/trunk/flex/src/actionscript/Student.as =================================================================== --- mentalmodels/trunk/flex/src/actionscript/Student.as 2009-09-28 22:53:16 UTC (rev 282) +++ mentalmodels/trunk/flex/src/actionscript/Student.as 2009-09-28 22:57:24 UTC (rev 283) @@ -16,6 +16,7 @@ public var timestamp:Date; public var gender:String; public var gameCode:String; + public var game:Game; /** * input: Modified: mentalmodels/trunk/flex/src/custom/FisheryExperimentCore.mxml =================================================================== --- mentalmodels/trunk/flex/src/custom/FisheryExperimentCore.mxml 2009-09-28 22:53:16 UTC (rev 282) +++ mentalmodels/trunk/flex/src/custom/FisheryExperimentCore.mxml 2009-09-28 22:57:24 UTC (rev 283) @@ -68,7 +68,7 @@ </mx:RemoteObject> - <mx:Consumer id="consumer" destination="chat" message="messageHandler(event)" fault="faultMsgHandler(event)" channelSet="{cs}" /> + <mx:Consumer id="consumer" destination="mme" message="messageHandler(event)" fault="faultMsgHandler(event)" channelSet="{cs}" /> <mx:ChannelSet id="cs"> <!-- <mx:StreamingAMFChannel url="http://localhost:8080/messagebroker/streamingamf"/> --> @@ -405,6 +405,7 @@ } else { + consumer.subtopic = studentObject.gameCode; consumer.subscribe(); //Alert.show("GameCode is '" + studentObject.gameCode + "'"); //Alert.show("subscribed to destination: " + consumer.destination); Modified: mentalmodels/trunk/src/main/db/init-mme.sql =================================================================== --- mentalmodels/trunk/src/main/db/init-mme.sql 2009-09-28 22:53:16 UTC (rev 282) +++ mentalmodels/trunk/src/main/db/init-mme.sql 2009-09-28 22:57:24 UTC (rev 283) @@ -292,6 +292,26 @@ -- Table structure for table `game` -- +DROP TABLE IF EXISTS `game`; +/*!40101 SET @saved_cs_client = @@character_set_client */; +/*!40101 SET character_set_client = utf8 */; +CREATE TABLE `game` ( + `id` bigint(20) NOT NULL AUTO_INCREMENT, + `gameCode` varchar(255) NOT NULL, + `money` double DEFAULT NULL, + `timestamp` datetime NOT NULL, + `current_block_id` bigint(20) DEFAULT NULL, + `current_round_id` bigint(20) DEFAULT NULL, + `gameConfig_id` bigint(20) NOT NULL, + PRIMARY KEY (`id`), + KEY `FK304BF2F1265AC7` (`current_block_id`), + KEY `FK304BF219A3AF27` (`current_round_id`), + KEY `FK304BF25E134D93` (`gameConfig_id`), + CONSTRAINT `FK304BF25E134D93` FOREIGN KEY (`gameConfig_id`) REFERENCES `game_config` (`id`), + CONSTRAINT `FK304BF219A3AF27` FOREIGN KEY (`current_round_id`) REFERENCES `round_config` (`id`), + CONSTRAINT `FK304BF2F1265AC7` FOREIGN KEY (`current_block_id`) REFERENCES `block` (`id`) +) ENGINE=InnoDB DEFAULT CHARSET=latin1; +/*!40101 SET character_set_client = @saved_cs_client */; -- -- Dumping data for table `game` @@ -299,16 +319,69 @@ LOCK TABLES `game` WRITE; /*!40000 ALTER TABLE `game` DISABLE KEYS */; -INSERT INTO `game` VALUES (1,'First game','island.jpg',30,5,0,4,4,'2009-07-19 17:30:35','Mental Model Experiment',3,2),(2,'dell2','null',30,100,0.01,0,2,'2009-08-21 14:58:14','test Game Title',1,1); /*!40000 ALTER TABLE `game` ENABLE KEYS */; UNLOCK TABLES; -- +-- Table structure for table `game_config` +-- + +DROP TABLE IF EXISTS `game_config`; +/*!40101 SET @saved_cs_client = @@character_set_client */; +/*!40101 SET character_set_client = utf8 */; +CREATE TABLE `game_config` ( + `id` bigint(20) NOT NULL AUTO_INCREMENT, + `description` longtext NOT NULL, + `image_location` varchar(255) DEFAULT NULL, + `max_days` int(11) NOT NULL, + `max_fish_harvest` int(11) NOT NULL, + `no_of_locations` int(11) NOT NULL, + `timestamp` datetime NOT NULL, + `title` varchar(255) NOT NULL, + PRIMARY KEY (`id`) +) ENGINE=InnoDB AUTO_INCREMENT=2 DEFAULT CHARSET=latin1; +/*!40101 SET character_set_client = @saved_cs_client */; + +-- +-- Dumping data for table `game_config` +-- + +LOCK TABLES `game_config` WRITE; +/*!40000 ALTER TABLE `game_config` DISABLE KEYS */; +INSERT INTO `game_config` VALUES (1,'Mental Model Experiment',NULL,30,5,4,'2009-09-28 11:26:14','E-Fishery'); +/*!40000 ALTER TABLE `game_config` ENABLE KEYS */; +UNLOCK TABLES; + +-- -- Table structure for table `game_round_config` -- +DROP TABLE IF EXISTS `game_round_config`; +/*!40101 SET @saved_cs_client = @@character_set_client */; +/*!40101 SET character_set_client = utf8 */; +CREATE TABLE `game_round_config` ( + `id` bigint(20) NOT NULL AUTO_INCREMENT, + `sequence_no` int(11) NOT NULL, + `gameConfig_id` bigint(20) NOT NULL, + `round_id` bigint(20) NOT NULL, + PRIMARY KEY (`id`), + KEY `FKA0C2A405E134D93` (`gameConfig_id`), + KEY `FKA0C2A4047CF2321` (`round_id`), + CONSTRAINT `FKA0C2A4047CF2321` FOREIGN KEY (`round_id`) REFERENCES `round_config` (`id`), + CONSTRAINT `FKA0C2A405E134D93` FOREIGN KEY (`gameConfig_id`) REFERENCES `game_config` (`id`) +) ENGINE=InnoDB AUTO_INCREMENT=5 DEFAULT CHARSET=latin1; +/*!40101 SET character_set_client = @saved_cs_client */; +-- +-- Dumping data for table `game_round_config` +-- +LOCK TABLES `game_round_config` WRITE; +/*!40000 ALTER TABLE `game_round_config` DISABLE KEYS */; +INSERT INTO `game_round_config` VALUES (1,1,1,1),(2,2,1,2),(3,3,1,3),(4,4,1,4); +/*!40000 ALTER TABLE `game_round_config` ENABLE KEYS */; +UNLOCK TABLES; + -- -- Table structure for table `grp` -- @@ -361,8 +434,35 @@ -- Table structure for table `location` -- +DROP TABLE IF EXISTS `location`; +/*!40101 SET @saved_cs_client = @@character_set_client */; +/*!40101 SET character_set_client = utf8 */; +CREATE TABLE `location` ( + `id` bigint(20) NOT NULL AUTO_INCREMENT, + `current_population` double DEFAULT NULL, + `fish_leaving` double DEFAULT NULL, + `fish_return` double DEFAULT NULL, + `growth_rate` double NOT NULL, + `initial_population` double NOT NULL, + `location_name` varchar(255) NOT NULL, + `max_capacity` double NOT NULL, + `gameConfig_id` bigint(20) DEFAULT NULL, + PRIMARY KEY (`id`), + KEY `FK714F9FB55E134D93` (`gameConfig_id`), + CONSTRAINT `FK714F9FB55E134D93` FOREIGN KEY (`gameConfig_id`) REFERENCES `game_config` (`id`) +) ENGINE=InnoDB DEFAULT CHARSET=latin1; +/*!40101 SET character_set_client = @saved_cs_client */; -- +-- Dumping data for table `location` +-- + +LOCK TABLES `location` WRITE; +/*!40000 ALTER TABLE `location` DISABLE KEYS */; +/*!40000 ALTER TABLE `location` ENABLE KEYS */; +UNLOCK TABLES; + +-- -- Table structure for table `module` -- @@ -534,6 +634,15 @@ -- Table structure for table `round_config` -- +DROP TABLE IF EXISTS `round_config`; +/*!40101 SET @saved_cs_client = @@character_set_client */; +/*!40101 SET character_set_client = utf8 */; +CREATE TABLE `round_config` ( + `id` bigint(20) NOT NULL AUTO_INCREMENT, + `communication_flag` tinyint(1) NOT NULL DEFAULT '0', + PRIMARY KEY (`id`) +) ENGINE=InnoDB AUTO_INCREMENT=5 DEFAULT CHARSET=latin1; +/*!40101 SET character_set_client = @saved_cs_client */; -- -- Dumping data for table `round_config` @@ -541,16 +650,14 @@ LOCK TABLES `round_config` WRITE; /*!40000 ALTER TABLE `round_config` DISABLE KEYS */; -INSERT INTO `round_config` VALUES (1,0,1),(2,0,2),(3,1,3),(4,0,4); +INSERT INTO `round_config` VALUES (1,0),(2,0),(3,1),(4,0); /*!40000 ALTER TABLE `round_config` ENABLE KEYS */; UNLOCK TABLES; -- --- Table structure for table `round_config_location` +-- Table structure for table `student` -- - - DROP TABLE IF EXISTS `student`; /*!40101 SET @saved_cs_client = @@character_set_client */; /*!40101 SET character_set_client = utf8 */; @@ -742,4 +849,4 @@ /*!40101 SET COLLATION_CONNECTION=@OLD_COLLATION_CONNECTION */; /*!40111 SET SQL_NOTES=@OLD_SQL_NOTES */; --- Dump completed on 2009-09-04 0:47:19 +-- Dump completed on 2009-09-28 18:29:10 Added: mentalmodels/trunk/src/main/java/edu/asu/commons/mme/dao/HibernateGameConfigDao.java =================================================================== --- mentalmodels/trunk/src/main/java/edu/asu/commons/mme/dao/HibernateGameConfigDao.java (rev 0) +++ mentalmodels/trunk/src/main/java/edu/asu/commons/mme/dao/HibernateGameConfigDao.java 2009-09-28 22:57:24 UTC (rev 283) @@ -0,0 +1,12 @@ +package edu.asu.commons.mme.dao; + +import edu.asu.commons.mme.entity.GameConfig; + +public class HibernateGameConfigDao extends HibernateDao<GameConfig> { + + public HibernateGameConfigDao() + { + super(GameConfig.class); + } + +} Modified: mentalmodels/trunk/src/main/java/edu/asu/commons/mme/entity/Game.java =================================================================== --- mentalmodels/trunk/src/main/java/edu/asu/commons/mme/entity/Game.java 2009-09-28 22:53:16 UTC (rev 282) +++ mentalmodels/trunk/src/main/java/edu/asu/commons/mme/entity/Game.java 2009-09-28 22:57:24 UTC (rev 283) @@ -2,17 +2,13 @@ import java.io.Serializable; import java.sql.Timestamp; -import java.util.List; import javax.persistence.Column; import javax.persistence.Entity; -import javax.persistence.FetchType; import javax.persistence.GeneratedValue; import javax.persistence.Id; import javax.persistence.JoinColumn; -import javax.persistence.Lob; import javax.persistence.ManyToOne; -import javax.persistence.OneToMany; import javax.persistence.Table; @Entity @@ -25,37 +21,19 @@ @GeneratedValue private Long id; - @Column(name="no_of_rounds",nullable = false) - private Integer numberOfRounds; + @ManyToOne + @JoinColumn(nullable = false) + private GameConfig gameConfig; - @Column(name="no_of_locations",nullable = false) - private Integer numberOfLocations; - - @Column(name="max_days",nullable = false) - private Integer maxDays; - - @Column(name="max_fish_harvest",nullable = false) - private Integer maxFishHarvest; - @Column(nullable=false) private Timestamp timestamp; @Column(nullable=false) - private String title; + private String gameCode; - @Lob - private String description; - @Column(scale=2) private Double money; - @Column(name="image_location") - private String imageLocation; - - // FIXME: should this be many-to-many instead? - @OneToMany(mappedBy = "game") - private List<GameRound> gameRounds; - @ManyToOne @JoinColumn(name="current_round_id", nullable=true) private Round currentRound; @@ -64,10 +42,6 @@ @JoinColumn(name="current_block_id", nullable=true) private Block currentBlock; - @OneToMany(mappedBy = "game") - private List<Location> locations; - - public void setId(Long id) { this.id = id; } @@ -75,18 +49,6 @@ return id; } - public void setTitle(String title) { - this.title = title; - } - public String getTitle() { - return title; - } - public void setDescription(String description) { - this.description = description; - } - public String getDescription() { - return description; - } public void setMoney(Double money) { this.money = money; } @@ -94,49 +56,12 @@ return money; } - /*public void setRoundconfig(List<Round> roundconfig) { - this.rounds = roundconfig; - } - public List<Round> getRoundconfig() { - return rounds; - }*/ public void setTimestamp(Timestamp timestamp) { this.timestamp = timestamp; } public Timestamp getTimestamp() { return timestamp; } - public Integer getNumberOfRounds() { - return numberOfRounds; - } - public void setNumberOfRounds(Integer numberOfRounds) { - this.numberOfRounds = numberOfRounds; - } - public Integer getNumberOfLocations() { - return numberOfLocations; - } - public void setNumberOfLocations(Integer numberOfLocations) { - this.numberOfLocations = numberOfLocations; - } - public Integer getMaxDays() { - return maxDays; - } - public void setMaxDays(Integer maxDays) { - this.maxDays = maxDays; - } - public Integer getMaxFishHarvest() { - return maxFishHarvest; - } - public void setMaxFishHarvest(Integer maxFishHarvest) { - this.maxFishHarvest = maxFishHarvest; - } - public String getImageLocation() { - return imageLocation; - } - public void setImageLocation(String imageLocation) { - this.imageLocation = imageLocation; - } - public void setCurrentRound(Round currentRound) { this.currentRound = currentRound; } @@ -149,17 +74,17 @@ public Block getCurrentBlock() { return currentBlock; } - public void setLocations(List<Location> locations) { - this.locations = locations; + public void setGameConfig(GameConfig gameConfig) { + this.gameConfig = gameConfig; } - public List<Location> getLocations() { - return locations; + public GameConfig getGameConfig() { + return gameConfig; } - public void setGameRounds(List<GameRound> gameRounds) { - this.gameRounds = gameRounds; + public void setGameCode(String gameCode) { + this.gameCode = gameCode; } - public List<GameRound> getGameRounds() { - return gameRounds; + public String getGameCode() { + return gameCode; } } Added: mentalmodels/trunk/src/main/java/edu/asu/commons/mme/entity/GameConfig.java =================================================================== --- mentalmodels/trunk/src/main/java/edu/asu/commons/mme/entity/GameConfig.java (rev 0) +++ mentalmodels/trunk/src/main/java/edu/asu/commons/mme/entity/GameConfig.java 2009-09-28 22:57:24 UTC (rev 283) @@ -0,0 +1,120 @@ +package edu.asu.commons.mme.entity; + +import java.io.Serializable; +import java.sql.Timestamp; +import java.util.List; + +import javax.persistence.Column; +import javax.persistence.Entity; +import javax.persistence.FetchType; +import javax.persistence.GeneratedValue; +import javax.persistence.Id; +import javax.persistence.Lob; +import javax.persistence.OneToMany; +import javax.persistence.Table; + +@Entity +@Table(name="game_config") +public class GameConfig implements Serializable{ + + /** + * + */ + private static final long serialVersionUID = -5758994275900963337L; + + @Id + @GeneratedValue + private Long id; + + @Column(nullable=false) + private String title; + + @Lob + @Column(nullable=false) + private String description; + + @Column(name="no_of_locations",nullable = false) + private Integer numberOfLocations; + + @Column(name="max_days",nullable = false) + private Integer maxDays; + + @Column(name="max_fish_harvest",nullable = false) + private Integer maxFishHarvest; + + @Column(nullable=false) + private Timestamp timestamp; + + @Column(name="image_location") + private String imageLocation; + + // FIXME: should this be many-to-many instead? +/* @OneToMany(mappedBy = "gameConfig") + private List<GameRound> gameRounds;*/ + + @OneToMany(mappedBy = "gameConfig") + private List<Location> locations; + + + public void setId(Long id) { + this.id = id; + } + public Long getId() { + return id; + } + + public void setTimestamp(Timestamp timestamp) { + this.timestamp = timestamp; + } + public Timestamp getTimestamp() { + return timestamp; + } + public Integer getNumberOfLocations() { + return numberOfLocations; + } + public void setNumberOfLocations(Integer numberOfLocations) { + this.numberOfLocations = numberOfLocations; + } + public Integer getMaxDays() { + return maxDays; + } + public void setMaxDays(Integer maxDays) { + this.maxDays = maxDays; + } + public Integer getMaxFishHarvest() { + return maxFishHarvest; + } + public void setMaxFishHarvest(Integer maxFishHarvest) { + this.maxFishHarvest = maxFishHarvest; + } + public String getImageLocation() { + return imageLocation; + } + public void setImageLocation(String imageLocation) { + this.imageLocation = imageLocation; + } + public void setLocations(List<Location> locations) { + this.locations = locations; + } + public List<Location> getLocations() { + return locations; + } + /*public void setGameRounds(List<GameRound> gameRounds) { + this.gameRounds = gameRounds; + } + public List<GameRound> getGameRounds() { + return gameRounds; + }*/ + public void setTitle(String title) { + this.title = title; + } + public String getTitle() { + return title; + } + public void setDescription(String description) { + this.description = description; + } + public String getDescription() { + return description; + } +} Modified: mentalmodels/trunk/src/main/java/edu/asu/commons/mme/entity/GameRound.java =================================================================== --- mentalmodels/trunk/src/main/java/edu/asu/commons/mme/entity/GameRound.java 2009-09-28 22:53:16 UTC (rev 282) +++ mentalmodels/trunk/src/main/java/edu/asu/commons/mme/entity/GameRound.java 2009-09-28 22:57:24 UTC (rev 283) @@ -2,11 +2,13 @@ import java.io.Serializable; +import javax.persistence.Column; import javax.persistence.Entity; import javax.persistence.GeneratedValue; import javax.persistence.Id; import javax.persistence.JoinColumn; import javax.persistence.ManyToOne; +import javax.persistence.OrderBy; import javax.persistence.Table; @Entity @@ -24,11 +26,15 @@ @ManyToOne @JoinColumn(nullable=false) + @OrderBy("seqNo") private Round round; @ManyToOne @JoinColumn(nullable=false) - private Game game; + private GameConfig gameConfig; + + @Column(name="sequence_no",nullable=false) + private Integer seqNo; public void setId(Long id) { this.id = id; @@ -46,12 +52,20 @@ return round; } - public void setGame(Game game) { - this.game = game; + public void setGameConfig(GameConfig gameConfig) { + this.gameConfig = gameConfig; } - public Game getGame() { - return game; + public GameConfig getGameConfig() { + return gameConfig; } + public void setSeqNo(Integer seqNo) { + this.seqNo = seqNo; + } + + public Integer getSeqNo() { + return seqNo; + } + } Added: mentalmodels/trunk/src/main/java/edu/asu/commons/mme/entity/Instructor.java =================================================================== --- mentalmodels/trunk/src/main/java/edu/asu/commons/mme/entity/Instructor.java (rev 0) +++ mentalmodels/trunk/src/main/java/edu/asu/commons/mme/entity/Instructor.java 2009-09-28 22:57:24 UTC (rev 283) @@ -0,0 +1,55 @@ +package edu.asu.commons.mme.entity; + +import java.io.Serializable; + +import javax.persistence.Column; +import javax.persistence.Entity; +import javax.persistence.GeneratedValue; +import javax.persistence.Id; +import javax.persistence.Table; + +@Entity +@Table(name = "instructor") +public class Instructor implements Serializable { + + /** + * + */ + private static final long serialVersionUID = 612372011522490955L; + + @Id + @GeneratedValue + private Long id; + + @Column + private String fname; + + @Column + private String lname; + + public void setId(Long id) { + this.id = id; + } + + public Long getId() { + return id; + } + + public void setFname(String fname) { + this.fname = fname; + } + + public String getFname() { + return fname; + } + + public void setLname(String lname) { + this.lname = lname; + } + + public String getLname() { + return lname; + } + + +} Modified: mentalmodels/trunk/src/main/java/edu/asu/commons/mme/entity/Location.java =================================================================== --- mentalmodels/trunk/src/main/java/edu/asu/commons/mme/entity/Location.java 2009-09-28 22:53:16 UTC (rev 282) +++ mentalmodels/trunk/src/main/java/edu/asu/commons/mme/entity/Location.java 2009-09-28 22:57:24 UTC (rev 283) @@ -1,14 +1,12 @@ package edu.asu.commons.mme.entity; import java.io.Serializable; -import java.util.List; import javax.persistence.Column; import javax.persistence.Entity; import javax.persistence.GeneratedValue; import javax.persistence.Id; import javax.persistence.ManyToOne; -import javax.persistence.OneToMany; import javax.persistence.Table; @Entity @@ -21,32 +19,29 @@ @GeneratedValue private Long id; -/* @OneToMany(mappedBy = "location") - private List<RoundLocation> roundLocations;*/ - @Column(nullable=false,name="location_name") private String locationName; - @Column(nullable=false,name="max_capacity") + @Column(nullable=false,name="max_capacity", scale=2) private Double maxCapacity; @Column(nullable=false,name="growth_rate", scale=2) private Double growthRate; - @Column(nullable=false,name="initial_population") + @Column(nullable=false,name="initial_population", scale=2) private Double initialPopulation; - @Column(name="current_population") + @Column(name="current_population", scale=2) private Double currentPopulation; - @Column(name="fish_leaving") + @Column(name="fish_leaving", scale=2) private Double fishLeaving; - @Column(name="fish_return") + @Column(name="fish_return", scale=2) private Double fishReturned; @ManyToOne - private Game game; + private GameConfig gameConfig; public void setId(Long id) { this.id = id; @@ -87,13 +82,6 @@ public Double getCurrentPopulation() { return currentPopulation; } - /*public void setRoundLocations(List<RoundLocation> roundLocations) { - this.roundLocations = roundLocations; - } - public List<RoundLocation> getRoundLocations() { - return roundLocations; - }*/ - public void setFishLeaving(Double fishLeaving) { this.fishLeaving = fishLeaving; } @@ -110,12 +98,12 @@ return fishReturned; } - public void setGame(Game game) { - this.game = game; + public void setGameConfig(GameConfig gameConfig) { + this.gameConfig = gameConfig; } - public Game getGame() { - return game; + public GameConfig getGameConfig() { + return gameConfig; } } Modified: mentalmodels/trunk/src/main/java/edu/asu/commons/mme/entity/Round.java =================================================================== --- mentalmodels/trunk/src/main/java/edu/asu/commons/mme/entity/Round.java 2009-09-28 22:53:16 UTC (rev 282) +++ mentalmodels/trunk/src/main/java/edu/asu/commons/mme/entity/Round.java 2009-09-28 22:57:24 UTC (rev 283) @@ -21,35 +21,20 @@ @GeneratedValue private Long id; - @Column(name="round_no",nullable=false) - private Integer roundNo; - - @OneToMany(mappedBy = "round") - private List<GameRound> gameRounds; + /*@OneToMany(mappedBy = "round") + private List<GameRound> gameRounds;*/ @Column(name="communication_flag",nullable=false,columnDefinition="Boolean default false") private boolean communicationFlag; - /*@ManyToOne - private ModuleRoundConfig round_config;*/ - - - /*@OneToMany(mappedBy = "round") - private List<RoundLocation> roundLocations; - */ public void setId(Long id) { this.id = id; } public Long getId() { return id; } - public void setRoundNo(Integer roundNo) { - this.roundNo = roundNo; - } - public Integer getRoundNo() { - return roundNo; - } + public void setCommunicationFlag(boolean communication_flag) { this.communicationFlag = communication_flag; } @@ -62,14 +47,14 @@ public List<RoundLocation> getRoundLocations() { return roundLocations; }*/ - public void setGameRounds(List<GameRound> gameRounds) { + /*public void setGameRounds(List<GameRound> gameRounds) { this.gameRounds = gameRounds; } public List<GameRound> getGameRounds() { return gameRounds; } + */ - /*public void setRound_config(ModuleRoundConfig round_config) { this.round_config = round_config; } Deleted: mentalmodels/trunk/src/main/java/edu/asu/commons/mme/entity/RoundLocation.java =================================================================== --- mentalmodels/trunk/src/main/java/edu/asu/commons/mme/entity/RoundLocation.java 2009-09-28 22:53:16 UTC (rev 282) +++ mentalmodels/trunk/src/main/java/edu/asu/commons/mme/entity/RoundLocation.java 2009-09-28 22:57:24 UTC (rev 283) @@ -1,57 +0,0 @@ -package edu.asu.commons.mme.entity; - -import java.io.Serializable; - -import javax.persistence.Entity; -import javax.persistence.GeneratedValue; -import javax.persistence.Id; -import javax.persistence.JoinColumn; -import javax.persistence.ManyToOne; -import javax.persistence.Table; - -@Entity -@Table(name="round_config_location") -public class RoundLocation implements Serializable { - - /** - * - */ - private static final long serialVersionUID = -3215898164475817212L; - - @Id - @GeneratedValue - private Long id; - - @ManyToOne - @JoinColumn(nullable=false) - private Round round; - - @ManyToOne - @JoinColumn(nullable=false) - private Location location; - - public void setId(Long id) { - this.id = id; - } - - public Long getId() { - return id; - } - - public void setRound(Round round) { - this.round = round; - } - - public Round getRound() { - return round; - } - - public void setLocation(Location location) { - this.location = location; - } - - public Location getLocation() { - return location; - } - -} Added: mentalmodels/trunk/src/main/java/edu/asu/commons/mme/service/GameConfigService.java =================================================================== --- mentalmodels/trunk/src/main/java/edu/asu/commons/mme/service/GameConfigService.java (rev 0) +++ mentalmodels/trunk/src/main/java/edu/asu/commons/mme/service/GameConfigService.java 2009-09-28 22:57:24 UTC (rev 283) @@ -0,0 +1,11 @@ +package edu.asu.commons.mme.service; + +import edu.asu.commons.mme.dao.HibernateGameConfigDao; +import edu.asu.commons.mme.entity.GameConfig; + +public class GameConfigService extends Service.Base<GameConfig, HibernateGameConfigDao>{ + + + + +} Modified: mentalmodels/trunk/src/main/java/edu/asu/commons/mme/service/LocationService.java =================================================================== --- mentalmodels/trunk/src/main/java/edu/asu/commons/mme/service/LocationService.java 2009-09-28 22:53:16 UTC (rev 282) +++ mentalmodels/trunk/src/main/java/edu/asu/commons/mme/service/LocationService.java 2009-09-28 22:57:24 UTC (rev 283) @@ -8,6 +8,7 @@ import edu.asu.commons.mme.dao.HibernateLocationDao; import edu.asu.commons.mme.entity.Game; +import edu.asu.commons.mme.entity.GameConfig; import edu.asu.commons.mme.entity.Location; import edu.asu.commons.mme.entity.Round; @@ -27,26 +28,27 @@ initLocation = locations.get(i); initializeLocation(initLocation); } + return locations; } public void initializeLocation(Location location) { // TODO Auto-generated method stub Hibernate.initialize(location); - //Hibernate.initialize(location.getRoundLocations()); - Game game = location.getGame(); - Hibernate.initialize(game); - Hibernate.initialize(game); - Hibernate.initialize(game.getCurrentBlock()); - Hibernate.initialize(game.getCurrentRound()); - Hibernate.initialize(game.getGameRounds()); - Hibernate.initialize(game.getLocations()); + Hibernate.initialize(location.getGameConfig()); + for(Location loc:location.getGameConfig().getLocations()) + { + Hibernate.initialize(loc); + + } + //getLogger().debug("the game rounds for round objects are : " + game.getCurrentRound().getGameRounds().get(0)); } public Location getLocation(String locationName) { // TODO Auto-generated method stub List<Location>locations = getAllLocations(); + Location location =new Location(); for(int i=0; i<locations.size(); i++) @@ -59,51 +61,58 @@ return location; } //FIXME: For the pilot experiment locations are set manually but in future might want to take inputs from user - public void setAllLocations(Game game) + public List<Location> setAllLocations(GameConfig gameConfig) { - Location harbor = new Location(); - harbor.setLocationName("Harbor"); - harbor.setCurrentPopulation(0.0); - harbor.setGrowthRate(0.0); - harbor.setInitialPopulation(0.0); - harbor.setMaxCapacity(0.0); - harbor.setGame(game); - getDao().save(harbor); + List<Location> locations = new ArrayList<Location>(); + try{ + Location harbor = new Location(); + harbor.setLocationName("Harbor"); + harbor.setCurrentPopulation(0.0); + harbor.setGrowthRate(0.0); + harbor.setInitialPopulation(0.0); + harbor.setMaxCapacity(0.0); + harbor.setGameConfig(gameConfig); + getDao().save(harbor); + getLogger().info("Saved Location "+harbor.getLocationName()+" with id " + harbor.getId()); + locations.add(harbor); + + Location bay1 = new Location(); + bay1.setLocationName("Bay1"); + bay1.setCurrentPopulation(5.0); + bay1.setInitialPopulation(5.0); + bay1.setGrowthRate(0.5); + bay1.setMaxCapacity(10.0); + bay1.setGameConfig(gameConfig); + getDao().save(bay1); + getLogger().info("Saved Location " + bay1.getLocationName() +" with id "+ bay1.getId()); + locations.add(bay1); + + Location bay2 = new Location(); + bay2.setLocationName("Bay2"); + bay2.setCurrentPopulation(10.0); + bay2.setInitialPopulation(10.0); + bay2.setGrowthRate(0.15); + bay2.setMaxCapacity(20.0); + bay2.setGameConfig(gameConfig); + getDao().save(bay2); + getLogger().info("Saved Location " + bay2.getLocationName() +" with id "+ bay2.getId()); + locations.add(bay2); + + Location bay3 = new Location(); + bay3.setLocationName("Bay3"); + bay3.setCurrentPopulation(15.0); + bay3.setInitialPopulation(15.0); + bay3.setGrowthRate(0.05); + bay3.setMaxCapacity(30.0); + bay3.setGameConfig(gameConfig); + getDao().save(bay3); + getLogger().info("Saved Location " + bay3.getLocationName() +" with id "+ bay3.getId()); + locations.add(bay3); + }catch(Exception e) + { + e.printStackTrace(); + } - getLogger().info("Saved Location "+harbor.getLocationName()+" with id " + harbor.getId()); - - Location bay1 = new Location(); - bay1.setLocationName("Bay1"); - bay1.setCurrentPopulation(5.0); - bay1.setInitialPopulation(5.0); - bay1.setGrowthRate(0.5); - bay1.setMaxCapacity(10.0); - bay1.setGame(game); - getDao().save(bay1); - - getLogger().info("Saved Location " + bay1.getLocationName() +" with id "+ bay1.getId()); - - Location bay2 = new Location(); - bay2.setLocationName("Bay2"); - bay2.setCurrentPopulation(10.0); - bay2.setInitialPopulation(10.0); - bay2.setGrowthRate(0.15); - bay2.setMaxCapacity(20.0); - bay2.setGame(game); - getDao().save(bay2); - - getLogger().info("Saved Location " + bay2.getLocationName() +" with id "+ bay2.getId()); - - Location bay3 = new Location(); - bay3.setLocationName("Bay3"); - bay3.setCurrentPopulation(15.0); - bay3.setInitialPopulation(15.0); - bay3.setGrowthRate(0.05); - bay3.setMaxCapacity(30.0); - bay3.setGame(game); - getDao().save(bay3); - - getLogger().info("Saved Location " + bay3.getLocationName() +" with id "+ bay3.getId()); - + return locations; } } Modified: mentalmodels/trunk/src/main/java/edu/asu/commons/mme/service/ModuleService.java =================================================================== --- mentalmodels/trunk/src/main/java/edu/asu/commons/mme/service/ModuleService.java 2009-09-28 22:53:16 UTC (rev 282) +++ mentalmodels/trunk/src/main/java/edu/asu/commons/mme/service/ModuleService.java 2009-09-28 22:57:24 UTC (rev 283) @@ -29,9 +29,7 @@ private boolean startGame = true; private Round currentRound; private int blockSeqNo; - private Block currentBlock; - public void test() { getLogger().debug("test to check if module service is working...." ); @@ -120,7 +118,7 @@ return null; } - private int getCurrentRoundNo() { + /*private int getCurrentRoundNo() { // TODO Auto-generated method stub //FIXME: Game id 1 is hard coded but needs to make it dynamic Game game = gameDao.find(1L); @@ -129,7 +127,7 @@ else return game.getCurrentRound().getRoundNo(); - } + }*/ private boolean isModuleFinished(Module module) { // TODO Auto-generated method stub @@ -219,9 +217,6 @@ } - - - public void setCurrentModule(Module currentModule) { this.currentModule = currentModule; } Modified: mentalmodels/trunk/src/main/java/edu/asu/commons/mme/service/RoundService.java =================================================================== --- mentalmodels/trunk/src/main/java/edu/asu/commons/mme/service/RoundService.java 2009-09-28 22:53:16 UTC (rev 282) +++ mentalmodels/trunk/src/main/java/edu/asu/commons/mme/service/RoundService.java 2009-09-28 22:57:24 UTC (rev 283) @@ -10,6 +10,7 @@ import org.springframework.transaction.annotation.Transactional; import edu.asu.commons.mme.dao.HibernateBlockDao; +import edu.asu.commons.mme.dao.HibernateGameConfigDao; import edu.asu.commons.mme.dao.HibernateGameDao; import edu.asu.commons.mme.dao.HibernateGameRoundDao; import edu.asu.commons.mme.dao.HibernateModuleDao; @@ -20,15 +21,14 @@ import edu.asu.commons.mme.entity.CategoricalOption; import edu.asu.commons.mme.entity.CategoricalQuestion; import edu.asu.commons.mme.entity.Game; +import edu.asu.commons.mme.entity.GameConfig; import edu.asu.commons.mme.entity.GameRound; -import edu.asu.commons.mme.entity.InformationWindow; import edu.asu.commons.mme.entity.Location; import edu.asu.commons.mme.entity.Module; import edu.asu.commons.mme.entity.ModuleRoundConfig; import edu.asu.commons.mme.entity.Question; import edu.asu.commons.mme.entity.QuestionGroup; import edu.asu.commons.mme.entity.Round; -import edu.asu.commons.mme.entity.RoundLocation; @Transactional public class RoundService extends Service.Base<Round, HibernateRoundConfigDao> { @@ -38,110 +38,131 @@ private HibernateGameDao gameDao; private HibernateModuleRoundConfigDao moduleRoundDao; private HibernateGameRoundDao gameRoundDao; + private HibernateGameConfigDao gameConfigDao; private LocationService locationService; - //private Module currentModule; - //private boolean startGame = true; - //private Round currentRound; - //private Block currentBlock; - private int blockSeqNo; - private boolean gameFinished; public RoundService() { - /*setCurrentGame(null); - setCurrentBlock(null); - setCurrentModule(null); - setCurrentModuleRoundConfig(null); - setCurrentRound(null);*/ setBlockSeqNo(0); setGameFinished(false); } + public GameConfig createGameConfig(GameConfig gameConfig) + { + GameConfig newGameConfig = null; + try{ + newGameConfig = new GameConfig(); + newGameConfig.setImageLocation(null); + newGameConfig.setTimestamp(gameConfig.getTimestamp()); + newGameConfig.setMaxDays(gameConfig.getMaxDays()); + newGameConfig.setMaxFishHarvest(gameConfig.getMaxFishHarvest()); + newGameConfig.setNumberOfLocations(gameConfig.getNumberOfLocations()); + getGameConfigDao().save(newGameConfig); + initializeGameRounds(newGameConfig); + initializeLocations(newGameConfig); + + }catch(Exception e) + { + e.printStackTrace(); + } + return newGameConfig; + } + + public Game createGame(Game game) { - getLogger().debug("game came from flex is : " + game.getDescription()); + getLogger().debug("game came from flex is : " + game.getGameCode()); Game newGame = new Game(); //currentGame = game; try { - newGame.setDescription(game.getDescription()); - newGame.setMaxDays(game.getMaxDays()); - newGame.setMaxFishHarvest(game.getMaxFishHarvest()); + newGame.setGameCode(game.getGameCode()); newGame.setMoney(game.getMoney()); - newGame.setNumberOfRounds(game.getNumberOfRounds()); - newGame.setNumberOfLocations(game.getNumberOfLocations()); newGame.setTimestamp(game.getTimestamp()); - newGame.setTitle(game.getTitle()); - newGame.setImageLocation("null"); + + //FIXME: Currently using default GameConfiguration whose id is 1 + GameConfig gameConfig = gameConfigDao.find(1L); + newGame.setGameConfig(gameConfig); getGameDao().save(newGame); - String str = newGame.getDescription()+newGame.getId(); + String str = newGame.getGameCode()+newGame.getId(); - if(getGameDao().findAllByProperty("description", str).size() != 0) + if(getGameDao().findAllByProperty("gameCode", str).size() != 0) { //getLogger().debug("in if loop "); newGame = null; } else { - newGame.setDescription(str); + newGame.setGameCode(str); getGameDao().save(newGame); getLogger().info("Created the game: " + newGame.getId()); - initializeGameRounds(newGame); - initializeLocations(newGame); + initializeLocations(gameConfig); initializeGame(newGame); } }catch(Exception e) { e.printStackTrace(); } - getLogger().debug("current game from flex is: " + newGame.getDescription()); + getLogger().debug("current game from flex is: " + newGame.getId()); return newGame; } - private void initializeGameRounds(Game newGame) { + private void initializeGameRounds(GameConfig gameConfig) { // TODO Auto-generated method stub List<GameRound> gameRounds = new ArrayList<GameRound>(); - for(Round round:getDao().findAll()) { GameRound gameRound = new GameRound(); - gameRound.setGame(newGame); + gameRound.setGameConfig(gameConfig); gameRound.setRound(round); gameRoundDao.save(gameRound); gameRounds.add(gameRound); } - newGame.setGameRounds(gameRounds); - getGameDao().save(newGame); + getGameConfigDao().save(gameConfig); } - private void initializeLocations(Game newGame) + private void initializeLocations(GameConfig gameConfig) { - locationService.setAllLocations(newGame); - newGame.setLocations(locationService.getAllLocations()); - getGameDao().save(newGame); + gameConfig.setLocations(locationService.setAllLocations(gameConfig)); + getGameConfigDao().save(gameConfig); } public void initializeGame(Game game) { // TODO Auto-generated method stub - Hibernate.initialize(game); - Hibernate.initialize(game.getCurrentBlock()); - Hibernate.initialize(game.getCurrentRound()); - // Hibernate.initialize(game.getLocations()); + try{ + Hibernate.initialize(game); + Hibernate.initialize(game.getCurrentBlock()); + + + GameConfig gameconfig = game.getGameConfig(); + Hibernate.initialize(gameconfig); + + for(Location location:gameconfig.getLocations()) + { + Hibernate.initialize(location); - for(GameRound gameRound :game.getGameRounds()){ - Hibernate.initialize(gameRound); - //Hibernate.initialize(gameRound.getGame()); - initializeRound(gameRound.getRound()); + } + + Round round = game.getCurrentRound(); + Hibernate.initialize(round); + /*for(GameRound gameRound:round.getGameRounds()) + { + getLogger().debug("gameround in initializing round is " + gameRound.getId()); + Hibernate.initialize(gameRound); + }*/ + + }catch(Exception e ) + { + e.printStackTrace(); } - for(Location location :game.getLocations()){ - locationService.initializeLocation(location); - } + //Hibernate.initialize(gameconfig.getGameRounds()); + + } - public Module getNextModule(int sequenceNo) { return getModule(sequenceNo); @@ -171,13 +192,18 @@ //check if it is a start of the game if(game.getCurrentRound() == null && game.getCurrentBlock() == null ) { - getLogger().debug("Current Round is null... "); - getLogger().debug("Current block is null... "); + getLogger().info("Current Round is null... "); + getLogger().info("Current block is null... "); + getLogger().info("Starting of the game...." + game.getGameCode()); - getLogger().debug("Starting of the game...." + game.getDescription()); - currentRound = getNextRound(null); + currentRound = getNextRound(game); + getLogger().info("Next Round object is "+ currentRound.getId()); + currentModuleRoundConfig = getModuleRoundConfig(0, currentRound); + getLogger().info("Next ModuleRound Config object is "+ currentModuleRoundConfig.getId()); + Module currentModule = getModuleForCurrentRound(currentModuleRoundConfig); + getLogger().info("Next Module object is "+ currentModule.getId()); currentBlock = getBlock(currentModule,1); } else @@ -202,9 +228,15 @@ else { //set the next round - currentRound = getNextRound(game.getCurrentRound()); + currentRound = getNextRound(game); + getLogger().info("Next Round object is "+ currentRound.getId()); + currentModuleRoundConfig = getModuleRoundConfig(0, currentRound); + getLogger().info("Next ModuleRound Config object is "+ currentModuleRoundConfig.getId()); + Module currentModule = getModuleForCurrentRound(currentModuleRoundConfig); + getLogger().info("Next Module object is "+ currentModule.getId()); + currentBlock = getBlock(currentModule,1); } } @@ -214,7 +246,11 @@ //currentRound = getNextRound(game.getCurrentRound()); currentModuleRoundConfig = getModuleRoundConfig(getPreviousModuleConfigSequenceNo(game), currentRound); + getLogger().info("Next ModuleRound Config object is "+ currentModuleRoundConfig.getId()); + Module currentModule = getModuleForCurrentRound(currentModuleRoundConfig); + getLogger().info("Next Module object is "+ currentModule.getId()); + currentBlock = getBlock(currentModule,1); } @@ -292,32 +328,52 @@ } - private Round getNextRound(Round currentRound) { + private Round getNextRound(Game game) { // TODO Auto-generated method stub Round returnRound = null; + Round currentRound = game.getCurrentRound(); + GameConfig gameConfig = game.getGameConfig(); + List<GameRound> gameRounds = new ArrayList<GameRound>(); if(currentRound == null) { - returnRound = getDao().findByProperty("roundNo", 1); - //returnRound = currentRound; - //initializeRound(returnRound); + //get the first round + Map<String, Object> variables = new HashMap<String, Object>(); + variables.put("gameConfig",gameConfig); + variables.put("seqNo", 1); + getGameRoundDao().findByEqCriteria(variables); + gameRounds = gameRoundDao.findByEqCriteria(variables); + if(gameRounds.size() == 1) + { + returnRound = gameRounds.get(0).getRound(); + gameRounds.clear(); + } } else { - getLogger().debug("current round no is: " + currentRound.getRoundNo()); - List<Round> rounds = getDao().findAll(); - for(int i = 0; i < rounds.size(); i++) + Map<String, Object> variables = new HashMap<String, Object>(); + variables.put("gameConfig",gameConfig); + variables.put("round", currentRound); + gameRounds = getGameRoundDao().findByEqCriteria(variables); + if(gameRounds.size() == 1) { - getLogger().debug("in for loop round no is: " + rounds.get(i).getRoundNo()); - if(currentRound.getRoundNo() < rounds.get(i).getRoundNo()) + int currentSeqNo = gameRounds.get(0).getSeqNo(); + gameRounds = getGameRoundDao().findAll(); + for(int i = 0; i < gameRounds.size(); i++) { - returnRound = rounds.get(i); - break; - //getLogger().debug("currentround object is "+ rounds.get(i).getId()); + if(currentSeqNo < gameRounds.get(i).getSeqNo()) + { + returnRound = gameRounds.get(i).getRound(); + break; + //getLogger().debug("currentround object is "+ rounds.get(i).getId()); + } } } + else + { + getLogger().error("Error Occured.. Game Config is associated with multiple Rounds "); + } } - getLogger().debug("currentround object is "+ returnRound.getId()); return returnRound; } @@ -332,6 +388,7 @@ } + @SuppressWarnings("unused") private void initializeCurrentBlock(Block block) { Hibernate.initialize(block); @@ -432,23 +489,35 @@ }*/ public boolean isGameFinished(Game game) { - List<GameRound> gameRounds = game.getGameRounds(); + GameConfig gameConfig = game.getGameConfig(); + List<GameRound> gameRounds = getGameRoundDao().findAllByProperty("gameConfig",game.getGameConfig()); boolean flag = false; - if(game.getCurrentRound().getRoundNo() == gameRounds.get(gameRounds.size() - 1).getRound().getRoundNo()) + Map<String, Object> variables = new HashMap<String, Object>(); + variables.put("gameConfig",gameConfig); + variables.put("round", game.getCurrentRound()); + gameRounds = getGameRoundDao().findByEqCriteria(variables); + if(gameRounds.size() == 1) { - flag = true; - } - else - { - for(GameRound gameRound:gameRounds) + int currentSeqNo = gameRounds.get(0).getSeqNo(); + gameRounds.clear(); + gameRounds = getGameRoundDao().findAllByProperty("gameConfig", gameConfig); + + if(currentSeqNo == gameRounds.get(gameRounds.size() - 1).getSeqNo()) { - if(game.getCurrentRound().getRoundNo() < game.getCurrentRound().getRoundNo()) + flag = true; + } + else + { + for(GameRound gameRound:gameRounds) { - flag = false; + if(currentSeqNo < gameRound.getSeqNo()) + { + flag = false; + } } + } - } return flag; } @@ -626,25 +695,6 @@ return currentRound; }*/ - private void initializeRound(Round round) { - // TODO Auto-generated method stub - Hibernate.initialize(round); - - //Hibernate.initialize(round.getRoundLocations()); - - /*for (RoundLocation roundLocation: round.getRoundLocations()) { - Hibernate.initialize(roundLocation); - //hibernateroundLocation.getLocation(); - }*/ - for (GameRound gameRound: round.getGameRounds()) { - Hibernate.initialize(gameRound); - //hibernateroundLocation.getLocation(); - } - - - //Hibernate.initialize(currentRound.getLocations()); - } - public void setGameDao(HibernateGameDao gameDao) { this.gameDao = gameDao; } @@ -673,7 +723,6 @@ return blockDao; } public void setGameFinished(boolean gameFinished) { - this.gameFinished = gameFinished; } @@ -686,9 +735,9 @@ return locationService; } - public String getDescription(Game game) { + public String getGameCode(Game game) { // TODO Auto-generated method stub - return game.getDescription(); + return game.getGameCode(); } public void setGameRoundDao(HibernateGameRoundDao gameRoundDao) { @@ -698,4 +747,12 @@ public HibernateGameRoundDao getGameRoundDao() { return gameRoundDao; } + + public void setGameConfigDao(HibernateGameConfigDao gameConfigDao) { + this.gameConfigDao = gameConfigDao; + } + + public HibernateGameConfigDao getGameConfigDao() { + return gameConfigDao; + } } Modified: mentalmodels/trunk/src/main/java/edu/asu/commons/mme/service/StartGame.java =================================================================== --- mentalmodels/trunk/src/main/java/edu/asu/commons/mme/service/StartGame.java 2009-09-28 22:53:16 UTC (rev 282) +++ mentalmodels/trunk/src/main/java/edu/asu/commons/mme/service/StartGame.java 2009-09-28 22:57:24 UTC (rev 283) @@ -36,18 +36,7 @@ public Student createStudent(Student student) { - // Game game = new Game(); - Game game = student.getGame(); - Student studentReturn = null; - //System.out.println("game description: " + game.getDescription() + " student game code is: " + student.getGameCode()); - if(game.getDescription().equals(student.getGameCode())) - { - student.setGame(game); - studentReturn = new Student(); - studentReturn = studentService.createStudent(student); - //System.out.println("student Return info: " + studentReturn.getGameCode()); - } - return studentReturn; + return studentService.createStudent(student); } public Game createGame(Game game) @@ -91,7 +80,7 @@ while (i<17) { i++; - String msgDestination = roundService.getDescription(game); + String msgDestination = roundService.getGameCode(newGameState); //Push the first block to the clients AsyncMessage msg = new AsyncMessage(); Modified: mentalmodels/trunk/src/main/java/edu/asu/commons/mme/service/StartupService.java =================================================================== --- mentalmodels/trunk/src/main/java/edu/asu/commons/mme/service/StartupService.java 2009-09-28 22:53:16 UTC (rev 282) +++ mentalmodels/trunk/src/main/java/edu/asu/commons/mme/service/StartupService.java 2009-09-28 22:57:24 UTC (rev 283) @@ -29,7 +29,18 @@ public Student createStudent(Student student) { - return getStartGame().createStudent(student); + //Game game = student.getGame(); + Student studentReturn = null; + //System.out.println("game description: " + game.getDescription() + " student game code is: " + student.getGameCode()); + for(StartGame startGame:currentGames) + { + if(startGame.getGame().getGameCode().equals(student.getGameCode())) + { + student.setGame(startGame.getGame()); + studentReturn = startGame.createStudent(student); + } + } + return studentReturn; } public Game createGame(Game game) @@ -54,6 +65,7 @@ { e.printStackTrace(); } + getStartGame().getRoundService().initializeGame(newGame); return newGame; } Modified: mentalmodels/trunk/src/main/webapp/WEB-INF/applicationContext.xml =================================================================== --- mentalmodels/trunk/src/main/webapp/WEB-INF/applicationContext.xml 2009-09-28 22:53:16 UTC (rev 282) +++ mentalmodels/trunk/src/main/webapp/WEB-INF/applicationContext.xml 2009-09-28 22:57:24 UTC (rev 283) @@ -97,6 +97,10 @@ <property name='sessionFactory' ref='sessionFactory'/> </bean> + <bean id='gameConfigDao' class='edu.asu.commons.mme.dao.HibernateGameConfigDao'> + <property name='sessionFactory' ref='sessionFactory'/> + </bean> + <bean id='moduleRoundDao' class='edu.asu.commons.mme.dao.HibernateModuleRoundConfigDao'> <property name='sessionFactory' ref='sessionFactory'/> </bean> @@ -116,6 +120,7 @@ <property name='dao' ref='roundConfigDao'/> <property name='moduleDao' ref='moduleDao'/> <property name='gameDao' ref='gameDao' /> + <property name='gameConfigDao' ref='gameConfigDao' /> <property name='moduleRoundDao' ref='moduleRoundDao' /> <property name='locationService' ref='locationService'/> <property name='gameRoundDao' ref='gameRoundDao'/> Modified: mentalmodels/trunk/src/main/webapp/WEB-INF/classes/log4j.properties =================================================================== --- mentalmodels/trunk/src/main/webapp/WEB-INF/classes/log4j.properties 2009-09-28 22:53:16 UTC (rev 282) +++ mentalmodels/trunk/src/main/webapp/WEB-INF/classes/log4j.properties 2009-09-28 22:57:24 UTC (rev 283) @@ -12,5 +12,5 @@ log4j.logger.edu.asu.commons=DEBUG #log4j.logger.org.springframework=DEBUG -log4j.logger.org.springframework=ERROR +log4j.logger.org.springframework=DEBUG log4j.logger.org.hibernate=ERROR Modified: mentalmodels/trunk/src/main/webapp/WEB-INF/hibernate.cfg.xml =================================================================== --- mentalmodels/trunk/src/main/webapp/WEB-INF/hibernate.cfg.xml 2009-09-28 22:53:16 UTC (rev 282) +++ mentalmodels/trunk/src/main/webapp/WEB-INF/hibernate.cfg.xml 2009-09-28 22:57:24 UTC (rev 283) @@ -7,8 +7,10 @@ "http://hibernate.sourceforge.net/hibernate-configuration-3.0.dtd"> <hibernate-configuration> <session-factory> + <mapping class='edu.asu.commons.mme.entity.GameConfig'/> <mapping class='edu.asu.commons.mme.entity.Game'/> - <mapping class='edu.asu.commons.mme.entity.Round'/> + <mapping class='edu.asu.commons.mme.entity.Round'/> + <mapping class='edu.asu.commons.mme.entity.GameRound'/> <mapping class='edu.asu.commons.mme.entity.Location'/> <!-- <mapping class='edu.asu.commons.mme.entity.RoundLocation'/> @@ -17,8 +19,8 @@ <mapping class='edu.asu.commons.mme.entity.Communication'/> <mapping class='edu.asu.commons.mme.entity.Group'/> <mapping class='edu.asu.commons.mme.entity.Student'/> - <mapping class='edu.asu.commons.mme.entity.GameRound'/> + <mapping class='edu.asu.commons.mme.entity.StudentRoundConfig'/> <mapping class='edu.asu.commons.mme.entity.StudentStrategy'/> This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <see...@us...> - 2009-09-28 22:53:34
|
Revision: 282 http://virtualcommons.svn.sourceforge.net/virtualcommons/?rev=282&view=rev Author: seematalele Date: 2009-09-28 22:53:16 +0000 (Mon, 28 Sep 2009) Log Message: ----------- somehow was getting error whicle committing the code.saying out of date....so trying to commit the the file separately. Modified Paths: -------------- mentalmodels/trunk/src/main/webapp/FisheryExperimentShell.swf Modified: mentalmodels/trunk/src/main/webapp/FisheryExperimentShell.swf =================================================================== (Binary files differ) This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <see...@us...> - 2009-09-24 19:16:50
|
Revision: 281 http://virtualcommons.svn.sourceforge.net/virtualcommons/?rev=281&view=rev Author: seematalele Date: 2009-09-24 19:16:41 +0000 (Thu, 24 Sep 2009) Log Message: ----------- Can create multiple games. Tested it by creating and starting 2 games at different times Made changes in the startGame.mxml Changed the schema of mme Modified Paths: -------------- mentalmodels/trunk/flex/src/StartGame.mxml mentalmodels/trunk/src/main/db/init-mme.sql mentalmodels/trunk/src/main/java/edu/asu/commons/mme/entity/Game.java mentalmodels/trunk/src/main/java/edu/asu/commons/mme/entity/Location.java mentalmodels/trunk/src/main/java/edu/asu/commons/mme/entity/ModuleRoundConfig.java mentalmodels/trunk/src/main/java/edu/asu/commons/mme/entity/Round.java mentalmodels/trunk/src/main/java/edu/asu/commons/mme/service/LocationService.java mentalmodels/trunk/src/main/java/edu/asu/commons/mme/service/RoundService.java mentalmodels/trunk/src/main/java/edu/asu/commons/mme/service/StartGame.java mentalmodels/trunk/src/main/java/edu/asu/commons/mme/service/StartupService.java mentalmodels/trunk/src/main/webapp/WEB-INF/applicationContext.xml mentalmodels/trunk/src/main/webapp/WEB-INF/hibernate.cfg.xml Added Paths: ----------- mentalmodels/trunk/src/main/java/edu/asu/commons/mme/dao/HibernateGameRoundDao.java mentalmodels/trunk/src/main/java/edu/asu/commons/mme/entity/GameRound.java Modified: mentalmodels/trunk/flex/src/StartGame.mxml =================================================================== --- mentalmodels/trunk/flex/src/StartGame.mxml 2009-09-16 21:14:48 UTC (rev 280) +++ mentalmodels/trunk/flex/src/StartGame.mxml 2009-09-24 19:16:41 UTC (rev 281) @@ -33,7 +33,7 @@ <mx:method name="startGame"/> </mx:RemoteObject> - <mx:Consumer id="consumer" destination="chat" message="messageHandler(event)" fault="faultMsgHandler(event)" channelSet="{cs}" /> + <mx:Consumer id="consumer" destination="mme" message="messageHandler(event)" fault="faultMsgHandler(event)" channelSet="{cs}" /> <mx:ChannelSet id="cs"> <!--<mx:StreamingAMFChannel url="http://localhost:8080/mme/messagebroker/streamingamf"/>--> @@ -64,6 +64,7 @@ [Bindable]private var pageNum:int = 0; public var currentBlock:Block = null; + public var game:Game = null; public function init():void { @@ -120,8 +121,8 @@ message.body = "got gameObject" + gameObject.description; producer.send(message); Alert.show("message is send"); */ - consumer.subscribe(); - Alert.show("subscribed to destination: " + consumer.destination); + + } public function start():void @@ -130,7 +131,7 @@ /*consumer.subscribe(); Alert.show("subscribed to destination: " + consumer.destination);*/ - startupService.startGame(); + startupService.startGame(game); //consumer.subtopic = "hello3"; } @@ -144,8 +145,14 @@ { if(event.result != null) { - txtGameID.text = (event.result as Game).description; + + var description:String = (event.result as Game).description; btnStartGame.enabled = true; + game = event.result as Game; + txtGameID.text = description; + consumer.subtopic = description; + consumer.subscribe(); + Alert.show("subscribed to destination: " + consumer.destination); } else { @@ -161,15 +168,14 @@ { //Alert.show("message from server came.."); var block:actionscript.Block = event.message.body as actionscript.Block; - Alert.show("String came from server is: " + block.id + " " + block.description); + //Alert.show("String came from server is: " + block.id + " " + block.description); - - /* if(currentBlock == null) + if(block == null) { Alert.show("Game is over!!"); } else - Alert.show("Block from server is : " + currentBlock.description); */ + Alert.show("Block from server is : " + block.description); } ]]> Modified: mentalmodels/trunk/src/main/db/init-mme.sql =================================================================== --- mentalmodels/trunk/src/main/db/init-mme.sql 2009-09-16 21:14:48 UTC (rev 280) +++ mentalmodels/trunk/src/main/db/init-mme.sql 2009-09-24 19:16:41 UTC (rev 281) @@ -292,29 +292,6 @@ -- Table structure for table `game` -- -DROP TABLE IF EXISTS `game`; -/*!40101 SET @saved_cs_client = @@character_set_client */; -/*!40101 SET character_set_client = utf8 */; -CREATE TABLE `game` ( - `id` bigint(20) NOT NULL AUTO_INCREMENT, - `description` longtext, - `image_location` varchar(255) DEFAULT NULL, - `max_days` int(11) NOT NULL, - `max_fish_harvest` int(11) NOT NULL, - `money` double DEFAULT NULL, - `no_of_locations` int(11) NOT NULL, - `no_of_rounds` int(11) NOT NULL, - `timestamp` datetime NOT NULL, - `title` varchar(255) NOT NULL, - `current_block_id` bigint(20) DEFAULT NULL, - `current_round_id` bigint(20) DEFAULT NULL, - PRIMARY KEY (`id`), - KEY `FK304BF2F1265AC7` (`current_block_id`), - KEY `FK304BF219A3AF27` (`current_round_id`), - CONSTRAINT `FK304BF219A3AF27` FOREIGN KEY (`current_round_id`) REFERENCES `round_config` (`id`), - CONSTRAINT `FK304BF2F1265AC7` FOREIGN KEY (`current_block_id`) REFERENCES `block` (`id`) -) ENGINE=InnoDB AUTO_INCREMENT=3 DEFAULT CHARSET=latin1; -/*!40101 SET character_set_client = @saved_cs_client */; -- -- Dumping data for table `game` @@ -330,29 +307,8 @@ -- Table structure for table `game_round_config` -- -DROP TABLE IF EXISTS `game_round_config`; -/*!40101 SET @saved_cs_client = @@character_set_client */; -/*!40101 SET character_set_client = utf8 */; -CREATE TABLE `game_round_config` ( - `game_id` bigint(20) NOT NULL, - `rounds_id` bigint(20) NOT NULL, - UNIQUE KEY `rounds_id` (`rounds_id`), - KEY `FKA0C2A407AC42F73` (`game_id`), - KEY `FKA0C2A40479268AA` (`rounds_id`), - CONSTRAINT `FKA0C2A40479268AA` FOREIGN KEY (`rounds_id`) REFERENCES `round_config` (`id`), - CONSTRAINT `FKA0C2A407AC42F73` FOREIGN KEY (`game_id`) REFERENCES `game` (`id`) -) ENGINE=InnoDB DEFAULT CHARSET=latin1; -/*!40101 SET character_set_client = @saved_cs_client */; --- --- Dumping data for table `game_round_config` --- -LOCK TABLES `game_round_config` WRITE; -/*!40000 ALTER TABLE `game_round_config` DISABLE KEYS */; -/*!40000 ALTER TABLE `game_round_config` ENABLE KEYS */; -UNLOCK TABLES; - -- -- Table structure for table `grp` -- @@ -578,16 +534,6 @@ -- Table structure for table `round_config` -- -DROP TABLE IF EXISTS `round_config`; -/*!40101 SET @saved_cs_client = @@character_set_client */; -/*!40101 SET character_set_client = utf8 */; -CREATE TABLE `round_config` ( - `id` bigint(20) NOT NULL AUTO_INCREMENT, - `communication_flag` tinyint(1) NOT NULL DEFAULT '0', - `round_no` int(11) NOT NULL, - PRIMARY KEY (`id`) -) ENGINE=InnoDB AUTO_INCREMENT=5 DEFAULT CHARSET=latin1; -/*!40101 SET character_set_client = @saved_cs_client */; -- -- Dumping data for table `round_config` @@ -603,34 +549,8 @@ -- Table structure for table `round_config_location` -- -DROP TABLE IF EXISTS `round_config_location`; -/*!40101 SET @saved_cs_client = @@character_set_client */; -/*!40101 SET character_set_client = utf8 */; -CREATE TABLE `round_config_location` ( - `id` bigint(20) NOT NULL AUTO_INCREMENT, - `location_id` bigint(20) NOT NULL, - `round_id` bigint(20) NOT NULL, - PRIMARY KEY (`id`), - KEY `FKC67B0361224FD013` (`location_id`), - KEY `FKC67B036147CF2321` (`round_id`), - CONSTRAINT `FKC67B036147CF2321` FOREIGN KEY (`round_id`) REFERENCES `round_config` (`id`), - CONSTRAINT `FKC67B0361224FD013` FOREIGN KEY (`location_id`) REFERENCES `location` (`id`) -) ENGINE=InnoDB DEFAULT CHARSET=latin1; -/*!40101 SET character_set_client = @saved_cs_client */; --- --- Dumping data for table `round_config_location` --- -LOCK TABLES `round_config_location` WRITE; -/*!40000 ALTER TABLE `round_config_location` DISABLE KEYS */; -/*!40000 ALTER TABLE `round_config_location` ENABLE KEYS */; -UNLOCK TABLES; - --- --- Table structure for table `student` --- - DROP TABLE IF EXISTS `student`; /*!40101 SET @saved_cs_client = @@character_set_client */; /*!40101 SET character_set_client = utf8 */; Added: mentalmodels/trunk/src/main/java/edu/asu/commons/mme/dao/HibernateGameRoundDao.java =================================================================== --- mentalmodels/trunk/src/main/java/edu/asu/commons/mme/dao/HibernateGameRoundDao.java (rev 0) +++ mentalmodels/trunk/src/main/java/edu/asu/commons/mme/dao/HibernateGameRoundDao.java 2009-09-24 19:16:41 UTC (rev 281) @@ -0,0 +1,11 @@ +package edu.asu.commons.mme.dao; + +import edu.asu.commons.mme.entity.GameRound; + +public class HibernateGameRoundDao extends HibernateDao<GameRound>{ + + public HibernateGameRoundDao() + { + super(GameRound.class); + } +} Modified: mentalmodels/trunk/src/main/java/edu/asu/commons/mme/entity/Game.java =================================================================== --- mentalmodels/trunk/src/main/java/edu/asu/commons/mme/entity/Game.java 2009-09-16 21:14:48 UTC (rev 280) +++ mentalmodels/trunk/src/main/java/edu/asu/commons/mme/entity/Game.java 2009-09-24 19:16:41 UTC (rev 281) @@ -6,16 +6,15 @@ import javax.persistence.Column; import javax.persistence.Entity; +import javax.persistence.FetchType; import javax.persistence.GeneratedValue; import javax.persistence.Id; import javax.persistence.JoinColumn; import javax.persistence.Lob; -import javax.persistence.ManyToMany; import javax.persistence.ManyToOne; +import javax.persistence.OneToMany; import javax.persistence.Table; -import org.hibernate.annotations.CollectionOfElements; - @Entity @Table(name="game") public class Game implements Serializable { @@ -54,9 +53,8 @@ private String imageLocation; // FIXME: should this be many-to-many instead? - @ManyToMany - @CollectionOfElements - private List<Round> rounds; + @OneToMany(mappedBy = "game") + private List<GameRound> gameRounds; @ManyToOne @JoinColumn(name="current_round_id", nullable=true) @@ -66,6 +64,9 @@ @JoinColumn(name="current_block_id", nullable=true) private Block currentBlock; + @OneToMany(mappedBy = "game") + private List<Location> locations; + public void setId(Long id) { this.id = id; @@ -135,12 +136,7 @@ public void setImageLocation(String imageLocation) { this.imageLocation = imageLocation; } - public List<Round> getRounds() { - return rounds; - } - public void setRounds(List<Round> rounds) { - this.rounds = rounds; - } + public void setCurrentRound(Round currentRound) { this.currentRound = currentRound; } @@ -153,7 +149,18 @@ public Block getCurrentBlock() { return currentBlock; } - - + public void setLocations(List<Location> locations) { + this.locations = locations; + } + public List<Location> getLocations() { + return locations; + } + public void setGameRounds(List<GameRound> gameRounds) { + this.gameRounds = gameRounds; + } + public List<GameRound> getGameRounds() { + return gameRounds; + } + } Added: mentalmodels/trunk/src/main/java/edu/asu/commons/mme/entity/GameRound.java =================================================================== --- mentalmodels/trunk/src/main/java/edu/asu/commons/mme/entity/GameRound.java (rev 0) +++ mentalmodels/trunk/src/main/java/edu/asu/commons/mme/entity/GameRound.java 2009-09-24 19:16:41 UTC (rev 281) @@ -0,0 +1,57 @@ +package edu.asu.commons.mme.entity; + +import java.io.Serializable; + +import javax.persistence.Entity; +import javax.persistence.GeneratedValue; +import javax.persistence.Id; +import javax.persistence.JoinColumn; +import javax.persistence.ManyToOne; +import javax.persistence.Table; + +@Entity +@Table(name = "game_round_config") +public class GameRound implements Serializable{ + + /** + * + */ + private static final long serialVersionUID = -2918858356542877284L; + + @Id + @GeneratedValue + private Long id; + + @ManyToOne + @JoinColumn(nullable=false) + private Round round; + + @ManyToOne + @JoinColumn(nullable=false) + private Game game; + + public void setId(Long id) { + this.id = id; + } + + public Long getId() { + return id; + } + + public void setRound(Round round) { + this.round = round; + } + + public Round getRound() { + return round; + } + + public void setGame(Game game) { + this.game = game; + } + + public Game getGame() { + return game; + } + +} Modified: mentalmodels/trunk/src/main/java/edu/asu/commons/mme/entity/Location.java =================================================================== --- mentalmodels/trunk/src/main/java/edu/asu/commons/mme/entity/Location.java 2009-09-16 21:14:48 UTC (rev 280) +++ mentalmodels/trunk/src/main/java/edu/asu/commons/mme/entity/Location.java 2009-09-24 19:16:41 UTC (rev 281) @@ -21,8 +21,8 @@ @GeneratedValue private Long id; - @OneToMany(mappedBy = "location") - private List<RoundLocation> roundLocations; +/* @OneToMany(mappedBy = "location") + private List<RoundLocation> roundLocations;*/ @Column(nullable=false,name="location_name") private String locationName; @@ -87,12 +87,12 @@ public Double getCurrentPopulation() { return currentPopulation; } - public void setRoundLocations(List<RoundLocation> roundLocations) { + /*public void setRoundLocations(List<RoundLocation> roundLocations) { this.roundLocations = roundLocations; } public List<RoundLocation> getRoundLocations() { return roundLocations; - } + }*/ public void setFishLeaving(Double fishLeaving) { this.fishLeaving = fishLeaving; Modified: mentalmodels/trunk/src/main/java/edu/asu/commons/mme/entity/ModuleRoundConfig.java =================================================================== --- mentalmodels/trunk/src/main/java/edu/asu/commons/mme/entity/ModuleRoundConfig.java 2009-09-16 21:14:48 UTC (rev 280) +++ mentalmodels/trunk/src/main/java/edu/asu/commons/mme/entity/ModuleRoundConfig.java 2009-09-24 19:16:41 UTC (rev 281) @@ -8,6 +8,7 @@ import javax.persistence.Id; import javax.persistence.JoinColumn; import javax.persistence.ManyToOne; +import javax.persistence.OrderBy; import javax.persistence.Table; @@ -33,6 +34,7 @@ @ManyToOne @JoinColumn(nullable = false) + @OrderBy("sequenceNo") private Round round; public void setSequenceNo(Integer sequenceNo) { Modified: mentalmodels/trunk/src/main/java/edu/asu/commons/mme/entity/Round.java =================================================================== --- mentalmodels/trunk/src/main/java/edu/asu/commons/mme/entity/Round.java 2009-09-16 21:14:48 UTC (rev 280) +++ mentalmodels/trunk/src/main/java/edu/asu/commons/mme/entity/Round.java 2009-09-24 19:16:41 UTC (rev 281) @@ -24,9 +24,8 @@ @Column(name="round_no",nullable=false) private Integer roundNo; - /*@ManyToMany - @CollectionOfElements - private List<Game> game;*/ + @OneToMany(mappedBy = "round") + private List<GameRound> gameRounds; @Column(name="communication_flag",nullable=false,columnDefinition="Boolean default false") private boolean communicationFlag; @@ -35,9 +34,9 @@ private ModuleRoundConfig round_config;*/ - @OneToMany(mappedBy = "round") + /*@OneToMany(mappedBy = "round") private List<RoundLocation> roundLocations; - + */ public void setId(Long id) { this.id = id; } @@ -57,13 +56,20 @@ public boolean getCommunicationFlag() { return communicationFlag; } - public void setRoundLocations(List<RoundLocation> roundLocations) { + /*public void setRoundLocations(List<RoundLocation> roundLocations) { this.roundLocations = roundLocations; } public List<RoundLocation> getRoundLocations() { return roundLocations; + }*/ + public void setGameRounds(List<GameRound> gameRounds) { + this.gameRounds = gameRounds; } + public List<GameRound> getGameRounds() { + return gameRounds; + } + /*public void setRound_config(ModuleRoundConfig round_config) { this.round_config = round_config; } Modified: mentalmodels/trunk/src/main/java/edu/asu/commons/mme/service/LocationService.java =================================================================== --- mentalmodels/trunk/src/main/java/edu/asu/commons/mme/service/LocationService.java 2009-09-16 21:14:48 UTC (rev 280) +++ mentalmodels/trunk/src/main/java/edu/asu/commons/mme/service/LocationService.java 2009-09-24 19:16:41 UTC (rev 281) @@ -9,6 +9,7 @@ import edu.asu.commons.mme.dao.HibernateLocationDao; import edu.asu.commons.mme.entity.Game; import edu.asu.commons.mme.entity.Location; +import edu.asu.commons.mme.entity.Round; @Transactional public class LocationService extends Service.Base<Location, HibernateLocationDao>{ @@ -24,13 +25,24 @@ for(int i = 0; i < locations.size(); i++) { initLocation = locations.get(i); - Hibernate.initialize(initLocation); - Hibernate.initialize(initLocation.getRoundLocations()); - + initializeLocation(initLocation); } return locations; } + public void initializeLocation(Location location) { + // TODO Auto-generated method stub + Hibernate.initialize(location); + //Hibernate.initialize(location.getRoundLocations()); + Game game = location.getGame(); + Hibernate.initialize(game); + Hibernate.initialize(game); + Hibernate.initialize(game.getCurrentBlock()); + Hibernate.initialize(game.getCurrentRound()); + Hibernate.initialize(game.getGameRounds()); + Hibernate.initialize(game.getLocations()); + } + public Location getLocation(String locationName) { // TODO Auto-generated method stub @@ -94,5 +106,4 @@ getLogger().info("Saved Location " + bay3.getLocationName() +" with id "+ bay3.getId()); } - } Modified: mentalmodels/trunk/src/main/java/edu/asu/commons/mme/service/RoundService.java =================================================================== --- mentalmodels/trunk/src/main/java/edu/asu/commons/mme/service/RoundService.java 2009-09-16 21:14:48 UTC (rev 280) +++ mentalmodels/trunk/src/main/java/edu/asu/commons/mme/service/RoundService.java 2009-09-24 19:16:41 UTC (rev 281) @@ -1,14 +1,17 @@ package edu.asu.commons.mme.service; import java.util.ArrayList; +import java.util.HashMap; import java.util.Iterator; import java.util.List; +import java.util.Map; import org.hibernate.Hibernate; import org.springframework.transaction.annotation.Transactional; import edu.asu.commons.mme.dao.HibernateBlockDao; import edu.asu.commons.mme.dao.HibernateGameDao; +import edu.asu.commons.mme.dao.HibernateGameRoundDao; import edu.asu.commons.mme.dao.HibernateModuleDao; import edu.asu.commons.mme.dao.HibernateModuleRoundConfigDao; import edu.asu.commons.mme.dao.HibernateRoundConfigDao; @@ -17,12 +20,15 @@ import edu.asu.commons.mme.entity.CategoricalOption; import edu.asu.commons.mme.entity.CategoricalQuestion; import edu.asu.commons.mme.entity.Game; +import edu.asu.commons.mme.entity.GameRound; import edu.asu.commons.mme.entity.InformationWindow; +import edu.asu.commons.mme.entity.Location; import edu.asu.commons.mme.entity.Module; import edu.asu.commons.mme.entity.ModuleRoundConfig; import edu.asu.commons.mme.entity.Question; import edu.asu.commons.mme.entity.QuestionGroup; import edu.asu.commons.mme.entity.Round; +import edu.asu.commons.mme.entity.RoundLocation; @Transactional public class RoundService extends Service.Base<Round, HibernateRoundConfigDao> { @@ -31,85 +37,109 @@ private HibernateBlockDao blockDao; private HibernateGameDao gameDao; private HibernateModuleRoundConfigDao moduleRoundDao; + private HibernateGameRoundDao gameRoundDao; private LocationService locationService; - - private Module currentModule; + + //private Module currentModule; //private boolean startGame = true; - private Round currentRound; - private Block currentBlock; - private List<Game> currentGames; + //private Round currentRound; + //private Block currentBlock; private int blockSeqNo; - private ModuleRoundConfig currentModuleRoundConfig; - - private boolean gameFinished; public RoundService() { - setCurrentGame(null); + /*setCurrentGame(null); setCurrentBlock(null); setCurrentModule(null); setCurrentModuleRoundConfig(null); - setCurrentRound(null); + setCurrentRound(null);*/ setBlockSeqNo(0); setGameFinished(false); } public Game createGame(Game game) { + getLogger().debug("game came from flex is : " + game.getDescription()); + Game newGame = new Game(); //currentGame = game; - newGame.setDescription(game.getDescription()); - newGame.setMaxDays(game.getMaxDays()); - newGame.setMaxFishHarvest(game.getMaxFishHarvest()); - newGame.setMoney(game.getMoney()); - newGame.setNumberOfRounds(game.getNumberOfRounds()); - newGame.setNumberOfLocations(game.getNumberOfLocations()); - newGame.setTimestamp(game.getTimestamp()); - newGame.setTitle(game.getTitle()); - newGame.setImageLocation("null"); - -// currentGame.setro// - getGameDao().save(newGame); - String str = newGame.getDescription()+newGame.getId(); - - if(getGameDao().findAllByProperty("description", str).size() != 0) + try { - getLogger().debug("in if loop "); - newGame = null; - setCurrentGame(newGame); - } - else + newGame.setDescription(game.getDescription()); + newGame.setMaxDays(game.getMaxDays()); + newGame.setMaxFishHarvest(game.getMaxFishHarvest()); + newGame.setMoney(game.getMoney()); + newGame.setNumberOfRounds(game.getNumberOfRounds()); + newGame.setNumberOfLocations(game.getNumberOfLocations()); + newGame.setTimestamp(game.getTimestamp()); + newGame.setTitle(game.getTitle()); + newGame.setImageLocation("null"); + getGameDao().save(newGame); + String str = newGame.getDescription()+newGame.getId(); + + if(getGameDao().findAllByProperty("description", str).size() != 0) + { + //getLogger().debug("in if loop "); + newGame = null; + } + else + { + newGame.setDescription(str); + getGameDao().save(newGame); + getLogger().info("Created the game: " + newGame.getId()); + initializeGameRounds(newGame); + initializeLocations(newGame); + initializeGame(newGame); + } + }catch(Exception e) { - newGame.setDescription(str); - getGameDao().save(newGame); - setCurrentGame(newGame); - - //initializeGame(newGame); - getLogger().info("Created the game: " + newGame.getId()); - initializeLocations(newGame); + e.printStackTrace(); } getLogger().debug("current game from flex is: " + newGame.getDescription()); return newGame; } - + + private void initializeGameRounds(Game newGame) { + // TODO Auto-generated method stub + List<GameRound> gameRounds = new ArrayList<GameRound>(); + + for(Round round:getDao().findAll()) + { + GameRound gameRound = new GameRound(); + gameRound.setGame(newGame); + gameRound.setRound(round); + gameRoundDao.save(gameRound); + gameRounds.add(gameRound); + } + newGame.setGameRounds(gameRounds); + getGameDao().save(newGame); + } + private void initializeLocations(Game newGame) { locationService.setAllLocations(newGame); + newGame.setLocations(locationService.getAllLocations()); + getGameDao().save(newGame); } - private void initializeGame(Game game) { + public void initializeGame(Game game) { // TODO Auto-generated method stub Hibernate.initialize(game); Hibernate.initialize(game.getCurrentBlock()); Hibernate.initialize(game.getCurrentRound()); - /*Iterator<Round> rounds = game.getRounds().iterator(); - while(rounds.hasNext()) - { - initializeRound(rounds.next()); - }*/ + // Hibernate.initialize(game.getLocations()); + + for(GameRound gameRound :game.getGameRounds()){ + Hibernate.initialize(gameRound); + //Hibernate.initialize(gameRound.getGame()); + initializeRound(gameRound.getRound()); + } + for(Location location :game.getLocations()){ + locationService.initializeLocation(location); + } } public Module getNextModule(int sequenceNo) @@ -130,82 +160,107 @@ *4) Find out the current block number *5) Return the next block */ - - public Block getBlock() + + public Game getBlock(Game game) { - //getLogger().debug("in getBlock "); - //setCurrentModuleRoundConfig(currentModuleRoundConfig); - //find out the current module number - if(currentModuleRoundConfig == null){ - currentModuleRoundConfig = new ModuleRoundConfig(); - if(currentRound == null) - { - setNextRound(); - setModuleForCurrentRound(0); - if(currentBlock == null) - { - setCurrentBlock(new Block()); - currentBlock = getBlock(1); - } - } + ModuleRoundConfig currentModuleRoundConfig; + Block currentBlock = null; + Round currentRound = null; + + //check if it is a start of the game + if(game.getCurrentRound() == null && game.getCurrentBlock() == null ) + { + getLogger().debug("Current Round is null... "); + getLogger().debug("Current block is null... "); + + getLogger().debug("Starting of the game...." + game.getDescription()); + currentRound = getNextRound(null); + currentModuleRoundConfig = getModuleRoundConfig(0, currentRound); + Module currentModule = getModuleForCurrentRound(currentModuleRoundConfig); + currentBlock = getBlock(currentModule,1); } else { - if(isCurrentModuleFinished()) + getLogger().debug("Current Round is : " + game.getCurrentRound().getId()); + getLogger().debug("Current block is : " + game.getCurrentBlock().getId()); + currentBlock = game.getCurrentBlock(); + currentRound = game.getCurrentRound(); + if(isModuleFinished(game.getCurrentBlock())) { getLogger().debug("current module is finished"); - if(isCurrentRoundFinished()) + //currentModuleRoundConfig = game.getCurrentRound(). + if(isCurrentRoundFinished(game)) { getLogger().debug("current round is finished"); - if(isGameFinished()) + if(isGameFinished(game)) { + getLogger().debug("Game is finished..." + game.getId()); return null; } else { //set the next round - setNextRound(); - setModuleForCurrentRound(0); - if(currentBlock == null) - { - setCurrentBlock(new Block()); - currentBlock = getBlock(1); - } + currentRound = getNextRound(game.getCurrentRound()); + currentModuleRoundConfig = getModuleRoundConfig(0, currentRound); + Module currentModule = getModuleForCurrentRound(currentModuleRoundConfig); + currentBlock = getBlock(currentModule,1); } } else { getLogger().debug("current round is not finished"); - setModuleForCurrentRound(getCurrentModuleRoundConfig().getSequenceNo()); - if(currentBlock == null) - { - setCurrentBlock(new Block()); - currentBlock = getBlock(1); - } + //currentRound = getNextRound(game.getCurrentRound()); + + currentModuleRoundConfig = getModuleRoundConfig(getPreviousModuleConfigSequenceNo(game), currentRound); + Module currentModule = getModuleForCurrentRound(currentModuleRoundConfig); + currentBlock = getBlock(currentModule,1); + } } else { //get the next block in the module - getLogger().debug("currentmodule is " + currentModule.getId()); - setNextBlock(); - getLogger().debug(currentBlock.getDescription()); + //getLogger().debug("currentmodule is " + game.getCurrentBlock().getModule().getId()); + currentBlock = getNextBlock(game.getCurrentBlock()); + getLogger().debug("the next block for the game is: " + game.getCurrentBlock().getDescription()); } } - saveGameState(currentBlock); - getLogger().debug("question group sizes is : " + currentBlock.getQuestionGroups().size()); - initializeCurrentBlock(currentBlock); - getLogger().debug("Module is " + currentModule.getId() + "Block sent to the server is: " + getCurrentBlock().getDescription()); - return getCurrentBlock(); + Game newGame = saveGameState(currentBlock,currentRound,game); + getLogger().debug("question group sizes is : " + newGame.getCurrentBlock().getQuestionGroups().size()); + //initializeCurrentBlock(newGame.getCurrentBlock()); + initializeGame(newGame); + getLogger().debug("Module is " + newGame.getCurrentBlock().getModule().getId() + "Block sent to the server is: " + currentBlock.getDescription()); + return newGame; } - private void setModuleForCurrentRound(int prevSeqNo) { + private int getPreviousModuleConfigSequenceNo(Game game) { // TODO Auto-generated method stub + List<ModuleRoundConfig> moduleRoundConfigs = new ArrayList<ModuleRoundConfig> (); + ModuleRoundConfig currentModuleRoundConfig = null; + + Map<String, Object> variables = new HashMap<String, Object>(); + variables.put("module",game.getCurrentBlock().getModule()); + variables.put("round", game.getCurrentRound()); + moduleRoundConfigs = moduleRoundDao.findByEqCriteria(variables); + if(moduleRoundConfigs.size() == 1) + { + currentModuleRoundConfig = moduleRoundConfigs.get(0); + moduleRoundConfigs.clear(); + } + getLogger().debug("the prev Sequence no is : " + currentModuleRoundConfig.getSequenceNo()); + if(currentModuleRoundConfig != null) + return currentModuleRoundConfig.getSequenceNo(); + return 0; + } + + private ModuleRoundConfig getModuleRoundConfig(int prevSeqNo, Round currentRound) { + // TODO Auto-generated method stub //int prevSeqNo = 0; List<ModuleRoundConfig> moduleRoundConfigs = new ArrayList<ModuleRoundConfig> (); + ModuleRoundConfig currentModuleRoundConfig = null; try { moduleRoundConfigs = moduleRoundDao.findAllByProperty("round",currentRound); @@ -214,94 +269,59 @@ if(moduleRoundConfigs.get(i).getSequenceNo() > prevSeqNo) { currentModuleRoundConfig = moduleRoundConfigs.get(i); - setCurrentModuleRoundConfig(currentModuleRoundConfig); - setCurrentModule(moduleRoundConfigs.get(i).getModule()); - getLogger().debug("current module is: " + getCurrentModule().getDescription()); - setCurrentBlock(null); break; + + /*setCurrentModule(moduleRoundConfigs.get(i).getModule()); + getLogger().debug("current module is: " + getCurrentModule().getDescription()); + currentBlock = null; + break;*/ } } }catch(Exception e) { e.printStackTrace(); } + return currentModuleRoundConfig; } + private Module getModuleForCurrentRound(ModuleRoundConfig moduleRoundConfig) { + // TODO Auto-generated method stub + //getLogger().debug("current module is: " + getCurrentModule().getDescription()); + return moduleRoundConfig.getModule(); + } - private void setNextRound() { + + private Round getNextRound(Round currentRound) { // TODO Auto-generated method stub + Round returnRound = null; if(currentRound == null) { - currentRound = new Round(); - currentRound = getDao().findByProperty("roundNo", 1); - setCurrentRound(currentRound); - initializeRound(currentRound); + returnRound = getDao().findByProperty("roundNo", 1); + //returnRound = currentRound; + //initializeRound(returnRound); } else { + getLogger().debug("current round no is: " + currentRound.getRoundNo()); List<Round> rounds = getDao().findAll(); for(int i = 0; i < rounds.size(); i++) { + getLogger().debug("in for loop round no is: " + rounds.get(i).getRoundNo()); if(currentRound.getRoundNo() < rounds.get(i).getRoundNo()) { - setCurrentRound(rounds.get(i)); + returnRound = rounds.get(i); break; + //getLogger().debug("currentround object is "+ rounds.get(i).getId()); } } } - getLogger().debug("currentround object is "+ currentRound.getId()); + getLogger().debug("currentround object is "+ returnRound.getId()); + return returnRound; } - - private boolean isCurrentRoundFinished() { - // TODO Auto-generated method stub - List<ModuleRoundConfig> moduleRoundConfigs = new ArrayList<ModuleRoundConfig> (); - moduleRoundConfigs = moduleRoundDao.findAllByProperty("round",currentRound); - - if(currentModuleRoundConfig == null) - { - getLogger().debug("currentModuleRoundConfig is null"); - return true; - } - else - { - if(moduleRoundConfigs.size() == 1) - { - return true; - - } - else - { - getLogger().debug("check condition is "+ moduleRoundConfigs.get(moduleRoundConfigs.size() - 1).getSequenceNo()); - int seqNo = moduleRoundConfigs.get(moduleRoundConfigs.size() - 1).getSequenceNo(); - if((currentModuleRoundConfig.getSequenceNo()) == seqNo) - { - getLogger().debug("flag return is true"); - return true; - - } - else - { - for(int i = 0; i < moduleRoundConfigs.size(); i++) - { - // getLogger().debug("moduleroundconfig seq no is" + moduleRoundConfigs.get(i).getSequenceNo()); - getLogger().debug("Current seq no is" + currentModuleRoundConfig.getSequenceNo() +"and the moduleroundconfig is "+ moduleRoundConfigs.get(i).getSequenceNo()); - - if(currentModuleRoundConfig.getSequenceNo() < moduleRoundConfigs.get(i).getSequenceNo()) - { - return false; - } - } - } - } - } - - return false; - } - public HibernateModuleDao getModuleDao() { return moduleDao; } @@ -339,25 +359,25 @@ Module module = block.getModule(); Hibernate.initialize(module); - initializeModule(currentModule); + initializeModule(module); } - private void setNextBlock() { + private Block getNextBlock(Block currentBlock) { // TODO Auto-generated method stub List<Block> blocks = new ArrayList<Block>(); - blocks = getCurrentModule().getBlocks(); - + blocks = currentBlock.getModule().getBlocks(); + Block returnBlock = null; for(int i = 0; i < blocks.size(); i++) { if(currentBlock.getSequenceNo() < blocks.get(i).getSequenceNo()) { - setCurrentBlock(blocks.get(i)); + returnBlock = blocks.get(i); break; } - } + return returnBlock; } @@ -373,7 +393,7 @@ return module; } - public Block getBlock(int seqNo) + public Block getBlock(Module currentModule, int seqNo) { //Module module = new Module(); // module = currentModule; @@ -390,7 +410,7 @@ return block; } - private void setRound(int roundNo) { + /* private void setRound(int roundNo) { // TODO Auto-generated method stub currentRound = new Round(); @@ -399,9 +419,9 @@ getLogger().debug("currentround object is "+ currentRound.getId()); setCurrentRound(currentRound); - } + }*/ - private int getCurrentRoundNo() { + /*private int getCurrentRoundNo() { // TODO Auto-generated method stub //FIXME: Game id 1 is hard coded but needs to make it dynamic //Game game = gameDao.find(1L); @@ -410,51 +430,134 @@ else return getCurrentGame().getCurrentRound().getRoundNo(); + }*/ + public boolean isGameFinished(Game game) { + List<GameRound> gameRounds = game.getGameRounds(); + boolean flag = false; + + if(game.getCurrentRound().getRoundNo() == gameRounds.get(gameRounds.size() - 1).getRound().getRoundNo()) + { + flag = true; + } + else + { + for(GameRound gameRound:gameRounds) + { + if(game.getCurrentRound().getRoundNo() < game.getCurrentRound().getRoundNo()) + { + flag = false; + } + } + + } + return flag; } - private boolean isCurrentModuleFinished() { + private boolean isCurrentRoundFinished(Game game) { + boolean flag = false; + List<ModuleRoundConfig> moduleRoundConfigs = new ArrayList<ModuleRoundConfig> (); + Round currentRound = game.getCurrentRound(); + Module currentModule = game.getCurrentBlock().getModule(); + + ModuleRoundConfig currentModuleRoundConfig = new ModuleRoundConfig(); + + Map<String, Object> variables = new HashMap<String, Object>(); + variables.put("module",currentModule); + variables.put("round", currentRound); + moduleRoundConfigs = moduleRoundDao.findByEqCriteria(variables); + if(moduleRoundConfigs.size() == 1) + { + currentModuleRoundConfig = moduleRoundConfigs.get(0); + moduleRoundConfigs.clear(); + } + moduleRoundConfigs = moduleRoundDao.findAllByProperty("round",currentRound); + getLogger().debug("the module round configs size is: " + moduleRoundConfigs.size()); + //check if it contains only one module, if yes then round is over + if(moduleRoundConfigs.size() == 1) + { + flag = true; + } + else + { + getLogger().debug("module round config is "+ moduleRoundConfigs.get(moduleRoundConfigs.size() - 1).getSequenceNo()); + int seqNo = moduleRoundConfigs.get(moduleRoundConfigs.size() - 1).getSequenceNo(); + if((currentModuleRoundConfig.getSequenceNo()) == seqNo) + { + flag = true; + } + else + { + for(int i = 0; i < moduleRoundConfigs.size(); i++) + { + // getLogger().debug("moduleroundconfig seq no is" + moduleRoundConfigs.get(i).getSequenceNo()); + getLogger().debug("Current seq no is" + currentModuleRoundConfig.getSequenceNo() +"and the moduleroundconfig is "+ moduleRoundConfigs.get(i).getSequenceNo()); + + if(currentModuleRoundConfig.getSequenceNo() == moduleRoundConfigs.get(moduleRoundConfigs.size() - 1).getSequenceNo()) + flag = true; + if(currentModuleRoundConfig.getSequenceNo() < moduleRoundConfigs.get(i).getSequenceNo()) + { + flag = false; + } + } + } + } + return flag; + } + + + private boolean isModuleFinished(Block currentBlock) { // TODO Auto-generated method stub + boolean flag = false; + List<Block> blocks = new ArrayList<Block>(); getLogger().debug("in iscurrentmodulefinished"); - if(currentModule == null) + if(currentBlock == null) { - return true; + flag = true; } else { - blocks = getCurrentModule().getBlocks(); + Module currentModule = currentBlock.getModule(); + //getBlocks() return blocks in order of sequence number + blocks = currentModule.getBlocks(); //select max(b.sequence_no) from block b where b.module_id=2; - getLogger().debug("no of blocks " + blocks.size() +"for module id: " + getCurrentModule().getId()); - + getLogger().debug("no of blocks " + blocks.size() +"for module id: " + currentModule.getId()); + //if module contains only one block if(blocks.size() == 1) - return true; + flag = true; else { for(int i = 0; i < blocks.size(); i++) { - if(currentBlock.getSequenceNo() == blocks.get(blocks.size() - 1).getSequenceNo()) - return true; + flag = true; if(currentBlock.getSequenceNo() < blocks.get(i).getSequenceNo()) { - return false; + flag = false; } } } } - return false; + return flag; } + private Game saveGameState(Block currentBlock, Round currentRound, Game game) { - private void saveGameState(Block currentBlock) { - //FIXME: Game id 1 is hard coded but needs to make it dynamic - //Game game = gameDao.find(1L); - - currentGame.setCurrentBlock(currentBlock); - currentGame.setCurrentRound(currentRound); - gameDao.save(currentGame); + getLogger().info(" Game id to SAVE is: " + game.getId()); + Game newGame = null; + newGame = gameDao.find(game.getId()); + getLogger().info("The current block is: " + currentBlock.getId() + " while the current Round is: " + currentRound.getId()); + if(newGame.getCurrentBlock() == null && newGame.getCurrentRound()==null) + getLogger().info("BEFORE GAME SAVE: The current block NULL while the current Round is NULL"); + else + getLogger().info("BEFORE GAME SAVE: The current block is: " + newGame.getCurrentBlock().getId() + " while the current Round is: " + newGame.getCurrentRound().getId()); + newGame.setCurrentBlock(currentBlock); + newGame.setCurrentRound(currentRound); + gameDao.save(newGame); + getLogger().info("The game state is saved. The current block : " + newGame.getCurrentBlock().getId() + "while the current Round is: " + newGame.getCurrentRound().getId()); + return newGame; } public Integer getTimerforBlock(Block block) @@ -502,49 +605,43 @@ } } - public Block getCurrentBlock() { + /*public Block getCurrentBlock() { //FIXEME: game id 1 is hard coded, it should be dynamic -// Game game = gameDao.find(1L); + // Game game = gameDao.find(1L); Block block = new Block(); block = currentGame.getCurrentBlock(); // Hibernate.initialize(block); return block; - } + }*/ - public void setCurrentModule(Module currentModule) { - this.currentModule = currentModule; - } - public Module getCurrentModule() { - return currentModule; - } - - public void setCurrentRound(Round currentRound) { - this.currentRound = currentRound; - } - - public Round getCurrentRound() { + /*public Round getCurrentRound() { getLogger().debug("in get current round funciton"); - /*Round round = currentGame.getCurrentRound(); + Round round = currentGame.getCurrentRound(); //Round round = getDao().find(getCurrentRound().getId()); - - initializeRound(round);*/ + + initializeRound(round); getLogger().debug("round no is " + currentRound.getRoundNo() + " " + currentRound.getId()); return currentRound; - } + }*/ private void initializeRound(Round round) { // TODO Auto-generated method stub Hibernate.initialize(round); - - Hibernate.initialize(round.getRoundLocations()); + //Hibernate.initialize(round.getRoundLocations()); + /*for (RoundLocation roundLocation: round.getRoundLocations()) { Hibernate.initialize(roundLocation); //hibernateroundLocation.getLocation(); }*/ - + for (GameRound gameRound: round.getGameRounds()) { + Hibernate.initialize(gameRound); + //hibernateroundLocation.getLocation(); + } + + //Hibernate.initialize(currentRound.getLocations()); } @@ -575,46 +672,12 @@ public HibernateBlockDao getBlockDao() { return blockDao; } - - public void setModuleRoundConfig(ModuleRoundConfig moduleRoundConfig) { - this.currentModuleRoundConfig = moduleRoundConfig; - } - - public ModuleRoundConfig getModuleRoundConfig() { - return currentModuleRoundConfig; - } - public void setGameFinished(boolean gameFinished) { this.gameFinished = gameFinished; } - public boolean isGameFinished() { - if(getCurrentGame().getCurrentRound().getRoundNo() < currentRound.getRoundNo()) - { - gameFinished = true; - } - return false; - } - public void setCurrentBlock(Block currentBlock) { - this.currentBlock = currentBlock; - } - public ModuleRoundConfig getCurrentModuleRoundConfig() { - return currentModuleRoundConfig; - } - - public void setCurrentModuleRoundConfig( - ModuleRoundConfig currentModuleRoundConfig) { - this.currentModuleRoundConfig = currentModuleRoundConfig; - } - public void setCurrentGame(Game game) { - this.currentGame = game; - } - public Game getCurrentGame() { - return currentGame; - } - public void setLocationService(LocationService locationService) { this.locationService = locationService; } @@ -623,11 +686,16 @@ return locationService; } - public void setCurrentGames(List<Game> currentGames) { - this.currentGames = currentGames; + public String getDescription(Game game) { + // TODO Auto-generated method stub + return game.getDescription(); } - public List<Game> getCurrentGames() { - return currentGames; + public void setGameRoundDao(HibernateGameRoundDao gameRoundDao) { + this.gameRoundDao = gameRoundDao; } + + public HibernateGameRoundDao getGameRoundDao() { + return gameRoundDao; + } } Modified: mentalmodels/trunk/src/main/java/edu/asu/commons/mme/service/StartGame.java =================================================================== --- mentalmodels/trunk/src/main/java/edu/asu/commons/mme/service/StartGame.java 2009-09-16 21:14:48 UTC (rev 280) +++ mentalmodels/trunk/src/main/java/edu/asu/commons/mme/service/StartGame.java 2009-09-24 19:16:41 UTC (rev 281) @@ -11,7 +11,7 @@ import flex.messaging.util.UUIDUtils; -public class StartGame extends Thread { +public class StartGame implements Runnable { private static Logger logger = Logger.getLogger(StartGame.class); private boolean running; @@ -20,19 +20,24 @@ private DayByDayDecisionsService dayBydayDecisionService; private StudentService studentService; private ModuleRoundConfig currentModuleRoundConfig; - + private Game game; + public StartGame() { - System.out.println("module service object is "); + //System.out.println("module service object is "); /*moduleService.test(); moduleService.setStartModule(true);*/ + /*setRoundService(new RoundService()); + setLocationService(new LocationService()); + */ setRunning(true); + } - + public Student createStudent(Student student) { -// Game game = new Game(); - Game game = roundService.getCurrentGame(); + // Game game = new Game(); + Game game = student.getGame(); Student studentReturn = null; //System.out.println("game description: " + game.getDescription() + " student game code is: " + student.getGameCode()); if(game.getDescription().equals(student.getGameCode())) @@ -44,13 +49,21 @@ } return studentReturn; } - + public Game createGame(Game game) { - System.out.println("game came from flex is: " + game.getDescription()); - return roundService.createGame(game); + //System.out.println("game came from flex is: " + game.getDescription()); + game = roundService.createGame(game); + System.out.println("game object return from round service is: " + game); + if(game != null) + { + setGame(game); + } + //roundService.initializeGame(game); + return game; + } - + public List<Student> assignGroups() { return studentService.assignGroups(); @@ -67,31 +80,43 @@ */ public void run() { - Block block = new Block(); + Game newGameState = null; + Block block = null; //roundService.test(); - MessageBroker msgBroker = MessageBroker.getMessageBroker("_messageBroker"); String clientID = UUIDUtils.createUUID(); + newGameState = game; int i=0; - while (i<5) { + while (i<17) { i++; - String msgDestination = roundService.getCurrentGame().getDescription(); + String msgDestination = roundService.getDescription(game); //Push the first block to the clients AsyncMessage msg = new AsyncMessage(); - msg.setDestination("chat"); - //msg.setHeader("DSSubtopic", "hello3"); + + msg.setDestination("mme"); + msg.setHeader("DSSubtopic", msgDestination); msg.setClientId(clientID); msg.setMessageId(UUIDUtils.createUUID()); msg.setTimestamp(System.currentTimeMillis()); - block = roundService.getBlock(); - msg.setBody(block); + + newGameState = roundService.getBlock(game); + setGame(newGameState); + if(newGameState == null) + { + msg.setBody(null); + } + else + { + block = newGameState.getCurrentBlock(); + msg.setBody(block); + } msgBroker.routeMessageToService(msg, null); logger.debug("message is sent to the client: " + msg); - - /* if(block.getDescription().equalsIgnoreCase("Day-by-day decisions game")) + + /* if(block.getDescription().equalsIgnoreCase("Day-by-day decisions game")) { //start day by day decision //getDayBydayDecisionService(). @@ -107,22 +132,18 @@ //start the timer for the block sent try { //for testing purpose 5000 is given as an argument - Thread.sleep(20000); + Thread.sleep(10000); if(block == null) { running = false; } } catch (InterruptedException e) { } - - } - } - + private boolean isGameOver() { // TODO Auto-generated method stub - return false; } @@ -166,5 +187,12 @@ this.studentService = studentService; } + public void setGame(Game game) { + this.game = game; + } + + public Game getGame() { + return game; + } } Modified: mentalmodels/trunk/src/main/java/edu/asu/commons/mme/service/StartupService.java =================================================================== --- mentalmodels/trunk/src/main/java/edu/asu/commons/mme/service/StartupService.java 2009-09-16 21:14:48 UTC (rev 280) +++ mentalmodels/trunk/src/main/java/edu/asu/commons/mme/service/StartupService.java 2009-09-24 19:16:41 UTC (rev 281) @@ -21,6 +21,7 @@ //private QuestionCreatorService questionCreatorService; private StartGame startGame; private ApplicationContext ctx; + private ArrayList<StartGame> currentGames; /*public void setQuestionCreatorService(QuestionCreatorService questionCreatorService) { this.questionCreatorService = questionCreatorService; @@ -33,11 +34,27 @@ public Game createGame(Game game) { - if(getStartGame() == null) + Game newGame = null; + try { setStartGame(); + newGame = getStartGame().createGame(game); + if(newGame != null) + { + System.out.println("new Game is: " + newGame); + if(currentGames == null) + { + currentGames = new ArrayList<StartGame>(); + } + System.out.println("startGame is: " + startGame); + System.out.println("current games are: " + currentGames); + currentGames.add(startGame); + } + }catch(Exception e ) + { + e.printStackTrace(); } - return startGame.createGame(game); + return newGame; } public void assignGroups() @@ -57,19 +74,34 @@ System.out.println("Students size is: " + students.size()); msgBroker.routeMessageToService(msg, null); - } - public void startGame() + public void startGame(Game game) { //push assign groups to all the students //assignGroups(); //start the game - this.startGame.run(); + System.out.println("Game came from client is to start: " + game.getId() + "size of currentGame is " + currentGames.size()); + try + { + for(int i = 0; i < currentGames.size(); i++) + { + System.out.println("game in for loop is: " + currentGames.get(i).getGame().getId()); + + if(currentGames.get(i).getGame().getId().equals(game.getId())) + { + System.out.println("Game is found"); + currentGames.get(i).run(); + } + } + }catch(Exception e) + { + e.printStackTrace(); + } } - public void stop() { + public void stop(Game game) { startGame.setRunning(false); startGame = null; } @@ -83,10 +115,8 @@ public void setStartGame() { try{ - if (startGame == null) { - this.startGame = (StartGame)ctx.getBean("startGame"); - - } + this.startGame = (StartGame)ctx.getBean("startGame"); + System.out.println("startGame is: " + startGame); }catch(Exception e) { System.out.println(e.getStackTrace()); @@ -94,7 +124,6 @@ } public StartGame getStartGame() { - return startGame; } } Modified: mentalmodels/trunk/src/main/webapp/WEB-INF/applicationContext.xml =================================================================== --- mentalmodels/trunk/src/main/webapp/WEB-INF/applicationContext.xml 2009-09-16 21:14:48 UTC (rev 280) +++ mentalmodels/trunk/src/main/webapp/WEB-INF/applicationContext.xml 2009-09-24 19:16:41 UTC (rev 281) @@ -100,6 +100,10 @@ <bean id='moduleRoundDao' class='edu.asu.commons.mme.dao.HibernateModuleRoundConfigDao'> <property name='sessionFactory' ref='sessionFactory'/> </bean> + + <bean id='gameRoundDao' class='edu.asu.commons.mme.dao.HibernateGameRoundDao'> + <property name='sessionFactory' ref='sessionFactory'/> + </bean> <!-- spring managed service layer --> @@ -114,7 +118,7 @@ <property name='gameDao' ref='gameDao' /> <property name='moduleRoundDao' ref='moduleRoundDao' /> <property name='locationService' ref='locationService'/> - <!-- <property name='blockDao' ref='blockDao'/> --> + <property name='gameRoundDao' ref='gameRoundDao'/> </bean> @@ -161,7 +165,7 @@ <property name="startModule" value="Testing String."/> </bean> --> - <bean id="startGame" class="edu.asu.commons.mme.service.StartGame"> + <bean id="startGame" class="edu.asu.commons.mme.service.StartGame" scope = "prototype"> <property name='roundService' ref='roundService'/> <property name='locationService' ref='locationService'/> <property name='studentService' ref='studentService'/> @@ -184,7 +188,7 @@ <!-- Expose services for Flex/BlazeDS messaging --> <flex:message-destination id="chat" /> - <flex:message-destination id="mme" /> + <flex:message-destination id="mme" allow-subtopics="true" subtopic-separator="." /> <!-- Flex related information ended--> <bean id="mmeDataSource" class="org.apache.commons.dbcp.BasicDataSource" destroy-method="close"> Modified: mentalmodels/trunk/src/main/webapp/WEB-INF/hibernate.cfg.xml =================================================================== --- mentalmodels/trunk/src/main/webapp/WEB-INF/hibernate.cfg.xml 2009-09-16 21:14:48 UTC (rev 280) +++ mentalmodels/trunk/src/main/webapp/WEB-INF/hibernate.cfg.xml 2009-09-24 19:16:41 UTC (rev 281) @@ -10,12 +10,15 @@ <mapping class='edu.asu.commons.mme.entity.Game'/> <mapping class='edu.asu.commons.mme.entity.Round'/> <mapping class='edu.asu.commons.mme.entity.Location'/> + <!-- <mapping class='edu.asu.commons.mme.entity.RoundLocation'/> + --> + <mapping class='edu.asu.commons.mme.entity.Communication'/> <mapping class='edu.asu.commons.mme.entity.Group'/> <mapping class='edu.asu.commons.mme.entity.Student'/> + <mapping class='edu.asu.commons.mme.entity.GameRound'/> - <mapping class='edu.asu.commons.mme.entity.StudentRoundConfig'/> <mapping class='edu.asu.commons.mme.entity.StudentStrategy'/> This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: Kalin J. <kj...@as...> - 2009-09-20 17:11:22
|
I will be checking out for now at 10:00am (2.25hr) I have added new parts to the documentation, and rearranged the URL's section On Sun, Sep 20, 2009 at 7:57 AM, Kalin Jonas <kj...@as...> wrote: > Early this morning I am working from home starting 7:45am > looking over the code and finding things that belong in the wiki > Will add as necessary > |
From: Kalin J. <kj...@as...> - 2009-09-20 14:57:40
|
Early this morning I am working from home starting 7:45am looking over the code and finding things that belong in the wiki Will add as necessary |
From: Kalin J. <kj...@as...> - 2009-09-19 21:35:15
|
I am checking out for now at 14:30pm (2.5hrs) I have added information about the informationwindow concept, and will add more about how they work later tonight or tomorrow morning On Sat, Sep 19, 2009 at 12:03 PM, Kalin Jonas <kj...@as...> wrote: > I work from home today at 12:00pm > I'm still working on the documentation, and will be adding more information > pertaining to our project in particular > |
From: Kalin J. <kj...@as...> - 2009-09-19 19:24:20
|
I work from home today at 12:00pm I'm still working on the documentation, and will be adding more information pertaining to our project in particular |
From: Kalin J. <kj...@as...> - 2009-09-18 21:36:10
|
I will be checking out for the day at 14:30 pm (3.5hr today) I have worked on Confluence, and wrote a couple sections on designing code and visuals. Just a rough copy, feel free to alter/add to it as need be On Fri, Sep 18, 2009 at 1:13 PM, Kalin Jonas <kj...@as...> wrote: > I come back from lunch at 13:00 pm > I will be working on the wiki for now > > On 9/18/09, Kalin Jonas <kj...@as...> wrote: > > I check out for lunch today at 12:00 > > > > On 9/18/09, Kalin Jonas <kj...@as...> wrote: > >> I come in today at 10:00 am > >> I will be repairing my code so it works with the server again > >> I will find out what errors it was making and try to fix any client-side > >> issues. > >> > > > |
From: Kalin J. <kj...@as...> - 2009-09-18 20:13:35
|
I come back from lunch at 13:00 pm I will be working on the wiki for now On 9/18/09, Kalin Jonas <kj...@as...> wrote: > I check out for lunch today at 12:00 > > On 9/18/09, Kalin Jonas <kj...@as...> wrote: >> I come in today at 10:00 am >> I will be repairing my code so it works with the server again >> I will find out what errors it was making and try to fix any client-side >> issues. >> > |
From: Kalin J. <kj...@as...> - 2009-09-18 19:30:04
|
I check out for lunch today at 12:00 On 9/18/09, Kalin Jonas <kj...@as...> wrote: > I come in today at 10:00 am > I will be repairing my code so it works with the server again > I will find out what errors it was making and try to fix any client-side > issues. > |
From: Kalin J. <kj...@as...> - 2009-09-18 17:40:06
|
I come in today at 10:00 am I will be repairing my code so it works with the server again I will find out what errors it was making and try to fix any client-side issues. |
From: Kalin J. <kj...@as...> - 2009-09-16 21:56:39
|
I have to run at 14:45 (1.25hr) On Wed, Sep 16, 2009 at 1:52 PM, Kalin Jonas <kj...@as...> wrote: > I came in today at 13:30pm > I have spoken to Seema about required changes to the server, and she tells > me she is working on getting multiple games running at the same time. > I will be getting the exact errors copied down, and try to figure out what > exactly needs to be altered to repair the client-server communications in > that respect > |