-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathevaluater.php
115 lines (91 loc) · 2.56 KB
/
evaluater.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
<?php
require_once("class_loader.php");
require_once("config/db_config.php");
define("CLOUD_RIGHT_ANSWERS", "abcdbcad");
define("SOFTWARE_RIGHT_ANSWERS", "bacbacda");
define("ENTREPRENEUR_RIGHT_ANSWERS", "dadaaccb");
define("NOT_ANSWERED_PLACEHOLDER", "e");
define("CLOUD", "Cloud");
define("ENTREPRENEUR", "Entrepreneur");
define("SOFTWARE", "Software");
$payload = $_POST["data"];
file_put_contents("payload.txt", var_export($payload, true));
$cloudAnswers = Question::fetch(CLOUD);
$sofrwareAnswers = Question::fetch(SOFTWARE);
$entrepreneurAnswers = Question::fetch(ENTREPRENEUR);
function getQuestionByType($type) {
global $cloudAnswers;
global $sofrwareAnswers;
global $entrepreneurAnswers;
switch($type) {
case CLOUD :
return $cloudAnswers;
break;
case SOFTWARE :
return $sofrwareAnswers;
break;
case ENTREPRENEUR :
return $entrepreneurAnswers;
break;
default :
return false;
break;
}
}
function score($quiz /*array of Questions*/, $givenAnswers /*string*/) {
$score = 0;
$givenAnswersIndex = 0;
foreach($quiz as $question) {
if($question->isCorrect($givenAnswers[$givenAnswersIndex++])) {
$score ++;
}
}
return $score;
}
function determineBonus($types) {
$types = array_unique($types);
if(count($types) === 0) {
return 0;
}
$bonuses = array(0,10,30);
return $bonuses[count($types) - 1];
}
function assert_correct_answers() {
global $cloudAnswers;
global $sofrwareAnswers;
global $entrepreneurAnswers;
$score = score($cloudAnswers, CLOUD_RIGHT_ANSWERS);
if($score === 8) {
//echo "Scoring cloud test is OK<br />";
} else {
die("<strong style='color:red'>Scoring cloud test FAILED</strong>");
}
$score = score($sofrwareAnswers, SOFTWARE_RIGHT_ANSWERS);
if($score === 8) {
//echo "Scoring Software test is OK<br />";
} else {
die("<strong style='color:red'>Scoring Software test FAILED</strong>");
}
$score = score($entrepreneurAnswers, ENTREPRENEUR_RIGHT_ANSWERS);
if($score === 8) {
//echo "Scoring Entrepreneur test is OK<br />";
} else {
die("<strong style='color:red'>Scoring Entrepreneur test FAILED</strong>");
}
}
assert_correct_answers();
$payloadScore = 0;
$bonus = 0;
$submitetTypes = array();
foreach($payload["quizes"] as $quiz) {
$payloadScore += score(getQuestionByType($quiz["type"]), $quiz["answers"]);
$submitetTypes[] = $quiz["type"];
}
$bonus = determineBonus($submitetTypes);
$returnedValue = array("data" => array(
"identification" => $payload["identificaton"],
"score" => $payloadScore,
"bonus" => $bonus),
"timestamp" => time());
echo json_encode($returnedValue);
?>