[virtualcommons-svn] SF.net SVN: virtualcommons:[23] vcweb/trunk/virtualcommons
Status: Beta
Brought to you by:
alllee
From: <al...@us...> - 2008-08-05 00:36:06
|
Revision: 23 http://virtualcommons.svn.sourceforge.net/virtualcommons/?rev=23&view=rev Author: alllee Date: 2008-08-05 00:36:14 +0000 (Tue, 05 Aug 2008) Log Message: ----------- refactored teacher_dashboard's stage display and getAllGroupRoundInfo to return a hashtable of stage_ids mapped to an array of arrays representing the group round info for that stage. some minor schema cleanup Modified Paths: -------------- vcweb/trunk/virtualcommons/experiment/experiment.inc vcweb/trunk/virtualcommons/experiment/experiment.install vcweb/trunk/virtualcommons/games/forestry_v2/forestry_v2.install vcweb/trunk/virtualcommons/games/teacher_dashboard/teacher_dashboard.install vcweb/trunk/virtualcommons/games/teacher_dashboard/teacher_dashboard.module Modified: vcweb/trunk/virtualcommons/experiment/experiment.inc =================================================================== --- vcweb/trunk/virtualcommons/experiment/experiment.inc 2008-08-04 20:13:03 UTC (rev 22) +++ vcweb/trunk/virtualcommons/experiment/experiment.inc 2008-08-05 00:36:14 UTC (rev 23) @@ -1,9 +1,11 @@ <?php + + class Session { public static function put($ses_var, $object) { //if( ! isset($_SESSION[$ses_var]) ) { - $_SESSION[$ses_var] = serialize($object); + $_SESSION[$ses_var] = serialize($object); //} } public static function get($ses_var) { @@ -46,15 +48,21 @@ return $this->no_of_students; } - public function getInitialStageId() { - return db_result(db_query("select id from vc_stage where vc_experiment_id=%d and stage_no=%d",$this->experiment_id,$this->current_stage_no)); + // FIXME: remove current_stage_no from this session object since it is + // unsafe if the browser exits + public function getStageId($current_stage_no) { + return db_result(db_query("select id from vc_stage where vc_experiment_id=%d and stage_no=%d",$this->experiment_id, $current_stage_no)); } public function getCurrentStageId() { return db_result(db_query("select vc_stage_id from vc_game where id=%d",$this->game_id)); } + public function getCurrentRoundNo() { + return db_result(db_query("select current_round_no from vc_game where id=%d",$this->game_id)); + } + public function getGameId() { return $this->game_id; } @@ -80,7 +88,7 @@ $this->teacher_id, $this->experiment_id, $this->no_of_students, - $this->getInitialStageId(), + $this->getStageId($this->current_stage_no), $this->current_round_no); } } @@ -103,7 +111,7 @@ { //drupal_set_message(t('Group Key is: %key<br>' ,array('%key'=>$key))); $group_id=db_next_id('vc_group_id'); - db_query("Insert into {vc_group} (id,group_no,vc_game_id,vc_stage_id) values(%d,%d,%d,%d)",$group_id,$group,$this->game_id,$this->stage_id); + db_query("Insert into {vc_group} (id,group_no,vc_game_id) values(%d,%d,%d)",$group_id,$group,$this->game_id); $i=0; foreach ($value as $key=>$student_id) { @@ -116,41 +124,37 @@ } } + public function isVotingEnabled() { + return db_result(db_query("select s.voting from vc_stage s inner join vc_game g on s.id=g.vc_stage_id and g.id=%d", $this->game_id)); + } + + public function isVotingEnabledForStage($stage_id) { + return db_result(db_query("select voting from vc_stage where id=%d", $stage_id)); + } + public function isVotingDone() { - $count=db_result(db_query("select count(*) from vc_group where vc_game_id=%d and vc_selected_rules_id is null",$game_id)); + $count=db_result(db_query("select count(*) from vc_group where vc_game_id=%d and vc_selected_rules_id is null",$this->game_id)); return $count==0; } - // FIXME: figure out if we can move to forestry at some point + // FIXME: turn into $forestryGame->init() overloaded method public function initForestry() { - $result_group=db_query(" select count(s.vc_group_id) as cnt, s.vc_group_id as group_id from vc_group g, vc_student s where s.vc_group_id=g.id and g.vc_game_id=%d group by s.vc_group_id;",$this->game_id); + $result_group=db_query("select count(s.vc_group_id) as cnt, s.vc_group_id as group_id from vc_group g, vc_student s where s.vc_group_id=g.id and g.vc_game_id=%d group by s.vc_group_id;",$this->game_id); while($data=db_fetch_object($result_group)) { $no_of_student=$data->cnt; - $group_no=$data->group_id; + $group_id=$data->group_id; //drupal_set_message(t($no_of_student.' '. $group_no)); - if($no_of_student == 5) - { - db_query("Insert into {vc_forestry_common_resource_pool} (vc_group_id,common_resource_pool,vc_game_id, harvest_decision,max_harvest_decision) values(%d,%d,%d,%d,%d)",$group_no,100,$this->game_id,0,100); - - } - - else if($no_of_student == 4) - { - db_query("Insert into {vc_forestry_common_resource_pool} (vc_group_id,common_resource_pool,vc_game_id, harvest_decision,max_harvest_decision) values(%d,%d,%d,%d,%d)",$group_no,80,$this->game_id,0,80); - } - - - else if($no_of_student == 3) - { - db_query("Insert into {vc_forestry_common_resource_pool} (vc_group_id,common_resource_pool,vc_game_id,harvest_decision,max_harvest_decision) values(%d,%d,%d,%d,%d)",$group_no,60,$this->game_id,0,60); - } - + $this->initGroup($no_of_student, $group_id); } + } - + private function initGroup($number_of_students, $group_id) { + $resource_max = $number_of_students * 20; + db_query("Insert into {vc_forestry_common_resource_pool} (vc_group_id,common_resource_pool,vc_game_id,max_resources) values(%d,%d,%d,%d)", + $group_id, $resource_max, $this->game_id, $resource_max); } public function updateStartFlag($flag) @@ -158,23 +162,31 @@ db_query("update vc_student set start_flag=%d where vc_group_id in (select id from vc_group where vc_game_id=%d)",$flag,$this->game_id); } + public function getStageNumber($stage_id) { + return db_result(db_query("SELECT stage_no FROM {vc_stage} WHERE id=%d", $stage_id)); + } + + // returns { stage_id -> {group round data, ...}, ... } public function getAllGroupRoundInfo() { - $result=db_query("SELECT round_no, vc_group_id, total_harvest_decision, resources_before, resources_after, vc_rules_id, dice - FROM {vc_forestry_group_round_info} - WHERE vc_game_id=%d and vc_stage_id=%d", - $this->game_id, $this->getCurrentStageId()); + $result=db_query("SELECT vc_stage_id, round_no, g.group_no as group_no, total_harvest_decision, resources_before, resources_after, vc_rules_id, dice + FROM {vc_forestry_group_round_info fgr,vc_group g} + WHERE g.vc_game_id=%d and fgr.vc_group_id=g.id + ORDER BY round_no", + $this->game_id); $stage_data = array(); while($data = db_fetch_object($result)) { $round_no=$data->round_no; - $group_id=$data->vc_group_id; + $group_no=$data->group_no; + $stage_id=$data->vc_stage_id; + $total_harvest_decision=$data->total_harvest_decision; $resources_before=$data->resources_before; $resources_after=$data->resources_after; - $group_round_data = array($round_no,$group_no,$total_harvest_decision,$resource_before,$resource_after); + $group_round_data = array($round_no,$group_no,$total_harvest_decision,$resources_before,$resources_after); if ( $data->vc_rules_id ) { array_push($group_round_data, $data->vc_rules_id, $data->dice); } - $stage_data[] = $group_round_data; + $stage_data[$stage_id][] = $group_round_data; } return $stage_data; } @@ -183,7 +195,59 @@ return db_result(db_query("SELECT s.stage_no FROM {vc_game g, vc_stage s} WHERE g.vc_stage_id=s.id AND g.id=%d", $this->game_id)); } + public function processGroups() + { + $round_no=$this->getCurrentRoundNo(); + $stage_id=$this->getCurrentStageId(); + $result = db_query(" select c.vc_group_id as group_id,c.common_resource_pool as crp,c.max_resources as max_r from vc_forestry_common_resource_pool c, vc_group g where c.vc_group_id =g.id and g.vc_game_id=%d",$this->game_id); + while($data = db_fetch_object($result)) + { + $group_id=$data->group_id; + $resources_before=$crp=$data->crp; + $max_resources=$data->max_r; + $total_harvest_decision = db_result(db_query("select sum(harvest_decision) + from vc_forestry_student + where vc_student_id in (select id from vc_student where vc_group_id=%d) and round_no=%d", + $group_id,$round_no)); + $resources_available=$crp-$total_harvest_decision; + $resources_available=$resources_available+($resources_available*0.1); + if($resources_available > $max_resources) { + $resources_available=$max_resources; + } + //insert into group-round info + db_query("Insert into {vc_forestry_group_round_info} (round_no,vc_game_id,vc_group_id,vc_stage_id,total_harvest_decision,resources_before,resources_after) + values(%d,%d,%d,%d,%d,%d,%d)", + $round_no,$this->game_id,$group_id,$stage_id,$total_harvest_decision,$resources_before,$resources_available); + //update forestry common pool + db_query("update {vc_forestry_common_resource_pool} set common_resource_pool=%d where vc_game_id=%d and vc_group_id=%d",$resources_available,$this->game_id,$group_id); + } + //update start flag + $this->updateStartFlag(true); + //update crrent round_no + $round_no=$round_no+1; + if ($round_no > ($this->getNumberOfRounds())) { + // reset round number to 1 + $this->current_round_no = 1; + // increment stage number and try to find a stage id for that stage + + $current_stage_no = $this->getCurrentStageNumber(); + $next_stage_id = $this->getStageId( $current_stage_no + 1 ); + if ($next_stage_id) { + db_query("UPDATE {vc_game} SET vc_stage_id=%d WHERE id=%d", $next_stage_id, $this->game_id); + } + else { + // experiment is over. figure out how to signal the end of + + } + } + else { + $this->current_round_no = $round_no; + } + db_query("UPDATE {vc_game} SET current_round_no=%d WHERE id=%d", $this->current_round_no, $this->game_id); + } + + }//end of class Game class Group { Modified: vcweb/trunk/virtualcommons/experiment/experiment.install =================================================================== --- vcweb/trunk/virtualcommons/experiment/experiment.install 2008-08-04 20:13:03 UTC (rev 22) +++ vcweb/trunk/virtualcommons/experiment/experiment.install 2008-08-05 00:36:14 UTC (rev 23) @@ -59,12 +59,10 @@ id INT AUTO_INCREMENT, group_no INT NOT NULL, vc_game_id INT NOT NULL, - vc_stage_id INT NOT NULL, vc_selected_rules_id INT NULL, PRIMARY KEY(id), FOREIGN KEY(vc_game_id) REFERENCES vc_game(id), - FOREIGN KEY(vc_stage_id) REFERENCES vc_stage(id), FOREIGN KEY(vc_selected_rules_id) REFERENCES vc_rules(id) ) ENGINE=InnoDB /*!40100 DEFAULT CHARACTER SET UTF8 */"); @@ -183,6 +181,8 @@ db_query("DROP TABLE {vc_student}"); db_query("DROP TABLE {vc_group}"); + db_query("delete from sequences where name='vc_game_id'"); + db_query("delete from sequences where name='vc_group_id'"); db_query("DROP TABLE {vc_game}"); db_query("DROP TABLE {vc_rules}"); db_query("DROP TABLE {vc_stage}"); Modified: vcweb/trunk/virtualcommons/games/forestry_v2/forestry_v2.install =================================================================== --- vcweb/trunk/virtualcommons/games/forestry_v2/forestry_v2.install 2008-08-04 20:13:03 UTC (rev 22) +++ vcweb/trunk/virtualcommons/games/forestry_v2/forestry_v2.install 2008-08-05 00:36:14 UTC (rev 23) @@ -13,9 +13,9 @@ id INT AUTO_INCREMENT, vc_group_id INT NOT NULL, common_resource_pool INT NOT NULL, - harvest_decision INT NOT NULL, + vc_game_id INT NOT NULL, - max_harvest_decision INT NOT NULL, + max_resources INT NOT NULL, PRIMARY KEY(id), FOREIGN KEY(vc_group_id) REFERENCES vc_group(id) Modified: vcweb/trunk/virtualcommons/games/teacher_dashboard/teacher_dashboard.install =================================================================== --- vcweb/trunk/virtualcommons/games/teacher_dashboard/teacher_dashboard.install 2008-08-04 20:13:03 UTC (rev 22) +++ vcweb/trunk/virtualcommons/games/teacher_dashboard/teacher_dashboard.install 2008-08-05 00:36:14 UTC (rev 23) @@ -20,7 +20,7 @@ total_harvest_decision int NOT NULL, resources_before int NOT NULL, resources_after int NOT NULL, - vc_rules_id int NOT NULL, + vc_rules_id int default NULL, dice int default 0, PRIMARY KEY(id), @@ -52,7 +52,7 @@ total_harvest_decision int NOT NULL, resources_before int NOT NULL, resources_after int NOT NULL, - vc_rules_id int NOT NULL, + vc_rules_id int default NULL, dice int default 0, Modified: vcweb/trunk/virtualcommons/games/teacher_dashboard/teacher_dashboard.module =================================================================== --- vcweb/trunk/virtualcommons/games/teacher_dashboard/teacher_dashboard.module 2008-08-04 20:13:03 UTC (rev 22) +++ vcweb/trunk/virtualcommons/games/teacher_dashboard/teacher_dashboard.module 2008-08-05 00:36:14 UTC (rev 23) @@ -3,359 +3,288 @@ function teacher_dashboard_menu($may_cache) { - $items = array(); - if ($may_cache) - { + $items = array(); + if ($may_cache) + { - $items[]=array( 'path' => 'teacher_dashboard', - 'title' => t('Teacher Dashboard'), - 'callback' => 'teacher_dashboard', - 'type'=>MENU_CALLBACK, - 'access' => user_access('Only Teachers') - ); + $items[]=array( 'path' => 'teacher_dashboard', + 'title' => t('Teacher Dashboard'), + 'callback' => 'teacher_dashboard', + 'type'=>MENU_CALLBACK, + 'access' => user_access('Only Teachers') + ); - $items[]=array( 'path' => 'teacher_dashboard_part2', - 'title' => t('Teacher Dashboard'), - 'callback'=>'teacher_dashboard_part2', - // 'callback argument' => array('forestry_game_stage1_part2'), - 'type'=>MENU_CALLBACK, - 'access' => user_access('Only Teachers') - ); - } - /*else { - teacher_load(); - }*/ - return $items; + $items[]=array( 'path' => 'teacher_dashboard_part2', + 'title' => t('Teacher Dashboard'), + 'callback'=>'teacher_dashboard_part2', + // 'callback argument' => array('forestry_game_stage1_part2'), + 'type'=>MENU_CALLBACK, + 'access' => user_access('Only Teachers') + ); + } + /*else { + teacher_load(); + }*/ + return $items; } function teacher_dashboard() { - // Return the HTML generated from the $form data structure. - $teacher_id=$GLOBALS['user']->uid; - //db_query( - //drupal_set_message(t($teacher_id)); -// $virtual_conduct_id=db_result(db_query("select max(id) from {virtualcommons_conducts} where users_id=%d group by users_id",$teacher_id)); + // Return the HTML generated from the $form data structure. + $teacher_id=$GLOBALS['user']->uid; + //db_query( + //drupal_set_message(t($teacher_id)); + // $virtual_conduct_id=db_result(db_query("select max(id) from {virtualcommons_conducts} where users_id=%d group by users_id",$teacher_id)); // $exp_name=db_result(db_query("select exp_name from virtualcommons_experiments where id =(select virtualcommons_experiments_id from virtualcommons_conducts where id=%d)",$virtual_conduct_id)); - $game = Session::get('game'); - $exp_name=$game->getExperimentName(); - $output=t('<br> <h2>'. $exp_name . '</h2>'); - $output .= drupal_get_form('teacher_dashboard_multiform'); - return $output; + $game = Session::get('game'); + $exp_name=$game->getExperimentName(); + $output=t('<br> <h2>'. $exp_name . '</h2>'); + $output .= drupal_get_form('teacher_dashboard_multiform'); + return $output; } function teacher_dashboard_multiform($form_values=NULL) { - $form['#id']='teacher_dashboard_multiform'; - $form['#multistep']=TRUE; - $game = Session::get('game'); - // $teacher_id=$GLOBALS['user']->uid; - $round_no=0; - $stage_flag=FALSE; + $form['#id']='teacher_dashboard_multiform'; + $form['#multistep']=TRUE; + $game = Session::get('game'); + // $teacher_id=$GLOBALS['user']->uid; + $round_no=0; + $stage_flag=FALSE; - //$virtual_conduct_id=db_result(db_query("select max(id),users_id from {virtualcommons_conducts} where users_id=%d group by users_id",$teacher_id)); + //$virtual_conduct_id=db_result(db_query("select max(id),users_id from {virtualcommons_conducts} where users_id=%d group by users_id",$teacher_id)); - //retrive values for stage 1 + //retrive values for stage 1 - $header_stage1=array('Round No','Group No', 'Group Harvest Decision','Resources Before','Resources After'); - $row_stage1 = $game->getAllGroupRoundInfo(); - if(!isset($form_values)) - { //$round_no=(int) $round_no; - $step=0; - drupal_set_message(t('step when form values are null: '.$step)); - } - else - { - $step=(int) $form_values['step']; - $step++; - drupal_set_message(t('step when form values are not null: '.$step)); - } + if(!isset($form_values)) + { //$round_no=(int) $round_no; + $step=0; + drupal_set_message(t('step when form values are null: '.$step)); + } + else + { + $step=(int) $form_values['step']; + $step++; + drupal_set_message(t('step when form values are not null: '.$step)); + } - $no_rounds= $game->getNumberOfRounds(); -// $no_rounds=(int) $no_rounds; - drupal_set_message(t('no of rounds are: '.$no_rounds)); - if($round_no==$no_rounds) + $no_rounds= $game->getNumberOfRounds(); + // $no_rounds=(int) $no_rounds; + drupal_set_message(t('no of rounds are: '.$no_rounds)); + if($round_no==$no_rounds) + { + if(isset($_SESSION['next_stage'])) { - if(isset($_SESSION['next_stage'])) - { - $stage_flag=FALSE; - unset($_SESSION['next_stage']); - } - else - $stage_flag=TRUE; + $stage_flag=FALSE; + unset($_SESSION['next_stage']); } + else + $stage_flag=TRUE; + } - // $_SESSION['step']=$step; + // $_SESSION['step']=$step; - //$form['#redirect']=FALSE; + //$form['#redirect']=FALSE; - $form['round_no']=array('#type'=>'hidden','#value'=>$round_no); - $form['game_id']=array('#type'=>'hidden','#value'=>$virtual_conduct_id); - //$form['exp_name']=array('#type'=>'hidden','#value'=>$exp_name); - //$form['step']=array('#type'=>'hidden','#value'=>$step); - $form['stage1']=array( - '#type'=>'fieldset', - '#title'=>t('<b>Stage 1</b>') - ); + $form['round_no']=array('#type'=>'hidden','#value'=>$round_no); + $form['game_id']=array('#type'=>'hidden','#value'=>$virtual_conduct_id); + //$form['exp_name']=array('#type'=>'hidden','#value'=>$exp_name); + //$form['step']=array('#type'=>'hidden','#value'=>$step); + $header_novoting=array('Round No','Group No', 'Group Harvest Decision','Resources Before','Resources After'); + $header_voting=array('Round No','Group No', 'Group Harvest Decision','Resources Before','Resources After', 'Dice', 'Rule #'); - $form['stage1']['table']=array( - '#type'=>'markup', - '#value'=>theme('table',$header_stage1,$row_stage1) - ); + // $row_stage1 = $game->getAllGroupRoundInfo(); + $all_stage_data = $game->getAllGroupRoundInfo(); - $form['stage2']=array( - '#type'=>'fieldset', - '#title'=>t('<b>Stage 2</b>') - ); + foreach ($all_stage_data as $stage_id => $stage_data) { + $stage_no = $game->getStageNumber($stage_id); + $form['stage_'.$stage_no]=array( + '#type'=>'fieldset', + '#title'=>t("<b>Stage ${stage_no}</b>") + ); + $header = ($game->isVotingEnabledForStage($stageId) ? $header_voting : $header_novoting); + $form['stage_'.$stage_no]['table']=array( + '#type'=>'markup', + '#value'=>theme('table',$header,$stage_data) + ); + } - $form['stage2']['table']=array( - '#type'=>'markup', - '#value'=>theme('table',$header_stage2,$row_stage2) - ); - if($stage_flag) - { - $form['submit'] = array( - '#type' => 'submit', - '#value' => t('Go to Stage 2') - ); - $stage_flag=FALSE; - } - else - { - $form['submit'] = array( - '#type' => 'submit', - '#value' => t('Next Round') - ); - } - return $form; -} + /* + $form['stage1']['table']=array( + '#type'=>'markup', + '#value'=>theme('table',$header_stage1,$row_stage1) + ); + $form['stage2']=array( + '#type'=>'fieldset', + '#title'=>t('<b>Stage 2</b>') + ); -function teacher_dashboard_multiform_validate($form_id,$form_values) -{ -// $virtual_conduct_id=(int) $form_values['game_id']; -$game= Session::get('game'); - if($form_values['submit']=="Next Round") - { - } -//students should vote initially, then only after students finished voting, teacher can go to next stage. - else if($form_values['submit']=="Go to Stage 2") - { - if($game->isVotingDone()) - { - form_set_error('submit',t('Please tell students to vote. Without voting you can not proceed to Stage 2')); - } - } + $form['stage2']['table']=array( + '#type'=>'markup', + '#value'=>theme('table',$header_stage2,$row_stage2) + ); + */ - return; + if($stage_flag) + { + $form['submit'] = array( + '#type' => 'submit', + '#value' => t('Go to Next Stage') + ); + $stage_flag=FALSE; + } + else + { + $form['submit'] = array( + '#type' => 'submit', + '#value' => t('Next Round') + ); + } + return $form; +} +function teacher_dashboard_multiform_validate($form_id,$form_values) +{ + // $virtual_conduct_id=(int) $form_values['game_id']; + $game= Session::get('game'); + if ($game->isVotingEnabled()) { + if ($game->isVotingDone()) { + form_set_error('submit',t('Please tell students to vote. Without voting you can not proceed to Stage 2')); + } + } } function teacher_dashboard_multiform_submit($form_id,$form_values) { - //for player 3, in stage 2; for even rounds only 1 student will be ramdomely chosen while for uneven rounds 2 students will ve randomely chosen. So, I set flag, when flag=TRUE it means round is even , when flag=FALSE it means that round is uneven. - $round_no=(int) $form_values['round_no']; - $virtual_conduct_id=$form_values['game_id']; - $group_no=0; - //$flag_stage2_3player=FALSE; - //$step=(int) $form_values['step']; - $exp_name=$form_values['exp_name']; - //to avoid teacher clicking the button multiple times. check step and round_no - //drupal_set_message(t('step: '.$form_values['step'].'round no: '.$round_no)); + //for player 3, in stage 2; for even rounds only 1 student will be ramdomely + //chosen while for uneven rounds 2 students will ve randomely chosen. So, I + //set flag, when flag=TRUE it means round is even , when flag=FALSE it means + //that round is uneven. Ja! + $game=Session::get('game'); + //to avoid teacher clicking the button multiple times. check step and round_no + //drupal_set_message(t('step: '.$form_values['step'].'round no: '.$round_no)); - if($form_values['submit']=="Next Round") - { - //if($step== $round_no) - //{ - drupal_set_message(t('in if. exp name: '.$exp_name)); + if($form_values['submit']=="Next Round") + { + $no_rounds = $game->getNumberOfRounds(); + $curr_round_no = $game->getCurrentRoundNo(); + $game->processGroups(); + } + else if($form_values['submit']=="Go to Stage 2") + { //initialise the stage 2 + // drupal_set_message(t('Go to stage 2')); + drupal_set_message(t('Go to stage 2')); + $round_no=1; + $_SESSION['next_stage']='pressed'; + //make initialisation for stage2 + $rule_no=db_result(db_query("select virtualcommons_rule_no from virtualcommons_conducts where id=%d",$virtual_conduct_id)); + $group_no=db_result(db_query(" select virtualcommons_student_group_no from {virtualcommons_forestry_student} where virtualcommons_student_id in (select id from {virtualcommons_student} where virtualcommons_conducts_id=%d) group by virtualcommons_student_group_no",$virtual_conduct_id)); + drupal_set_message(t($group_no .' ' . $virtual_conduct_id)); + $max_resource=db_result(db_query("select max_harvest_decision from virtualcommons_forestry_common_resource_pool where virtualcommons_student_group_no=%d and virtualcommons_conducts_id=%d",$group_no,$virtual_conduct_id)); + db_query("update {virtualcommons_forestry_common_resource_pool} set common_resource_pool=%d, harvest_decision=%d where virtualcommons_student_group_no=%d and virtualcommons_conducts_id=%d",$max_resource,$harvest_decision,$group_no,$virtual_conduct_id); - // FIXME - $stage_no=db_result(db_query("select virtualcommons_stage_no from virtualcommons_conducts where id=%d",$virtual_conduct_id)); - $exp_id=db_result(db_query("Select id from virtualcommons_experiments where exp_name='Forestry Game' ")); - $curr_stage_no=(int)$stage_no; - $no_rounds=db_result(db_query("select no_of_rounds from virtualcommons_stage where virtualcommons_experiments_id=%d and stage_no=%d",$exp_id,$curr_stage_no)); - $no_rounds=(int) $no_rounds; + $result_group=db_query("select count(group_no) AS cnt,group_no from {virtualcommons_student} where virtualcommons_conducts_id= %d group by group_no",$virtual_conduct_id); - - $result=db_query(" select max(round_no) as round_no,virtualcommons_student_group_no,virtualcommons_stage_no from {virtualcommons_forestry_student} where virtualcommons_student_id in (select id from {virtualcommons_student} where virtualcommons_conducts_id=%d) group by virtualcommons_student_group_no",$virtual_conduct_id); - // drupal_set_message(t($result)); - while($data=db_fetch_object($result)) + if($rule_no==1) + { + while($data=db_fetch_object($result_group)) + { + $no_of_student=$data->cnt; + $group_no=$data->group_no; + if($no_of_student==3) { - $round_no=$data->round_no; - $group_no=$data->virtualcommons_student_group_no; - $curr_stage_no=$data->virtualcommons_stage_no; - drupal_set_message(t('no of rounds: '. $no_rounds.'curr round no'.$round_no)); + if(($round_no%2)==0) //even + { + $stud=rand(1,$no_of_student); + drupal_set_message(t('1 insert')); + db_query("insert into {virtualcommons_forestry_turn_sequence} + (virtualcommons_stage_no,round_no,virtualcommons_student_group_no,virtualcommons_rules_no,turn_sequence,virtualcommons_conducts_id) + values (%d,%d,%d,%d,'%s',%d)",2,$round_no,$group_no,$rule_no,$stud,$virtual_conduct_id); + } + else //uneven + { + $stud1=rand(1,$no_of_student); + $stud2=rand(1,$no_of_student); - if($no_rounds >= $round_no) + while($stud1 == $stud2) { - //stage 1 is going on. retrive values from stage1 - drupal_set_message(t('forestry stage1')); - $result= db_query("Select common_resource_pool,max_harvest_decision from virtualcommons_forestry_common_resource_pool where virtualcommons_student_group_no=%d and virtualcommons_conducts_id=%d",$group_no,$virtual_conduct_id); - while($data=db_fetch_object($result)) - { - $resource_available=(int) $data->common_resource_pool; - $max_resource=(int) $data->max_harvest_decision; - - } - - //get the total harvest decision - $harvest_decision= db_result(db_query("Select harvest_decision from virtualcommons_forestry_common_resource_pool where virtualcommons_student_group_no=%d and virtualcommons_conducts_id=%d",$group_no,$virtual_conduct_id)); - $harvest_decision=(int) $harvest_decision; - $resources_before=$resource_available; - - //subtract the total harvest decision for that round from the resources - $temp=$resource_available - $harvest_decision; - - - //assign 10% of the available resource - $temp_resource_available=(int) ($temp/10); - $resource_available=$temp + $temp_resource_available; - - if($resource_available >= $max_resource) - $resource_available=$max_resource; - - db_query("Insert into {virtualcommons_forestry_group_information}(round_no,virtualcommons_conducts_id,virtualcommons_student_group_no,total_harvest_decision,resources_before,resources_after,virtualcommons_stage_no) values(%d,%d,%d,%d,%d,%d,%d)",$round_no,$virtual_conduct_id,$group_no,$harvest_decision,$resources_before,$resource_available,1); - - $harvest_decision=0; - //update the virtualcommons_forestry_common_resource_pool and virtualcommons_student - db_query("update {virtualcommons_forestry_common_resource_pool} set common_resource_pool=%d, harvest_decision=%d where virtualcommons_student_group_no=%d and virtualcommons_conducts_id=%d",$resource_available,$harvest_decision,$group_no,$virtual_conduct_id); - - - - //update the virtualcommons_forestry_student_stage1 table also - //db_query("update {virtualcommons_forestry_student_stage1} set resources_after=%d where virtualcommons_student_group_no=%d and round_no=%d",$resource_available,$group_no,$round_no); - db_query("update virtualcommons_student set start_flag=true where virtualcommons_conducts_id=%d and group_no=%d",$virtual_conduct_id,$group_no); - if($round_no==$no_rounds) - { //initialise for stage2 - - - } + $stud1=rand(1,$no_of_student); + $stud2=rand(1,$no_of_student); } + $stud=$stud1.$stud2; + drupal_set_message(t('2 insert')); + db_query("insert into {virtualcommons_forestry_turn_sequence} + (virtualcommons_stage_no,round_no,virtualcommons_student_group_no,virtualcommons_rules_no,turn_sequence,virtualcommons_conducts_id) + values (%d,%d,%d,%d,'%s',%d)",2,$round_no,$group_no,$rule_no,$stud,$virtual_conduct_id); + } + } - else - { - //stage2 - drupal_set_message(t('forestry stage2')); - db_query("update virtualcommons_student set start_flag=true where virtualcommons_conducts_id=%d and group_no=%d",$virtual_conduct_id,$group_no); - } - }//end of 2nd while + if($no_of_student==4) + { + $stud1=rand(1,$no_of_student); + $stud2=rand(1,$no_of_student); - } - else if($form_values['submit']=="Go to Stage 2") - { //initialise the stage 2 - // drupal_set_message(t('Go to stage 2')); - drupal_set_message(t('Go to stage 2')); - $round_no=1; - $_SESSION['next_stage']='pressed'; - //make initialisation for stage2 - $rule_no=db_result(db_query("select virtualcommons_rule_no from virtualcommons_conducts where id=%d",$virtual_conduct_id)); - $group_no=db_result(db_query(" select virtualcommons_student_group_no from {virtualcommons_forestry_student} where virtualcommons_student_id in (select id from {virtualcommons_student} where virtualcommons_conducts_id=%d) group by virtualcommons_student_group_no",$virtual_conduct_id)); - drupal_set_message(t($group_no .' ' . $virtual_conduct_id)); - $max_resource=db_result(db_query("select max_harvest_decision from virtualcommons_forestry_common_resource_pool where virtualcommons_student_group_no=%d and virtualcommons_conducts_id=%d",$group_no,$virtual_conduct_id)); - db_query("update {virtualcommons_forestry_common_resource_pool} set common_resource_pool=%d, harvest_decision=%d where virtualcommons_student_group_no=%d and virtualcommons_conducts_id=%d",$max_resource,$harvest_decision,$group_no,$virtual_conduct_id); + while($stud1 == $stud2) + { + $stud1=rand(1,$no_of_student); + $stud2=rand(1,$no_of_student); + } + $stud=$stud1.$stud2; + drupal_set_message(t('3 insert')); + db_query("insert into {virtualcommons_forestry_turn_sequence} + (virtualcommons_stage_no,round_no,virtualcommons_student_group_no,virtualcommons_rules_no,turn_sequence,virtualcommons_conducts_id) + values (%d,%d,%d,%d,'%s',%d)",2,$round_no,$group_no,$rule_no,$stud,$virtual_conduct_id); + } - $result_group=db_query("select count(group_no) AS cnt,group_no from {virtualcommons_student} where virtualcommons_conducts_id= %d group by group_no",$virtual_conduct_id); - if($rule_no==1) + if($no_of_student==5) { - while($data=db_fetch_object($result_group)) - { - $no_of_student=$data->cnt; - $group_no=$data->group_no; - if($no_of_student==3) - { - if(($round_no%2)==0) //even - { - $stud=rand(1,$no_of_student); - drupal_set_message(t('1 insert')); - db_query("insert into {virtualcommons_forestry_turn_sequence} - (virtualcommons_stage_no,round_no,virtualcommons_student_group_no,virtualcommons_rules_no,turn_sequence,virtualcommons_conducts_id) - values (%d,%d,%d,%d,'%s',%d)",2,$round_no,$group_no,$rule_no,$stud,$virtual_conduct_id); - } - else //uneven - { - $stud1=rand(1,$no_of_student); - $stud2=rand(1,$no_of_student); + $stud1=rand(1,$no_of_student); + $stud2=rand(1,$no_of_student); - while($stud1 == $stud2) - { - $stud1=rand(1,$no_of_student); - $stud2=rand(1,$no_of_student); - } - $stud=$stud1.$stud2; - drupal_set_message(t('2 insert')); - db_query("insert into {virtualcommons_forestry_turn_sequence} - (virtualcommons_stage_no,round_no,virtualcommons_student_group_no,virtualcommons_rules_no,turn_sequence,virtualcommons_conducts_id) - values (%d,%d,%d,%d,'%s',%d)",2,$round_no,$group_no,$rule_no,$stud,$virtual_conduct_id); - } - } + while($stud1 == $stud2) + { + $stud1=rand(1,$no_of_student); + $stud2=rand(1,$no_of_student); + } + $stud=$stud1.$stud2; + drupal_set_message(t('4 insert')); + db_query("insert into {virtualcommons_forestry_turn_sequence} + (virtualcommons_stage_no,round_no,virtualcommons_student_group_no,virtualcommons_rules_no,turn_sequence,virtualcommons_conducts_id) + values (%d,%d,%d,%d,'%s',%d)",2,$round_no,$group_no,$rule_no,$stud,$virtual_conduct_id); + } - if($no_of_student==4) - { - $stud1=rand(1,$no_of_student); - $stud2=rand(1,$no_of_student); + }//end of while - while($stud1 == $stud2) - { - $stud1=rand(1,$no_of_student); - $stud2=rand(1,$no_of_student); - } - $stud=$stud1.$stud2; - drupal_set_message(t('3 insert')); - db_query("insert into {virtualcommons_forestry_turn_sequence} - (virtualcommons_stage_no,round_no,virtualcommons_student_group_no,virtualcommons_rules_no,turn_sequence,virtualcommons_conducts_id) - values (%d,%d,%d,%d,'%s',%d)",2,$round_no,$group_no,$rule_no,$stud,$virtual_conduct_id); - } - - - if($no_of_student==5) - { - $stud1=rand(1,$no_of_student); - $stud2=rand(1,$no_of_student); - - while($stud1 == $stud2) - { - $stud1=rand(1,$no_of_student); - $stud2=rand(1,$no_of_student); - } - $stud=$stud1.$stud2; - drupal_set_message(t('4 insert')); - db_query("insert into {virtualcommons_forestry_turn_sequence} - (virtualcommons_stage_no,round_no,virtualcommons_student_group_no,virtualcommons_rules_no,turn_sequence,virtualcommons_conducts_id) - values (%d,%d,%d,%d,'%s',%d)",2,$round_no,$group_no,$rule_no,$stud,$virtual_conduct_id); - - } - - - }//end of while - - }//end of rule 1 - else if($rule_no==2) - { - } - else if($rule_no==3) - { - } - } - return 'teacher_dashboard'; - + }//end of rule 1 + else if($rule_no==2) + { } + else if($rule_no==3) + { + } + } + return 'teacher_dashboard'; + } + This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |