This repository was archived by the owner on Mar 28, 2023. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathindex.html
More file actions
521 lines (411 loc) · 20.5 KB
/
index.html
File metadata and controls
521 lines (411 loc) · 20.5 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
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="utf-8">
<meta name="viewport" content="width=device-width, initial-scale=1, shrink-to-fit=no">
<meta name="description" content="">
<meta name="author" content="">
<link rel="icon" href="../../../../favicon.ico">
<title>Timetable Calculator</title>
<!-- Bootstrap core CSS -->
<link rel="stylesheet" href="https://stackpath.bootstrapcdn.com/bootstrap/4.1.0/css/bootstrap.min.css" integrity="sha384-9gVQ4dYFwwWSjIDZnLEWnxCjeSWFphJiwGPXr1jddIhOegiu1FwO5qRGvFXOdJZ4" crossorigin="anonymous">
<!-- Custom styles for this template -->
<style type="text/css">
body {
padding-top: 5rem;
background-color: grey;
}
</style>
</head>
<body>
<nav class="navbar navbar-expand-md navbar-dark bg-dark fixed-top">
<a class="navbar-brand" href="#">Navbar</a>
<button class="navbar-toggler" type="button" data-toggle="collapse" data-target="#navbarsExampleDefault" aria-controls="navbarsExampleDefault" aria-expanded="false" aria-label="Toggle navigation">
<span class="navbar-toggler-icon"></span>
</button>
<div class="collapse navbar-collapse" id="navbarsExampleDefault">
<ul class="navbar-nav mr-auto">
<li class="nav-item active">
<a class="nav-link" href="#">Home <span class="sr-only">(current)</span></a>
</li>
<li class="nav-item">
<a class="nav-link" href="#">Link</a>
</li>
<li class="nav-item">
<a class="nav-link disabled" href="#">Disabled</a>
</li>
<li class="nav-item dropdown">
<a class="nav-link dropdown-toggle" href="http://example.com" id="dropdown01" data-toggle="dropdown" aria-haspopup="true" aria-expanded="false">Dropdown</a>
<div class="dropdown-menu" aria-labelledby="dropdown01">
<a class="dropdown-item" href="#">Action</a>
<a class="dropdown-item" href="#">Another action</a>
<a class="dropdown-item" href="#">Something else here</a>
</div>
</li>
</ul>
</div>
</nav>
<main role="main" class="container">
<div class="container">
<div class="row">
<div class="col-md-2">
<br><br><br><br><br><br>
<h1>Select Lesson:</h1>
<div class="custom-control custom-radio">
<input id="button1" class="custom-control-input" name="buttons" value="1" type="radio" ></input>
<label for="button1" class="custom-control-label font-weight-bold">Subject 1</label>
</div>
<div class="custom-control custom-radio">
<input id="button2" class="custom-control-input" name="buttons" value="2" type="radio" ></input>
<label for="button2" class="custom-control-label font-weight-bold">Subject 2</label>
</div>
<div class="custom-control custom-radio">
<input id="button3" class="custom-control-input" name="buttons" value="3" type="radio" ></input>
<label for="button3" class="custom-control-label font-weight-bold">Subject 3</label>
</div>
<div class="custom-control custom-radio">
<input id="button4" class="custom-control-input" name="buttons" value="4" type="radio" ></input>
<label for="button4" class="custom-control-label font-weight-bold">Subject 4</label>
</div>
<div class="custom-control custom-radio">
<input id="button5" class="custom-control-input" name="buttons" value="5" type="radio" ></input>
<label for="button5" class="custom-control-label font-weight-bold">Subject 5</label>
</div>
<div class="custom-control custom-radio">
<input id="button6" class="custom-control-input" name="buttons" value="6" type="radio" ></input>
<label for="button6" class="custom-control-label font-weight-bold">Subject 6</label>
</div>
</div>
<div class="col-md-8">
<div>
<h1 class="text-center" style="text-decoration: underline;">Timetable Calculator</h1>
<br>
</div>
<b>Week 1</b>
<table id="week1Table" class="table table-dark table-sm"></table>
<b>Week 2</b>
<table id="week2Table" class="table table-dark table-sm"></table>
</div>
</div>
</div>
<div class="form-group ">
<div class="row">
<div class="col">
<label for="lesson1" style="font-weight: bold;">Subject 1: </label>
<input id="lesson1" name="lessons" class="form-control" style="background-color:fuchsia"></input>
</div>
<div class="col">
<label for="lesson2" style="font-weight: bold;">Subject 2: </label>
<input id="lesson2" name="lessons" class="form-control" style="background-color:olive"></input>
</div>
<div class="col">
<label for="lesson3" style="font-weight: bold;">Subject 3: </label>
<input id="lesson3" name="lessons" class="form-control" style="background-color:aqua"></input>
</div>
</div>
<div class="row">
<div class="col">
<label for="lesson4" style="font-weight: bold;">Subject 4: </label>
<input id="lesson4" name="lessons" class="form-control" style="background-color:silver"></input>
</div>
<div class="col">
<label for="lesson5" style="font-weight: bold;">Subject 5: </label>
<input id="lesson5" name="lessons" class="form-control" style="background-color:maroon"></input>
</div>
<div class="col">
<label for="lesson6" style="font-weight: bold;">Subject 6: </label>
<input id="lesson6" name="lessons" class="form-control" style="background-color:lime"></input>
</div>
</div>
</div>
<button class="btn" onclick="calcLessons()">Click me</button>
<br>
<h1 id="answer">Answer Will appear here</h1>
<br><br>
</main>
<!-- /.container -->
<script type="text/javascript">
function getSelected(){
let buttons = document.getElementsByName('buttons');
for (let button of buttons){
if (button.checked) return(button.value);
}
return('');
}
function cellClicked(myId){
let subject = getSelected();
if (subject){
let colors = ['fuchsia','olive','aqua','silver','maroon','lime'];
myId.style.backgroundColor = colors[subject - 1];
let lesson = document.getElementById('lesson' + subject);
myId.value = lesson.value;
}
}
function getTimetable(){
let array = [[[],[],[],[],[]],[[],[],[],[],[]]];
for (let i = 0; i < 5; i++){
for (let t = 0; t < 5; t++){
for (let j = 0; j < 2; j++){
let currCellId = 'cell' + j + t + i;
let currCell = document.getElementById(currCellId);
let value = currCell.value;
array[j][i].push(value);
}
}
}
return(array);
}
function getSubjects(){
let array = []
let lessons = document.getElementsByName('lessons');
for (let lesson of lessons){
array.push(lesson.value)
}
return(array);
}
function makeTable(myId,num){
let table = document.getElementById(myId);
let row = table.insertRow(0);
row.insertCell(0).innerHTML = '';
row.insertCell(1).innerHTML = 'Period 1';
row.insertCell(2).innerHTML = 'Period 2';
row.insertCell(3).innerHTML = 'Period 3';
row.insertCell(4).innerHTML = 'Period 4';
row.insertCell(5).innerHTML = 'Period 5';
let days = ['Monday','Tuesday','Wednesday','Thursday','Friday'];
for (let i=1; i < 6; i++){
let newRow = table.insertRow(i);
for (let t=0; t<6; t++){
let cellid = 'cell' + num + (t-1) + (i-1);
let insideHtml = "<input size='1' class='form-control' id = '" + cellid + "' onclick='cellClicked(" + cellid + ")' readonly> </input>";
if (t==0) {
newRow.insertCell(t).innerHTML = days[i - 1];
}else{
newRow.insertCell(t).innerHTML = insideHtml;
}
}
}
}
makeTable('week1Table',0);
makeTable('week2Table',1);
let t1start = new Date(2019,8,4);//give the starts as the first day back and the ends as the last school day
let t1end = new Date(2019,9,25);
let t2start = new Date(2019,10,4);
let t2end = new Date(2019,11,20);
let t3start = new Date(2020,0,7);
let t3end = new Date(2020,1,14);
let t4start = new Date(2020,1,24);
let t4end = new Date(2020,3,3);
let t5start = new Date(2020,2,20);
let t5end = new Date(2020,4,22);
let t6start = new Date(2020,5,1);
let t6end = new Date(2020,6,17);
let dates = [t1start,t1end,t2start,t2end,t3start,t3end,t4start,t4end,t5start,t5end,t6start,t6end];
let p1start = [9,0];//means 9:00 am
let p1end = [10,0]
let p2start = [10,15];
let p2end = [11,15];
let p3start = [11,30];
let p3end = [12,30];
let p4start = [13,20];
let p4end = [14,20];
let p5start = [14,25];
let p5end = [15,25];
let times = [p1start,p1end,p2start,p2end,p3start,p3end,p4start,p4end,p5start,p5end];
//let s1 = 'Maths';
//let s2 = 'Further Maths';
//let s3 = 'Computing';
//let s4 = 'Physics';
//let s5 = 'Tutor Group';
//let s6 = 'Free';
//let subjects = [s1,s2,s3,s4,s5,s6];
//let timetable = [[[s6,s4,s4,s4,s6],[s2,s3,s3,s1,s2],[s2,s4,s2,s3,s3],[s2,s1,s1,s3,s3],[s4,s4,s6,s4,s1]],
//[[s3,s2,s3,s4,s1],[s6,s1,s4,s1,s1],[s2,s3,s5,s6,s6],[s3,s2,s1,s6,s2],[s1,s4,s6,s2,s6]]];
function getWeekday(date) {
let day = date.getDay();
if (day == 0) {
day = 7;
}
return(day);
}
function checkSameDay(date1,date2) {
if(getDayString(date1) === getDayString(date2)){
return(true);
}else{
return(false);
}
}
function getDayString(date) {
let month = String(date.getMonth());
month = (month.length == 1) ? '0' + month : month;
let num = String(date.getDate());
num = (num.length == 1) ? '0' + num : num;
let output = String(date.getFullYear() + month + num);
return(output);
}
function addDay(date) {
let result = new Date(date);
result.setDate(result.getDate() + 1);
return(result);
}
function checkSchoolDay(date) {
let schoolTerm = false;
if (getWeekday(date) < 6){
for(let i = 0;i<12;i += 2){
schoolTerm = (getDayString(date) >= getDayString(dates[i]) && getDayString(date) <= getDayString(dates[i+1])) ? true : false;
if (schoolTerm){
break;
}
}
}
return(schoolTerm);
}
function calcWholeDays(date1,date2) {
let loop = true;
let week = 1;//0 = week1 1 = week2 starts on week2 because it flips before adding the day
let currDate = t1start;
let days = [[0,0,0,0,0],[0,0,0,0,0]];
let lastDate = new Date(1111,1,1);
while(loop){
if (checkSchoolDay(currDate)){
if (getDayString(currDate) > getDayString(addDay(lastDate))){//if its been more than a days since the last schoolday
week = (week) ? 0 : 1;//flips week
}
if (getDayString(currDate) > getDayString(date1)){
days[week][getWeekday(currDate) - 1] += 1;//adds 1 to days tally
}
lastDate = currDate;
}
currDate = addDay(currDate);//loop incrementor
if (getDayString(currDate) >= getDayString(date2)){//loop breaker if they are on the same day or after
loop = false;
}
}
return(days);
}
function countOccurence(item,list) {//counts number of times item occurs in list
let count = 0;
for(let i = 0 ; i < list.length ; i++){
if (list[i] == item){
count++;
}
}
return(count);
}
function calcSubjectPerDay(subjects,timetable) {
let timetableTotals = [[[0,0,0,0,0,0],[0,0,0,0,0,0],[0,0,0,0,0,0],[0,0,0,0,0,0],[0,0,0,0,0,0]],[[0,0,0,0,0,0],[0,0,0,0,0,0],[0,0,0,0,0,0],[0,0,0,0,0,0],[0,0,0,0,0,0]]];
for (let i = 0; i < 5; i++){
for (let j = 0; j < 6; j++){
timetableTotals[0][i][j] += countOccurence(subjects[j],timetable[0][i]);
timetableTotals[1][i][j] += countOccurence(subjects[j],timetable[1][i]);
}
}
return(timetableTotals);
}
function calcTotalSubjects(date1,date2,subjects,timetable) {
let SubjectsPerDay = calcSubjectPerDay(subjects,timetable);
let WholeDays = calcWholeDays(date1,date2);
let totalSubjects = [0,0,0,0,0,0];
for (let i = 0; i < 6; i++){
for (let j = 0; j < 5; j++){
totalSubjects[i] += WholeDays[0][j] * SubjectsPerDay[0][j][i];
totalSubjects[i] += WholeDays[1][j] * SubjectsPerDay[1][j][i];
}
}
return(totalSubjects);
}
function getCurrentPeriod(date) {
let hour = date.getHours() + 1;//+1 because we want 1 to mean 12am - 1am not 1am - 2am
let minute = date.getMinutes() + 1;//same reason
let totalMinutes = hour * 60 + minute;
let timesTotalMinutes = 0;
let period = null;
for (let i = 0; i < 10; i++){
timesTotalMinutes = times[i][0] * 60 + times[i][1]
if (totalMinutes < timesTotalMinutes){
period = i;
break;
}
}
if (totalMinutes >= timesTotalMinutes){
period = 10;
}
return(period);
}
function getWeekNum(date) {//warning if run on a holiday it will return the week number prior to the holiday
let loop = true;
let currDate = t1start;
let week = 1;//0 = week1 1 = week2 starts on week2 because it flips before adding the day
let lastDate = new Date(1111,1,1);
let actualWeek = null;
while (loop == true){
if (checkSchoolDay(currDate)){
if (getDayString(currDate) > getDayString(addDay(lastDate))){//if its been more than a days since the last schoolday
week = (week) ? 0 : 1;//flips week
}
lastDate = currDate;
}
if (getDayString(currDate) == getDayString(date)){//loop breaker if day is a school day
loop = false;
actualWeek = week;
}
currDate = addDay(currDate);//loop incrementor
}
return(actualWeek);
}
function addPartialDayLessons(date,totalSubjects,start,subjects,timetable) {//0 = all 1 = period2 onwards ...
let dayNumber = getWeekday(date);
let index = 0;
let week = getWeekNum(date);
for (let i = start; i < 5; i++){
index = subjects.indexOf(timetable[week][dayNumber - 1][i]);
totalSubjects[index]++;
}
return(totalSubjects);
}
function addTodaysLessons(date,totalSubjects,subjects,timetable) {
if (checkSchoolDay(date)){
let period = getCurrentPeriod(date);
let start = Math.ceil(period/2);
if (period < 9){
totalSubjects = addPartialDayLessons(date,totalSubjects,start,subjects,timetable);
}
}
return(totalSubjects);
}
function calcCompleteLessonsBetween(subjects,timetable) {
let date1 = new Date();
let date2 = new Date(2020,6,17);
let totalSubjects = calcTotalSubjects(date1,date2,subjects,timetable);
totalSubjects = addTodaysLessons(date1,totalSubjects,subjects,timetable);
return(totalSubjects);
}
function calcLessons(){
let subjects = getSubjects();
let timetable = getTimetable();
let output = calcCompleteLessonsBetween(subjects,timetable);
for (let i = 0; i < subjects.length; i++){//search linealy through the array for any duplicates and deletes their output along with their subject
for (let t = 0; t < subjects.length; t++){
if (subjects[i] == subjects[t] && i != t){
output.splice(t,1);
subjects.splice(t,1);
t -= 1; //need to decrease t as the list just got shorter
}
}
}
for (let i = 0; i < subjects.length; i++){
if (subjects[i] == ""){
subjects[i] = 'Free(s)';
}
}
answer.innerHTML = output + subjects;
}
</script>
<!-- Bootstrap core JavaScript
================================================== -->
<!-- Placed at the end of the document so the pages load faster -->
<script src="https://code.jquery.com/jquery-3.3.1.slim.min.js" integrity="sha384-q8i/X+965DzO0rT7abK41JStQIAqVgRVzpbzo5smXKp4YfRvH+8abtTE1Pi6jizo" crossorigin="anonymous"></script>
<script src="https://cdnjs.cloudflare.com/ajax/libs/popper.js/1.14.0/umd/popper.min.js" integrity="sha384-cs/chFZiN24E4KMATLdqdvsezGxaGsi4hLGOzlXwp5UZB1LY//20VyM2taTB4QvJ" crossorigin="anonymous"></script>
<script src="https://stackpath.bootstrapcdn.com/bootstrap/4.1.0/js/bootstrap.min.js" integrity="sha384-uefMccjFJAIv6A+rW+L4AHf99KvxDjWSu1z9VI8SKNVmz4sk7buKt/6v9KI65qnm" crossorigin="anonymous"></script>
</body>
</html>