-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathpreferencing.js
161 lines (148 loc) · 4.66 KB
/
preferencing.js
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
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
//variables used to store the responses. Here we ensure the list is filled with NA such that a required
//unanswered question will be flagged when the user tries to submit an empty form
var responses = [];
var numberOfQuestions = 5;
for(i = 0; i < numberOfQuestions; i ++){
responses[i] = 'na';
}
//Set slide to the first one when you first render the website.
var slideIndex = 1;
showSlides(slideIndex);
//function called when you press the arrow button at the side of the screen.
function plusSlides(n) {
showSlides(slideIndex += n);
}
//function called when you press the buttons at the bottom of the screen.
function currentSlide(n) {
showSlides(slideIndex = n);
}
//this function is the core of how the transitions work
function showSlides(n) {
var i;
var slides = document.getElementsByClassName("myQuestions");
var dots = document.getElementsByClassName("dot");
if (n > slides.length) {slideIndex = 1}
if (n < 1) {slideIndex = slides.length}
for (i = 0; i < slides.length; i++) {
slides[i].style.display = "none";
}
for (i = 0; i < dots.length; i++) {
dots[i].className = dots[i].className.replace(" active", "");
}
slides[slideIndex-1].style.display = "block";
dots[slideIndex-1].className += " active";
if(slideIndex != 1){
document.getElementById("prev").style.display = "block";
}else{
document.getElementById("prev").style.display = "none";
}
if(slideIndex != numberOfQuestions+1){
document.getElementById("next").style.display = "block";
}else{
document.getElementById("next").style.display = "none";
}
}
//function used to get the option selected. Remember that you must put the option chosen and the question number.
//Remember that qn 1 is 0, qn 2 is 1, etc.
//You must also ensure that the name and the id of the option is appropriately set.
//name -> question(insert qn number), i.e for question 1 all options will have name = 'question1'
//id -> just make the id the name of the options. i.e for that data analyst option, id = 'Data Analyst'
function makeSelection(optionChosen, qnNumber){
responses[qnNumber] = optionChosen;
optionsOfQuestion = document.getElementsByName(document.getElementById(optionChosen).name);
for(i= 0; i < optionsOfQuestion.length;i++){
optionsOfQuestion[i].style.background = "#0088cc";
}
document.getElementById(optionChosen).style.background = "#979797";
}
function preferenceCalculator(){
ans1 = responses[0];
ans2 = responses[1];
ans3 = responses[2];
ans4 = responses[3];
ans5 = responses[4];
ansValues = [0,0,0,0,0];
//these configs assign different weightage to each question
//These are changed, whereas the values associated with each answer
//will remain constant
configA = [0.3,0.3,0.1,0.2,0.1];
configB = [0.2,0.3,0.1,0.3,0.1];
configC = [0.15,0.35,0.2,0.3,0.1];
configs = [[],configA,configB,configC];
//Here we use a random number generator get select a config to use
selectedConfig = Math.floor(Math.random() * 3) + 1;
// alert(selectedConfig);
if(ans1 == "Cooking"){
ansValues[0] = 1;
}
if(ans1 == "Eating out"){
ansValues[0] = 2;
}
if(ans2 == "$$$"){
ansValues[1] = 3;
}
if(ans2 == "$$"){
ansValues[1] = 2;
}
if(ans2 == "$"){
ansValues[1] = 1;
}
if(ans3 == "Chinese Food"){
ansValues[2] = 2
}
if(ans3 == "Indian Food"){
ansValues[2] = 2
}
if(ans3 == "Western Food"){
ansValues[2] = 2
}
if(ans3 == "Thai Food"){
ansValues[2] = 2
}
if(ans3 == "Viet Food"){
ansValues[2] = 2
}
if(ans4 == "Expert"){
ansValues[3] = 1
}
if(ans4 == "Intermediate"){
ansValues[3] = 1
}
if(ans4 == "Beginner"){
ansValues[3] = 1
}
if(ans5 == "2km"){
ansValues[4] = 1
}
if(ans5 == "5km"){
ansValues[4] = 1
}
if(ans5 == "10km"){
ansValues[4] = 1
}
outputValue = 0;
for(i = 0; i < ansValues.length;i++){
//alert(ansValues[i] + " " + configs[selectedConfig][i]);
outputValue += ansValues[i]*configs[selectedConfig][i];
}
//*0.5 since we are doing normalization on the dataset and expected value of any individual is 0.5
alert(outputValue*0.5);
}
//Submits to questionaire at the submit button, will not allow a submission if there is a question that is not done.
function submitQuestionaire(){
var checker = true;
for(i = 0; i < responses.length;i++){
if(responses[i] == 'na'){
checker = false;
}
}
if(!checker){
alert('Please answer all required questions!')
}else{
//preferenceCalculator();
location.href='./SearchPage.html';
}
}
// to do:
// use r to simulate then find the value that can differentiate 70/30.
// write documentation