mirror of
https://github.com/wulkanowy/wulkanowy.git
synced 2025-01-19 00:16:48 -06:00
Add to Grade semester and symbol properties (#12)
This commit is contained in:
parent
8bad7b8e1e
commit
3d6515bcf2
@ -19,6 +19,7 @@ import java.util.Map;
|
||||
import io.github.wulkanowy.R;
|
||||
import io.github.wulkanowy.api.Cookies;
|
||||
import io.github.wulkanowy.api.StudentAndParent;
|
||||
import io.github.wulkanowy.api.grades.Grades;
|
||||
import io.github.wulkanowy.api.grades.GradesList;
|
||||
import io.github.wulkanowy.api.grades.Subject;
|
||||
import io.github.wulkanowy.api.grades.SubjectsList;
|
||||
@ -105,7 +106,8 @@ public class MarksFragment extends Fragment {
|
||||
subjectsName.add(subject.getName());
|
||||
}
|
||||
|
||||
GradesList gradesList = new GradesList(snp.getCookiesObject(), snp);
|
||||
Grades gradesObject = new Grades(snp.getCookiesObject(), snp);
|
||||
GradesList gradesList = new GradesList(gradesObject, snp);
|
||||
GradesDatabase gradesDatabase = new GradesDatabase(mContext);
|
||||
gradesDatabase.open();
|
||||
gradesDatabase.put(gradesList.getAll());
|
||||
|
@ -84,6 +84,11 @@ public class StudentAndParent extends Vulcan {
|
||||
url = url.replace("{ID}", getID());
|
||||
|
||||
Document gradesPage = getPageByUrl(url);
|
||||
|
||||
return getSemesters(gradesPage);
|
||||
}
|
||||
|
||||
public List<Semester> getSemesters(Document gradesPage) {
|
||||
Elements semesterOptions = gradesPage.select("#okresyKlasyfikacyjneDropDownList option");
|
||||
|
||||
List<Semester> semesters = new ArrayList<>();
|
||||
|
@ -10,23 +10,23 @@ public class Grade {
|
||||
|
||||
private int subjectID;
|
||||
|
||||
private String subject;
|
||||
private String subject = "";
|
||||
|
||||
private String value;
|
||||
private String value = "";
|
||||
|
||||
private String color;
|
||||
private String color = "";
|
||||
|
||||
private String symbol;
|
||||
private String symbol = "";
|
||||
|
||||
private String description;
|
||||
private String description = "";
|
||||
|
||||
private String weight;
|
||||
private String weight = "";
|
||||
|
||||
private String date;
|
||||
private String date = "";
|
||||
|
||||
private String teacher;
|
||||
private String teacher = "";
|
||||
|
||||
private String semester;
|
||||
private String semester = "";
|
||||
|
||||
private boolean isNew;
|
||||
|
||||
@ -156,6 +156,7 @@ public class Grade {
|
||||
|
||||
public Grade setIsNew(boolean isNew) {
|
||||
this.isNew = isNew;
|
||||
|
||||
return this;
|
||||
}
|
||||
|
||||
|
28
app/src/main/java/io/github/wulkanowy/api/grades/Grades.java
Normal file
28
app/src/main/java/io/github/wulkanowy/api/grades/Grades.java
Normal file
@ -0,0 +1,28 @@
|
||||
package io.github.wulkanowy.api.grades;
|
||||
|
||||
import org.jsoup.nodes.Document;
|
||||
|
||||
import java.io.IOException;
|
||||
|
||||
import io.github.wulkanowy.api.Cookies;
|
||||
import io.github.wulkanowy.api.StudentAndParent;
|
||||
import io.github.wulkanowy.api.Vulcan;
|
||||
import io.github.wulkanowy.api.login.LoginErrorException;
|
||||
|
||||
public class Grades extends Vulcan {
|
||||
|
||||
private StudentAndParent snp = null;
|
||||
|
||||
public Grades(Cookies cookies, StudentAndParent snp) {
|
||||
this.cookies = cookies;
|
||||
this.snp = snp;
|
||||
}
|
||||
|
||||
//TODO: move to snp
|
||||
public Document getGradesPageDocument(String url) throws IOException, LoginErrorException {
|
||||
return getPageByUrl(url
|
||||
.replace("{locationID}", snp.getLocationID())
|
||||
.replace("{ID}", snp.getID())
|
||||
);
|
||||
}
|
||||
}
|
@ -10,22 +10,23 @@ import java.util.List;
|
||||
import java.util.regex.Matcher;
|
||||
import java.util.regex.Pattern;
|
||||
|
||||
import io.github.wulkanowy.api.Cookies;
|
||||
import io.github.wulkanowy.api.Semester;
|
||||
import io.github.wulkanowy.api.StudentAndParent;
|
||||
import io.github.wulkanowy.api.Vulcan;
|
||||
import io.github.wulkanowy.api.login.LoginErrorException;
|
||||
|
||||
public class GradesList extends Vulcan {
|
||||
|
||||
private Grades grades = null;
|
||||
private StudentAndParent snp = null;
|
||||
|
||||
private String gradesPageUrl = "https://uonetplus-opiekun.vulcan.net.pl/{locationID}/{ID}"
|
||||
+ "/Oceny/Wszystkie?details=2&okres=";
|
||||
|
||||
private List<Grade> grades = new ArrayList<>();
|
||||
private List<Grade> gradesList = new ArrayList<>();
|
||||
|
||||
public GradesList(Cookies cookies, StudentAndParent snp) {
|
||||
this.cookies = cookies;
|
||||
public GradesList(Grades grades, StudentAndParent snp) {
|
||||
this.grades = grades;
|
||||
this.snp = snp;
|
||||
}
|
||||
|
||||
@ -34,39 +35,41 @@ public class GradesList extends Vulcan {
|
||||
}
|
||||
|
||||
public List<Grade> getAll() throws IOException, LoginErrorException {
|
||||
return getAll(snp.getCurrentSemester(snp.getSemesters()).getNumber());
|
||||
return getAll("");
|
||||
}
|
||||
|
||||
public List<Grade> getAll(String semester) throws IOException, LoginErrorException {
|
||||
String url = getGradesPageUrl();
|
||||
url = url.replace("{locationID}", snp.getLocationID());
|
||||
url = url.replace("{ID}", snp.getID());
|
||||
Document gradesPage = grades.getGradesPageDocument(getGradesPageUrl() + semester);
|
||||
Elements gradesRows = gradesPage.select(".ocenySzczegoly-table > tbody > tr");
|
||||
Semester currentSemester = snp.getCurrentSemester(snp.getSemesters(gradesPage));
|
||||
|
||||
Document marksPage = getPageByUrl(url + semester);
|
||||
Elements marksRows = marksPage.select(".ocenySzczegoly-table > tbody > tr");
|
||||
|
||||
for (Element row : marksRows) {
|
||||
Pattern pattern = Pattern.compile("#([A-Fa-f0-9]{6}|[A-Fa-f0-9]{3})");
|
||||
Matcher matcher = pattern.matcher(
|
||||
row.select("td:nth-child(2) span.ocenaCzastkowa").attr("style"));
|
||||
String color;
|
||||
if (!matcher.find()) {
|
||||
color = "000000";
|
||||
} else {
|
||||
color = matcher.group(1);
|
||||
for (Element row : gradesRows) {
|
||||
if ("Brak ocen".equals(row.select("td:nth-child(2)").text())) {
|
||||
continue;
|
||||
}
|
||||
|
||||
grades.add(new Grade()
|
||||
String descriptions = row.select("td:nth-child(3)").text();
|
||||
String symbol = descriptions.split(", ")[0];
|
||||
String description = descriptions.replaceFirst(symbol, "").replaceFirst(", ", "");
|
||||
|
||||
Pattern pattern = Pattern.compile("#([A-Fa-f0-9]{6}|[A-Fa-f0-9]{3})");
|
||||
Matcher matcher = pattern.matcher(row.select("td:nth-child(2) span.ocenaCzastkowa")
|
||||
.attr("style"));
|
||||
String color = matcher.find() ? matcher.group(1) : "";
|
||||
|
||||
gradesList.add(new Grade()
|
||||
.setSubject(row.select("td:nth-child(1)").text())
|
||||
.setValue(row.select("td:nth-child(2)").text())
|
||||
.setColor(color)
|
||||
.setDescription(row.select("td:nth-child(3)").text())
|
||||
.setSymbol(symbol)
|
||||
.setDescription(description)
|
||||
.setWeight(row.select("td:nth-child(4)").text())
|
||||
.setDate(row.select("td:nth-child(5)").text())
|
||||
.setTeacher(row.select("td:nth-child(6)").text())
|
||||
.setSemester(currentSemester.getNumber())
|
||||
);
|
||||
}
|
||||
|
||||
return grades;
|
||||
return gradesList;
|
||||
}
|
||||
}
|
||||
|
@ -1,6 +1,5 @@
|
||||
package io.github.wulkanowy.api.grades;
|
||||
|
||||
import org.jsoup.Jsoup;
|
||||
import org.jsoup.nodes.Document;
|
||||
import org.jsoup.nodes.Element;
|
||||
import org.jsoup.select.Elements;
|
||||
@ -32,9 +31,7 @@ public class SubjectsList extends Vulcan {
|
||||
subjectsPageUrl = subjectsPageUrl.replace("{locationID}", snp.getLocationID());
|
||||
subjectsPageUrl = subjectsPageUrl.replace("{ID}", snp.getID());
|
||||
|
||||
Document subjectPage = Jsoup.connect(subjectsPageUrl)
|
||||
.cookies(getCookies())
|
||||
.get();
|
||||
Document subjectPage = getPageByUrl(subjectsPageUrl);
|
||||
|
||||
Elements rows = subjectPage.select(".ocenyZwykle-table > tbody > tr");
|
||||
|
||||
|
@ -10,6 +10,7 @@ import org.powermock.api.mockito.PowerMockito;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
||||
public class StudentAndParentTest {
|
||||
|
||||
private String fixtureFileName = "OcenyWszystkie-semester.html";
|
||||
@ -30,7 +31,9 @@ public class StudentAndParentTest {
|
||||
Mockito.when(snp.getLocationID()).thenReturn("symbol");
|
||||
Mockito.when(snp.getID()).thenReturn("123456");
|
||||
Mockito.when(snp.getSemesters()).thenCallRealMethod();
|
||||
Mockito.when(snp.getCurrentSemester(Mockito.anyListOf(Semester.class))).thenCallRealMethod();
|
||||
Mockito.when(snp.getSemesters(Mockito.any(Document.class))).thenCallRealMethod();
|
||||
Mockito.when(snp.getCurrentSemester(Mockito.anyListOf(Semester.class)))
|
||||
.thenCallRealMethod();
|
||||
}
|
||||
|
||||
@Test
|
||||
|
@ -0,0 +1,95 @@
|
||||
package io.github.wulkanowy.api.grades;
|
||||
|
||||
import org.jsoup.Jsoup;
|
||||
import org.jsoup.nodes.Document;
|
||||
import org.junit.Assert;
|
||||
import org.junit.Before;
|
||||
import org.junit.Test;
|
||||
import org.mockito.Mockito;
|
||||
import org.powermock.api.mockito.PowerMockito;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
import io.github.wulkanowy.api.FixtureHelper;
|
||||
import io.github.wulkanowy.api.Semester;
|
||||
import io.github.wulkanowy.api.StudentAndParent;
|
||||
|
||||
public class GradesListTest {
|
||||
|
||||
private String fixtureFileName = "OcenyWszystkie-filled.html";
|
||||
|
||||
private GradesList gradesList;
|
||||
|
||||
@Before
|
||||
public void setUp() throws Exception {
|
||||
String input = FixtureHelper.getAsString(getClass().getResourceAsStream(fixtureFileName));
|
||||
Document gradesPageDocument = Jsoup.parse(input);
|
||||
|
||||
StudentAndParent snp = Mockito.mock(StudentAndParent.class);
|
||||
PowerMockito.whenNew(StudentAndParent.class).withAnyArguments().thenReturn(snp);
|
||||
Mockito.when(snp.getLocationID()).thenReturn("symbol");
|
||||
Mockito.when(snp.getID()).thenReturn("123456");
|
||||
Mockito.when(snp.getGradesPageUrl()).thenReturn("http://example.null");
|
||||
Mockito.when(snp.getSemesters()).thenCallRealMethod();
|
||||
Mockito.when(snp.getSemesters(Mockito.any(Document.class))).thenCallRealMethod();
|
||||
Mockito.when(snp.getCurrentSemester(Mockito.anyListOf(Semester.class)))
|
||||
.thenCallRealMethod();
|
||||
|
||||
Grades grades = Mockito.mock(Grades.class);
|
||||
PowerMockito.whenNew(Grades.class).withAnyArguments().thenReturn(grades);
|
||||
Mockito.when(grades.getGradesPageDocument(Mockito.anyString()))
|
||||
.thenReturn(gradesPageDocument);
|
||||
|
||||
gradesList = new GradesList(grades, snp);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void getAllTest() throws Exception {
|
||||
List<Grade> grades = gradesList.getAll();
|
||||
Assert.assertEquals(6, grades.size()); // 2 items are skipped
|
||||
|
||||
Grade grade1 = grades.get(0);
|
||||
Assert.assertEquals("Zajęcia z wychowawcą", grade1.getSubject());
|
||||
Assert.assertEquals("5", grade1.getValue());
|
||||
Assert.assertEquals("000000", grade1.getColor());
|
||||
Assert.assertEquals("A1", grade1.getSymbol());
|
||||
Assert.assertEquals("Dzień Kobiet w naszej klasie", grade1.getDescription());
|
||||
Assert.assertEquals("1,00", grade1.getWeight());
|
||||
Assert.assertEquals("21.03.2017", grade1.getDate());
|
||||
Assert.assertEquals("Patryk Maciejewski", grade1.getTeacher());
|
||||
Assert.assertEquals("7654321", grade1.getSemester());
|
||||
|
||||
Grade grade2 = grades.get(3);
|
||||
Assert.assertEquals("Język angielski", grade2.getSubject());
|
||||
Assert.assertEquals("5", grade2.getValue());
|
||||
Assert.assertEquals("1289F7", grade2.getColor());
|
||||
Assert.assertEquals("BW3", grade2.getSymbol());
|
||||
Assert.assertEquals("Writing", grade2.getDescription());
|
||||
Assert.assertEquals("3,00", grade2.getWeight());
|
||||
Assert.assertEquals("02.06.2017", grade2.getDate());
|
||||
Assert.assertEquals("Oliwia Woźniak", grade2.getTeacher());
|
||||
Assert.assertEquals("7654321", grade2.getSemester());
|
||||
|
||||
Grade grade3 = grades.get(4);
|
||||
Assert.assertEquals("Wychowanie fizyczne", grade3.getSubject());
|
||||
Assert.assertEquals("1", grade3.getValue());
|
||||
Assert.assertEquals("6ECD07", grade3.getColor());
|
||||
Assert.assertEquals("STR", grade3.getSymbol());
|
||||
Assert.assertEquals("", grade3.getDescription());
|
||||
Assert.assertEquals("8,00", grade3.getWeight());
|
||||
Assert.assertEquals("02.04.2017", grade3.getDate());
|
||||
Assert.assertEquals("Klaudia Dziedzic", grade3.getTeacher());
|
||||
Assert.assertEquals("7654321", grade3.getSemester());
|
||||
|
||||
Grade grade4 = grades.get(5);
|
||||
Assert.assertEquals("Język polski", grade4.getSubject());
|
||||
Assert.assertEquals("1", grade4.getValue());
|
||||
Assert.assertEquals("6ECD07", grade4.getColor());
|
||||
Assert.assertEquals("K", grade4.getSymbol());
|
||||
Assert.assertEquals("Kordian", grade4.getDescription());
|
||||
Assert.assertEquals("5,00", grade4.getWeight());
|
||||
Assert.assertEquals("06.02.2017", grade4.getDate());
|
||||
Assert.assertEquals("Amelia Stępień", grade4.getTeacher());
|
||||
Assert.assertEquals("7654321", grade4.getSemester());
|
||||
}
|
||||
}
|
@ -0,0 +1,108 @@
|
||||
<!DOCTYPE html>
|
||||
<html lang="pl">
|
||||
<head>
|
||||
<meta charset="utf-8">
|
||||
<title>Witryna ucznia i rodzica – Oceny</title>
|
||||
</head>
|
||||
<body>
|
||||
<main class="mainContainer">
|
||||
<h1>Oceny</h1>
|
||||
<div class="filters">
|
||||
<div>
|
||||
<label for="okresyKlasyfikacyjneDropDownList">Okres klasyfikacyjny:</label>
|
||||
<select id="okresyKlasyfikacyjneDropDownList" name="okresyKlasyfikacyjneDropDownList">
|
||||
<option value="1234567">1</option>
|
||||
<option selected="selected" value="7654321">2</option>
|
||||
</select>
|
||||
</div>
|
||||
</div>
|
||||
<table class="ocenySzczegoly-table">
|
||||
<thead>
|
||||
<tr>
|
||||
<th>Przedmiot</th>
|
||||
<th>Ocena cząstkowa</th>
|
||||
<th>Opis</th>
|
||||
<th>Waga</th>
|
||||
<th>Data</th>
|
||||
<th>Nauczyciel</th>
|
||||
</tr>
|
||||
</thead>
|
||||
<tbody>
|
||||
<tr>
|
||||
<td>Zachowanie</td>
|
||||
<td>Brak ocen</td>
|
||||
<td></td>
|
||||
<td></td>
|
||||
<td></td>
|
||||
<td></td>
|
||||
</tr>
|
||||
<tr>
|
||||
<td>Zajęcia z wychowawcą</td>
|
||||
<td class="break-word">
|
||||
<span class="ocenaCzastkowa" style="color:#000000;">5</span>
|
||||
</td>
|
||||
<td class="break-word">A1, Dzień Kobiet w naszej klasie</td>
|
||||
<td>1,00</td>
|
||||
<td>21.03.2017</td>
|
||||
<td>Patryk Maciejewski</td>
|
||||
</tr>
|
||||
<tr>
|
||||
<td>Edukacja dla bezpieczeństwa</td>
|
||||
<td class="break-word">
|
||||
<span class="ocenaCzastkowa" style="color:#F04C4C;">4-</span>
|
||||
</td>
|
||||
<td class="break-word">S1, PIERWSZA POMOC I RESUSCYTACJA</td>
|
||||
<td>5,00</td>
|
||||
<td>31.03.2017</td>
|
||||
<td>Weronika Ratajczak</td>
|
||||
</tr>
|
||||
<tr>
|
||||
<td>Fizyka</td>
|
||||
<td class="break-word">
|
||||
<span class="ocenaCzastkowa" style="color:#6ECD07;">2</span>
|
||||
</td>
|
||||
<td class="break-word">O, Odpowiedź</td>
|
||||
<td>3,00</td>
|
||||
<td>25.06.2017</td>
|
||||
<td>Jakub Michalak</td>
|
||||
</tr>
|
||||
<tr>
|
||||
<td>Język angielski</td>
|
||||
<td class="break-word">
|
||||
<span class="ocenaCzastkowa" style="color:#1289F7;">5</span>
|
||||
</td>
|
||||
<td class="break-word">BW3, Writing</td>
|
||||
<td>3,00</td>
|
||||
<td>02.06.2017</td>
|
||||
<td>Oliwia Woźniak</td>
|
||||
</tr>
|
||||
<tr>
|
||||
<td>Wiedza o społeczeństwie</td>
|
||||
<td>Brak ocen</td>
|
||||
<td></td>
|
||||
<td></td>
|
||||
<td></td>
|
||||
<td></td>
|
||||
</tr>
|
||||
<tr>
|
||||
<td>Wychowanie fizyczne</td>
|
||||
<td class="break-word"><span class="ocenaCzastkowa" style="color:#6ECD07;">1</span></td>
|
||||
<td class="break-word">STR</td>
|
||||
<td>8,00</td>
|
||||
<td>02.04.2017</td>
|
||||
<td>Klaudia Dziedzic</td>
|
||||
</tr>
|
||||
<tr>
|
||||
<td>Język polski</td>
|
||||
<td class="break-word"><span class="ocenaCzastkowa" style="color:#6ECD07;">1</span></td>
|
||||
<td class="break-word">K, Kordian</td>
|
||||
<td>5,00</td>
|
||||
<td>06.02.2017</td>
|
||||
<td>Amelia Stępień</td>
|
||||
</tr>
|
||||
</tbody>
|
||||
</table>
|
||||
</main>
|
||||
<footer>wersja: 17.02.0000.23328</footer>
|
||||
</body>
|
||||
</html>
|
Loading…
x
Reference in New Issue
Block a user