Search in sources :

Example 21 with Substitution

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

the class SubstitutionTextUtilsTest2 method testGetTeachers1.

@Test
public void testGetTeachers1() {
    Substitution s = new Substitution();
    s.setPreviousTeacher("A");
    s.setTeacher("B");
    assertEquals("B statt A", SubstitutionTextUtils.getTeachers(s));
}
Also used : Substitution(me.vertretungsplan.objects.Substitution) Test(org.junit.Test)

Example 22 with Substitution

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

the class DiffTest method testDiffSame.

@Test
public void testDiffSame() {
    Substitution s1 = new Substitution();
    s1.setClasses(new HashSet<>(Arrays.asList(new String[] { "07B" })));
    s1.setLesson("6");
    s1.setType("Enfall");
    s1.setSubject("Entfall");
    s1.setPreviousSubject("SPA");
    s1.setTeachers(new HashSet<>(Arrays.asList(new String[] { "KW", "ER" })));
    s1.setPreviousTeachers(new HashSet<String>());
    s1.setColor("#F44336");
    s1.setDesc("fällt aus");
    Substitution s2 = new Substitution();
    s2.setClasses(new HashSet<>(Arrays.asList(new String[] { "07B" })));
    s2.setLesson("6");
    s2.setType("Enfall");
    s2.setSubject("Entfall");
    s2.setPreviousSubject("SPA");
    s2.setTeachers(new HashSet<>(Arrays.asList(new String[] { "KW", "ER" })));
    s2.setPreviousTeachers(new HashSet<String>());
    s2.setColor("#F44336");
    s2.setDesc("fällt aus");
    assertTrue(s1.equals(s2));
    SubstitutionScheduleDay d1 = new SubstitutionScheduleDay();
    d1.addSubstitution(s1);
    SubstitutionScheduleDay d2 = new SubstitutionScheduleDay();
    d2.addSubstitution(s2);
    SubstitutionScheduleDayDiff dayDiff = SubstitutionScheduleDayDiff.compare(d1, d2);
    assertTrue(!dayDiff.isNotEmpty());
}
Also used : Substitution(me.vertretungsplan.objects.Substitution) SubstitutionScheduleDay(me.vertretungsplan.objects.SubstitutionScheduleDay) Test(org.junit.Test)

Example 23 with Substitution

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

the class CSVDemoTest method demoTest.

@Test
public void demoTest() throws IOException, JSONException {
    SubstitutionSchedule schedule = parser.parseCSV(csv);
    assertEquals(2, schedule.getDays().size());
    SubstitutionScheduleDay day = schedule.getDays().get(0);
    assertEquals(new LocalDate(2016, 9, 5), day.getDate());
    assertEquals(new LocalDateTime(2016, 9, 2, 8, 16), day.getLastChange());
    assertEquals(1, day.getSubstitutions().size());
    assertEquals(0, day.getMessages().size());
    Substitution subst = day.getSubstitutions().iterator().next();
    assertEquals(1, subst.getClasses().size());
    assertEquals("05A", subst.getClasses().iterator().next());
    assertEquals("6", subst.getLesson());
    assertEquals("!Ma", subst.getSubject());
    assertEquals("!DROE", subst.getTeacher());
    assertEquals("!B203", subst.getRoom());
    assertEquals("für Mu REN", subst.getDesc());
    assertEquals("Vertretung", subst.getType());
}
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) Test(org.junit.Test)

Example 24 with Substitution

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

the class DaVinciDemoTest method checkSubstitutions.

private void checkSubstitutions(SubstitutionScheduleDay day) {
    for (Substitution subst : day.getSubstitutions()) {
        assertTrue(subst.getClasses().size() > 0);
        assertNotEmpty(subst.getLesson());
        assertNotEmpty(subst.getPreviousSubject());
        assertNullOrNotEmpty(subst.getSubject());
        assertNullOrNotEmpty(subst.getRoom());
        assertNullOrNotEmpty(subst.getTeacher());
        assertNullOrNotEmpty(subst.getDesc());
        assertNotEmpty(subst.getType());
    }
}
Also used : Substitution(me.vertretungsplan.objects.Substitution)

Example 25 with Substitution

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

the class CSVParser method parseCSV.

@NotNull
SubstitutionSchedule parseCSV(String response) throws JSONException, IOException {
    SubstitutionSchedule schedule = SubstitutionSchedule.fromData(scheduleData);
    String[] lines = response.split("\n");
    String separator = data.getString(PARAM_SEPARATOR);
    for (int i = data.optInt(PARAM_SKIP_LINES, 0); i < lines.length; i++) {
        String[] columns = lines[i].split(separator);
        Substitution v = new Substitution();
        String dayName = null;
        String stand = "";
        int j = 0;
        for (String column : columns) {
            String type = data.getJSONArray(PARAM_COLUMNS).getString(j);
            switch(type) {
                case "lesson":
                    v.setLesson(column);
                    break;
                case "subject":
                    v.setSubject(column);
                    break;
                case "previousSubject":
                    v.setPreviousSubject(column);
                    break;
                case "type":
                    v.setType(column);
                    v.setColor(colorProvider.getColor(column));
                    break;
                case "type-entfall":
                    if (column.equals("x")) {
                        v.setType("Entfall");
                        v.setColor(colorProvider.getColor("Entfall"));
                    } else {
                        v.setType("Vertretung");
                        v.setColor(colorProvider.getColor("Vertretung"));
                    }
                    break;
                case "room":
                    v.setRoom(column);
                    break;
                case "teacher":
                    v.setTeacher(column);
                    break;
                case "previousTeacher":
                    v.setPreviousTeacher(column);
                    break;
                case "desc":
                    v.setDesc(column);
                    break;
                case "desc-type":
                    v.setDesc(column);
                    String recognizedType = recognizeType(column);
                    v.setType(recognizedType);
                    v.setColor(colorProvider.getColor(recognizedType));
                    break;
                case "previousRoom":
                    v.setPreviousRoom(column);
                    break;
                case "class":
                    v.getClasses().add(getClassName(column, data));
                    break;
                case "day":
                    dayName = column;
                    break;
                case "stand":
                    stand = column;
                    break;
                case "ignore":
                    break;
                default:
                    throw new IllegalArgumentException("Unknown column type: " + column);
            }
            j++;
        }
        if (v.getType() == null) {
            v.setType("Vertretung");
            v.setColor(colorProvider.getColor("Vertretung"));
        }
        if (dayName != null) {
            SubstitutionScheduleDay day = new SubstitutionScheduleDay();
            day.setDateString(dayName);
            day.setDate(ParserUtils.parseDate(dayName));
            day.setLastChangeString(stand);
            day.setLastChange(ParserUtils.parseDateTime(stand));
            day.addSubstitution(v);
            schedule.addDay(day);
        }
    }
    if (scheduleData.getData().has(PARAM_WEBSITE)) {
        schedule.setWebsite(scheduleData.getData().getString(PARAM_WEBSITE));
    }
    schedule.setClasses(getAllClasses());
    schedule.setTeachers(getAllTeachers());
    return schedule;
}
Also used : Substitution(me.vertretungsplan.objects.Substitution) SubstitutionSchedule(me.vertretungsplan.objects.SubstitutionSchedule) SubstitutionScheduleDay(me.vertretungsplan.objects.SubstitutionScheduleDay) NotNull(org.jetbrains.annotations.NotNull)

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