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