|
@@ 4386-4531 (lines=146) @@
|
| 4383 |
|
} |
| 4384 |
|
$user_array = substr($user_array, 0, -1); |
| 4385 |
|
|
| 4386 |
|
if ($next) { |
| 4387 |
|
$user_answer = $user_array; |
| 4388 |
|
// we compare only the delineation not the other points |
| 4389 |
|
$answer_question = $_SESSION['hotspot_coord'][1]; |
| 4390 |
|
$answerDestination = $_SESSION['hotspot_dest'][1]; |
| 4391 |
|
|
| 4392 |
|
//calculating the area |
| 4393 |
|
$poly_user = convert_coordinates($user_answer, '/'); |
| 4394 |
|
$poly_answer = convert_coordinates($answer_question, '|'); |
| 4395 |
|
$max_coord = poly_get_max($poly_user, $poly_answer); |
| 4396 |
|
$poly_user_compiled = poly_compile($poly_user, $max_coord); |
| 4397 |
|
$poly_answer_compiled = poly_compile($poly_answer, $max_coord); |
| 4398 |
|
$poly_results = poly_result($poly_answer_compiled, $poly_user_compiled, $max_coord); |
| 4399 |
|
|
| 4400 |
|
$overlap = $poly_results['both']; |
| 4401 |
|
$poly_answer_area = $poly_results['s1']; |
| 4402 |
|
$poly_user_area = $poly_results['s2']; |
| 4403 |
|
$missing = $poly_results['s1Only']; |
| 4404 |
|
$excess = $poly_results['s2Only']; |
| 4405 |
|
|
| 4406 |
|
//$overlap = round(polygons_overlap($poly_answer,$poly_user)); |
| 4407 |
|
// //this is an area in pixels |
| 4408 |
|
if ($debug > 0) { |
| 4409 |
|
error_log(__LINE__.' - Polygons results are '.print_r($poly_results, 1), 0); |
| 4410 |
|
} |
| 4411 |
|
|
| 4412 |
|
if ($overlap < 1) { |
| 4413 |
|
//shortcut to avoid complicated calculations |
| 4414 |
|
$final_overlap = 0; |
| 4415 |
|
$final_missing = 100; |
| 4416 |
|
$final_excess = 100; |
| 4417 |
|
} else { |
| 4418 |
|
// the final overlap is the percentage of the initial polygon |
| 4419 |
|
// that is overlapped by the user's polygon |
| 4420 |
|
$final_overlap = round(((float) $overlap / (float) $poly_answer_area) * 100); |
| 4421 |
|
if ($debug > 1) { |
| 4422 |
|
error_log(__LINE__.' - Final overlap is '.$final_overlap, 0); |
| 4423 |
|
} |
| 4424 |
|
// the final missing area is the percentage of the initial polygon |
| 4425 |
|
// that is not overlapped by the user's polygon |
| 4426 |
|
$final_missing = 100 - $final_overlap; |
| 4427 |
|
if ($debug > 1) { |
| 4428 |
|
error_log(__LINE__.' - Final missing is '.$final_missing, 0); |
| 4429 |
|
} |
| 4430 |
|
// the final excess area is the percentage of the initial polygon's size |
| 4431 |
|
// that is covered by the user's polygon outside of the initial polygon |
| 4432 |
|
$final_excess = round((((float) $poly_user_area - (float) $overlap) / (float) $poly_answer_area) * 100); |
| 4433 |
|
if ($debug > 1) { |
| 4434 |
|
error_log(__LINE__.' - Final excess is '.$final_excess, 0); |
| 4435 |
|
} |
| 4436 |
|
} |
| 4437 |
|
|
| 4438 |
|
//checking the destination parameters parsing the "@@" |
| 4439 |
|
$destination_items = explode( |
| 4440 |
|
'@@', |
| 4441 |
|
$answerDestination |
| 4442 |
|
); |
| 4443 |
|
$threadhold_total = $destination_items[0]; |
| 4444 |
|
$threadhold_items = explode( |
| 4445 |
|
';', |
| 4446 |
|
$threadhold_total |
| 4447 |
|
); |
| 4448 |
|
$threadhold1 = $threadhold_items[0]; // overlap |
| 4449 |
|
$threadhold2 = $threadhold_items[1]; // excess |
| 4450 |
|
$threadhold3 = $threadhold_items[2]; //missing |
| 4451 |
|
|
| 4452 |
|
// if is delineation |
| 4453 |
|
if ($answerId === 1) { |
| 4454 |
|
//setting colors |
| 4455 |
|
if ($final_overlap >= $threadhold1) { |
| 4456 |
|
$overlap_color = true; //echo 'a'; |
| 4457 |
|
} |
| 4458 |
|
//echo $excess.'-'.$threadhold2; |
| 4459 |
|
if ($final_excess <= $threadhold2) { |
| 4460 |
|
$excess_color = true; //echo 'b'; |
| 4461 |
|
} |
| 4462 |
|
//echo '--------'.$missing.'-'.$threadhold3; |
| 4463 |
|
if ($final_missing <= $threadhold3) { |
| 4464 |
|
$missing_color = true; //echo 'c'; |
| 4465 |
|
} |
| 4466 |
|
|
| 4467 |
|
// if pass |
| 4468 |
|
if ( |
| 4469 |
|
$final_overlap >= $threadhold1 && |
| 4470 |
|
$final_missing <= $threadhold3 && |
| 4471 |
|
$final_excess <= $threadhold2 |
| 4472 |
|
) { |
| 4473 |
|
$next = 1; //go to the oars |
| 4474 |
|
$result_comment = get_lang('Acceptable'); |
| 4475 |
|
$final_answer = 1; // do not update with update_exercise_attempt |
| 4476 |
|
} else { |
| 4477 |
|
$next = 0; |
| 4478 |
|
$result_comment = get_lang('Unacceptable'); |
| 4479 |
|
$comment = $answerDestination = $objAnswerTmp->selectComment(1); |
| 4480 |
|
$answerDestination = $objAnswerTmp->selectDestination(1); |
| 4481 |
|
//checking the destination parameters parsing the "@@" |
| 4482 |
|
$destination_items = explode('@@', $answerDestination); |
| 4483 |
|
} |
| 4484 |
|
} elseif ($answerId > 1) { |
| 4485 |
|
if ($objAnswerTmp->selectHotspotType($answerId) == 'noerror') { |
| 4486 |
|
if ($debug > 0) { |
| 4487 |
|
error_log(__LINE__.' - answerId is of type noerror', 0); |
| 4488 |
|
} |
| 4489 |
|
//type no error shouldn't be treated |
| 4490 |
|
$next = 1; |
| 4491 |
|
continue; |
| 4492 |
|
} |
| 4493 |
|
if ($debug > 0) { |
| 4494 |
|
error_log(__LINE__.' - answerId is >1 so we\'re probably in OAR', 0); |
| 4495 |
|
} |
| 4496 |
|
//check the intersection between the oar and the user |
| 4497 |
|
//echo 'user'; print_r($x_user_list); print_r($y_user_list); |
| 4498 |
|
//echo 'official';print_r($x_list);print_r($y_list); |
| 4499 |
|
//$result = get_intersection_data($x_list,$y_list,$x_user_list,$y_user_list); |
| 4500 |
|
$inter = $result['success']; |
| 4501 |
|
$delineation_cord = $objAnswerTmp->selectHotspotCoordinates($answerId); |
| 4502 |
|
$poly_answer = convert_coordinates($delineation_cord, '|'); |
| 4503 |
|
$max_coord = poly_get_max($poly_user, $poly_answer); |
| 4504 |
|
$poly_answer_compiled = poly_compile($poly_answer, $max_coord); |
| 4505 |
|
$overlap = poly_touch($poly_user_compiled, $poly_answer_compiled, $max_coord); |
| 4506 |
|
|
| 4507 |
|
if ($overlap == false) { |
| 4508 |
|
//all good, no overlap |
| 4509 |
|
$next = 1; |
| 4510 |
|
continue; |
| 4511 |
|
} else { |
| 4512 |
|
if ($debug > 0) { |
| 4513 |
|
error_log(__LINE__.' - Overlap is '.$overlap.': OAR hit', 0); |
| 4514 |
|
} |
| 4515 |
|
$organs_at_risk_hit++; |
| 4516 |
|
//show the feedback |
| 4517 |
|
$next = 0; |
| 4518 |
|
$comment = $answerDestination = $objAnswerTmp->selectComment($answerId); |
| 4519 |
|
$answerDestination = $objAnswerTmp->selectDestination($answerId); |
| 4520 |
|
|
| 4521 |
|
$destination_items = explode('@@', $answerDestination); |
| 4522 |
|
$try_hotspot = $destination_items[1]; |
| 4523 |
|
$lp_hotspot = $destination_items[2]; |
| 4524 |
|
$select_question_hotspot = $destination_items[3]; |
| 4525 |
|
$url_hotspot = $destination_items[4]; |
| 4526 |
|
} |
| 4527 |
|
} |
| 4528 |
|
} else { // the first delineation feedback |
| 4529 |
|
if ($debug > 0) { |
| 4530 |
|
error_log(__LINE__.' first', 0); |
| 4531 |
|
} |
| 4532 |
|
} |
| 4533 |
|
} elseif (in_array($answerType, [MATCHING, MATCHING_DRAGGABLE])) { |
| 4534 |
|
echo '<tr>'; |
|
@@ 4723-4878 (lines=156) @@
|
| 4720 |
|
break; |
| 4721 |
|
case HOT_SPOT_DELINEATION: |
| 4722 |
|
$user_answer = $user_array; |
| 4723 |
|
if ($next) { |
| 4724 |
|
//$tbl_track_e_hotspot = Database::get_main_table(TABLE_STATISTIC_TRACK_E_HOTSPOT); |
| 4725 |
|
// Save into db |
| 4726 |
|
/* $sql = "INSERT INTO $tbl_track_e_hotspot ( |
| 4727 |
|
* hotspot_user_id, |
| 4728 |
|
* hotspot_course_code, |
| 4729 |
|
* hotspot_exe_id, |
| 4730 |
|
* hotspot_question_id, |
| 4731 |
|
* hotspot_answer_id, |
| 4732 |
|
* hotspot_correct, |
| 4733 |
|
* hotspot_coordinate |
| 4734 |
|
* ) |
| 4735 |
|
VALUES ( |
| 4736 |
|
* '".Database::escape_string($_user['user_id'])."', |
| 4737 |
|
* '".Database::escape_string($_course['id'])."', |
| 4738 |
|
* '".Database::escape_string($exeId)."', '".Database::escape_string($questionId)."', |
| 4739 |
|
* '".Database::escape_string($answerId)."', |
| 4740 |
|
* '".Database::escape_string($studentChoice)."', |
| 4741 |
|
* '".Database::escape_string($user_array)."')"; |
| 4742 |
|
$result = Database::query($sql,__FILE__,__LINE__); |
| 4743 |
|
*/ |
| 4744 |
|
$user_answer = $user_array; |
| 4745 |
|
// we compare only the delineation not the other points |
| 4746 |
|
$answer_question = $_SESSION['hotspot_coord'][1]; |
| 4747 |
|
$answerDestination = $_SESSION['hotspot_dest'][1]; |
| 4748 |
|
|
| 4749 |
|
// calculating the area |
| 4750 |
|
$poly_user = convert_coordinates($user_answer, '/'); |
| 4751 |
|
$poly_answer = convert_coordinates($answer_question, '|'); |
| 4752 |
|
$max_coord = poly_get_max($poly_user, $poly_answer); |
| 4753 |
|
$poly_user_compiled = poly_compile($poly_user, $max_coord); |
| 4754 |
|
$poly_answer_compiled = poly_compile($poly_answer, $max_coord); |
| 4755 |
|
$poly_results = poly_result($poly_answer_compiled, $poly_user_compiled, $max_coord); |
| 4756 |
|
|
| 4757 |
|
$overlap = $poly_results['both']; |
| 4758 |
|
$poly_answer_area = $poly_results['s1']; |
| 4759 |
|
$poly_user_area = $poly_results['s2']; |
| 4760 |
|
$missing = $poly_results['s1Only']; |
| 4761 |
|
$excess = $poly_results['s2Only']; |
| 4762 |
|
if ($debug > 0) { |
| 4763 |
|
error_log(__LINE__.' - Polygons results are '.print_r($poly_results, 1), 0); |
| 4764 |
|
} |
| 4765 |
|
if ($overlap < 1) { |
| 4766 |
|
//shortcut to avoid complicated calculations |
| 4767 |
|
$final_overlap = 0; |
| 4768 |
|
$final_missing = 100; |
| 4769 |
|
$final_excess = 100; |
| 4770 |
|
} else { |
| 4771 |
|
// the final overlap is the percentage of the initial polygon that is overlapped by the user's polygon |
| 4772 |
|
$final_overlap = round(((float) $overlap / (float) $poly_answer_area) * 100); |
| 4773 |
|
if ($debug > 1) { |
| 4774 |
|
error_log(__LINE__.' - Final overlap is '.$final_overlap, 0); |
| 4775 |
|
} |
| 4776 |
|
// the final missing area is the percentage of the initial polygon that is not overlapped by the user's polygon |
| 4777 |
|
$final_missing = 100 - $final_overlap; |
| 4778 |
|
if ($debug > 1) { |
| 4779 |
|
error_log(__LINE__.' - Final missing is '.$final_missing, 0); |
| 4780 |
|
} |
| 4781 |
|
// the final excess area is the percentage of the initial polygon's size that is covered by the user's polygon outside of the initial polygon |
| 4782 |
|
$final_excess = round((((float) $poly_user_area - (float) $overlap) / (float) $poly_answer_area) * 100); |
| 4783 |
|
if ($debug > 1) { |
| 4784 |
|
error_log(__LINE__.' - Final excess is '.$final_excess, 0); |
| 4785 |
|
} |
| 4786 |
|
} |
| 4787 |
|
|
| 4788 |
|
// Checking the destination parameters parsing the "@@" |
| 4789 |
|
$destination_items = explode('@@', $answerDestination); |
| 4790 |
|
$threadhold_total = $destination_items[0]; |
| 4791 |
|
$threadhold_items = explode(';', $threadhold_total); |
| 4792 |
|
$threadhold1 = $threadhold_items[0]; // overlap |
| 4793 |
|
$threadhold2 = $threadhold_items[1]; // excess |
| 4794 |
|
$threadhold3 = $threadhold_items[2]; //missing |
| 4795 |
|
// if is delineation |
| 4796 |
|
if ($answerId === 1) { |
| 4797 |
|
//setting colors |
| 4798 |
|
if ($final_overlap >= $threadhold1) { |
| 4799 |
|
$overlap_color = true; //echo 'a'; |
| 4800 |
|
} |
| 4801 |
|
//echo $excess.'-'.$threadhold2; |
| 4802 |
|
if ($final_excess <= $threadhold2) { |
| 4803 |
|
$excess_color = true; //echo 'b'; |
| 4804 |
|
} |
| 4805 |
|
//echo '--------'.$missing.'-'.$threadhold3; |
| 4806 |
|
if ($final_missing <= $threadhold3) { |
| 4807 |
|
$missing_color = true; //echo 'c'; |
| 4808 |
|
} |
| 4809 |
|
|
| 4810 |
|
// if pass |
| 4811 |
|
if ($final_overlap >= $threadhold1 && |
| 4812 |
|
$final_missing <= $threadhold3 && |
| 4813 |
|
$final_excess <= $threadhold2 |
| 4814 |
|
) { |
| 4815 |
|
$next = 1; //go to the oars |
| 4816 |
|
$result_comment = get_lang('Acceptable'); |
| 4817 |
|
$final_answer = 1; // do not update with update_exercise_attempt |
| 4818 |
|
} else { |
| 4819 |
|
$next = 0; |
| 4820 |
|
$result_comment = get_lang('Unacceptable'); |
| 4821 |
|
$comment = $answerDestination = $objAnswerTmp->selectComment(1); |
| 4822 |
|
$answerDestination = $objAnswerTmp->selectDestination(1); |
| 4823 |
|
//checking the destination parameters parsing the "@@" |
| 4824 |
|
$destination_items = explode('@@', $answerDestination); |
| 4825 |
|
} |
| 4826 |
|
} elseif ($answerId > 1) { |
| 4827 |
|
if ($objAnswerTmp->selectHotspotType($answerId) == 'noerror') { |
| 4828 |
|
if ($debug > 0) { |
| 4829 |
|
error_log(__LINE__.' - answerId is of type noerror', 0); |
| 4830 |
|
} |
| 4831 |
|
//type no error shouldn't be treated |
| 4832 |
|
$next = 1; |
| 4833 |
|
continue; |
| 4834 |
|
} |
| 4835 |
|
if ($debug > 0) { |
| 4836 |
|
error_log(__LINE__.' - answerId is >1 so we\'re probably in OAR', 0); |
| 4837 |
|
} |
| 4838 |
|
//check the intersection between the oar and the user |
| 4839 |
|
//echo 'user'; print_r($x_user_list); print_r($y_user_list); |
| 4840 |
|
//echo 'official';print_r($x_list);print_r($y_list); |
| 4841 |
|
//$result = get_intersection_data($x_list,$y_list,$x_user_list,$y_user_list); |
| 4842 |
|
$inter = $result['success']; |
| 4843 |
|
|
| 4844 |
|
//$delineation_cord=$objAnswerTmp->selectHotspotCoordinates($answerId); |
| 4845 |
|
$delineation_cord = $objAnswerTmp->selectHotspotCoordinates($answerId); |
| 4846 |
|
|
| 4847 |
|
$poly_answer = convert_coordinates($delineation_cord, '|'); |
| 4848 |
|
$max_coord = poly_get_max($poly_user, $poly_answer); |
| 4849 |
|
$poly_answer_compiled = poly_compile($poly_answer, $max_coord); |
| 4850 |
|
$overlap = poly_touch($poly_user_compiled, $poly_answer_compiled, $max_coord); |
| 4851 |
|
|
| 4852 |
|
if ($overlap == false) { |
| 4853 |
|
//all good, no overlap |
| 4854 |
|
$next = 1; |
| 4855 |
|
continue; |
| 4856 |
|
} else { |
| 4857 |
|
if ($debug > 0) { |
| 4858 |
|
error_log(__LINE__.' - Overlap is '.$overlap.': OAR hit', 0); |
| 4859 |
|
} |
| 4860 |
|
$organs_at_risk_hit++; |
| 4861 |
|
//show the feedback |
| 4862 |
|
$next = 0; |
| 4863 |
|
$comment = $answerDestination = $objAnswerTmp->selectComment($answerId); |
| 4864 |
|
$answerDestination = $objAnswerTmp->selectDestination($answerId); |
| 4865 |
|
|
| 4866 |
|
$destination_items = explode('@@', $answerDestination); |
| 4867 |
|
$try_hotspot = $destination_items[1]; |
| 4868 |
|
$lp_hotspot = $destination_items[2]; |
| 4869 |
|
$select_question_hotspot = $destination_items[3]; |
| 4870 |
|
$url_hotspot = $destination_items[4]; |
| 4871 |
|
} |
| 4872 |
|
} |
| 4873 |
|
} else { // the first delineation feedback |
| 4874 |
|
if ($debug > 0) { |
| 4875 |
|
error_log(__LINE__.' first', 0); |
| 4876 |
|
} |
| 4877 |
|
} |
| 4878 |
|
break; |
| 4879 |
|
case HOT_SPOT_ORDER: |
| 4880 |
|
ExerciseShowFunctions::display_hotspot_order_answer( |
| 4881 |
|
$feedback_type, |