@@ 4294-4439 (lines=146) @@ | ||
4291 | } |
|
4292 | $user_array = substr($user_array,0,-1); |
|
4293 | ||
4294 | if ($next) { |
|
4295 | ||
4296 | $user_answer = $user_array; |
|
4297 | ||
4298 | // we compare only the delineation not the other points |
|
4299 | $answer_question = $_SESSION['hotspot_coord'][1]; |
|
4300 | $answerDestination = $_SESSION['hotspot_dest'][1]; |
|
4301 | ||
4302 | //calculating the area |
|
4303 | $poly_user = convert_coordinates($user_answer, '/'); |
|
4304 | $poly_answer = convert_coordinates($answer_question, '|'); |
|
4305 | $max_coord = poly_get_max($poly_user, $poly_answer); |
|
4306 | $poly_user_compiled = poly_compile($poly_user, $max_coord); |
|
4307 | $poly_answer_compiled = poly_compile($poly_answer, $max_coord); |
|
4308 | $poly_results = poly_result($poly_answer_compiled, $poly_user_compiled, $max_coord); |
|
4309 | ||
4310 | $overlap = $poly_results['both']; |
|
4311 | $poly_answer_area = $poly_results['s1']; |
|
4312 | $poly_user_area = $poly_results['s2']; |
|
4313 | $missing = $poly_results['s1Only']; |
|
4314 | $excess = $poly_results['s2Only']; |
|
4315 | ||
4316 | //$overlap = round(polygons_overlap($poly_answer,$poly_user)); |
|
4317 | // //this is an area in pixels |
|
4318 | if ($debug > 0) { |
|
4319 | error_log(__LINE__ . ' - Polygons results are ' . print_r($poly_results, 1), 0); |
|
4320 | } |
|
4321 | ||
4322 | if ($overlap < 1) { |
|
4323 | //shortcut to avoid complicated calculations |
|
4324 | $final_overlap = 0; |
|
4325 | $final_missing = 100; |
|
4326 | $final_excess = 100; |
|
4327 | } else { |
|
4328 | // the final overlap is the percentage of the initial polygon |
|
4329 | // that is overlapped by the user's polygon |
|
4330 | $final_overlap = round(((float) $overlap / (float) $poly_answer_area) * 100); |
|
4331 | if ($debug > 1) { |
|
4332 | error_log(__LINE__ . ' - Final overlap is ' . $final_overlap, 0); |
|
4333 | } |
|
4334 | // the final missing area is the percentage of the initial polygon |
|
4335 | // that is not overlapped by the user's polygon |
|
4336 | $final_missing = 100 - $final_overlap; |
|
4337 | if ($debug > 1) { |
|
4338 | error_log(__LINE__ . ' - Final missing is ' . $final_missing, 0); |
|
4339 | } |
|
4340 | // the final excess area is the percentage of the initial polygon's size |
|
4341 | // that is covered by the user's polygon outside of the initial polygon |
|
4342 | $final_excess = round((((float) $poly_user_area - (float) $overlap) / (float) $poly_answer_area) * 100); |
|
4343 | if ($debug > 1) { |
|
4344 | error_log(__LINE__ . ' - Final excess is ' . $final_excess, 0); |
|
4345 | } |
|
4346 | } |
|
4347 | ||
4348 | //checking the destination parameters parsing the "@@" |
|
4349 | $destination_items= explode('@@', $answerDestination); |
|
4350 | $threadhold_total = $destination_items[0]; |
|
4351 | $threadhold_items=explode(';',$threadhold_total); |
|
4352 | $threadhold1 = $threadhold_items[0]; // overlap |
|
4353 | $threadhold2 = $threadhold_items[1]; // excess |
|
4354 | $threadhold3 = $threadhold_items[2]; //missing |
|
4355 | ||
4356 | // if is delineation |
|
4357 | if ($answerId===1) { |
|
4358 | //setting colors |
|
4359 | if ($final_overlap>=$threadhold1) { |
|
4360 | $overlap_color=true; //echo 'a'; |
|
4361 | } |
|
4362 | //echo $excess.'-'.$threadhold2; |
|
4363 | if ($final_excess<=$threadhold2) { |
|
4364 | $excess_color=true; //echo 'b'; |
|
4365 | } |
|
4366 | //echo '--------'.$missing.'-'.$threadhold3; |
|
4367 | if ($final_missing<=$threadhold3) { |
|
4368 | $missing_color=true; //echo 'c'; |
|
4369 | } |
|
4370 | ||
4371 | // if pass |
|
4372 | if ( |
|
4373 | $final_overlap >= $threadhold1 && |
|
4374 | $final_missing <= $threadhold3 && |
|
4375 | $final_excess <= $threadhold2 |
|
4376 | ) { |
|
4377 | $next=1; //go to the oars |
|
4378 | $result_comment=get_lang('Acceptable'); |
|
4379 | $final_answer = 1; // do not update with update_exercise_attempt |
|
4380 | } else { |
|
4381 | $next=0; |
|
4382 | $result_comment=get_lang('Unacceptable'); |
|
4383 | $comment=$answerDestination=$objAnswerTmp->selectComment(1); |
|
4384 | $answerDestination=$objAnswerTmp->selectDestination(1); |
|
4385 | //checking the destination parameters parsing the "@@" |
|
4386 | $destination_items= explode('@@', $answerDestination); |
|
4387 | } |
|
4388 | } elseif($answerId>1) { |
|
4389 | if ($objAnswerTmp->selectHotspotType($answerId) == 'noerror') { |
|
4390 | if ($debug>0) { |
|
4391 | error_log(__LINE__.' - answerId is of type noerror',0); |
|
4392 | } |
|
4393 | //type no error shouldn't be treated |
|
4394 | $next = 1; |
|
4395 | continue; |
|
4396 | } |
|
4397 | if ($debug>0) { |
|
4398 | error_log(__LINE__.' - answerId is >1 so we\'re probably in OAR',0); |
|
4399 | } |
|
4400 | //check the intersection between the oar and the user |
|
4401 | //echo 'user'; print_r($x_user_list); print_r($y_user_list); |
|
4402 | //echo 'official';print_r($x_list);print_r($y_list); |
|
4403 | //$result = get_intersection_data($x_list,$y_list,$x_user_list,$y_user_list); |
|
4404 | $inter= $result['success']; |
|
4405 | ||
4406 | //$delineation_cord=$objAnswerTmp->selectHotspotCoordinates($answerId); |
|
4407 | $delineation_cord=$objAnswerTmp->selectHotspotCoordinates($answerId); |
|
4408 | ||
4409 | $poly_answer = convert_coordinates($delineation_cord,'|'); |
|
4410 | $max_coord = poly_get_max($poly_user,$poly_answer); |
|
4411 | $poly_answer_compiled = poly_compile($poly_answer,$max_coord); |
|
4412 | $overlap = poly_touch($poly_user_compiled, $poly_answer_compiled,$max_coord); |
|
4413 | ||
4414 | if ($overlap == false) { |
|
4415 | //all good, no overlap |
|
4416 | $next = 1; |
|
4417 | continue; |
|
4418 | } else { |
|
4419 | if ($debug>0) { |
|
4420 | error_log(__LINE__.' - Overlap is '.$overlap.': OAR hit',0); |
|
4421 | } |
|
4422 | $organs_at_risk_hit++; |
|
4423 | //show the feedback |
|
4424 | $next=0; |
|
4425 | $comment=$answerDestination=$objAnswerTmp->selectComment($answerId); |
|
4426 | $answerDestination=$objAnswerTmp->selectDestination($answerId); |
|
4427 | ||
4428 | $destination_items= explode('@@', $answerDestination); |
|
4429 | $try_hotspot=$destination_items[1]; |
|
4430 | $lp_hotspot=$destination_items[2]; |
|
4431 | $select_question_hotspot=$destination_items[3]; |
|
4432 | $url_hotspot=$destination_items[4]; |
|
4433 | } |
|
4434 | } |
|
4435 | } else { // the first delineation feedback |
|
4436 | if ($debug>0) { |
|
4437 | error_log(__LINE__.' first',0); |
|
4438 | } |
|
4439 | } |
|
4440 | } elseif (in_array($answerType, [MATCHING, MATCHING_DRAGGABLE])) { |
|
4441 | echo '<tr>'; |
|
4442 | echo Display::tag('td', $answerMatching[$answerId]); |
|
@@ 4614-4769 (lines=156) @@ | ||
4611 | break; |
|
4612 | case HOT_SPOT_DELINEATION: |
|
4613 | $user_answer = $user_array; |
|
4614 | if ($next) { |
|
4615 | //$tbl_track_e_hotspot = Database::get_main_table(TABLE_STATISTIC_TRACK_E_HOTSPOT); |
|
4616 | // Save into db |
|
4617 | /* $sql = "INSERT INTO $tbl_track_e_hotspot ( |
|
4618 | * hotspot_user_id, |
|
4619 | * hotspot_course_code, |
|
4620 | * hotspot_exe_id, |
|
4621 | * hotspot_question_id, |
|
4622 | * hotspot_answer_id, |
|
4623 | * hotspot_correct, |
|
4624 | * hotspot_coordinate |
|
4625 | * ) |
|
4626 | VALUES ( |
|
4627 | * '".Database::escape_string($_user['user_id'])."', |
|
4628 | * '".Database::escape_string($_course['id'])."', |
|
4629 | * '".Database::escape_string($exeId)."', '".Database::escape_string($questionId)."', |
|
4630 | * '".Database::escape_string($answerId)."', |
|
4631 | * '".Database::escape_string($studentChoice)."', |
|
4632 | * '".Database::escape_string($user_array)."')"; |
|
4633 | $result = Database::query($sql,__FILE__,__LINE__); |
|
4634 | */ |
|
4635 | $user_answer = $user_array; |
|
4636 | ||
4637 | // we compare only the delineation not the other points |
|
4638 | $answer_question = $_SESSION['hotspot_coord'][1]; |
|
4639 | $answerDestination = $_SESSION['hotspot_dest'][1]; |
|
4640 | ||
4641 | //calculating the area |
|
4642 | $poly_user = convert_coordinates($user_answer, '/'); |
|
4643 | $poly_answer = convert_coordinates($answer_question, '|'); |
|
4644 | ||
4645 | $max_coord = poly_get_max($poly_user, $poly_answer); |
|
4646 | $poly_user_compiled = poly_compile($poly_user, $max_coord); |
|
4647 | $poly_answer_compiled = poly_compile($poly_answer, $max_coord); |
|
4648 | $poly_results = poly_result($poly_answer_compiled, $poly_user_compiled, $max_coord); |
|
4649 | ||
4650 | $overlap = $poly_results['both']; |
|
4651 | $poly_answer_area = $poly_results['s1']; |
|
4652 | $poly_user_area = $poly_results['s2']; |
|
4653 | $missing = $poly_results['s1Only']; |
|
4654 | $excess = $poly_results['s2Only']; |
|
4655 | ||
4656 | //$overlap = round(polygons_overlap($poly_answer,$poly_user)); //this is an area in pixels |
|
4657 | if ($debug > 0) { |
|
4658 | error_log(__LINE__ . ' - Polygons results are ' . print_r($poly_results, 1), 0); |
|
4659 | } |
|
4660 | if ($overlap < 1) { |
|
4661 | //shortcut to avoid complicated calculations |
|
4662 | $final_overlap = 0; |
|
4663 | $final_missing = 100; |
|
4664 | $final_excess = 100; |
|
4665 | } else { |
|
4666 | // the final overlap is the percentage of the initial polygon that is overlapped by the user's polygon |
|
4667 | $final_overlap = round(((float) $overlap / (float) $poly_answer_area) * 100); |
|
4668 | if ($debug > 1) { |
|
4669 | error_log(__LINE__ . ' - Final overlap is ' . $final_overlap, 0); |
|
4670 | } |
|
4671 | // the final missing area is the percentage of the initial polygon that is not overlapped by the user's polygon |
|
4672 | $final_missing = 100 - $final_overlap; |
|
4673 | if ($debug > 1) { |
|
4674 | error_log(__LINE__ . ' - Final missing is ' . $final_missing, 0); |
|
4675 | } |
|
4676 | // 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 |
|
4677 | $final_excess = round((((float) $poly_user_area - (float) $overlap) / (float) $poly_answer_area) * 100); |
|
4678 | if ($debug > 1) { |
|
4679 | error_log(__LINE__ . ' - Final excess is ' . $final_excess, 0); |
|
4680 | } |
|
4681 | } |
|
4682 | ||
4683 | //checking the destination parameters parsing the "@@" |
|
4684 | $destination_items = explode('@@', $answerDestination); |
|
4685 | $threadhold_total = $destination_items[0]; |
|
4686 | $threadhold_items = explode(';', $threadhold_total); |
|
4687 | $threadhold1 = $threadhold_items[0]; // overlap |
|
4688 | $threadhold2 = $threadhold_items[1]; // excess |
|
4689 | $threadhold3 = $threadhold_items[2]; //missing |
|
4690 | // if is delineation |
|
4691 | if ($answerId === 1) { |
|
4692 | //setting colors |
|
4693 | if ($final_overlap >= $threadhold1) { |
|
4694 | $overlap_color = true; //echo 'a'; |
|
4695 | } |
|
4696 | //echo $excess.'-'.$threadhold2; |
|
4697 | if ($final_excess <= $threadhold2) { |
|
4698 | $excess_color = true; //echo 'b'; |
|
4699 | } |
|
4700 | //echo '--------'.$missing.'-'.$threadhold3; |
|
4701 | if ($final_missing <= $threadhold3) { |
|
4702 | $missing_color = true; //echo 'c'; |
|
4703 | } |
|
4704 | ||
4705 | // if pass |
|
4706 | if ($final_overlap >= $threadhold1 && $final_missing <= $threadhold3 && $final_excess <= $threadhold2) { |
|
4707 | $next = 1; //go to the oars |
|
4708 | $result_comment = get_lang('Acceptable'); |
|
4709 | $final_answer = 1; // do not update with update_exercise_attempt |
|
4710 | } else { |
|
4711 | $next = 0; |
|
4712 | $result_comment = get_lang('Unacceptable'); |
|
4713 | $comment = $answerDestination = $objAnswerTmp->selectComment(1); |
|
4714 | $answerDestination = $objAnswerTmp->selectDestination(1); |
|
4715 | //checking the destination parameters parsing the "@@" |
|
4716 | $destination_items = explode('@@', $answerDestination); |
|
4717 | } |
|
4718 | } elseif ($answerId > 1) { |
|
4719 | if ($objAnswerTmp->selectHotspotType($answerId) == 'noerror') { |
|
4720 | if ($debug > 0) { |
|
4721 | error_log(__LINE__ . ' - answerId is of type noerror', 0); |
|
4722 | } |
|
4723 | //type no error shouldn't be treated |
|
4724 | $next = 1; |
|
4725 | continue; |
|
4726 | } |
|
4727 | if ($debug > 0) { |
|
4728 | error_log(__LINE__ . ' - answerId is >1 so we\'re probably in OAR', 0); |
|
4729 | } |
|
4730 | //check the intersection between the oar and the user |
|
4731 | //echo 'user'; print_r($x_user_list); print_r($y_user_list); |
|
4732 | //echo 'official';print_r($x_list);print_r($y_list); |
|
4733 | //$result = get_intersection_data($x_list,$y_list,$x_user_list,$y_user_list); |
|
4734 | $inter = $result['success']; |
|
4735 | ||
4736 | //$delineation_cord=$objAnswerTmp->selectHotspotCoordinates($answerId); |
|
4737 | $delineation_cord = $objAnswerTmp->selectHotspotCoordinates($answerId); |
|
4738 | ||
4739 | $poly_answer = convert_coordinates($delineation_cord, '|'); |
|
4740 | $max_coord = poly_get_max($poly_user, $poly_answer); |
|
4741 | $poly_answer_compiled = poly_compile($poly_answer, $max_coord); |
|
4742 | $overlap = poly_touch($poly_user_compiled, $poly_answer_compiled,$max_coord); |
|
4743 | ||
4744 | if ($overlap == false) { |
|
4745 | //all good, no overlap |
|
4746 | $next = 1; |
|
4747 | continue; |
|
4748 | } else { |
|
4749 | if ($debug > 0) { |
|
4750 | error_log(__LINE__ . ' - Overlap is ' . $overlap . ': OAR hit', 0); |
|
4751 | } |
|
4752 | $organs_at_risk_hit++; |
|
4753 | //show the feedback |
|
4754 | $next = 0; |
|
4755 | $comment = $answerDestination = $objAnswerTmp->selectComment($answerId); |
|
4756 | $answerDestination = $objAnswerTmp->selectDestination($answerId); |
|
4757 | ||
4758 | $destination_items = explode('@@', $answerDestination); |
|
4759 | $try_hotspot = $destination_items[1]; |
|
4760 | $lp_hotspot = $destination_items[2]; |
|
4761 | $select_question_hotspot = $destination_items[3]; |
|
4762 | $url_hotspot=$destination_items[4]; |
|
4763 | } |
|
4764 | } |
|
4765 | } else { // the first delineation feedback |
|
4766 | if ($debug > 0) { |
|
4767 | error_log(__LINE__ . ' first', 0); |
|
4768 | } |
|
4769 | } |
|
4770 | break; |
|
4771 | case HOT_SPOT_ORDER: |
|
4772 | ExerciseShowFunctions::display_hotspot_order_answer( |