[virtualcommons-svn] SF.net SVN: virtualcommons:[41] vcweb/trunk/virtualcommons/experiment
Status: Beta
Brought to you by:
alllee
From: <see...@us...> - 2008-08-15 00:15:05
|
Revision: 41 http://virtualcommons.svn.sourceforge.net/virtualcommons/?rev=41&view=rev Author: seematalele Date: 2008-08-15 00:15:12 +0000 (Fri, 15 Aug 2008) Log Message: ----------- Made some changes in experiment.inc and teacher_dashboard and forestry_v2.module in order to work stage transition smoothly. Rule 1 is working correctly. Modified Paths: -------------- vcweb/trunk/virtualcommons/experiment/experiment.inc vcweb/trunk/virtualcommons/experiment/experiment.module vcweb/trunk/virtualcommons/experiment/games/forestry_v2/forestry_v2.module vcweb/trunk/virtualcommons/experiment/teacher_dashboard/teacher_dashboard.module Modified: vcweb/trunk/virtualcommons/experiment/experiment.inc =================================================================== --- vcweb/trunk/virtualcommons/experiment/experiment.inc 2008-08-14 00:12:32 UTC (rev 40) +++ vcweb/trunk/virtualcommons/experiment/experiment.inc 2008-08-15 00:15:12 UTC (rev 41) @@ -150,7 +150,7 @@ public function isVotingEnabled() { $flag=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)); - drupal_set_message(t('Voting Flag is: '.$flag)); + // drupal_set_message(t('Voting Flag is: '.$flag)); return $flag; } @@ -158,11 +158,37 @@ return db_result(db_query("select voting from vc_stage where id=%d", $stage_id)); } - public function isVotingDone() + //determine if rule is selected for every group + public function isRuleSelected() { $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; } + //determine whether all students have done voting. + public function isVotingDone() + { + $flag=0; + $result_group_id=db_query("select id from vc_group where vc_game_id=%d",$this->game_id); + while($data=db_fetch_object($result_group_id)) + { + $stud_voting_cnt=db_result(db_query("select count(*) from vc_student_voting v where v.vc_student_id in (select id from vc_student where vc_group_id=%d)",$data->id)); + $actual_student=db_result(db_query(" select count(*) from vc_student where vc_group_id=%d",$data->id)); + // drupal_set_message(t('stud_voting_cnt: '. $stud_voting_cnt)); + //drupal_set_message(t('actual students are: '.$actual_student)); + if($stud_voting_cnt==$actual_student) + { + $flag=1; + } + else + { + $flag=0; + drupal_set_message(t('else Flag is: '.$flag)); + } + + } + drupal_set_message(t('isvotingDone Flag is: '.$flag)); + return $flag; + } // FIXME: turn into $forestryGame->init() overloaded method public function initForestry() { @@ -304,23 +330,27 @@ private function generate_default_decisions($group_id, $round_no, $stage_id) { $result = db_query('SELECT id FROM vc_student WHERE vc_group_id=%d', $group_id); - + drupal_get_messages(); while ($fetch_object = db_fetch_object($result)) { $student_id = $fetch_object->id; $harvest_decision = db_result(db_query("SELECT harvest_decision FROM vc_forestry_student WHERE vc_student_id='%s' AND round_no=%d AND vc_stage_id=%d", $student_id, $round_no, $stage_id)); - if (! $harvest_decision) { - $this->insert_default_decision($student_id, $round_no); + + drupal_set_message("harvest decision is submitted is student :" . $harvest_decision); + if ($harvest_decision == '') + { + drupal_set_message("if harvest decision is submitted is empty :" . $harvest_decision); + $this->insert_default_decision($student_id, $round_no,$stage_id); } } } - private function insert_default_decision($student_id, $round_no) { + private function insert_default_decision($student_id, $round_no,$stage_id) { // FIXME: how will this work for IrrigationStudent or FisheryStudent $student = new ForestryStudent($student_id); - $student->save($round_no, DEFAULT_HARVEST_DECISION); + $student->save($round_no, DEFAULT_HARVEST_DECISION, $stage_id); } @@ -368,7 +398,7 @@ } $selected_rule_id=db_result(db_query("select vc_selected_rules_id from vc_group where id=%d",$group_id)); // db_query("insert into {vc_forestry_group_round_info}(vc_rules_id,dice) values (%d,%d) where vc_game_id=%d and vc_stage_id=%d and vc_group_id=%d",$selected_rule_id,$dice,$this->game_id,$stage_id,$group_id); - $this->initRules(); + //$this->initRules(); 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,vc_rules_id,dice) values(%d,%d,%d,%d,%d,%d,%d,%d,%d)", $round_no,$this->game_id,$group_id,$stage_id,$total_harvest_decision,$resources_before,$resources_available,$selected_rule_id,$dice); @@ -388,12 +418,12 @@ if (! $this->isLastRound()) { $this->updateStartFlag(true); } - $this->prev_round_no=$round_no; + // $this->prev_round_no=$round_no; //update current round_no $round_no=$round_no+1; $this->current_round_no = $round_no; - drupal_set_message(t('Round no which is over is :' . $this->prev_round_no . 'Current round no set to is: ' . $this->current_round_no)); + // drupal_set_message(t('Round no which is over is :' . $this->prev_round_no . 'Current round no set to is: ' . $this->current_round_no)); //call setRound function /* if ($round_no > ($this->getNumberOfRounds())) { // reset round number to 1 @@ -463,14 +493,15 @@ $result_resource=db_query("select max_resources,vc_group_id from vc_forestry_common_resource_pool where vc_game_id=%d",$this->game_id); while($data=db_fetch_object($result_resource)) { - db_query("update {vc_forestry_common_resource_pool} set common_resource_pool=%d where vc_group_id=%d and vc_game_id=%d",$data->max_resources,$data->vc_group_id,$this>game_id); + db_query("update vc_forestry_common_resource_pool set common_resource_pool=%d where vc_group_id=%d and vc_game_id=%d",$data->max_resources,$data->vc_group_id,$this>game_id); drupal_set_message("vc_forestry_common_resource_pool si updated for group id, max resources: " . $data->vc_group_id . ', ' . $data->max_resources . ', ' . $this->game_id ); } + $this->setRoundNo($this->getCurrentRoundNo()); + } - + public function assign_Rules_To_Groups() + { //determine the rule for a group - - $result_group=db_query("select id from vc_group where vc_game_id=%d",$this->game_id); while($data=db_fetch_object($result_group)) { @@ -488,59 +519,66 @@ //$voting[$data->vc_rules_id]=$data->rule_cnt; } - //drupal_set_message(t('count of an array is :' . count($rule_cnt))); - for($i=0;$i<count($rule_cnt);$i++)//for1 + drupal_set_message(t('count of an array is :' . count($rule_cnt))); + if(count($rule_cnt)==1) { - for($j=$i+1;$j<count($rule_cnt);$j++)//for2 - { + $max_rule_cnt=$rule_cnt[0]; + $max_rule_id=$rule_id[0]; + drupal_set_message(t( 'NOT Tie' . '$max_rule_id: ' . $max_rule_id)); + db_query("update vc_group set vc_selected_rules_id =%d where id=%d",$max_rule_id,$group_id); + } + else + { + for($i=0;$i<count($rule_cnt);$i++)//for1 + { + for($j=$i+1;$j<count($rule_cnt);$j++)//for2 + { + if($rule_cnt[$i]<$rule_cnt[$j]) + { + if($max_rule_cnt < $rule_cnt[$j]) + { + $max_rule_cnt=$rule_cnt[$j]; + $max_rule_id=$rule_id[$j]; + drupal_set_message(t( '$max_rule_id is : ' . $rule_id[$j])); + } + } + else + { - - if($rule_cnt[$i]<$rule_cnt[$j]) - { - if($max_rule_cnt < $rule_cnt[$j]) - { - $max_rule_cnt=$rule_cnt[$j]; - $max_rule_id=$rule_id[$j]; - drupal_set_message(t( '$max_rule_id is : ' . $rule_id[$j])); - } - } - else - { - - if($rule_cnt[$i]==$rule_cnt[$j]) - { + if($rule_cnt[$i]==$rule_cnt[$j]) + { //echo '<br/>Equal $i ' . $i. ' $j ' .$j; - array_push($tie_rules,$rule_id[$i],$rule_id[$j]); - $tie_rule_cnt=$rule_cnt[$i]; - drupal_set_message(t('rule cnt i: '. $tie_rules[$i] . 'rule cnt j: '.$tie_rules[$j])); - } - else if($max < $rule_cnt[$i]) - { - $max_rule_cnt=$rule_cnt[$i]; - $max_rule_id=$rule_id[$i]; - drupal_set_message(t( '$max_rule_id is : ' . $rule_id[$i])); - } - } + array_push($tie_rules,$rule_id[$i],$rule_id[$j]); + $tie_rule_cnt=$rule_cnt[$i]; + drupal_set_message(t('rule cnt i: '. $tie_rules[$i] . 'rule cnt j: '.$tie_rules[$j])); + } + else if($max < $rule_cnt[$i]) + { + $max_rule_cnt=$rule_cnt[$i]; + $max_rule_id=$rule_id[$i]; + drupal_set_message(t( '$max_rule_id is : ' . $rule_id[$i])); + } + } - } + } - }//end of for1 - + }//end of for1 + //echo '<br/> Max: '. $max ; - drupal_set_message(t( '$max_rule_cnt is : ' . $max_rule_cnt)); - if(($max_rule_cnt==$tie_rule_cnt) || ($max_rule_cnt==0)) - { - drupal_set_message(t( 'Tie')); + drupal_set_message(t( '$max_rule_cnt is : ' . $max_rule_cnt)); + if(($max_rule_cnt==$tie_rule_cnt) || ($max_rule_cnt==0)) + { + drupal_set_message(t( 'Tie')); - } - else - { - drupal_set_message(t( 'NOT Tie' . '$max_rule_id: ' . $max_rule_id)); - db_query("update vc_group set vc_selected_rules_id =%d where id=%d",$max_rule_id,$group_id); - } + } + else + { + drupal_set_message(t( 'NOT Tie' . '$max_rule_id: ' . $max_rule_id)); + db_query("update vc_group set vc_selected_rules_id =%d where id=%d",$max_rule_id,$group_id); + } // drupal_set_message(t('Rule id : ' . $final_rule_id.'Group id is: ' . $group_id)); - + } }//end of while @@ -554,10 +592,16 @@ drupal_set_message("no of students need to be selected for this round are :" . $how_many); $keys = array_rand( range(1, $no_of_students), $how_many ); $turn_sequence = array(); - foreach ($keys as $key) { - $turn_sequence[] = $students[$key]; - } - return $turn_sequence; + + for($i=0;$i<count($keys);$i++) + { + drupal_set_message($students[$i]); + $turn_sequence[] = $students[$i]; + } + + + return $turn_sequence; + } public function initRules() @@ -786,25 +830,8 @@ db_result(db_query("select description select vc_selected_rules_id from vc_group where id=%d",$this->group_id)); }*/ - public function isTurn($stud_id) - { - $flag=FALSE; - if(!($this->isGameFinished())) - { - $valid_id=$this->game->getValidStudentIds($this->group_id); - drupal_set_message(t('Group id is : '. $this->group_id. 'Student Id is : '. $stud_id . ' Valid student ids are: ' . $valid_id[0] . ',' . $valid_id[1])); - if(in_array($stud_id,$valid_id)) - { - $flag= TRUE; - } - } - else - $flag= FALSE; - drupal_set_message(t('flag for student turn : '. $flag)); - return $flag; - } + - }//end of Group /** @@ -854,7 +881,7 @@ $stage_ids = $game->getAllStageIds(); $all_data = array(); foreach ($stage_ids as $stage_id) { - $all_data[] = $this->getStageData($stage_id); + $all_data[$stage_id][] = $this->getStageData($stage_id); } return $all_data; } @@ -941,15 +968,20 @@ } */ - public function save($round_no, $harvest_decision) + public function save($round_no, $harvest_decision,$stage_id=0) { - $stage_id = $this->getGroup()->getGame()->getCurrentStageId(); + drupal_set_message($stage_id); + if($stage_id <> 0) + { + // $stage_id = $this->getGroup()->getGame()->getCurrentStageId(); + } $total = db_result(db_query("SELECT sum(harvest_decision) FROM {vc_forestry_student} WHERE vc_student_id='%s' AND vc_stage_id=%d", $this->stud_id, $stage_id)); + $total=$total+$harvest_decision; db_query("INSERT INTO {vc_forestry_student} (round_no,vc_student_id,vc_stage_id,harvest_decision, total_points) VALUES (%d,'%s',%d,%d, %d)", $round_no,$this->stud_id,$stage_id,$harvest_decision, $total); } @@ -969,8 +1001,26 @@ return $this->getGroup()->getGame()->isVotingEnabled() && $this->getGroup()->isTieHappened(); } + + public function isTurn() + { + $flag=FALSE; + if(!($this->getGroup()->isGameFinished())) + { + $valid_id=$this->getGroup()->getGame()->getValidStudentIds($this->getGroup()->getId()); + drupal_set_message(t('Group id is : '. $this->group_id. 'Student Id is : '. $this->stud_id . ' Valid student ids are: ' . $valid_id[0] . ',' . $valid_id[1])); + if(in_array($this->stud_id,$valid_id)) + { + $flag= TRUE; + } + } + else + $flag= FALSE; + drupal_set_message(t('flag for student turn : '. $flag)); + return $flag; + } + - /* XXX: unsafe operation, should only be set by the facilitator (teacher) public function updateStageId($stage_no,$experiment_id,$game_id) { Modified: vcweb/trunk/virtualcommons/experiment/experiment.module =================================================================== --- vcweb/trunk/virtualcommons/experiment/experiment.module 2008-08-14 00:12:32 UTC (rev 40) +++ vcweb/trunk/virtualcommons/experiment/experiment.module 2008-08-15 00:15:12 UTC (rev 41) @@ -196,10 +196,10 @@ $form['#id']='studentgroup'; $game=Session::get('game'); $exp_name = $game->getExperimentName(); - drupal_set_message(t("experiment name: " . $exp_name)); +// drupal_set_message(t("experiment name: " . $exp_name)); $no_of_student = $game->getNumberOfStudents(); - drupal_set_message(t("num students: " . $no_of_student)); + //drupal_set_message(t("num students: " . $no_of_student)); $no_of_groups=0; $groups_3=0; $groups_4=0; @@ -319,7 +319,7 @@ $form['game_info']=array( '#type'=>'fieldset', - '#title'=>t('Experiment Information'), + '#title'=>t('<b>Experiment Information</b>'), '#tree' => TRUE ); @@ -332,7 +332,7 @@ $form['group_info']=array( '#type'=>'fieldset', - '#title'=>t('Group Information'), + '#title'=>t('<b>Group Information</b>'), '#tree' => TRUE ); Modified: vcweb/trunk/virtualcommons/experiment/games/forestry_v2/forestry_v2.module =================================================================== --- vcweb/trunk/virtualcommons/experiment/games/forestry_v2/forestry_v2.module 2008-08-14 00:12:32 UTC (rev 40) +++ vcweb/trunk/virtualcommons/experiment/games/forestry_v2/forestry_v2.module 2008-08-15 00:15:12 UTC (rev 41) @@ -96,16 +96,23 @@ function generate_all_results_table() { $student = Session::get('student'); $table_data_array = $student->getAllStageData(); - $result = '<fieldset><legend><b>Round Results</b></legend>'; + //$result = '<fieldset><legend><b>Round Results</b></legend>'; if ($student->getGroup()->getGame()->getCurrentRoundNo() == 1) { - $result .= 'No results available yet for the first round'; + $result = 'No results available yet for the first round'; } else { - foreach ($table_data_array as $table_data) { - $result .= theme_table($table_data->header, $table_data->rows); + foreach ($table_data_array as $stage_id=>$table_data) { + $stage_no = $student->getGroup()->getGame()->getStageNumber($stage_id); + $result.='<fieldset><legend><b>Stage '.$stage_no.'</b></legend>'; + foreach($table_data as $key=>$value) + { + + $result .= theme_table($value->header, $value->rows); + } + $result .= '</fieldset>'; } } - $result .= '</fieldset>'; +// $result .= '</fieldset>'; return $result; } @@ -136,7 +143,7 @@ } $group = $student->getGroup(); if ($group->getGame()->isFinished()) { - $output = 'The experiment is now over. Your results are listed below. Thanks for participating!'; + $output = '<br/><h3 align="center" style="color:#990000">The experiment is now over. Your results are listed below. Thanks for participating!</h3><br/>'; $output .= generate_all_results_table(); } else if ($student->shouldVote()) @@ -147,6 +154,7 @@ { $output .= generate_harvest_table(); $output .= generate_results_table(); + $output .= ( $student->canStart() ) ? drupal_get_form('forestry_play_multiform') : drupal_get_form('forestry_wait_form'); } return $output; @@ -167,6 +175,19 @@ $round_no = $group->getGame()->getCurrentRoundNo(); +if($student->getGroup()->getGame()->isVotingEnabled()) +{ + + if($student->isTurn()) + { + $form['turn']=array( + '#type'=>'item', + '#value'=>t('You have been chosen for this round. You can harvest.') + + ); + + } +} //store the round no in hidden field $form['round_no']=array( '#type'=>'hidden', @@ -302,37 +323,11 @@ $round_no=$form_values['round_no']; - /* - //get the student and set it - $stud_id=$_SESSION['student_id']; - $student=new ForestryStudent(); - $student->setStudentId($stud_id); - $stage_id=$group->getCurrentStageId(); - $resources_before=(int) $_SESSION['prev_resource']; - drupal_set_message(t('resource_before:'. $resources_before)); - $student->setStageId($stage_id); - */ - - - $student->save($round_no,$stud_harvest_decision); + + $student->save($round_no,$stud_harvest_decision,$group->getGame()->getCurrentStageId()); $student->updateStartFlag(false); return 'forestry/play'; - /* - $no_rounds=$group->getNumberOfRounds(); - if($form_values['indicator']['submit']=="Next Stage") - { - //$stage_no=2; - // $exp_id=$group->getExperimentId(); - //$game_id=$group->getGameId(); - drupal_set_message("in next stage button functionality"); - unset($_SESSION['prev_resource']); - - return 'rules'; - } - else - return 'forestry_stage1_part2'; - */ } function theme_forestry_play_multiform($form) Modified: vcweb/trunk/virtualcommons/experiment/teacher_dashboard/teacher_dashboard.module =================================================================== --- vcweb/trunk/virtualcommons/experiment/teacher_dashboard/teacher_dashboard.module 2008-08-14 00:12:32 UTC (rev 40) +++ vcweb/trunk/virtualcommons/experiment/teacher_dashboard/teacher_dashboard.module 2008-08-15 00:15:12 UTC (rev 41) @@ -103,9 +103,9 @@ else { if ($game->isVotingEnabled()) { - if (!($game->isVotingDone())) + if (!($game->isRuleSelected())) { - $stage_flag=TRUE; + $start_flag=TRUE; } } else @@ -123,7 +123,18 @@ '#value' => ($stage_flag) ? t('Go to Next Stage') : t('Next Round'), '#attributes' => array('onClick' => 'return confirm("Go to the next round? Any participants with unsubmitted harvest decisions will receive a default harvest decision.")') ); + if($start_flag) + { + drupal_set_message(t('This stage needs voting. Please tell students to vote.'),'warning',FALSE); + $form['submit'] = array( + '#type' => 'submit', + '#value' => t('Start Stage') + ); + // unset($_SESSION['next_stage']); + + } + } return $form; @@ -134,8 +145,8 @@ { // $virtual_conduct_id=(int) $form_values['game_id']; $game= Session::get('game'); - drupal_set_message(t($form_values['submit'])); - /* if($form_values['submit']=="Go to Next Stage") + // drupal_set_message(t($form_values['submit'])); + /* if($form_values['submit']=="Start Stage") { if (($game->isVotingEnabled())) { @@ -167,13 +178,12 @@ { //initialise the stage 2 - drupal_set_message(t('Go to stage 2')); + // drupal_set_message(t('Go to stage 2')); // FIXME: initNextStage is actually an initialization for voting stage - // remove that assumption - - $game->setRoundNo($game->getCurrentRoundNo()); $game->initNextStage(); - if ($game->isVotingEnabled()) + + /*if ($game->isVotingEnabled()) { if ($game->isVotingDone()) { @@ -182,10 +192,28 @@ else form_set_error('submit',t('Please tell students to vote. Without voting you can not proceed to Stage 2')); - } - + }*/ +// $_SESSION['next_stage']='pressed'; } + else if($form_values['submit']=="Start Stage") + { + if ($game->isVotingEnabled()) + { + if($game->isvotingDone()) + { + if(! $game->isRuleSelected()) + { + $game->assign_Rules_To_Groups(); + $rule_no=$game->initRules(); + } + } + else + form_set_error('submit',t('Please tell students to vote. Without voting you can not proceed to Stage 2')); + + } + //$game->is_Rule_Selected_For_All_Groups(); + } return 'teacher_dashboard'; } This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |