Search in sources :

Example 26 with Substitution

use of me.vertretungsplan.objects.Substitution in project substitution-schedule-parser by vertretungsplanme.

the class DaVinciParser method parseDaVinciTable.

static void parseDaVinciTable(Element table, SubstitutionSchedule v, String klasse, SubstitutionScheduleDay day, ColorProvider colorProvider) {
    boolean skipRow = false;
    List<String> headers = new ArrayList<>();
    for (Element header : table.select("thead tr th")) {
        headers.add(header.text());
    }
    if (headers.size() == 0) {
        skipRow = true;
        for (Element header : table.select(" tr:first-child td")) {
            headers.add(header.text());
        }
    }
    // These three variables can
    Set<String> classes = new HashSet<>();
    String lesson = null;
    LocalDate currentDate = null;
    Pattern previousCurrentPattern = Pattern.compile("\\+([^\\s]+) \\(([^)]+)\\)");
    Pattern previousPattern = Pattern.compile("\\(([^)]+)\\)");
    for (Element row : table.select("tr:not(thead tr)")) {
        if (skipRow) {
            skipRow = false;
            continue;
        }
        Substitution subst = new Substitution();
        LocalDate substDate = null;
        Elements columns = row.select("td");
        for (int i = 0; i < headers.size(); i++) {
            String value = columns.get(i).text().replace("\u00a0", "");
            String header = headers.get(i);
            if (value.isEmpty()) {
                if (header.equals("Klasse"))
                    subst.setClasses(new HashSet<>(classes));
                if (header.equals("Pos") || header.equals("Stunde") || header.equals("Std.") || header.equals("Dstd.")) {
                    subst.setLesson(lesson);
                }
                if (header.equals("Art") || header.equals("Merkmal"))
                    subst.setType("Vertretung");
                if (header.equals("Datum"))
                    substDate = currentDate;
                continue;
            }
            Matcher previousCurrentMatcher = previousCurrentPattern.matcher(value);
            Matcher previousMatcher = previousPattern.matcher(value);
            switch(header) {
                case "Klasse":
                    String classesStr = value;
                    if (previousMatcher.find()) {
                        classesStr = previousMatcher.group(1);
                    }
                    classes = new HashSet<>(Arrays.asList(classesStr.split(", ")));
                    subst.setClasses(classes);
                    break;
                case "Pos":
                case "Stunde":
                case "Std.":
                case "Dstd.":
                    lesson = value;
                    subst.setLesson(lesson);
                    break;
                case "VLehrer Kürzel":
                case "VLehrer":
                case "Vertreter":
                case "Vertretungslehrkraft":
                    if (!value.startsWith("*")) {
                        subst.setTeacher(value);
                    } else {
                        subst.setType(value.substring(1));
                    }
                    break;
                case "Lehrer":
                case "Lehrer Kürzel":
                case "Lehrer Name":
                case "Lehrkraft":
                    if (previousCurrentMatcher.find()) {
                        subst.setTeacher(previousCurrentMatcher.group(1));
                        subst.setPreviousTeacher(previousCurrentMatcher.group(2));
                    } else if (previousMatcher.find()) {
                        subst.setPreviousTeacher(previousMatcher.group(1));
                    } else {
                        subst.setPreviousTeacher(value);
                    }
                    break;
                case "VFach":
                case "V Fach":
                    subst.setSubject(value);
                    break;
                case "Fach":
                case "Original Fach":
                    if (previousCurrentMatcher.find()) {
                        subst.setSubject(previousCurrentMatcher.group(1));
                        subst.setPreviousSubject(previousCurrentMatcher.group(2));
                    } else {
                        subst.setPreviousSubject(value);
                    }
                    break;
                case "VRaum":
                case "V Raum":
                    subst.setRoom(value);
                    break;
                case "Raum":
                case "Original Raum":
                    if (previousCurrentMatcher.find()) {
                        subst.setRoom(previousCurrentMatcher.group(1));
                        subst.setPreviousRoom(previousCurrentMatcher.group(2));
                    } else {
                        subst.setPreviousRoom(value);
                    }
                    break;
                case "Art":
                case "Merkmal":
                    subst.setType(value);
                    break;
                case "Info":
                case "Mitteilung":
                    subst.setDesc(value);
                    break;
                case "Datum":
                    substDate = ParserUtils.parseDate(value);
                    currentDate = substDate;
                    break;
            }
        }
        if (klasse != null) {
            Set<String> fixedClasses = new HashSet<>();
            fixedClasses.add(klasse);
            subst.setClasses(fixedClasses);
        }
        if (subst.getType() == null) {
            String recognizedType = null;
            if (subst.getDesc() != null)
                recognizedType = recognizeType(subst.getDesc());
            subst.setType(recognizedType != null ? recognizedType : "Vertretung");
        }
        subst.setColor(colorProvider.getColor(subst.getType()));
        if (substDate == null && day == null)
            continue;
        if (day == null || substDate != null && !substDate.equals(day.getDate())) {
            day = null;
            for (SubstitutionScheduleDay d : v.getDays()) {
                if (d.getDate().equals(substDate)) {
                    day = d;
                }
            }
            if (day == null) {
                day = new SubstitutionScheduleDay();
                day.setDate(substDate);
                v.addDay(day);
            }
        }
        day.addSubstitution(subst);
    }
}
Also used : Pattern(java.util.regex.Pattern) Matcher(java.util.regex.Matcher) Element(org.jsoup.nodes.Element) Elements(org.jsoup.select.Elements) LocalDate(org.joda.time.LocalDate) Substitution(me.vertretungsplan.objects.Substitution) SubstitutionScheduleDay(me.vertretungsplan.objects.SubstitutionScheduleDay)

Example 27 with Substitution

use of me.vertretungsplan.objects.Substitution in project substitution-schedule-parser by vertretungsplanme.

the class IndiwareMobileParser method parseDay.

static SubstitutionScheduleDay parseDay(Document doc, ColorProvider colorProvider, SubstitutionScheduleData scheduleData) {
    SubstitutionScheduleDay day = new SubstitutionScheduleDay();
    day.setDate(ParserUtils.parseDate(doc.select("Kopf > DatumPlan").text()));
    day.setLastChange(ParserUtils.parseDateTime(doc.select("Kopf > Zeitstempel").text()));
    for (Element klasse : doc.select("Klassen > Kl")) {
        String className = klasse.select("Kurz").first().text();
        HashSet<String> classes = new HashSet<>();
        classes.add(className);
        for (Element lesson : klasse.select("Pl > Std")) {
            if (lesson.select("If:not(:empty), Le[LeAe], Ra[RaAe], Fa[FaAe]").size() == 0) {
                continue;
            }
            Substitution subst = new Substitution();
            subst.setLesson(text(lesson.select("St")));
            if (scheduleData.getType() == SubstitutionSchedule.Type.STUDENT) {
                subst.setTeachers(split(text(lesson.select("Le"))));
                subst.setClasses(classes);
            } else {
                subst.setClasses(split(text(lesson.select("Le"))));
                subst.setTeachers(classes);
            }
            subst.setSubject(text(lesson.select("Fa")));
            subst.setRoom(text(lesson.select("Ra")));
            IndiwareParser.handleDescription(subst, text(lesson.select("If")), scheduleData.getType() == SubstitutionSchedule.Type.TEACHER);
            if (subst.getType() == null)
                subst.setType("Vertretung");
            subst.setColor(colorProvider.getColor(subst.getType()));
            day.addSubstitution(subst);
        }
    }
    for (Element info : doc.select("ZusatzInfo > ZiZeile")) {
        day.getMessages().add(info.text());
    }
    return day;
}
Also used : Substitution(me.vertretungsplan.objects.Substitution) Element(org.jsoup.nodes.Element) SubstitutionScheduleDay(me.vertretungsplan.objects.SubstitutionScheduleDay) HashSet(java.util.HashSet)

Example 28 with Substitution

use of me.vertretungsplan.objects.Substitution in project substitution-schedule-parser by vertretungsplanme.

the class NotCompatibleParser method getSubstitutionSchedule.

@Override
public SubstitutionSchedule getSubstitutionSchedule() throws IOException, JSONException, CredentialInvalidException {
    SubstitutionSchedule v = SubstitutionSchedule.fromData(scheduleData);
    v.setLastChange(new LocalDateTime(2017, 10, 18, 12, 4));
    SubstitutionScheduleDay today = new SubstitutionScheduleDay();
    today.setDate(new LocalDate(2018, 1, 1));
    Substitution subst = new Substitution();
    subst.setLesson("0");
    subst.setClasses(new HashSet<>(getAllClasses()));
    subst.setType("siehe Nachrichten");
    subst.setDesc("Der Vertretungsplan kann von dieser Schule nicht mehr abgerufen werden. Genauere Informationen" + " findest du unter \"Nachrichten\".");
    subst.setColor("#F44336");
    today.addSubstitution(subst);
    today.addMessage("Aus technischen Gründen kann der Vertretungsplan dieser Schule mit dieser App nicht mehr " + "abgerufen werden. " + (scheduleData.getApi().equals("dsbmobile") ? "Als Alternative kannst du vorerst die offizielle " + "App \"DSBmobile\" nutzen. " : "") + "Falls Sie eine Lehrkraft oder Schulleiter/-in an der Schule sind, melden Sie sich " + "bitte unter info@vertretungsplan.me bei uns, um herauszufinden, wie der Plan wieder in die App " + "aufgenommen werden kann. Falls Sie die Pro-Version der App gekauft haben, können wir " + "Ihnen das Geld zurückerstatten, wenn Sie sich per E-Mail an info@vertretungsplan.me bei uns melden.");
    v.addDay(today);
    v.setClasses(getAllClasses());
    v.setTeachers(new ArrayList<String>());
    return v;
}
Also used : LocalDateTime(org.joda.time.LocalDateTime) Substitution(me.vertretungsplan.objects.Substitution) SubstitutionSchedule(me.vertretungsplan.objects.SubstitutionSchedule) SubstitutionScheduleDay(me.vertretungsplan.objects.SubstitutionScheduleDay) LocalDate(org.joda.time.LocalDate)

Example 29 with Substitution

use of me.vertretungsplan.objects.Substitution in project substitution-schedule-parser by vertretungsplanme.

the class SVPlanParser method parseSvPlanDay.

private void parseSvPlanDay(SubstitutionSchedule v, Element svp, Document doc) throws IOException, JSONException {
    SubstitutionScheduleDay day = new SubstitutionScheduleDay();
    if ((svp.select(".svp-plandatum-heute, .svp-plandatum-morgen, .Titel").size() > 0 || doc.title().startsWith("Vertretungsplan für "))) {
        setDate(svp, doc, day);
        final Elements tables = svp.select(".svp-tabelle, table:has(.Klasse)");
        if (tables.size() > 0) {
            Iterator<Element> iter = tables.iterator();
            while (iter.hasNext()) {
                Element table = iter.next();
                if (!table.hasClass("svp-tabelle") && table.select("> tbody > tr > td.Klasse").size() == 0) {
                    iter.remove();
                }
            }
            Elements rows = tables.select("tr");
            String lastLesson = "";
            String lastClass = "";
            for (Element row : rows) {
                if ((doc.select(".svp-header").size() > 0 && row.hasClass("svp-header")) || row.select("th").size() > 0 || row.text().trim().equals("")) {
                    continue;
                }
                Substitution substitution = new Substitution();
                for (Element column : row.select("td")) {
                    String type = column.className();
                    if (!hasData(column.text())) {
                        if ((type.startsWith("svp-stunde") || type.startsWith("Stunde")) && hasData(lastLesson)) {
                            substitution.setLesson(lastLesson);
                        } else if ((type.startsWith("svp-klasse") || type.startsWith("Klasse")) && hasData(lastClass) && data.optBoolean(PARAM_REPEAT_CLASS, true)) {
                            substitution.getClasses().addAll(getClasses(lastClass));
                        }
                        continue;
                    }
                    if (type.startsWith("svp-stunde") || type.startsWith("Stunde")) {
                        substitution.setLesson(column.text());
                        lastLesson = column.text();
                    } else if (type.startsWith("svp-klasse") || type.startsWith("Klasse")) {
                        substitution.getClasses().addAll(getClasses(column.text()));
                        lastClass = column.text();
                    } else if (type.startsWith("svp-esfehlt") || type.startsWith("Lehrer")) {
                        if (!data.optBoolean(PARAM_EXCLUDE_TEACHERS)) {
                            substitution.setPreviousTeacher(column.text());
                        }
                    } else if (type.startsWith("svp-esvertritt") || type.startsWith("Vertretung")) {
                        if (!data.optBoolean(PARAM_EXCLUDE_TEACHERS)) {
                            substitution.setTeacher(column.text().replaceAll(" \\+$", ""));
                        }
                    } else if (type.startsWith("svp-fach") || type.startsWith("Fach")) {
                        substitution.setSubject(column.text());
                    } else if (type.startsWith("svp-bemerkung") || type.startsWith("Anmerkung")) {
                        substitution.setDesc(column.text());
                        String recognizedType = recognizeType(column.text());
                        substitution.setType(recognizedType);
                        substitution.setColor(colorProvider.getColor(recognizedType));
                    } else if (type.startsWith("svp-raum") || type.startsWith("Raum")) {
                        substitution.setRoom(column.text());
                    }
                }
                if (substitution.getType() == null) {
                    substitution.setType("Vertretung");
                    substitution.setColor(colorProvider.getColor("Vertretung"));
                }
                day.addSubstitution(substitution);
            }
        }
        if (svp.select(".LehrerVerplant").size() > 0) {
            day.addMessage("<b>Verplante Lehrer:</b> " + svp.select(".LehrerVerplant").text());
        }
        if (svp.select(".Abwesenheiten").size() > 0) {
            day.addMessage("<b>Abwesenheiten:</b> " + svp.select(".Abwesenheiten").text());
        }
        if (svp.select("h2:contains(Mitteilungen)").size() > 0) {
            Element h2 = svp.select("h2:contains(Mitteilungen)").first();
            Element sibling = h2.nextElementSibling();
            while (sibling != null && sibling.tagName().equals("p")) {
                for (String nachricht : TextNode.createFromEncoded(sibling.html(), null).getWholeText().split("<br />\\s*<br />")) {
                    if (hasData(nachricht))
                        day.addMessage(nachricht);
                }
                sibling = sibling.nextElementSibling();
            }
        } else if (svp.select(".Mitteilungen").size() > 0) {
            for (Element p : svp.select(".Mitteilungen")) {
                for (String nachricht : TextNode.createFromEncoded(p.html(), null).getWholeText().split("<br />\\s*<br />")) {
                    if (hasData(nachricht))
                        day.addMessage(nachricht);
                }
            }
        }
        v.addDay(day);
    } else {
        throw new IOException("keine SVPlan-Tabelle gefunden");
    }
}
Also used : Substitution(me.vertretungsplan.objects.Substitution) Element(org.jsoup.nodes.Element) SubstitutionScheduleDay(me.vertretungsplan.objects.SubstitutionScheduleDay) IOException(java.io.IOException) Elements(org.jsoup.select.Elements)

Example 30 with Substitution

