From 1bdba54ed5fa725ac1933c3297ca500cec66c103 Mon Sep 17 00:00:00 2001 From: dave Date: Wed, 28 Mar 2007 06:16:41 +0000 Subject: [PATCH] - Add a special awards feature (off by default) to the judge scheduler. It: - Creates a judging team for each special award - Assigns judges to special awards based on the number of students self nominated. - Obeys the judges special award preferences (if enabled), and also judges that specify if they are a judge for a specific special award (if enabled). - Add 2 new config variables. - Enable the special award scheduler - Specify the max. number of projects each special award judge can handle (default: 20) - Delete an extra blank line in register_participants_students.php --- admin/judges_sa.php | 259 +++++++++++++++++++++++++++-- db/db.code.version.txt | 2 +- db/db.update.49.sql | 4 + register_participants_students.php | 1 - 4 files changed, 252 insertions(+), 14 deletions(-) create mode 100644 db/db.update.49.sql diff --git a/admin/judges_sa.php b/admin/judges_sa.php index 4efa643..78d0ed4 100644 --- a/admin/judges_sa.php +++ b/admin/judges_sa.php @@ -24,6 +24,7 @@ id; @@ -394,7 +398,7 @@ while($r = mysql_fetch_object($q)) { mysql_query("DELETE FROM judges_teams_timeslots_projects_link WHERE judges_teams_id='$jteam_id' AND year={$config['FAIRYEAR']}"); print mysql_error(); } -/* Findally, delete all the autocreated judges teams */ +/* Finally, delete all the autocreated judges teams */ mysql_query("DELETE FROM judges_teams WHERE autocreate_type_id=1 AND year={$config['FAIRYEAR']}"); print mysql_error(); TRACE(" Done.\n"); @@ -408,8 +412,7 @@ $q=mysql_query("SELECT judges.* FROM judges,judges_years WHERE ". ); $judges=array(); - - +$sa_judges = array(); while($r=mysql_fetch_object($q)) { @@ -456,7 +459,36 @@ while($r=mysql_fetch_object($q)) if($r2->answer == 'yes') $willing_chair = 'yes'; } - $judges[$r->id]=array( + $sa_only = 'no'; + if($r->typepref == 'speconly') $sa_only = 'yes'; + $sa_sel = array(); + + + if($sa_only == 'yes') { + TRACE("Judge [{$r->firstname} {$r->lastname}] is a special awards only.\n"); + /* Find their special award id */ + $qq = mysql_query("SELECT award_awards.id,award_awards.name FROM + judges_specialaward_sel,award_awards + WHERE + award_awards.id=judges_specialaward_sel.award_awards_id + AND judges_specialaward_sel.judges_id='{$r->id}' + AND judges_specialaward_sel.year='{$config['FAIRYEAR']}' + AND award_awards.year='{$config['FAIRYEAR']}'"); + echo mysql_error(); + if(mysql_num_rows($qq) == 0) { + TRACE(" - NO special award selected! (removing special award only request)\n"); + $sa_only = 'no'; + } else if(mysql_num_rows($qq) > 1) { + TRACE(" - More than ONE special award selected (removing special award only request):\n"); + $sa_only = 'no'; + } + while($rr = mysql_fetch_object($qq)) { + TRACE(" ".$rr->name."\n"); + $sa_sel[] = $rr->id; + } + } + + $j=array( "judges_id"=>"$r->id", "name"=>"$r->firstname $r->lastname", "years_school"=>$r->years_school, @@ -465,8 +497,20 @@ while($r=mysql_fetch_object($q)) "willing_chair"=>$willing_chair, "divprefs"=>$divprefs, "catprefs"=>$catprefs, - "languages"=>$langprefs + "languages"=>$langprefs, + "sa_only"=>$sa_only, + "sa_sel"=>$sa_sel, ); + + /* If it's a special award only judge, keep them + * out of the judges list for the divisional annealer */ + if($sa_only == 'yes') { + $sa_judges[$r->id] = $j; + } else { + $judges[$r->id] = $j; + } + + } TRACE("Loaded ".count($judges)." judges.\n"); $jteam[0]['max_judges'] = count($judges); @@ -522,8 +566,8 @@ TRACE("Max Judging Team Number is currently $max_jteam_num\n"); for($x=1;$xbucket_cost[$x]} "); + $max_jteam_num++; + print("Judging Team $max_jteam_num: cost={$a->bucket_cost[$x]} "); print("langs=("); $langstr=""; for($y=0; $ybucket[0]; -for($y=0; $y $t['max_judges']) ? $c - $t['max_judges'] : 0; + $cost += $min * 50; + $cost += $max * 10; + + /* For each judge on the team, score their preferences */ + for($x=0; $xpick_move(); + + /* See if $b1,$i1 is movable */ + $id1 = $a->bucket[$b1][$i1]; + $j1 =& $sa_judges[$id1]; +// print("J1:"); +// print_r($j1); + if($j1['sa_only'] == 'yes') continue; + + if($i2 != -1) { + $id2 = $a->bucket[$b2][$i2]; + $j2 =& $sa_judges[$id2]; +// print("J2:"); +// print_r($j2); + if($j2['sa_only'] == 'yes') continue; + } + + return array($b1, $i1, $b2, $i2); + } +} + + +if($config['scheduler_enable_sa_scheduling'] == 'yes') { + set_status("Creating Special Award Judging Teams (one team per award)"); + $q = "SELECT award_awards.name,award_awards.id FROM award_awards,award_types + WHERE + award_awards.year='{$config['FAIRYEAR']}' + AND award_types.id=award_awards.award_types_id + AND award_types.year='{$config['FAIRYEAR']}' + AND award_types.type='Special' + "; + $r = mysql_query($q); + print(mysql_error()); + /* sa_jteam for leftover judges, if any */ + $sa_jteam = array(); + $sa_jteam[0]['id'] = 0; + $sa_jteam[0]['projects'] = array(); + $sa_jteam[0]['langs'] = array(); + $sa_jteam[0]['min_judges'] = 0; + $sa_jteam[0]['max_judges'] = 0; + $sa_jteam[0]['award_ids'] = array(); + + $x=1; + while($i = mysql_fetch_object($r)) { + $projects = getProjectsNominatedForSpecialAward($i->id); + + $max_jteam_num++; /* Pre-increment before using */ + + $pids = array_keys($projects); + $sa_jteam[$x]['id'] = $jteam_id; + $sa_jteam[$x]['projects'] = $pids; + $sa_jteam[$x]['sub'] = 0; + $sa_jteam[$x]['langs'] = array(); + $min = floor(count($pids) / $config['projects_per_special_award_judge']) + 1; + $sa_jteam[$x]['min_judges'] = $min; + $sa_jteam[$x]['max_judges'] = $min; + $sa_jteam[$x]['award_ids'] = array($i->id); + + $tn = "{$i->name}"; + /* Write this team to the DB */ + mysql_query("INSERT INTO judges_teams (num,name,autocreate_type_id,year) + VALUES ('$max_jteam_num','$tn','1','{$config['FAIRYEAR']}')"); + $sa_jteam[$x]['id'] = mysql_insert_id(); + + /* Link the award to this team */ + mysql_query("INSERT INTO judges_teams_awards_link (award_awards_id,judges_teams_id,year) + VALUES ('{$i->id}','{$sa_jteam[$x]['id']}','{$config['FAIRYEAR']}')"); + + TRACE("Created Team: $tn\n"); + $jteam_id++; + $x++; + } + + + + /* ====================================================================*/ + set_status("Assigning Judges to Special Award Teams\n"); + + + $judge_ids = array_keys($sa_judges); + $e = $config['effort']; + $a = new annealer(count($sa_jteam), 25, $e, 0.98, judges_sa_cost_function, $judge_ids); + //$a->set_update_callback(judges_to_teams_update); + //$a->set_pick_move(judges_sa_pick_move); + $a->anneal(); + + + $x=0; + foreach($sa_jteam as $tid => $t) { + if($tid == 0) { + $x++; + continue; + } + print("Judging Team {$t['id']}: cost={$a->bucket_cost[$x]} #=({$t['min_judges']},{$t['max_judges']}) "); + // print("langs=("); + /* $langstr=""; + for($y=0; $ybucket[$x]; + for($y=0; $y$r->date, "starttime"=>substr($r->starttime,0,-3), "endtime"=>substr($r->endtime,0,-3)); - print(" -".$available_timeslots[$x]['starttime']." -> ". + print(" ".$available_timeslots[$x]['starttime']." -> ". $available_timeslots[$x]['endtime']."\n"); $x++; } diff --git a/db/db.code.version.txt b/db/db.code.version.txt index 21e72e8..95f9650 100644 --- a/db/db.code.version.txt +++ b/db/db.code.version.txt @@ -1 +1 @@ -48 +49 diff --git a/db/db.update.49.sql b/db/db.update.49.sql new file mode 100644 index 0000000..18b11ba --- /dev/null +++ b/db/db.update.49.sql @@ -0,0 +1,4 @@ +INSERT INTO `config` ( `var` , `val` , `category` , `type` , `type_values` , `ord` , `description` , `year` ) VALUES ( 'scheduler_enable_sa_scheduling', 'no', 'Judge Scheduler', 'yesno', '', '900', 'Allow the scheduler to automatically create a judging team for each special award, and assigned unused divisional judges to special awards.', '-1'); + +INSERT INTO `config` ( `var` , `val` , `category` , `type` , `type_values` , `ord` , `description` , `year` ) VALUES ( 'projects_per_special_award_judge', '20', 'Judge Scheduler', 'number', '', '1000', 'The maximum number of projects that each special awards judge can judge.', '-1'); + diff --git a/register_participants_students.php b/register_participants_students.php index 54dc6c4..07dc36a 100644 --- a/register_participants_students.php +++ b/register_participants_students.php @@ -229,7 +229,6 @@ else if($newstatus=="complete") else $numtoshow=$numfound; - echo "
"; echo i18n("Number of students that worked on the project: "); echo "