From 9a00ce4877661bf9f99191b62ce586e4b5f1dc22 Mon Sep 17 00:00:00 2001 From: dave Date: Sat, 3 Apr 2010 19:16:11 +0000 Subject: [PATCH] Properly do timeslot->project->jteam linking for special awards --- admin/judges_sa.php | 47 +++++++++++++++++++++++++++++++++++++++++---- 1 file changed, 43 insertions(+), 4 deletions(-) diff --git a/admin/judges_sa.php b/admin/judges_sa.php index c890e05..9684082 100644 --- a/admin/judges_sa.php +++ b/admin/judges_sa.php @@ -357,6 +357,16 @@ $q = mysql_query("SELECT * FROM judges_timeslots WHERE round_id='0' AND `year`=' /* Loads judges_timeslots.id, .starttime, .endtime, .date, .name */ while($r = mysql_fetch_assoc($q)) { TRACE(" id:{$r['id']} type:{$r['type']} name:{$r['name']}\n"); + + $qq = mysql_query("SELECT * FROM judges_timeslots WHERE round_id='{$r['id']}'"); + if(mysql_num_rows($qq) == 0) { + echo "ERROR: Round type:{$r['type']} name:{$r['name']} has no judging timeslots! Abort.\n"; + exit; + } + while($rr = mysql_fetch_assoc($qq)) { + TRACE(" Timeslot: {$rr['starttime']}-{$rr['endtime']}\n"); + $r['timeslots'][] = $rr; + } $round[] = $r; if($r['type'] == 'divisional1') $round_divisional1 = $r; @@ -586,6 +596,7 @@ function judge_team_add_judge($team_id, $users_id) (users_id,judges_teams_id,captain,year) VALUES ('$users_id','$team_id','{$judges[$users_id]['willing_chair']}', '{$config['FAIRYEAR']}')"); + echo mysql_error(); } /**************************************************************************** @@ -889,6 +900,13 @@ function judges_sa_cost_function($annealer, $bucket_id, $ids) if($bucket_id == 0) { /* This is the placeholder */ $cost = count($ids) * 50; + /* But check for judges who should be on a special award */ + for($x=0; $xname); /* Note, we use $x instead of the ID, because the DB id could be zero. */ - $sa_jteam[$x]['projects'] = $pids; + $sa_jteam[$x]['projects'] = $projects; $sa_jteam[$x]['round'] = NULL; $sa_jteam[$x]['sub'] = 0; $sa_jteam[$x]['langs'] = array(); - $min = floor(count($pids) / $config['projects_per_special_award_judge']) + 1; + $min = floor(count($projects) / $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); @@ -1018,7 +1038,7 @@ if($config['scheduler_enable_sa_scheduling'] == 'yes') { 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: {$i->name}, $min judges needed (db id:{$sa_jteam[$x]['id']}) \n"); + TRACE("Created Team: {$i->name}, ".count($projects)." projects => $min judges needed (db id:{$sa_jteam[$x]['id']}) \n"); $x++; } TRACE("Total Judges: $total_judges, Required: $required_judges\n"); @@ -1092,6 +1112,11 @@ if($config['scheduler_enable_sa_scheduling'] == 'yes') { $round_special_awards[$highest_offset]['assigned_judges'] += $jt['min_judges']; TRACE("Pre-assigning Team {$jt['name']} to Round {$round_special_awards[$highest_offset]['name']}\n"); $jt['assigned'] = true; + + /* If the max judges for the jteam is less than the max, update the max, + * this prevents the scheduler from trying to remove sa-only judges + * from the jteam because of the over-max cost penalty */ + if($jt['max_judges'] < count($sa_judges)) $jt['max_judges'] = count($sa_judges); } unset($jt); @@ -1122,6 +1147,7 @@ if($config['scheduler_enable_sa_scheduling'] == 'yes') { /* Assign this jteam id to the special award round */ $round_special_awards[$highest_offset]['jteam_ids'][] = $x; $round_special_awards[$highest_offset]['assigned_judges'] += $jt['min_judges']; + TRACE("Assigned Team {$jt['name']} to Round {$round_special_awards[$highest_offset]['name']}\n"); } /* Now, anneal in each special award round */ @@ -1160,6 +1186,19 @@ if($config['scheduler_enable_sa_scheduling'] == 'yes') { print("$langstr)");*/ print("\n"); + /* Do timeslot and project timeslot assignment */ + mysql_query("INSERT INTO judges_teams_timeslots_link + (judges_teams_id,judges_timeslots_id,year) + VALUES ('{$t['id']}', '{$r['timeslots'][0]['id']}', '{$config['FAIRYEAR']}')"); + echo mysql_error(); + + foreach($t['projects'] as $proj) { + $pid = $proj['id']; + mysql_query("INSERT INTO judges_teams_timeslots_projects_link + (judges_teams_id,judges_timeslots_id,projects_id,year) + VALUES ('{$t['id']}', '{$r['timeslots'][0]['id']}', '$pid', '{$config['FAIRYEAR']}')"); + echo mysql_error(); + } $ids = $a->bucket[$x]; foreach($a->bucket[$x] as $jid) { // pr_judge($t, $ids[$y]);