-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathscript.js
More file actions
241 lines (199 loc) · 9.9 KB
/
Copy pathscript.js
File metadata and controls
241 lines (199 loc) · 9.9 KB
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
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
////////////////////////// σε περιπτωση νεου τμηματος, προσθεστε το με την ιδια δομη στην παρακατω λιστα
let thesis_weights = {
ece : ["ΗΜΤΥ" , 15],
ceid : ["CEID", 10],
chemeng_civil: ["Χημικοί/Πολιτικοί Μηχανικοί", 18],
}
let input_counter = Object.keys(thesis_weights).length;
///////////////////////////////////////////////// radio button και πληροφοριες διπλωματικης ανα σχολη
let thesis_weight_info = document.querySelector('.thesis_weight')
let school_selected = document.querySelector(".school-selection")
let checked_radio = 1
for(let thesis_w in thesis_weights){
///// πληροφορια για τον συντελεστη διπλωματικης
const par = document.createElement("p")
let par_text = document.createTextNode(`${thesis_weights[thesis_w][0]} - συντελεστής διπλωματικής: ${thesis_weights[thesis_w][1]}`);
par.appendChild(par_text)
thesis_weight_info.appendChild(par)
///// radio button για επιλογη σχολης
const div_school = document.createElement("div")
let lab = document.createElement("label")
lab.setAttribute("for",thesis_w)
let label_text = document.createTextNode(thesis_weights[thesis_w][0])
lab.appendChild(label_text)
const radio = document.createElement("input")
radio.setAttribute("type", "radio")
radio.setAttribute("id", thesis_w)
radio.setAttribute("name", "school")
radio.setAttribute("value", thesis_w)
if(checked_radio == 1)
radio.checked = true
checked_radio=0
div_school.appendChild(lab)
div_school.appendChild(radio)
school_selected.appendChild(div_school)
}
////////////////////////////////////////////////////////////////// import WDPS.xls file function
let readSingleFileCounter = 0
let lessons11 = 0;
let lessons21 = 0;
let lessons_thesis = 0;
let average = 0
function readSingleFile(evt) {
var f = evt.target.files[0];
if (f) {
var r = new FileReader();
r.onload = function (e) {
var contents = e.target.result;
var ct = r.result;
var words = ct.split(' '); //this is not needed
let input_file_as_text = words.join(); //this is bullshit
input_file_as_text = input_file_as_text.replace("\n", " "); //remove newline characters
const regex = /.*([5-9]|10),(0|5).*2.*(1,5|2,0|1,0)/g; // basically match a passing grade (e.g. 8,5 or 10,0 or 5,0) followed by anything and then a "2" (the 2022 following grades in a line, this is to differentiate from other random text that follows thsi pattern) then followed by anything and finally followed by one of 1,0 1,5 1,2
const found = input_file_as_text.match(regex); //find matches for pattern
let grade_sum = 0;
let weight_sum = 0;
for (let i = 0; i < found.length; i++) {
line = found[i].replace(/[\u0009]/g, " "); //replace control character to space for spliting later
let grade = line.split(" ")[5].replace(",", "."); //get 6.5 from 6,5
let weight = line.split(",,").at(-1).replace(",", ".");
let mathima = line.split(" ")[4]
// console.log(i + " " + grade + " " + mathima + " " + weight);
if (weight == 1.5 || weight == 1.0) {
lessons11 = lessons11 + 1;
}
if (weight == 2.0) {
lessons21 = lessons21 + 1;
}
if (weight == '.12,0' && grade >= 5) { // don't know why .xls has thesis weight like that (this if-block will probably not work for other schools)
let school = document.querySelector('input[name="school"]:checked').value;
weight = thesis_weights[school][1]
thesis_grade = grade
lessons_thesis = lessons_thesis + 1;
}
grade_sum = grade_sum + parseFloat(grade)*parseFloat(weight);
weight_sum = weight_sum + parseFloat(weight);
}
average = Math.round(100 * grade_sum / weight_sum) / 100;
document.getElementById("lessons1").value = lessons11;
document.getElementById("lessons2").value = lessons21;
document.getElementById("mo").value = average;
if(lessons_thesis == 1) {
thesis_text.innerText = `-> Βαθμός διπλωματικής: ${thesis_grade}`
thesis_text.style.color = 'red'
document.getElementById("thesis").disabled = true;
}
readSingleFileCounter++
return { lessons11, lessons21, average, readSingleFileCounter }
}
r.readAsText(f, "CP1253");
}
else {
alert("Failed to load file");
}
}
document.getElementById('fileinput').addEventListener('change', readSingleFile, false);
////////////////////////////////////////////////////// read inputs and calculate average
function getMO() {
let lessons1, lessons2, mo
// ελεγχος αν εγινε import του WDP.xls
if (readSingleFileCounter > 0) {
lessons1 = lessons11
lessons2 = lessons21
mo = average
}
else {
////////// αριθμος περασμενων μαθηματων + τωρινος Μ.0
lessons1 = parseInt(Number(document.querySelectorAll('input')[input_counter+1].value));
lessons2 = parseInt(Number(document.querySelectorAll('input')[input_counter+2].value));
mo = (document.querySelectorAll('input')[input_counter+3].value);
}
////////// επιλογη σχολης
let school = document.querySelector('input[name="school"]:checked').value;
console.log("input_counter", input_counter)
////////// διπλωματικη + βαθμοι μαθηματων
let lesson = document.querySelectorAll('input')
let inputs1 = []
let inputs2 = []
let sum1 = 0
let sum2 = 0
for (let i = 3; i < lesson.length - 1; i++) {
let grade = Number(lesson[i].value)
if (lesson[i].name == "input1" && grade >= 5 && grade <= 10) {
inputs1.push(grade * 1.5)
sum1 = sum1 + grade * 1.5
}
if (lesson[i].name == "input2" && grade >= 5 && grade <= 10) {
inputs2.push(grade * 2)
sum2 = sum2 + grade * 2
}
}
let length1 = inputs1.length
let length2 = inputs2.length
/////// βαθμος και συντελεστης διπλωματικης ανα σχολη
let thesis = Number(document.getElementById('thesis').value);
let thesis_weight;
for(let sch in thesis_weights){
if (school == sch){
thesis_weight = thesis_weights[sch][1]
}
}
////////// αρχικος μ.ο και μεταβλητες υπολογισμου
let grades = (lessons1 > 0 || lessons2 > 0) ? (lessons1 * 1.5 + lessons2 * 2) : window.alert("Δώσε τα περασμένα μαθήματά σου")
let current = mo * grades
let lessons = (thesis >= 5 && thesis <= 10) ? (grades + length1 * 1.5 + length2 * 2 + thesis_weight) : (grades + length1 * 1.5 + length2 * 2)
/// ελεγχοι για τιμες μεταξυ 5 και 10
thesis = (thesis >= 5 && thesis <= 10) ? thesis : 0
lessons1 = (lessons1 >= 0 && lessons1 <= 39) ? lessons1 : window.alert("Αρ. μαθημάτων με συντελεστή 1.5 για πτυχίο: 27 μαθήματα κορμού + το πολύ 12 κατεύθυνσης")
lessons2 = (lessons2 >= 0 && lessons2 <= 27) ? lessons2 : window.alert("Αρ. μαθημάτων με συντελεστή 2 για πτυχίο: 11 μαθήματα κορμού + τουλάχιστον 4 και το πολύ 16 κατεύθυνσης")
mo = (mo >= 5 && mo <= 10) ? mo : window.alert("Πες την αλήθεια ωρέ, τι Μ.Ο έχεις;")
////////// νεος Μ.Ο.
let new_mo = (current + sum1 + sum2 + thesis * thesis_weight) / lessons ;
new_mo = new_mo.toPrecision(3)
/////////// Πληροφορια για τον νεο ΜΟ
let show = document.createElement('div')
let text = show.innerText
if(school == 'ece')
show.innerText = `Συγχαρητήρια μηχανευτή. Ο νέος Μ.Ο. σου είναι: ${new_mo}`
else
show.innerText = `Συγχαρητήρια! Ο νέος Μ.Ο. σου είναι: ${new_mo}`
show.style.color = "blue";
if(!isNaN(new_mo))
document.querySelector('form').appendChild(show)
}
/////////////////////////////////////////////////////// προσθηκη και αφαιρεση μαθηματων
function addLesson(k) {
// console.log(`Προστέθηκε μάθημα με συντελεστή: ${k}`)
let input = document.createElement('input')
input.type = "number"
input.placeholder = 0
input.innerText = "test"
input.style.color = "black";
input.style.margin = "5px"
input.style.value = "0"
input.style.width = "100px"
input.min = 5
input.max = 10
input.step = 0.5
let button = document.createElement('button')
button.textContent = "-"
button.style.color = "blue"
if (k == 1.5) {
input.name = "input1"
document.getElementById('input1').appendChild(input)
document.getElementById('input1').appendChild(button)
button.addEventListener('click', () => {
input.remove()
button.remove()
});
}
if (k == 2) {
input.name = "input2"
document.getElementById('input2').appendChild(input)
document.getElementById('input2').appendChild(button)
button.addEventListener('click', () => {
input.remove()
button.remove()
});
}
}