-
Notifications
You must be signed in to change notification settings - Fork 3
/
index.js
133 lines (117 loc) · 3.12 KB
/
index.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
const spCountContainer = document.getElementById('sp-count');
const spCountDescription = document.getElementById('sp-description');
const taskPropertiesContainer = document.getElementById('task-properties');
let taskProperties = null;
const spMatrix = {
'low': {
'low': {
'low': 1,
'medium': 2,
'high': 5,
},
'medium': {
'low': 2,
'medium': 3,
'high': 5,
},
'high': {
'low': 3,
'medium': 5,
'high': 8,
},
},
'medium': {
'low': {
'low': 3,
'medium': 5,
'high': 8,
},
'medium': {
'low': 5,
'medium': 5,
'high': 8,
},
'high': {
'low': 5,
'medium': 8,
'high': 13,
},
},
'high': {
'low': {
'low': 8,
'medium': 8,
'high': 13,
},
'medium': {
'low': 8,
'medium': 8,
'high': 13,
},
'high': {
'low': 13,
'medium': 13,
'high': 21,
},
},
}
const getActualTaskPropertes = () => {
const complexityInput = document.querySelector('[name=complexity]:checked');
const effortInput = document.querySelector('[name=effort]:checked');
const uncertaintyInput = document.querySelector('[name=uncertainty]:checked');
return {
complexity: complexityInput.value,
effort: effortInput.value,
uncertainty: uncertaintyInput.value,
}
}
const calculateSp = (properties) => {
const { effort, complexity, uncertainty } = properties;
try {
return spMatrix[uncertainty][complexity][effort];
} catch {
return -1
}
}
const updateSpDescription = (sp) => {
if (sp < 5) {
spCountDescription.innerText = ''
}
if (sp >= 5 && sp < 8) {
spCountDescription.innerText = 'Сложная задача! Попробуй декомпозировать ее!'
}
if (sp >= 8 && sp < 13) {
spCountDescription.innerText = 'Сложная задача! Нужна декомпозиция!'
}
if (sp >= 13) {
spCountDescription.innerText = 'Это точно задача, а не эпик? ©'
}
}
const updateSpColor = (sp) => {
if (sp < 5) {
spCountContainer.style.color = '#009688';
}
if (sp >= 5 && sp < 8) {
spCountContainer.style.color = '#ff8f00';
}
if (sp >= 8) {
spCountContainer.style.color = '#b71c1c';
}
}
const updateSpValue = () => {
const taskProperties = getActualTaskPropertes();
const sp = calculateSp(taskProperties);
if (sp < 0) {
spCountContainer.innerText = 'Не удалось посчитать sp';
} else {
spCountContainer.innerText = `${calculateSp(taskProperties)} sp`;
}
updateSpDescription(sp);
updateSpColor(sp);
}
taskPropertiesContainer.addEventListener('click', ({ target }) => {
if (target.type === 'radio') {
updateSpValue();
}
});
updateSpValue();