[virtualcommons-svn] SF.net SVN: virtualcommons:[255] mentalmodels/trunk/src/main
Status: Beta
Brought to you by:
alllee
From: <see...@us...> - 2009-08-18 01:53:20
|
Revision: 255 http://virtualcommons.svn.sourceforge.net/virtualcommons/?rev=255&view=rev Author: seematalele Date: 2009-08-18 01:53:12 +0000 (Tue, 18 Aug 2009) Log Message: ----------- Removed Game from Group entity Changed the StartupService.java so that it will create game, create Students , assign groups and start the game. Changed the application Context according to the changes made in the services. StartupService.java is not completely written. Following changes needs to be made 1) assign groups to the student. Only algorithm is written to from groups. 2) push assigned groups number students to the each client 3) test for start game function. Modified Paths: -------------- mentalmodels/trunk/src/main/java/edu/asu/commons/mme/entity/Group.java mentalmodels/trunk/src/main/java/edu/asu/commons/mme/entity/ModuleRoundConfig.java mentalmodels/trunk/src/main/java/edu/asu/commons/mme/entity/Student.java mentalmodels/trunk/src/main/java/edu/asu/commons/mme/entity/StudentStrategy.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/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/java/edu/asu/commons/mme/service/StudentService.java mentalmodels/trunk/src/main/webapp/WEB-INF/applicationContext.xml 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-08-15 01:03:03 UTC (rev 254) +++ mentalmodels/trunk/src/main/java/edu/asu/commons/mme/entity/Group.java 2009-08-18 01:53:12 UTC (rev 255) @@ -29,10 +29,10 @@ @Column(name="grp_number",nullable=false) private Integer number; - + /* @ManyToOne @JoinColumn(nullable = false) - private Game game; + private Game game;*/ public Long getId() { return id; @@ -50,12 +50,12 @@ this.number = no; } - public void setGame(Game game) { + /*public void setGame(Game game) { this.game = game; } public Game getGame() { return game; } - +*/ } 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-08-15 01:03:03 UTC (rev 254) +++ mentalmodels/trunk/src/main/java/edu/asu/commons/mme/entity/ModuleRoundConfig.java 2009-08-18 01:53:12 UTC (rev 255) @@ -38,7 +38,6 @@ @JoinColumn(nullable = false) private Round round; - public void setSequenceNo(Integer sequenceNo) { this.sequenceNo = sequenceNo; } 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-08-15 01:03:03 UTC (rev 254) +++ mentalmodels/trunk/src/main/java/edu/asu/commons/mme/entity/Student.java 2009-08-18 01:53:12 UTC (rev 255) @@ -9,6 +9,7 @@ import javax.persistence.Enumerated; import javax.persistence.GeneratedValue; import javax.persistence.Id; +import javax.persistence.JoinColumn; import javax.persistence.ManyToOne; import javax.persistence.Table; import javax.persistence.Temporal; @@ -39,6 +40,10 @@ private String semester; + @ManyToOne + @JoinColumn(nullable = false) + private Game game; + @Temporal(TemporalType.TIMESTAMP) private Date timestamp; @@ -109,4 +114,12 @@ this.timestamp = timestamp; } + public void setGame(Game game) { + this.game = game; + } + + public Game getGame() { + return game; + } + } Modified: mentalmodels/trunk/src/main/java/edu/asu/commons/mme/entity/StudentStrategy.java =================================================================== --- mentalmodels/trunk/src/main/java/edu/asu/commons/mme/entity/StudentStrategy.java 2009-08-15 01:03:03 UTC (rev 254) +++ mentalmodels/trunk/src/main/java/edu/asu/commons/mme/entity/StudentStrategy.java 2009-08-18 01:53:12 UTC (rev 255) @@ -32,7 +32,7 @@ @ManyToOne @JoinColumn(nullable=false) - private Round roundConfig; + private Round round; @Column(name = "allocation_sequence_no",nullable=false) private Integer allocationSeqNo; @@ -49,9 +49,7 @@ @Column (name="repeated_decisions",columnDefinition="Boolean", nullable=false) public boolean repeatedDecisions; - - public void setId(Long id) { this.id = id; } @@ -92,12 +90,12 @@ return repeatedDecisions; } - public void setRoundConfig(Round roundConfig) { - this.roundConfig = roundConfig; + public void setRound(Round round) { + this.round = round; } - public Round getRoundConfig() { - return roundConfig; + public Round getRound() { + return round; } public void setLocation(Location location) { 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-08-15 01:03:03 UTC (rev 254) +++ mentalmodels/trunk/src/main/java/edu/asu/commons/mme/service/AnsweringService.java 2009-08-18 01:53:12 UTC (rev 255) @@ -35,7 +35,6 @@ StudentResponse clientStudentResponse = new StudentResponse(); for(int i = 0; i < studentResponses.size(); i++ ) { - clientStudentResponse = (StudentResponse) studentResponses.get(i); getLogger().debug("Question is: " + clientStudentResponse.getQuestion()); getLogger().debug("Response is: " + clientStudentResponse.getResponse()); @@ -46,7 +45,6 @@ studentResponse.setStudent(clientStudentResponse.getStudent()); getDao().save(studentResponse); } - //return moduleService.getBlock(); } @@ -55,15 +53,13 @@ StudentStrategy clientStudentStrategy = new StudentStrategy(); for(int i = 0; i < studentStrategies.size(); i++ ) { - clientStudentStrategy = (StudentStrategy) studentStrategies.get(i); - studentStrategy = new StudentStrategy(); studentStrategy.setLocation(clientStudentStrategy.getLocation()); studentStrategy.setAllocationSeqNo(clientStudentStrategy.getAllocationSeqNo()); studentStrategy.setDays(clientStudentStrategy.getDays()); studentStrategy.setRepeatedDecisions(clientStudentStrategy.isRepeatedDecisions()); - studentStrategy.setRoundConfig(clientStudentStrategy.getRoundConfig()); + studentStrategy.setRound(clientStudentStrategy.getRound()); studentStrategy.setStudent(clientStudentStrategy.getStudent()); getStudentStrategyDao().save(studentStrategy); } 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-08-15 01:03:03 UTC (rev 254) +++ mentalmodels/trunk/src/main/java/edu/asu/commons/mme/service/DayByDayDecisionsService.java 2009-08-18 01:53:12 UTC (rev 255) @@ -13,37 +13,42 @@ @Transactional public class DayByDayDecisionsService extends Service.Base<DayByDayDecisions, HibernateDayByDayDecisionsDao> { - private List<DayByDayDecisions> studentdecisions = new ArrayList<DayByDayDecisions>(); + private List<DayByDayDecisions> studentDecisions = new ArrayList<DayByDayDecisions>(); - public void setStudentdecisions(List<DayByDayDecisions> studentdecisions) { - this.studentdecisions = studentdecisions; + public void setStudentDecisions(List<DayByDayDecisions> studentDecisions) { + this.studentDecisions = studentDecisions; } - public List<DayByDayDecisions> getStudentdecisions() { - return studentdecisions; + public List<DayByDayDecisions> getStudentDecisions() { + return studentDecisions; } public void saveStudentDecision(DayByDayDecisions studentDecision) { - if (studentdecisions == null) { - studentdecisions = new ArrayList<DayByDayDecisions>(); - studentdecisions.add(studentDecision); - + if (studentDecisions == null) + { + studentDecisions = new ArrayList<DayByDayDecisions>(); + studentDecisions.add(studentDecision); } else { - if(!this.studentdecisions.contains(studentDecision)) + if(!this.studentDecisions.contains(studentDecision)) { - studentdecisions.add(studentDecision); - + studentDecisions.add(studentDecision); } else { System.out.println("Student Decision already exists!!"); } } + } + + public void executeStrategy() + { - } - + + + + } 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-08-15 01:03:03 UTC (rev 254) +++ mentalmodels/trunk/src/main/java/edu/asu/commons/mme/service/RoundService.java 2009-08-18 01:53:12 UTC (rev 255) @@ -31,18 +31,37 @@ private HibernateGameDao gameDao; private HibernateModuleRoundConfigDao moduleRoundDao; - private Module currentModule=null; - private boolean startGame = true; - private Round currentRound=null; - private Block currentBlock=null; - - private int blockSeqNo=0; + private Module currentModule; + //private boolean startGame = true; + private Round currentRound; + private Block currentBlock; + private Game currentGame; + + private int blockSeqNo; private ModuleRoundConfig currentModuleRoundConfig; - private boolean gameFinished = false; + private boolean gameFinished; + public RoundService() + { + setCurrentGame(null); + setCurrentBlock(null); + setCurrentModule(null); + setCurrentModuleRoundConfig(null); + setCurrentRound(null); + setBlockSeqNo(0); + setGameFinished(false); + } + public Game createGame(Game game) + { + currentGame = new Game(); + currentGame = game; + getGameDao().save(currentGame); + setCurrentGame(currentGame); + return getCurrentGame(); + } public Module getNextModule(int sequenceNo) { return getModule(sequenceNo); @@ -233,16 +252,9 @@ } - private Game getCurrentGame() { - // TODO Auto-generated method stub - Game game = gameDao.find(1L); - //Hibernate.initialize(game); - //getLogger().debug("round size is: " + game.getRounds().size()); - return game; + - } - public HibernateModuleDao getModuleDao() { return moduleDao; } @@ -478,14 +490,14 @@ } - public void setStartModule(Boolean startModule) { + /*public void setStartModule(Boolean startModule) { this.startGame = startModule; } public Boolean getStartModule() { return startGame; - } + }*/ public void setGameDao(HibernateGameDao gameDao) { @@ -554,6 +566,12 @@ ModuleRoundConfig currentModuleRoundConfig) { this.currentModuleRoundConfig = currentModuleRoundConfig; } + public void setCurrentGame(Game game) { + this.currentGame = game; + } + public Game getCurrentGame() { + return currentGame; + } 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-08-15 01:03:03 UTC (rev 254) +++ mentalmodels/trunk/src/main/java/edu/asu/commons/mme/service/StartGame.java 2009-08-18 01:53:12 UTC (rev 255) @@ -11,6 +11,7 @@ private boolean running; private RoundService roundService; private LocationService locationService; + private DayByDayDecisionsService dayBydayDecisionService; private ModuleRoundConfig currentModuleRoundConfig; @@ -27,6 +28,8 @@ /** * 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 * @@ -35,7 +38,7 @@ Block block = new Block(); //roundService.test(); - roundService.setStartModule(true); + MessageBroker msgBroker = MessageBroker.getMessageBroker(null); String clientID = UUIDUtils.createUUID(); @@ -50,26 +53,40 @@ }*/ //Push the first block to the clients - AsyncMessage msg = new AsyncMessage(); - msg.setDestination("DataPush"); - //msg.setHeader("DSSubtopic", "hello"); - msg.setClientId(clientID); - msg.setMessageId(UUIDUtils.createUUID()); - msg.setTimestamp(System.currentTimeMillis()); - System.out.println("in while loop: "); - block = roundService.getBlock(); - System.out.println("after block "); - msg.setBody("Here is a block!!!" + block); - System.out.println("Message broker is: "+ msgBroker); - System.out.println("Message is: "+ block.getDescription()); - msgBroker.routeMessageToService(msg, null); - //get the timer for the block - Integer timer = roundService.getTimerforBlock(block); - //start the timer for the block sent - try { - Thread.sleep(5000); - running = false; - } catch (InterruptedException e) { + if(block == null) + { + AsyncMessage msg = new AsyncMessage(); + msg.setDestination("DataPush"); + //msg.setHeader("DSSubtopic", "hello"); + msg.setClientId(clientID); + msg.setMessageId(UUIDUtils.createUUID()); + msg.setTimestamp(System.currentTimeMillis()); + System.out.println("in while loop: "); + block = roundService.getBlock(); + System.out.println("after block "); + msg.setBody("Here is a block!!!" + block); + System.out.println("Message broker is: "+ msgBroker); + System.out.println("Message is: "+ block.getDescription()); + msgBroker.routeMessageToService(msg, null); + 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 { + Thread.sleep(5000); + running = false; + } catch (InterruptedException e) { + } } } @@ -112,5 +129,13 @@ this.locationService = locationService; } + public void setDayBydayDecisionService(DayByDayDecisionsService dayBydayDecisionService) { + this.dayBydayDecisionService = dayBydayDecisionService; + } + + public DayByDayDecisionsService getDayBydayDecisionService() { + return dayBydayDecisionService; + } + } 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-08-15 01:03:03 UTC (rev 254) +++ mentalmodels/trunk/src/main/java/edu/asu/commons/mme/service/StartupService.java 2009-08-18 01:53:12 UTC (rev 255) @@ -1,34 +1,29 @@ package edu.asu.commons.mme.service; +import org.springframework.beans.BeansException; +import org.springframework.context.ApplicationContext; +import org.springframework.context.ApplicationContextAware; import org.springframework.context.ApplicationEvent; import org.springframework.context.ApplicationListener; import org.springframework.context.event.ContextRefreshedEvent; import org.springframework.transaction.annotation.Transactional; +import edu.asu.commons.mme.dao.HibernateGameDao; +import edu.asu.commons.mme.entity.Game; import edu.asu.commons.mme.entity.Student; @Transactional -public class StartupService implements ApplicationListener { +public class StartupService implements ApplicationContextAware { - private QuestionCreatorService questionCreatorService; + //private QuestionCreatorService questionCreatorService; private StudentService studentService; - private ModuleService moduleService; + private RoundService roundService; + private StartGame thread; + private ApplicationContext ctx; - private volatile boolean alreadyInitialized; - - @Override - public void onApplicationEvent(ApplicationEvent event) { - if (event instanceof ContextRefreshedEvent && ! alreadyInitialized) { - //questionCreatorService.createQuestions(); - - alreadyInitialized = true; - } - - } - - public void setQuestionCreatorService(QuestionCreatorService questionCreatorService) { + /*public void setQuestionCreatorService(QuestionCreatorService questionCreatorService) { this.questionCreatorService = questionCreatorService; - } + }*/ public void setStudentService(StudentService studentService) { this.studentService = studentService; @@ -39,15 +34,54 @@ return studentService.createStudent(birthYear, semester, gender, major); } - /*public Block getFirstBlock() + public Game createGame(Game game) { - //studentService.formGroups(); - return moduleService.getBlock(); - }*/ + return roundService.createGame(game); + + } + public void assignGroups() + { + studentService.assignGroups(); + } - public void setModuleService(ModuleService moduleService) { - this.moduleService = moduleService; + public void startGame() + { + //push assign groups to all the students + + //start the game + try{ + if (thread == null) { + thread = (StartGame)ctx.getBean("startGame"); + thread.run(); + } + }catch(Exception e) + { + System.out.println(e.getStackTrace()); + } } + public void stop() { + thread.setRunning(false); + thread = null; + } + + + @Override + public void setApplicationContext(ApplicationContext context) + throws BeansException { + // TODO Auto-generated method stub + this.ctx = context; + + } + + public void setRoundService(RoundService roundService) { + this.roundService = roundService; + } + + public RoundService getRoundService() { + return roundService; + } + + } 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-08-15 01:03:03 UTC (rev 254) +++ mentalmodels/trunk/src/main/java/edu/asu/commons/mme/service/StudentService.java 2009-08-18 01:53:12 UTC (rev 255) @@ -61,9 +61,54 @@ } - public void formGroups() + public void assignGroups() { //write an algorithm to form groups + + int totalStudents = students.size(); + int groupSize3=0; + int groupSize4=0; + int groupSize5=0; + int x; + + + //no of groups + groupSize5=((int)(totalStudents/5)); + + x= totalStudents%5; + + /* if(x==0) + { + totalGroups=groupSize5; + } + else*/ + if(x==1) + { + groupSize5=groupSize5 - 1; + groupSize3=2; + // totalGroups=groupSize5 + groupSize3; + } + + else if(x==2) + { + groupSize5=groupSize5-1; + groupSize3=1; + groupSize4=1; + // totalGroups=groupSize5 + groupSize3 + groupSize4; + } + else if(x==3) + { + groupSize3=1; + // totalGroups=groupSize3 + groupSize5; + } + + else if(x==4) + { + groupSize4=1; +// totalGroups=groupSize4 + groupSize5; + } + + } } Modified: mentalmodels/trunk/src/main/webapp/WEB-INF/applicationContext.xml =================================================================== --- mentalmodels/trunk/src/main/webapp/WEB-INF/applicationContext.xml 2009-08-15 01:03:03 UTC (rev 254) +++ mentalmodels/trunk/src/main/webapp/WEB-INF/applicationContext.xml 2009-08-18 01:53:12 UTC (rev 255) @@ -128,7 +128,7 @@ </bean> <bean id='startupService' class='edu.asu.commons.mme.service.StartupService'> - <property name='questionCreatorService' ref='questionCreatorService'/> + <property name='roundService' ref='roundService'/> <property name='studentService' ref='studentService'/> </bean> This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |