Hong-Phuc Bui
2025-01-16 2889de7f0c2d587a17fbd322af57c29e84238620
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
import {calculateHomeworkTime} from "../study.js";
 
export function makeEffortTable(lecturesInformation) {
    let table = `<table>
    <tr><th class="name">Vorlesung</th><th class="effort">Aufwand pro Woche in Stunden</th></tr>\n`;
    for(let l of lecturesInformation) {
        table += `<tr><td class="name">${l.name}</td> <td class="effort">${l.homework}</td></tr>\n`
    }
    table += "</table>";
    return table;
}
 
 
export function calculateSemesterEffort(lectures) {
    let lecturesInformation = []
    for(let lecture of lectures ) {
        let homework = calculateHomeworkTime(lecture.ects, lecture.sws/2);
        let newLecture = Object.assign({},lecture);
        newLecture.homework = homework;
        // handle omitted sws or ects
        let sws = newLecture["sws"] || 0;
        newLecture["sws"] = sws;
        let ects = newLecture["ects"] || 0;
        newLecture["ects"] = ects;
        lecturesInformation.push(newLecture);
    }
    return lecturesInformation;
}
/**
 * columns of csv: order is matter!
 * name; code; sws; ects
 * */
export function parseCSV(csvFormat) {
    let csv = csvFormat.trim();
    let data = [];
    for(let line of csv.split("\n") ) {
        let values = line.split(";");
        let name = values[0].trim();
        let code = values[1] ;
        code = code ? code.trim() : code; // if code is not an undefined, then trim it
        let sws = Number.parseInt(values[2], 10);
        let ects = Number.parseInt(values[3], 10);
        data.push({name, code, sws, ects});
    }
    return data;
}