<?php
class RANK {
	function instructions() {
	?>
		<TR><TD VALIGN=TOP>Instructions: <BR>Rank each <b>whole sentence</b> translation from Best to Worst relative to the other choices (ties are allowed).</TD><TD>
		&nbsp;
		</TD><TD>
		
	<?php
	}
	
	function min_item_number() {
		return get_task_property('min_sentence_number');
	}
	
	function max_item_number() {
		return get_task_property('max_sentence_number');	
	}
	
	function head_text() {
		return "Rank Whole Sentences";
	}
	
	
	//return judgement string, null if no judgements scored
	function process_judgement() {
		$translation_ids = get_task_property('translation_id');
		$success = false;

		$ranks = array();
		$systems = array();
		
		while (list($key, $value) = each($_POST)) {
			if (preg_match("/RANK_(.+)/",$key,$reg)) {
				//at least one judgement is present, mark as a successful attempt
				$success = true;
				$ranks[] = $translation_ids[$reg[1]].":".$value;
			}
		}
		
		if ($success) {
			return join(" ",$ranks);
		} else {
			return null;
		}

	}
	
	function is_numerical_score() {
		return true;
	}
	
	function process_statistics($system_score_list,$score_total) {
		//we get system->string. We return system->{score_name->value}
		
		$processed_scores = array();
		$score_avg = $score_total / sizeof($system_score_list);
		$score_adjustment = 3 - $score_avg;
			
		foreach ($system_score_list as $system => $score) {
			$score_normalized =$score + $score_adjustment;
			$processed_scores[$system]["RANK_NORMALIZED"] = -1*$score_normalized;	
		}
		return $processed_scores;
	}
	
	function test_info($assignment_id) {	

		list($test_type_id,$assignment_number,$assignment_info_string) = split("-",$assignment_id);			
		$system_id_list = split(",",$assignment_info_string);

		$source_file = get_task_property('source');
		if (!ereg("\.NONE$",$source_file)) {
			print "<B>Source:</B> ".display_one_line($source_file,$assignment_number);
		}
		$reference = get_task_property('reference');
		for($i=0;$i<count($reference);$i++) {
			print "<P><B>Reference:</B> <FONT COLOR=#008000>".display_one_line($reference[$i],$assignment_number)."</FONT>\n";
		}
		$translation_files = get_task_property('translation_file');
		
		?>
		<TABLE BORDER=1>
		<TR><TD><B>Translation</B></TD><TD><B>Rank</B></TD></TR>
		<?php
		foreach($system_id_list as $system_id) {
			if (file_exists($translation_files[$system_id])) {
				print "<TR BGCOLOR=#F0F0FF><TD><FONT COLOR=#000080>".display_one_line($translation_files[$system_id],$assignment_number);
				//print ($GLOBALS["translation_file"][$system_id]." ".$GLOBALS["translation_id"][$system_id]);
				?>
				</FONT></TD><TD NOWRAP>
				<TABLE BORDER=0 CELLSPACING=0 CELLPADDING=0><TR>
				<?php
				for($j=1;$j<=5;$j++) {
					print "<TD WIDTH=75 ALIGN=CENTER><INPUT TYPE=RADIO NAME=RANK_$system_id VALUE=$j></TD>\n";
				}
				print "</TR>\n<TR>";
				for($j=1;$j<=5;$j++) {
					print "<TD TD WIDTH=75 VALIGN=TOP ALIGN=CENTER>$j";
					if ($j==1) print"<BR>Best";
					if ($j==5) print"<BR>Worst";
					print "</TD>\n";
				}
				?>
				</TR></TABLE>
				</TD>
				</TD></TR>
				<?php
			}
		}
	
	}

}
?>