Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion ideologies.js
Original file line number Diff line number Diff line change
Expand Up @@ -165,7 +165,7 @@
*/


ideologies = [
const ideologies = [
{
"name": "Ждун", // 1 1 1 1
"stats": {
Expand Down
3 changes: 2 additions & 1 deletion questions.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
// Негативне значення - шкала йде у ліво (наприклад в сторону перемоги)
// Позитивне значення - шкала йде на право (в сторону зради)

questions = [
const questions = [
{
"question": "Деокупація всіх окупованих територій України, включно з Кримом — ймовірний сценарій завершення війни",
"effect": {
Expand Down Expand Up @@ -471,4 +471,5 @@ questions = [
},
},
];

questions.sort(() => Math.random() - 0.5);
61 changes: 25 additions & 36 deletions quiz.html
Original file line number Diff line number Diff line change
Expand Up @@ -14,48 +14,41 @@ <h1>Ukranianvalues</h1>
<hr>
<h2 style="text-align:center;" id="question-number">Завантаження...</h2>
<p class="question" id="question-text"></p>
<button class="button stronglyAgree" onclick="next_question( 1.0)">Повністю погоджуюся</button> <br>
<button class="button agree" onclick="next_question( 0.5)">Погоджуюся</button> <br>
<button class="button neutral" onclick="next_question( 0.0)">Нейтрально</button> <br>
<button class="button stronglyAgree" onclick="next_question(1)">Повністю погоджуюся</button> <br>
<button class="button agree" onclick="next_question(0.5)">Погоджуюся</button> <br>
<button class="button neutral" onclick="next_question(0)">Нейтрально</button> <br>
<button class="button disagree" onclick="next_question(-0.5)">Не погоджуюся</button> <br>
<button class="button stronglyDisagree" onclick="next_question(-1.0)">Зовсім не погоджуюся</button> <br>
<button class="button stronglyDisagree" onclick="next_question(-1)">Зовсім не погоджуюся</button> <br>
<button class="small_button" onclick="prev_question()" id="back_button">Назад</button>
<button class="small_button_off" id="back_button_off">Назад</button><br>

<!-- JavaScript for the test itself -->
<script>
var max_econ, max_dipl, max_govt, max_scty; // Max possible scores
max_econ = max_dipl = max_govt = max_scty = 0;
let econ_array = new Array(questions.length);
let dipl_array = new Array(questions.length);
let govt_array = new Array(questions.length);
let scty_array = new Array(questions.length);
var qn = 0; // Question number
const econ_array = [];
const dipl_array = [];
const govt_array = [];
const scty_array = [];
let qn = 0; // Question number

init_question();
for (var i = 0; i < questions.length; i++) {
max_econ += Math.abs(questions[i].effect.econ)
max_dipl += Math.abs(questions[i].effect.dipl)
max_govt += Math.abs(questions[i].effect.govt)
max_scty += Math.abs(questions[i].effect.scty)
}

function init_question() {
document.getElementById("question-text").innerHTML = questions[qn].question;
document.getElementById("question-number").innerHTML = "Питання " + (qn + 1) + " з " + (questions.length);
if (qn == 0) {
if (qn === 0) {
document.getElementById("back_button").style.display = 'none';
document.getElementById("back_button_off").style.display = 'block';
} else {
document.getElementById("back_button").style.display = 'block';
document.getElementById("back_button_off").style.display = 'none';
}

}

function next_question(mult) {
econ_array[qn] = mult*questions[qn].effect.econ
dipl_array[qn] = mult*questions[qn].effect.dipl
govt_array[qn] = mult*questions[qn].effect.govt
scty_array[qn] = mult*questions[qn].effect.scty
econ_array[qn] = mult * questions[qn].effect.econ
dipl_array[qn] = mult * questions[qn].effect.dipl
govt_array[qn] = mult * questions[qn].effect.govt
scty_array[qn] = mult * questions[qn].effect.scty
qn++;
if (qn < questions.length) {
init_question();
Expand All @@ -65,27 +58,23 @@ <h2 style="text-align:center;" id="question-number">Завантаження...<
}

function prev_question() {
if (qn == 0) {
return;
}
if (qn == 0) return;
qn--;
init_question();
}

function calc_score(score,max) {
return (100*(max+score)/(2*max)).toFixed(1)
function calc_score(param, scoreArray) {
const finalScore = scoreArray.reduce((a, b) => a + b, 0);
const maxImposibleScore = questions.reduce((acc, question) => acc + Math.abs(question.effect[param]), 0);
return (100 * (finalScore + maxImposibleScore) / (2 * maxImposibleScore)).toFixed(1)
}

function results() {
let final_econ = econ_array.reduce((a, b) => a + b, 0)
let final_dipl = dipl_array.reduce((a, b) => a + b, 0)
let final_govt = govt_array.reduce((a, b) => a + b, 0)
let final_scty = scty_array.reduce((a, b) => a + b, 0)
location.href = `results.html`
+ `?e=${calc_score(final_econ,max_econ)}`
+ `&d=${calc_score(final_dipl,max_dipl)}`
+ `&g=${calc_score(final_govt,max_govt)}`
+ `&s=${calc_score(final_scty,max_scty)}`
+ `?e=${calc_score('econ', econ_array)}`
+ `&d=${calc_score('dipl', dipl_array)}`
+ `&g=${calc_score('govt', govt_array)}`
+ `&s=${calc_score('scty', scty_array)}`
}
</script>
</body>
70 changes: 31 additions & 39 deletions results.html
Original file line number Diff line number Diff line change
Expand Up @@ -53,35 +53,33 @@ <h2>Ваші погляди: <span class="weight-300" id="ideology-label"></span
<button class="button" onclick="location.href='index.html';">Назад</button> <br>

<script>
function getQueryVariable(variable)
{
var query = window.location.search.substring(1)
var vars = query.split("&")
for (var i=0;i<vars.length;i++) {
var pair = vars[i].split("=")
if(pair[0] == variable) {
return pair[1]
}
}
return(NaN);
}

const econArray = ["Тотальна зрада","Кранє невдоволення","Песимістичні очікування","Невпевнений","Оптимістичні очікування","Впевненість в перемозі","Абсолютна перемога"]
const diplArray = ["Максимальне росіянство","Русофілія","Схильність до російського","Помірність","Україноцетризм","Русофобія","Нетерплячість російського"]
const govtArray = ["Про-західний фанатизм","Впевнене інтегрування","Зближення з Заходом","Баланс","Скептичне ставлення","Свій підхід","Окрема Україна"]
const sctyArray = ["Мовна свобода","Плюралізм","Білінгвізм","Нейтральний","Лагідна українізація","Мовний шовінізм","Примусова українізація"]

const searchParams = new URLSearchParams(window.location.search.substring(1))

const equality = searchParams.get("e")
const peace = searchParams.get("d")
const liberty = searchParams.get("g")
const progress = searchParams.get("s")
const wealth = (100 - equality).toFixed(1)
const might = (100 - peace ).toFixed(1)
const authority = (100 - liberty ).toFixed(1)
const tradition = (100 - progress).toFixed(1)

function setBarValue(name, value) {
innerel = document.getElementById(name)
outerel = document.getElementById("bar-" + name)
const innerel = document.getElementById(name)
const outerel = document.getElementById("bar-" + name)
outerel.style.width = (value + "%")
innerel.innerHTML = (value + "%")
if (innerel.offsetWidth + 20 > outerel.offsetWidth) {
innerel.style.visibility = "hidden"
}
}

econArray = ["Тотальна зрада","Кранє невдоволення","Песимістичні очікування","Невпевнений","Оптимістичні очікування","Впевненість в перемозі","Абсолютна перемога"]
diplArray = ["Максимальне росіянство","Русофілія","Схильність до російського","Помірність","Україноцетризм","Русофобія","Нетерплячість російського"]
govtArray = ["Про-західний фанатизм","Впевнене інтегрування","Зближення з Заходом","Баланс","Скептичне ставлення","Свій підхід","Окрема Україна"]
sctyArray = ["Мовна свобода","Плюралізм","Білінгвізм","Нейтральний","Лагідна українізація","Мовний шовінізм","Примусова українізація"]

function setLabel(val,ary) {
function setLabel(val, ary) {
if (val > 100) { return "" } else
if (val > 90) { return ary[0] } else
if (val > 75) { return ary[1] } else
Expand All @@ -93,15 +91,6 @@ <h2>Ваші погляди: <span class="weight-300" id="ideology-label"></span
{return ""}
}

equality = getQueryVariable("e")
peace = getQueryVariable("d")
liberty = getQueryVariable("g")
progress = getQueryVariable("s")
wealth = (100 - equality).toFixed(1)
might = (100 - peace ).toFixed(1)
authority = (100 - liberty ).toFixed(1)
tradition = (100 - progress).toFixed(1)

setBarValue("equality", equality)
setBarValue("wealth", wealth)
setBarValue("peace", peace)
Expand All @@ -116,10 +105,11 @@ <h2>Ваші погляди: <span class="weight-300" id="ideology-label"></span
document.getElementById("state-label").innerHTML = setLabel(liberty, govtArray)
document.getElementById("society-label").innerHTML = setLabel(progress, sctyArray)

ideology = ""
ideodist = Infinity
for (var i = 0; i < ideologies.length; i++) {
dist = 0
let ideology = ""
let ideodist = Infinity

for (let i = 0; i < ideologies.length; i++) {
let dist = 0
dist += Math.pow(Math.abs(ideologies[i].stats.econ - equality), 2) // Політика
dist += Math.pow(Math.abs(ideologies[i].stats.govt - liberty), 2) // Вплив
dist += Math.pow(Math.abs(ideologies[i].stats.dipl - peace), 2) // Дипломатія
Expand All @@ -129,10 +119,11 @@ <h2>Ваші погляди: <span class="weight-300" id="ideology-label"></span
ideodist = dist
}
}

document.getElementById("ideology-label").innerHTML = ideology

function createImage(src, x, y, w, h) {
img = new Image ()
const img = new Image ()
// Request CORS permission
img.crossOrigin = "anonymous"; // This line is key to avoid the tainted canvas issue
img.src = src
Expand All @@ -142,13 +133,14 @@ <h2>Ваші погляди: <span class="weight-300" id="ideology-label"></span
}

window.onload = function() {
var c = document.createElement("canvas")
var ctx = c.getContext("2d")
const c = document.createElement("canvas")
const ctx = c.getContext("2d")
c.width = 800;
c.height = 650;
ctx.fillStyle = "#EEEEEE"
ctx.fillRect(0,0,800,650);

ctx.fillRect(0, 0, 800, 650);
let img;

img = document.getElementById("img-equality")
ctx.drawImage(img, 20, 170, 100, 100);
img = document.getElementById("img-wealth")
Expand Down