use of me.vertretungsplan.objects.Substitution in project substitution-schedule-parser by vertretungsplanme.

the class TurboVertretungParser method parseTurboVertretungDay.

private void parseTurboVertretungDay(SubstitutionSchedule v, Document doc) {
    SubstitutionScheduleDay day = new SubstitutionScheduleDay();
    String date = doc.select(".Titel").text().replaceFirst("Vertretungsplan( für)? ", "");
    day.setDate(DateTimeFormat.forPattern("EEEE, d. MMMM yyyy").withLocale(Locale.GERMAN).parseLocalDate(date));
    String lastChange = doc.select(".Stand").text();
    day.setLastChange(ParserUtils.parseDateTime(lastChange));
    if (doc.text().contains("Kein Vertretungsplan")) {
        v.addDay(day);
        return;
    }
    if (doc.select(".LehrerFrueher").size() > 0) {
        day.addMessage(doc.select(".LehrerFrueherLabel").text() + "\n" + doc.select(".LehrerFrueher").text());
    }
    if (doc.select(".LehrerVerplant").size() > 0) {
        day.addMessage(doc.select(".LehrerVerplantLabel").text() + "\n" + doc.select(".LehrerVerplant").text());
    }
    if (doc.select(".Abwesenheiten-Klassen").size() > 0) {
        day.addMessage(doc.select(".Abwesenheiten-KlassenLabel").text() + "\n" + doc.select(".Abwesenheiten-Klassen").text());
    }
    if (doc.select(".Abwesenheiten").size() > 0) {
        day.addMessage(doc.select(".AbwesenheitenLabel").text() + "\n" + doc.select(".Abwesenheiten").text());
    }
    Element table = doc.select("table").first();
    for (Element row : table.select("tr:has(td)")) {
        if (row.select(".Klasseleer").size() > 0)
            continue;
        Substitution substitution = new Substitution();
        substitution.setLesson(row.select(query("Stunde")).text());
        substitution.setPreviousTeacher(row.select(query("Lehrer")).text());
        substitution.setTeacher(row.select(query("Vertretung")).text());
        substitution.setClasses(new HashSet<>(Arrays.asList(row.select(query("Klasse")).text().split(" "))));
        substitution.setSubject(row.select(query("Fach")).text());
        substitution.setDesc(row.select(query("Anmerkung")).text());
        substitution.setRoom(row.select(query("Raum")).text());
        String type = recognizeType(row.select(query("Anmerkung")).text());
        if (type == null)
            type = "Vertretung";
        substitution.setType(type);
        substitution.setColor(colorProvider.getColor(type));
        day.addSubstitution(substitution);
    }
    v.addDay(day);
}
Also used : Substitution(me.vertretungsplan.objects.Substitution) Element(org.jsoup.nodes.Element) SubstitutionScheduleDay(me.vertretungsplan.objects.SubstitutionScheduleDay)

Aggregations

Substitution (me.vertretungsplan.objects.Substitution)35 Test (org.junit.Test)15 SubstitutionScheduleDay (me.vertretungsplan.objects.SubstitutionScheduleDay)14 Element (org.jsoup.nodes.Element)11 LocalDate (org.joda.time.LocalDate)9 SubstitutionSchedule (me.vertretungsplan.objects.SubstitutionSchedule)8 LocalDateTime (org.joda.time.LocalDateTime)7 Elements (org.jsoup.select.Elements)5 IOException (java.io.IOException)4 ArrayList (java.util.ArrayList)4 Document (org.jsoup.nodes.Document)4 Matcher (java.util.regex.Matcher)3 Pattern (java.util.regex.Pattern)2 JSONArray (org.json.JSONArray)2 JSONObject (org.json.JSONObject)2 HashSet (java.util.HashSet)1 SubstitutionDiff (me.vertretungsplan.objects.diff.SubstitutionDiff)1 NotNull (org.jetbrains.annotations.NotNull)1