diff --git a/web/newWebsite/questions-main.js b/web/newWebsite/questions-main.js index 8703471..4326b92 100644 --- a/web/newWebsite/questions-main.js +++ b/web/newWebsite/questions-main.js @@ -4,39 +4,51 @@ let awa; data(); -async function data(){ -fetch("http://145.92.8.114/getQuestionData") -.then(response => { - if (!response.ok) { - throw new Error('Network response was not ok'); - } - return response.json(); -}) -.then(data => { - console.log(data); - let Q1Array = data.filter(item => item.Question_QuestionID == 1); - console.log(Q1Array); - let R1Array = Q1Array.filter(item => item.Result == 0); - awa = R1Array.length; - graph() -}) +async function data() { + fetch("http://145.92.8.114/getQuestionData") + .then(response => { + if (!response.ok) { + throw new Error('Network response was not ok'); + } + return response.json(); + }) + .then(data => { + console.log(data); -} + // Initialize an array to hold the counts for each question + let questionCounts = [[0, 0, 0], [0, 0, 0], [0, 0, 0], [0, 0, 0], [0, 0, 0]]; + + // Iterate over the data + for (let item of data) { + // Increment the count for the appropriate question and result + questionCounts[item.Question_QuestionID - 1][item.Result]++; + } + + // Log the counts for each question + for (let i = 0; i < questionCounts.length; i++) { + console.log(`Question ${i + 1} counts: ${questionCounts[i]}`); + } + + // Update the dummydata arrays + dummydata1 = questionCounts[0]; + dummydata2 = questionCounts[1]; + dummydata3 = questionCounts[2]; + dummydata4 = questionCounts[3]; + dummydata5 = questionCounts[4]; + + graph(); + }) +} // for each(Result == 0) in async function graph() { -let dummydata1 = [awa, 3, 5]; let questionOptionsDummy1 = ['disgusting','clean', 'fine']; -let dummydata2 = [25, 35, 40]; let questionOptionsDummy2 = ['disgusting', 'clean', 'normal']; -let dummydata3 = [30, 20, 20]; let questionOptionsDummy3 = ['cold', 'perfect', 'hot']; -let dummydata4 = [30, 20, 20]; let questionOptionsDummy4 = ['really crowded','not at all', 'its fine', ]; -let dummydata5 = [30, 20, 20]; let questionOptionsDummy5 = ['no','yes', 'decently']; //make arrays to store data.