[virtualcommons-svn] SF.net SVN: virtualcommons:[278] mentalmodels/trunk/src/main
Status: Beta
Brought to you by:
alllee
From: <see...@us...> - 2009-09-11 23:22:25
|
Revision: 278 http://virtualcommons.svn.sourceforge.net/virtualcommons/?rev=278&view=rev Author: seematalele Date: 2009-09-11 22:14:03 +0000 (Fri, 11 Sep 2009) Log Message: ----------- 1) Written code for fish population calculation needs testing 2) Created the array list for storing the current games but has lot of errors Modified Paths: -------------- mentalmodels/trunk/src/main/db/init-mme.sql mentalmodels/trunk/src/main/java/edu/asu/commons/mme/entity/DayByDayDecisions.java mentalmodels/trunk/src/main/java/edu/asu/commons/mme/entity/Location.java mentalmodels/trunk/src/main/java/edu/asu/commons/mme/service/AnsweringService.java mentalmodels/trunk/src/main/java/edu/asu/commons/mme/service/DayByDayDecisionsService.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/StartupService.java mentalmodels/trunk/src/main/webapp/WEB-INF/applicationContext.xml Modified: mentalmodels/trunk/src/main/db/init-mme.sql =================================================================== --- mentalmodels/trunk/src/main/db/init-mme.sql 2009-09-04 01:12:28 UTC (rev 277) +++ mentalmodels/trunk/src/main/db/init-mme.sql 2009-09-11 22:14:03 UTC (rev 278) @@ -405,31 +405,8 @@ -- 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` int(11) DEFAULT NULL, - `growth_rate` double NOT NULL, - `initial_population` int(11) NOT NULL, - `location_name` varchar(255) NOT NULL, - `max_capacity` 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 `location` --- - -LOCK TABLES `location` WRITE; -/*!40000 ALTER TABLE `location` DISABLE KEYS */; -INSERT INTO `location` VALUES (1,NULL,0,0,'Harbor',0),(2,NULL,0.5,5,'Bay1',10),(3,NULL,0.15,10,'Bay2',20),(4,NULL,0.05,15,'Bay3',30); -/*!40000 ALTER TABLE `location` ENABLE KEYS */; -UNLOCK TABLES; - --- -- Table structure for table `module` -- Modified: mentalmodels/trunk/src/main/java/edu/asu/commons/mme/entity/DayByDayDecisions.java =================================================================== --- mentalmodels/trunk/src/main/java/edu/asu/commons/mme/entity/DayByDayDecisions.java 2009-09-04 01:12:28 UTC (rev 277) +++ mentalmodels/trunk/src/main/java/edu/asu/commons/mme/entity/DayByDayDecisions.java 2009-09-11 22:14:03 UTC (rev 278) @@ -36,7 +36,6 @@ @Column(nullable=false) private Double earnings; - @Column(nullable=false) private Double money; 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-04 01:12:28 UTC (rev 277) +++ mentalmodels/trunk/src/main/java/edu/asu/commons/mme/entity/Location.java 2009-09-11 22:14:03 UTC (rev 278) @@ -7,6 +7,7 @@ import javax.persistence.Entity; import javax.persistence.GeneratedValue; import javax.persistence.Id; +import javax.persistence.ManyToOne; import javax.persistence.OneToMany; import javax.persistence.Table; @@ -27,21 +28,30 @@ private String locationName; @Column(nullable=false,name="max_capacity") - private Integer maxCapacity; + private Double maxCapacity; @Column(nullable=false,name="growth_rate", scale=2) private Double growthRate; @Column(nullable=false,name="initial_population") - private Integer initialPopulation; + private Double initialPopulation; @Column(name="current_population") - private Integer currentPopulation; + private Double currentPopulation; + @Column(name="fish_leaving") + private Double fishLeaving; + @Column(name="fish_return") + private Double fishReturned; + + @ManyToOne + private Game game; + public void setId(Long id) { this.id = id; } + public Long getId() { return id; } @@ -58,23 +68,23 @@ public void setLocationName(String locationName) { this.locationName = locationName; } - public Integer getMaxCapacity() { + public Double getMaxCapacity() { return maxCapacity; } - public void setMaxCapacity(Integer maxCapacity) { + public void setMaxCapacity(Double maxCapacity) { this.maxCapacity = maxCapacity; } - public Integer getInitialPopulation() { + public Double getInitialPopulation() { return initialPopulation; } - public void setInitialPopulation(Integer initialPopulation) { + public void setInitialPopulation(Double initialPopulation) { this.initialPopulation = initialPopulation; } - public void setCurrentPopulation(Integer currentPopulation) { + public void setCurrentPopulation(Double currentPopulation) { this.currentPopulation = currentPopulation; } - public Integer getCurrentPopulation() { + public Double getCurrentPopulation() { return currentPopulation; } public void setRoundLocations(List<RoundLocation> roundLocations) { @@ -84,4 +94,28 @@ return roundLocations; } + public void setFishLeaving(Double fishLeaving) { + this.fishLeaving = fishLeaving; + } + + public Double getFishLeaving() { + return fishLeaving; + } + + public void setFishReturned(Double fishReturned) { + this.fishReturned = fishReturned; + } + + public Double getFishReturned() { + return fishReturned; + } + + public void setGame(Game game) { + this.game = game; + } + + public Game getGame() { + return game; + } + } 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-09-04 01:12:28 UTC (rev 277) +++ mentalmodels/trunk/src/main/java/edu/asu/commons/mme/service/AnsweringService.java 2009-09-11 22:14:03 UTC (rev 278) @@ -41,7 +41,7 @@ studentResponse.setStudent(clientStudentResponse.getStudent()); getDao().save(studentResponse); } - //return moduleService.getBlock(); + } public void saveStrategy(List<StudentStrategy> studentStrategies) @@ -94,6 +94,4 @@ public HibernateStudentStrategyDao getStudentStrategyDao() { return studentStrategyDao; } - - } Modified: mentalmodels/trunk/src/main/java/edu/asu/commons/mme/service/DayByDayDecisionsService.java =================================================================== --- mentalmodels/trunk/src/main/java/edu/asu/commons/mme/service/DayByDayDecisionsService.java 2009-09-04 01:12:28 UTC (rev 277) +++ mentalmodels/trunk/src/main/java/edu/asu/commons/mme/service/DayByDayDecisionsService.java 2009-09-11 22:14:03 UTC (rev 278) @@ -1,20 +1,74 @@ package edu.asu.commons.mme.service; import java.util.ArrayList; +import java.util.HashMap; import java.util.List; +import java.util.Map; import org.springframework.transaction.annotation.Transactional; import edu.asu.commons.mme.dao.HibernateDayByDayDecisionsDao; import edu.asu.commons.mme.entity.DayByDayDecisions; +import edu.asu.commons.mme.entity.Group; import edu.asu.commons.mme.entity.Location; +/*** + 1) Harvesting - Find out the amount of fish per agent and calculate the current population after harvesting + Fishing capacity: All agents have the same limit of what they can maximally catch on a day. + fish_cap = 5 + amount_per_agent_i = Fish_cap \xD7 actualPopulation_i / capacity_i + IF number_of_agents_i \xD7 amount_per_agent > actualPopulation + amount_per_agent = actualPopulation / number_of_agents_i + actualPopulation_i = acutalPopulation_i \x96 number_of_agents_i \xD7 amount_per_agent + +2)Growth: Growth is calculated based on the fish population after harvesting. Thus, for Bay i: + growth_i = actualPopulation_i \xD7 growthRate _i + +3)Fish leaving location: The decrease of growth and reproduction with increasing population size is modeled here as fish leaving the bays. The amount of fish leaving the bay is set exactly to the same value as the reduction of growth/reproduction in the traditional logistic growth function. (It is assumed that fish do not simply stay in a bay even though there is not enough food to grow and they feel too uncomfortable to reproduce, but they leave the bay to look for a better place. Even though this tendency makes sense, it is not exactly what is commonly modeled with a logistic growth. To come closer to the traditional concept of a logistic growth the loss parameter can be set to higher values. However, the diffusion not only makes sense in an evolutionary sense but also is easy to explain to the subjects. Further, this leads to a psychologically much more interest-ing system behavior.) The amount of fish leaving the bays is calculated based on the population after har-vesting, i.e. still without considering the increase of the population due to regrowth. Thus the population of Bay i is reduced as follows: + leaving_i = actualPopulation_i \xD7 growthRate _i \xD7 actualPopulation_i / capacity_i + + 4)Population during diffusion: The fish population in Bay i after harvesting, growth and the leaving of the fish is + actualPopulation_i = actualPopulation_i + growth_i \x96 leaving_i + + 5) Redistribution: The fish that left their bays due to overcrowding now return to the bays. However, two processes lead to changes of the fish populations in the different bays compared to if the fish never would have left their bays: + + 6) Loss: Some fish are lost in the process (e.g. eaten by predatory fish or died in the open ocean). These losses also model reduction of the growth/reproduction rate of overcrowded locations according to a tradi-tional concept of the logistic growth. + However, for the pilot experiments the losses are set to 0. + For the pilot experiments the losses will be set to 0. To simulate the one-location condition, this parameter can be set to 1. + + totalLeaving = leaving_1 + leaving_2 + leaving_3 + totalLoss = totalLeaving \xD7 lossRate + totalReturn = totalLeaving \x96 totalLoss + +7)Redistribution: Fish that survive the diffusion process try to enter the three bays again. Fish will preferably go to the less crowded bays, what leads to a redistribution of the fish. Further, the more crowded a bay is, the less fish can enter. Into bays with a fish population near its capacity no fish can enter while all fish can escape in a completely empty bay. Fish that cannot enter a bay are also eliminated from the system, i.e. they die in the ocean. Thus, the amount of fish returning is calcu-lated as follows: + + FOR i = 1 TO 3 + receptivity_i = 1 \x96 actualPopulation_i / capacity_i + END FOR + + receptivity_total = receptivity_1 + receptivity_2 + receptivity_3 + + FOR i = 1 TO 3 + IF receptivity_total = 0 + returning_i = 0 + ELSE + returning_i = receptivity_i \xD7 totalReturn \xD7 receptivity_i / receptivity_total + END FOR + +8) New population: The new fish population, with which the next simulation day starts, is calculated as + actualPopulation_i = actualPopulation_i + returning_i + +*/ + @Transactional public class DayByDayDecisionsService extends Service.Base<DayByDayDecisions, HibernateDayByDayDecisionsDao> { LocationService locationService; - + StudentService studentService; + private List<DayByDayDecisions> studentDecisions = new ArrayList<DayByDayDecisions>(); + private double totalFishLeaving; + public void setStudentDecisions(List<DayByDayDecisions> studentDecisions) { this.studentDecisions = studentDecisions; } @@ -22,7 +76,23 @@ public List<DayByDayDecisions> getStudentDecisions() { return studentDecisions; } + + public double getTotalFishLeaving() { + return totalFishLeaving; + } + + public void setTotalFishLeaving(double totalFishLeaving) { + this.totalFishLeaving = totalFishLeaving; + } + public StudentService getStudentService() { + return studentService; + } + + public void setStudentService(StudentService studentService) { + this.studentService = studentService; + } + public void saveStudentDecision(DayByDayDecisions studentDecision) { if (studentDecisions == null) @@ -42,49 +112,205 @@ } } } - + public void allocateStudentForEachBay() { DayByDayDecisions studentDecision = new DayByDayDecisions(); - List<DayByDayDecisions> bay1 = new ArrayList<DayByDayDecisions>(); - List<DayByDayDecisions> bay2 = new ArrayList<DayByDayDecisions>(); - List<DayByDayDecisions> bay3 = new ArrayList<DayByDayDecisions>(); - List<DayByDayDecisions> harbor = new ArrayList<DayByDayDecisions>(); - - + List<DayByDayDecisions> bay1Students = new ArrayList<DayByDayDecisions>(); + List<DayByDayDecisions> bay2Students = new ArrayList<DayByDayDecisions>(); + List<DayByDayDecisions> bay3Students = new ArrayList<DayByDayDecisions>(); + List<DayByDayDecisions> harborStudents = new ArrayList<DayByDayDecisions>(); + for(int i = 0; i < studentDecisions.size(); i++) { studentDecision = studentDecisions.get(i); if(studentDecision.getLocation().getLocationName().equalsIgnoreCase("Bay1")) { - bay1.add(studentDecision); + bay1Students.add(studentDecision); } else if(studentDecision.getLocation().getLocationName().equalsIgnoreCase("Bay2")) { - bay2.add(studentDecision); + bay2Students.add(studentDecision); } else if(studentDecision.getLocation().getLocationName().equalsIgnoreCase("Bay3")) { - bay3.add(studentDecision); + bay3Students.add(studentDecision); } else if(studentDecision.getLocation().getLocationName().equalsIgnoreCase("Harbor")) { - harbor.add(studentDecision); + harborStudents.add(studentDecision); } } - executeStrategy(bay1,"Bay1"); - executeStrategy(bay2,"Bay2"); - executeStrategy(bay3,"Bay3"); - executeStrategy(harbor,"Harbor"); + + /** + * Calculate the following in the order it is mention + * 1) The actual population of each bay after growth and fish leaving and assign the harvest to each agent. + * 2) Total fish leaving = leaving from bay1 + leaving from bay2 + leaving from bay3 + * 2) Receptivity for each bay + * 3) Total receptivity + * 4) Fish Return for each bay + * 5) New population at each bay + */ + + + calculateHarvest(bay1Students,"Bay1"); + calculateHarvest(bay2Students,"Bay2"); + calculateHarvest(bay3Students,"Bay3"); + calculateHarvest(harborStudents,"Harbor"); + + calculateTotalFishLeaving(); + + calculateFishReturned(); + + calculateNewPopulation(); + } + + //FIXME: max_fish_capacity is hard coded to 5 but actually this value should get from game object + - public void executeStrategy(List<DayByDayDecisions> bay,String locationName) + + public void calculateHarvest(List<DayByDayDecisions> bayStudents,String locationName) { - Location location = locationService.getLocation(locationName); - location.getCurrentPopulation(); - + double maxFishCapacity = 5.0; + double amountPerAgent = 0.0; + double actualPopulation = 0.0; + double growth = 0.0; + double fishLeaving = 0.0; + + try + { + Location location = locationService.getLocation(locationName); + + actualPopulation = location.getCurrentPopulation(); + + //1)Harvesting + //Find out the amount of fish per agent + + amountPerAgent = maxFishCapacity * location.getCurrentPopulation() / location.getMaxCapacity(); + + if((bayStudents.size() * amountPerAgent) > actualPopulation) + { + amountPerAgent = actualPopulation / bayStudents.size(); + } + //FIXME: allocate this amountPerAgent to each student + + //calculate the current population after harvesting + actualPopulation = actualPopulation - bayStudents.size() * amountPerAgent; + + location.setCurrentPopulation(actualPopulation); + + //2)Growth + growth = actualPopulation * location.getGrowthRate(); + getLogger().info("Fish growth at " + locationName + " is: " + growth); + + //3) Fish leaving location + fishLeaving = actualPopulation * growth / location.getMaxCapacity(); + getLogger().info("Fish leaving at " + locationName + " is: " + fishLeaving); + + location.setFishLeaving(fishLeaving); + + //4) Population after diffusion + actualPopulation = actualPopulation + growth - fishLeaving; + getLogger().info("Fish population at " + locationName + " after diffusion is: " + actualPopulation); + locationService.save(location); + + for(DayByDayDecisions dayByDayDecisions : bayStudents) + { + dayByDayDecisions.setEarnings(amountPerAgent); + Group group = dayByDayDecisions.getStudent().getGroup(); + + } + + }catch(Exception e) + { + getLogger().error(e.fillInStackTrace()); + } } + + private void calculateTotalFishLeaving() { + + double totalFishLeaving = 0; + + for(Location location : locationService.getAllLocations()) + { + totalFishLeaving = totalFishLeaving + location.getFishLeaving(); + } + setTotalFishLeaving(totalFishLeaving); + + } + +/**INFO: loss rate is 0 - according to the Dr Tobias' document, loss rate for the pilot experiment is 0 + but for single location it will be 1 */ + + private void calculateFishReturned() { + + double totalLoss = 0.0; + double lossRate = 0.0; + double totalReturn = 0.0; + double maxFishCapacity = 5.0; + double totalReceptivity = 0.0; + double receptivity = 0.0; + + + Map<String,Double> bayReceptivity = new HashMap<String, Double>(); + try + { + + //calculate loss + totalLoss = getTotalFishLeaving() * lossRate; + totalReturn = getTotalFishLeaving() - totalLoss; + + getLogger().info("Total Return is: " + totalReturn); + + //calculate the receptivity for each bay and total receptivity + for(Location location : locationService.getAllLocations()) + { + receptivity = 1 - location.getCurrentPopulation() / maxFishCapacity; + getLogger().info(location.getLocationName() + " receptivity is: " + receptivity); + bayReceptivity.put(location.getLocationName(), receptivity); + totalReceptivity = receptivity + totalReceptivity; + } + getLogger().info("Total receptivity is: " + totalReceptivity); + + //calculte the returning for each bay + /**FOR i = 1 TO 3 + IF receptivity_total = 0 + returning_i = 0 + ELSE + returning_i = receptivity_i \xD7 totalReturn \xD7 receptivity_i / receptivity_total + END FOR */ + receptivity = 0.0; + for(Location location : locationService.getAllLocations()) + { + if(totalReceptivity == 0) + { + location.setFishReturned(0.0); + } + else + { + receptivity = bayReceptivity.get(location.getLocationName()); + location.setFishReturned(receptivity * totalReturn * receptivity / totalReceptivity); + getLogger().debug("Fish returned to " + location.getLocationName() + "is " + location.getFishReturned()); + } + } + + }catch(Exception e) + { + e.printStackTrace(); + } + } + private void calculateNewPopulation() { + + for(Location location:locationService.getAllLocations()) + { + location.setCurrentPopulation(location.getCurrentPopulation() + location.getFishReturned()); + getLogger().debug("New population at " + location.getLocationName() + " is: " + location.getCurrentPopulation()); + } + + } + public LocationService getLocationService() { return locationService; } @@ -92,5 +318,5 @@ public void setLocationService(LocationService locationService) { this.locationService = locationService; } - + } 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-04 01:12:28 UTC (rev 277) +++ mentalmodels/trunk/src/main/java/edu/asu/commons/mme/service/LocationService.java 2009-09-11 22:14:03 UTC (rev 278) @@ -7,12 +7,15 @@ import org.springframework.transaction.annotation.Transactional; import edu.asu.commons.mme.dao.HibernateLocationDao; +import edu.asu.commons.mme.entity.Game; import edu.asu.commons.mme.entity.Location; @Transactional public class LocationService extends Service.Base<Location, HibernateLocationDao>{ - + + double totalFishLeaving; + public List<Location> getAllLocations() { List<Location> locations = new ArrayList<Location>(); @@ -22,9 +25,8 @@ { initLocation = locations.get(i); Hibernate.initialize(initLocation); - Hibernate.initialize(initLocation.getRoundLocations()); - + } return locations; } @@ -34,7 +36,7 @@ // TODO Auto-generated method stub List<Location>locations = getAllLocations(); Location location =new Location(); - + for(int i=0; i<locations.size(); i++) { if(locations.get(i).getLocationName().equalsIgnoreCase(locationName)) @@ -44,5 +46,53 @@ } 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) + { + 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); + + 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()); + + } + } 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-04 01:12:28 UTC (rev 277) +++ mentalmodels/trunk/src/main/java/edu/asu/commons/mme/service/RoundService.java 2009-09-11 22:14:03 UTC (rev 278) @@ -32,11 +32,13 @@ private HibernateGameDao gameDao; private HibernateModuleRoundConfigDao moduleRoundDao; + private LocationService locationService; + private Module currentModule; //private boolean startGame = true; private Round currentRound; private Block currentBlock; - private Game currentGame; + private List<Game> currentGames; private int blockSeqNo; private ModuleRoundConfig currentModuleRoundConfig; @@ -57,42 +59,47 @@ public Game createGame(Game game) { - - currentGame = new Game(); + Game newGame = new Game(); //currentGame = game; - - currentGame.setDescription(game.getDescription()); - currentGame.setMaxDays(game.getMaxDays()); - currentGame.setMaxFishHarvest(game.getMaxFishHarvest()); - currentGame.setMoney(game.getMoney()); - currentGame.setNumberOfRounds(game.getNumberOfRounds()); - currentGame.setNumberOfLocations(game.getNumberOfLocations()); - currentGame.setTimestamp(game.getTimestamp()); - currentGame.setTitle(game.getTitle()); - currentGame.setImageLocation("null"); + 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(currentGame); - String str = currentGame.getDescription()+currentGame.getId(); + getGameDao().save(newGame); + String str = newGame.getDescription()+newGame.getId(); if(getGameDao().findAllByProperty("description", str).size() != 0) { getLogger().debug("in if loop "); - currentGame = null; - setCurrentGame(currentGame); + newGame = null; + setCurrentGame(newGame); } else { - currentGame.setDescription(str); - getGameDao().save(currentGame); - getLogger().debug("in else loop 1 " + str); - setCurrentGame(currentGame); - getLogger().debug("in else loop 2 " + str); - //initializeGame(currentGame); - getLogger().debug("in else loop 3 " + str); + newGame.setDescription(str); + getGameDao().save(newGame); + setCurrentGame(newGame); + + //initializeGame(newGame); + getLogger().info("Created the game: " + newGame.getId()); + initializeLocations(newGame); } - getLogger().debug("current game from flex is: " + currentGame.getDescription()); - return currentGame; + getLogger().debug("current game from flex is: " + newGame.getDescription()); + return newGame; } + + private void initializeLocations(Game newGame) + { + locationService.setAllLocations(newGame); + } + private void initializeGame(Game game) { // TODO Auto-generated method stub Hibernate.initialize(game); @@ -115,16 +122,17 @@ 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 Block getBlock() { - /* - *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 - */ //getLogger().debug("in getBlock "); //setCurrentModuleRoundConfig(currentModuleRoundConfig); @@ -165,8 +173,6 @@ setCurrentBlock(new Block()); currentBlock = getBlock(1); } - - } } else @@ -494,11 +500,8 @@ } } - - } - public Block getCurrentBlock() { //FIXEME: game id 1 is hard coded, it should be dynamic // Game game = gameDao.find(1L); @@ -509,22 +512,18 @@ 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() { getLogger().debug("in get current round funciton"); /*Round round = currentGame.getCurrentRound(); @@ -535,7 +534,6 @@ return currentRound; } - private void initializeRound(Round round) { // TODO Auto-generated method stub Hibernate.initialize(round); @@ -578,22 +576,18 @@ 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()) { @@ -602,7 +596,6 @@ return false; } - public void setCurrentBlock(Block currentBlock) { this.currentBlock = currentBlock; } @@ -611,7 +604,6 @@ return currentModuleRoundConfig; } - public void setCurrentModuleRoundConfig( ModuleRoundConfig currentModuleRoundConfig) { this.currentModuleRoundConfig = currentModuleRoundConfig; @@ -623,6 +615,19 @@ return currentGame; } + public void setLocationService(LocationService locationService) { + this.locationService = locationService; + } + public LocationService getLocationService() { + return locationService; + } + public void setCurrentGames(List<Game> currentGames) { + this.currentGames = currentGames; + } + + public List<Game> getCurrentGames() { + return currentGames; + } } 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-04 01:12:28 UTC (rev 277) +++ mentalmodels/trunk/src/main/java/edu/asu/commons/mme/service/StartupService.java 2009-09-11 22:14:03 UTC (rev 278) @@ -74,7 +74,6 @@ startGame = null; } - @Override public void setApplicationContext(ApplicationContext context) throws BeansException { @@ -82,7 +81,6 @@ this.ctx = context; } - public void setStartGame() { try{ if (startGame == null) { @@ -99,6 +97,4 @@ return startGame; } - - } Modified: mentalmodels/trunk/src/main/webapp/WEB-INF/applicationContext.xml =================================================================== --- mentalmodels/trunk/src/main/webapp/WEB-INF/applicationContext.xml 2009-09-04 01:12:28 UTC (rev 277) +++ mentalmodels/trunk/src/main/webapp/WEB-INF/applicationContext.xml 2009-09-11 22:14:03 UTC (rev 278) @@ -113,6 +113,7 @@ <property name='moduleDao' ref='moduleDao'/> <property name='gameDao' ref='gameDao' /> <property name='moduleRoundDao' ref='moduleRoundDao' /> + <property name='locationService' ref='locationService'/> <!-- <property name='blockDao' ref='blockDao'/> --> </bean> This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |