[virtualcommons-svn] SF.net SVN: virtualcommons:[44] vcweb/trunk/virtualcommons/experiment
Status: Beta
Brought to you by:
alllee
From: <see...@us...> - 2008-08-18 23:05:37
|
Revision: 44 http://virtualcommons.svn.sourceforge.net/virtualcommons/?rev=44&view=rev Author: seematalele Date: 2008-08-18 23:05:42 +0000 (Mon, 18 Aug 2008) Log Message: ----------- rule 2 and rule 3 are working properly for 3,4,5 groups and vc_tie table is created.Values are inserted into the vc_tie table properly. Modified Paths: -------------- vcweb/trunk/virtualcommons/experiment/experiment.inc vcweb/trunk/virtualcommons/experiment/rules/rules.install vcweb/trunk/virtualcommons/experiment/survey/survey.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-18 06:44:06 UTC (rev 43) +++ vcweb/trunk/virtualcommons/experiment/experiment.inc 2008-08-18 23:05:42 UTC (rev 44) @@ -236,7 +236,8 @@ $resources_after=$data->resources_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); + + array_push($group_round_data, db_result(db_query("select rule_no from vc_rules where id=%d",$data->vc_rules_id)), $data->dice); } $stage_data[$stage_id][] = $group_round_data; } @@ -273,10 +274,8 @@ } public function getTurnSequence($group_id) { - return db_result(db_query('select turn_sequence - FROM vc_forestry_turn_sequence s, vc_group gr, vc_game ga - WHERE s.vc_group_id=%d AND ga.id=gr.vc_game_id AND ga.current_round_no=s.round_no AND s.vc_rules_id=gr.vc_selected_rules_id', - $group_id)); + return db_result(db_query(' select turn_sequence from vc_forestry_turn_sequence where vc_group_id=%d and vc_game_id=%d and round_no=%d', + $group_id,$this->game_id,$this->getCurrentRoundNo())); } public function getValidStudentIds($group_id) { @@ -301,7 +300,8 @@ WHERE fs.harvest_decision > 0 AND s.vc_group_id=%d AND fs.round_no=%d - AND s.turn_no NOT IN (%s)', $group_id, $this->getCurrentRoundNo(), $turn_sequence); + AND fs.vc_stage_id=%d + AND s.turn_no NOT IN (%s)', $group_id, $this->getCurrentRoundNo(),$this->getCurrentStageId(), $turn_sequence); while ($data = db_fetch_object($result)) { $fine = $data->harvest_decision + 3; $dice = 6; @@ -313,32 +313,29 @@ } private function assessFines($group_id, $current_rule_number) { - switch ($current_rule_number) { + switch ($current_rule_number) + { case 1: case 2: - $this->assessTurnSequenceFines($group_id); - break; + $this->assessTurnSequenceFines($group_id); + break; case 3: - $students=db_query("select id from vc_student where vc_group_id=%d",$group_id); - while($student_data=db_fetch_object($students)) - { - $result=db_query("Select id,harvest_decision,total_points from vc_forestry_student - where vc_student_id='%s' and round_no=%d ",$student_data->id,$this->getCurrentRoundNo()); - if($data=db_fetch_object($result)) + //$students=db_query("select id from vc_student where vc_group_id=%d",$group_id); + $result = db_query("SELECT fs.id, fs.harvest_decision, fs.total_points + FROM vc_forestry_student fs INNER JOIN vc_student s ON fs.vc_student_id=s.id + WHERE fs.harvest_decision > 2 + AND s.vc_group_id=%d + AND fs.round_no=%d + AND fs.vc_stage_id=%d", + $group_id, $this->getCurrentRoundNo(),$this->getCurrentStageId()); + while($data=db_fetch_object($result)) { - if($data->harvest_decision > 2) - { - $fine = $data->harvest_decision + 3; - $total_points = $data->total_points - $fine; - db_query('UPDATE vc_forestry_student SET fine=%d, total_points=%d - WHERE id=%d', $fine, $total_points, $data->id); - } - + $fine = $data->harvest_decision + 3; + $total_points = $data->total_points - $fine; + db_query('UPDATE vc_forestry_student SET fine=%d, total_points=%d + WHERE id=%d', $fine, $total_points, $data->id); } - - } - - break; + break; default: form_set_error(t('Current rule number is invalid: ' . $current_rule_number)); break; @@ -407,7 +404,7 @@ { // roll the dice $dice = rand(1, 6); - // $dice = 6; + $dice = 6; if ($dice == 6) { // check to see if we need to assess fines @@ -572,15 +569,22 @@ //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')); + + $tie=implode(',',$tie_rules); + drupal_get_messages(); + drupal_set_message(t( 'Tie happened in Group no: ' . $group_id .'.<br> Rules are :' . $tie),'warning'); + db_query("Insert into {vc_tie} (vc_group_id,tie_rules_id) values (%d,'%s')",$group_id,$tie); + return TRUE; } 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); + db_query("update vc_group set vc_selected_rules_id =%d where id=%d",$max_rule_id,$group_id); + return FALSE; } // drupal_set_message(t('Rule id : ' . $final_rule_id.'Group id is: ' . $group_id)); @@ -589,6 +593,11 @@ }//end of init function + + public function saveTie() + { + + } // several ways to implement this - // 1. use array_rand to get a set of random keys into the array @@ -695,14 +704,14 @@ $prev_round_no=$round_no-1; $turn_seq=array(); //get the sequnce number for the last round number, determine the sequence - $seq=db_query("Select turn_sequence from vc_forestry_turn_sequence where vc_game_id=%d and vc_group_id=%d and round_no=%d and vc_rules_id=%d",$this->game_id,$group_id,$prev_round_no,$selected_rule_id); + $seq=db_result(db_query("Select turn_sequence from vc_forestry_turn_sequence where vc_game_id=%d and vc_group_id=%d and round_no=%d and vc_rules_id=%d",$this->game_id,$group_id,$prev_round_no,$selected_rule_id)); $temp_seq=explode(',',$seq); $last_element=end($temp_seq); for($j=0;$j<$how_many;$j++) { if($last_element<$no_of_student) { - $turn_seq[]=$last_element++; + $turn_seq[]=++$last_element; } else { @@ -710,8 +719,9 @@ $last_element=1; } } + $turn_sequence = implode(',',$turn_seq); } - $turn_sequence = implode(',',$turn_seq); + break; default: @@ -787,9 +797,6 @@ return new TableData(array('Resource Level', 'Maximum Harvest Decision'), $data); } - - - public function getTurnSequence() { return $this->game->getTurnSequence($this->group_id); } @@ -842,23 +849,26 @@ public function getSelectedRule() { $result_rule=db_query("select rule_no, description from vc_rules r, vc_group g where r.id =g.vc_selected_rules_id and g.id=%d",$this->group_id); - //$rule=array(); + $rule=array(); if ($data_rule=db_fetch_object($result_rule)) { - $rule[]=array($data_rule->rule_no); - $rule[]=array($data_rule->description); + //$rule[]=array($data_rule->rule_no); + //$rule[]=array($data_rule->description); + array_push($rule,$data_rule->rule_no,$data_rule->description); //drupal_set_message(t($data_rule->description)); } // drupal_set_message(t('Description is:' . $rule[1][0] )); return $rule; } - public function getRuleNo() + /*public function getRuleNo() { + $result_voting=db_query(" select vc_rules_id, count(vc_rules_id) from vc_student_voting v where v.time_created >= (select max(time_created) from vc_student_voting vv where v.vc_student_id=vv.vc_student_id) and - v.vc_student_id in (select id from vc_student where vc_group_id=%d) group by vc_rules_id",$group_id); - $rule_id=array(); + v.vc_student_id in (select id from vc_student where vc_group_id=%d) group by vc_rules_id",$group_id); + $result_voting=db_result(db_query("select tie_rules_id from vc_tie where vc_group_id=%d ",$this->group_id)); + $rule_id=array(); $rule_cnt=array(); $final_rule_no=array(); while($data=db_fetch_object($result_voting)) @@ -884,7 +894,26 @@ } //drupal_set_message(t('Rule no : ' . $final_rule_no[0].' ' .$final_rule_no[1]. 'Group id is: ' . $this->group_id)); return $final_rule_no; + }*/ + + public function getRuleNo() + { + + $result_voting=db_result(db_query("select tie_rules_id from vc_tie where vc_group_id=%d ",$this->group_id)); + $rule_id=array(); + $final_rule_no=array(); + $rule_id=explode(',',$result_voting); + drupal_set_message(t('Tie Rules are : ' . $result_voting)); + for($i=0;$i<count($rule_id);$i++) + { + array_push($final_rule_no,db_result(db_query("select rule_no from vc_rules where id =%d",$rule_id[$i]))); + drupal_set_message(t('Tie Rules are : ' . $rule_id[$i] )); + + } + //drupal_set_message(t('Rule no : ' . $final_rule_no[0].' ' .$final_rule_no[1]. 'Group id is: ' . $this->group_id)); + return $final_rule_no; } + public function getResourcesAvailable() { return db_result(db_query('SELECT common_resource_pool @@ -977,9 +1006,10 @@ $decision_table = array(); $voting_enabled=db_result(db_query("select voting from vc_stage where id=%d",$stage_id)); - $round_header = array('Round Number', 'Your Harvest Decision', 'Resources Before', 'Resources After'); + $round_header = array('Round Number', 'Your Harvest Decision', 'Resources Before', 'Resources After','Total Points'); if ($voting_enabled) { - array_push($round_header, 'Penalty', 'Total Points'); + $round_header = array('Round Number', 'Your Harvest Decision', 'Resources Before', 'Resources After','Penalty','Total Points'); + //array_push($round_header, 'Penalty', 'Total Points'); } while($student_data=db_fetch_object($student_decision)) { @@ -1001,9 +1031,10 @@ $resources_after="?"; } - $current_round_data = array($round_no,$harvest_decision,$resources_before,$resources_after); + $current_round_data = array($round_no,$harvest_decision,$resources_before,$resources_after,$total_points); if($voting_enabled) { - array_push($current_round_data, $fine, $total_points); + $current_round_data = array($round_no,$harvest_decision,$resources_before,$resources_after,$fine,$total_points); + //array_push($current_round_data, $fine, $total_points); } $round_data[] = $current_round_data; } @@ -1057,12 +1088,13 @@ { // $stage_id = $this->getGroup()->getGame()->getCurrentStageId(); } - $total = db_result(db_query("SELECT sum(harvest_decision) + $total = db_result(db_query("SELECT total_points FROM {vc_forestry_student} WHERE vc_student_id='%s' - AND vc_stage_id=%d", + AND vc_stage_id=%d + AND round_no=%d", $this->stud_id, - $stage_id)); + $stage_id,$round_no-1)); $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); Modified: vcweb/trunk/virtualcommons/experiment/rules/rules.install =================================================================== --- vcweb/trunk/virtualcommons/experiment/rules/rules.install 2008-08-18 06:44:06 UTC (rev 43) +++ vcweb/trunk/virtualcommons/experiment/rules/rules.install 2008-08-18 23:05:42 UTC (rev 44) @@ -23,9 +23,26 @@ ON DELETE CASCADE )ENGINE=InnoDB /*!40100 DEFAULT CHARACTER SET UTF8 */"); + + + db_query("CREATE TABLE {vc_tie} + ( + id INT AUTO_INCREMENT, + vc_group_id INT NOT NULL, + tie_rules_id varchar(255) NOT NULL, + + time_created TIMESTAMP NOT NULL, + PRIMARY KEY(id), + FOREIGN KEY(vc_group_id) REFERENCES vc_group(id) + ON DELETE CASCADE + )ENGINE=InnoDB /*!40100 DEFAULT CHARACTER SET UTF8 */"); + + $flag=TRUE; + + break; case 'pgsql': Modified: vcweb/trunk/virtualcommons/experiment/survey/survey.module =================================================================== --- vcweb/trunk/virtualcommons/experiment/survey/survey.module 2008-08-18 06:44:06 UTC (rev 43) +++ vcweb/trunk/virtualcommons/experiment/survey/survey.module 2008-08-18 23:05:42 UTC (rev 44) @@ -6,7 +6,7 @@ static $loaded = FALSE; if (!$loaded) { - $path = drupal_get_path('module', 'forestry_stage1'); + $path = drupal_get_path('module', 'forestry_v2'); drupal_add_css($path .'/form.css'); $loaded = TRUE; } @@ -180,7 +180,8 @@ else { $rule_info=$group->getSelectedRule(); - foreach ($rule_info as $key=>$value) + // foreach ($rule_info as $key=>$value) + for($i=0;$i<count($rule_info);$i++) { //drupal_set_message(t('Selected rule no is: '. $key . 'Description is : ' . $value)); @@ -192,12 +193,12 @@ $form['rule']=array( '#title'=>t('Selected Rule no is '), '#type'=>'item', - '#value'=>$key + '#value'=>$rule_info[0] ); $form['rule_description']=array( '#title'=>t('Description for this rule is '), '#type'=>'item', - '#value'=>$value[0] + '#value'=>$rule_info[1] ); $form['submit'] = array( '#type' => 'submit', Modified: vcweb/trunk/virtualcommons/experiment/teacher_dashboard/teacher_dashboard.module =================================================================== --- vcweb/trunk/virtualcommons/experiment/teacher_dashboard/teacher_dashboard.module 2008-08-18 06:44:06 UTC (rev 43) +++ vcweb/trunk/virtualcommons/experiment/teacher_dashboard/teacher_dashboard.module 2008-08-18 23:05:42 UTC (rev 44) @@ -47,7 +47,7 @@ function display_stage_data($game) { $all_stage_data = $game->getAllGroupRoundInfo(); $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 #'); + $header_voting=array('Round No','Group No', 'Group Harvest Decision','Resources Before','Resources After', 'Rule #','Dice'); foreach ($all_stage_data as $stage_id => $stage_data) { $stage_no = $game->getStageNumber($stage_id); @@ -125,7 +125,7 @@ ); if($start_flag) { - drupal_get_messages(); + //drupal_get_messages(); drupal_set_message(t('This stage needs voting. Please tell students to vote.'),'warning',FALSE); $form['submit'] = array( '#type' => 'submit', @@ -205,8 +205,14 @@ { if(! $game->isRuleSelected()) { - $game->assign_Rules_To_Groups(); - $rule_no=$game->initRules(); + if($game->assign_Rules_To_Groups()) + { + $game->saveTie(); + } + else + { + $rule_no=$game->initRules(); + } } } else This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |