浏览代码

display results

master
DemiSel 2 年前
父节点
当前提交
6937fbf361

+ 11
- 0
backend/src/main/java/Application.java 查看文件

@@ -44,6 +44,17 @@ public class Application {
44 44
                                         new Answer("Explain to other equally impatient people in the room that the doctor is always running late ", vExtrovertTrait, 0.3f),
45 45
                                         new Answer("Complain in a loud voice, while tapping your foot impatiently", vExtrovertTrait, 0.7f)
46 46
                                 )
47
+                        ),
48
+                        //------------------------------------
49
+                        // Third question
50
+                        //------------------------------------
51
+                        new Question(
52
+                                "Blah blah blah ? Blah.",
53
+                                Arrays.asList(
54
+                                        new Answer("Yes.", vIntrovertTrait, 0.2f),
55
+                                        new Answer("Sure", vExtrovertTrait, 0.3f),
56
+                                        new Answer("Meh", vExtrovertTrait, 0.7f)
57
+                                )
47 58
                         )
48 59
                 )
49 60
         );

+ 99
- 0
frontend/src/App.css 查看文件

@@ -0,0 +1,99 @@
1
+h1{
2
+  color: #111111;
3
+}
4
+
5
+.app{
6
+  margin: 0 auto;
7
+  max-width: 50em;
8
+  font-family: "Helvetica", "Arial", sans-serif;
9
+  line-height: 1.5;
10
+  padding: 4em 1em;
11
+  color: #333333;
12
+  --interactible-color: #007C00;
13
+  --jauge-color: #AAAACC;
14
+}
15
+
16
+.display_flex{
17
+  display: flex;
18
+}
19
+
20
+.flex_vertical{
21
+  flex-direction: column;
22
+}
23
+
24
+.flex_horizontal{
25
+  flex-direction: row;
26
+}
27
+
28
+.flex_wrap{
29
+  flex-wrap: wrap;
30
+}
31
+
32
+.bordered{
33
+  border-style: solid;
34
+  border-radius: 2em;
35
+  border-width: 1px;
36
+  padding: 0.5em 1em;
37
+}
38
+
39
+.raised{
40
+  z-index: 2;
41
+  background-color: #eaecea;
42
+  border-style:ridge;
43
+  margin: 0.5em;
44
+  padding: 0.5em;
45
+  transition: all 0.2s ease-in-out 0.1;
46
+}
47
+
48
+.spaced{
49
+  margin: 0.5em;
50
+  padding: 0.5em;
51
+}
52
+
53
+.raised:hover{
54
+  border-style: solid;
55
+}
56
+
57
+.hoverable{
58
+  cursor: pointer;
59
+}
60
+
61
+.interactible{
62
+  color: var(--interactible-color);
63
+  border-style: solid;
64
+  border-radius: 2em;
65
+  border-width: 1px;
66
+  cursor: pointer;
67
+  margin: 1em;
68
+  padding: 1em;
69
+  display: flex;
70
+  justify-content: center;
71
+  
72
+}
73
+
74
+.space_between{
75
+  justify-content: space-between;
76
+  justify-items: space-between;
77
+}
78
+
79
+.center{
80
+  justify-content: center;
81
+  justify-items: center;
82
+}
83
+
84
+.fill_width{
85
+  width:100%
86
+}
87
+
88
+.position_static{
89
+  position: static;
90
+}
91
+
92
+.position_absolute{
93
+  position: absolute;
94
+}
95
+
96
+.gradient{
97
+  transition: all 0.5s ease-in-out 1s;
98
+  background: linear-gradient(90deg, var(--jauge-color) 0%, var(--jauge-color) var(--data-weight), #FFFFFF var(--data-grad-offset), #FFFFFF 100%); 
99
+}

+ 8
- 4
frontend/src/App.js 查看文件

@@ -29,20 +29,24 @@ function App() {
29 29
   }
30 30
 
31 31
   return (
32
-    <div>
32
+    <div className="app display_flex flex_vertical">
33 33
       <h1>
34 34
         Are you an introvert or an extrovert ?
35 35
       </h1>
36
-      <div>
36
+      { !questionnaireStarted &&
37
+      <h2>
37 38
         Take this <i>✨ totally legit personality test ✨</i> and find out !
38
-      </div>
39
+      </h2>
40
+      }
39 41
       {
40 42
         null === sessionIdReceived &&
43
+        <div>
41 44
         <div> {null === errorOccured ? "Contacting server..." : "A server error occured 😨 : "+errorOccured} </div>
45
+        </div>
42 46
       }
43 47
       {
44 48
         !questionnaireStarted && null!=sessionIdReceived &&
45
-        <div
49
+        <div className="interactible"
46 50
         onClick={() => onStartQuestionnaire(true)}>
47 51
           Start
48 52
         </div>

+ 5
- 4
frontend/src/component/question.js 查看文件

@@ -13,7 +13,7 @@ function Question(props){
13 13
     current_question.answers.forEach(answer => {
14 14
         let dom_id = "answer"+answer.id
15 15
         question_answers.push(
16
-            <div key={dom_id}>
16
+            <div className="spaced hoverable" key={dom_id}>
17 17
                 <input name="answer" id={dom_id} type="radio" value={answer.id} defaultChecked={answer.id === selectedAnswer}/>
18 18
                 <label htmlFor={dom_id}>{answer.description}</label>
19 19
             </div>
@@ -21,12 +21,13 @@ function Question(props){
21 21
     });
22 22
     
23 23
     return (
24
-    <div>
25
-        <div> {current_question.name} </div>
26
-        <div onChange={(value) => onSelectAnswer(value.target.value)}>
24
+    <div className="bordered">
25
+        <h3> {current_question.name} </h3>
26
+        <div className="display_flex flex_vertical" onChange={(value) => onSelectAnswer(value.target.value)}>
27 27
         {question_answers}
28 28
         </div>
29 29
         <div
30
+            className="interactible"
30 31
             onClick={() => {
31 32
                 //-------------------------------
32 33
                 // POST question answer

+ 3
- 3
frontend/src/component/questionnaire.js 查看文件

@@ -39,13 +39,13 @@ function Questionnaire(props){
39 39
                 moveToQuestion={onMoveToIndex}
40 40
                 questionnaireCompleted={onQuestionnaireCompleted}/>
41 41
         }
42
-        <div>
42
+        <div className="display_flex flex_horizontal">
43 43
         {
44
-            currentIndex > 0 ? <div onClick={() => onMoveToIndex(currentIndex-1)}>Previous Question</div> : ''  
44
+            currentIndex > 0 ? <div className="interactible" onClick={() => onMoveToIndex(currentIndex-1)}>Previous Question</div> : ''  
45 45
         }
46 46
         {
47 47
             null != questionnaireDataFetched && currentIndex < questionnaireDataFetched.questions.length - 1 && 'answer' in questionnaireDataFetched.questions[currentIndex] && 
48
-            <div onClick={() => onMoveToIndex(currentIndex+1)}>Next Question</div>
48
+            <div className="interactible" onClick={() => onMoveToIndex(currentIndex+1)}>Next Question</div>
49 49
         }
50 50
         </div>
51 51
         </React.Fragment>

+ 40
- 2
frontend/src/component/questionnaire_result.js 查看文件

@@ -1,23 +1,61 @@
1 1
 import React from 'react';
2
+import { createPortal } from 'react-dom';
2 3
 import url from '../server';
3 4
 
4 5
 function QuestionnaireResult(props){
5 6
     const [resultsFetched, onResultsFetched] = React.useState(null);
6 7
     console.log(resultsFetched);
8
+    let dominant_weight = 0;
9
+    let dominant = null;
10
+    let scale_ends = ["Introvert","Extrovert"];
11
+    let display_dominant = 0;
7 12
 
8 13
     if(null === resultsFetched)
9 14
     {
10 15
         fetch(url+"/session/"+props.sessionId) 
11 16
         .then(response => response.json())
12 17
         .then(result => {
13
-            onResultsFetched(result);
18
+            onResultsFetched(result.results);
14 19
         })
15 20
         .catch( e => console.error(e));
16 21
     }
22
+    else
23
+    {
24
+        let total = 0;
25
+        let max = 0;
26
+        
27
+        resultsFetched.traits.forEach(trait => {
28
+            total += trait.weight;
29
+            if(max < trait.weight)
30
+            {
31
+                max = trait.weight;
32
+                dominant = trait;
33
+            }
34
+            dominant_weight = dominant.weight/total;
35
+        })
36
+        display_dominant = dominant.name === "Introvert" ? dominant_weight : 1-dominant_weight
37
+    }
17 38
     return(
39
+        <React.Fragment>
40
+        <div className="gradient bordered" 
41
+        style={{
42
+            "--data-weight": display_dominant*100+"%",
43
+            "--data-grad-offset": display_dominant*100+1+"%",
44
+            }}>
45
+            <div className="display_flex flex_horizontal space_between position_static fill_width">
46
+            <div>Introvert</div>
47
+            <div>Extrovert</div>
48
+            </div>
49
+            <div className="display_flex position_static fill_width center">
50
+            {resultsFetched ? (dominant_weight*100).toFixed(1)+"% "+dominant.name : "Results loading"}
51
+            </div>
52
+        </div>
53
+        {null != dominant &&
18 54
         <div>
19
-            Results
55
+            🎉{dominant.description}
20 56
         </div>
57
+        }
58
+        </React.Fragment>
21 59
     )
22 60
 }
23 61
 

正在加载...
取消
保存