Add missing timetable headers from eduOne
This commit is contained in:
parent
c2f8981ad4
commit
3ee9a2e132
6 changed files with 113 additions and 17 deletions
|
@ -18,7 +18,7 @@ ext {
|
||||||
moshi = "1.13.0"
|
moshi = "1.13.0"
|
||||||
}
|
}
|
||||||
|
|
||||||
version = "2.5.2"
|
version = "2.5.3-SNAPSHOT"
|
||||||
group = "io.github.wulkanowy"
|
group = "io.github.wulkanowy"
|
||||||
|
|
||||||
nexusPublishing {
|
nexusPublishing {
|
||||||
|
|
|
@ -29,6 +29,7 @@ import io.github.wulkanowy.sdk.scrapper.service.StudentPlusService
|
||||||
import io.github.wulkanowy.sdk.scrapper.timetable.CompletedLesson
|
import io.github.wulkanowy.sdk.scrapper.timetable.CompletedLesson
|
||||||
import io.github.wulkanowy.sdk.scrapper.timetable.Lesson
|
import io.github.wulkanowy.sdk.scrapper.timetable.Lesson
|
||||||
import io.github.wulkanowy.sdk.scrapper.timetable.Timetable
|
import io.github.wulkanowy.sdk.scrapper.timetable.Timetable
|
||||||
|
import io.github.wulkanowy.sdk.scrapper.timetable.TimetableDayHeader
|
||||||
import io.github.wulkanowy.sdk.scrapper.timetable.mapCompletedLessons
|
import io.github.wulkanowy.sdk.scrapper.timetable.mapCompletedLessons
|
||||||
import io.github.wulkanowy.sdk.scrapper.toFormat
|
import io.github.wulkanowy.sdk.scrapper.toFormat
|
||||||
import org.jsoup.Jsoup
|
import org.jsoup.Jsoup
|
||||||
|
@ -255,10 +256,11 @@ internal class StudentPlusRepository(
|
||||||
|
|
||||||
suspend fun getTimetable(startDate: LocalDate, endDate: LocalDate?, studentId: Int, diaryId: Int, unitId: Int): Timetable {
|
suspend fun getTimetable(startDate: LocalDate, endDate: LocalDate?, studentId: Int, diaryId: Int, unitId: Int): Timetable {
|
||||||
val key = getEncodedKey(studentId, diaryId, unitId)
|
val key = getEncodedKey(studentId, diaryId, unitId)
|
||||||
|
val defaultEndDate = (endDate ?: startDate.plusDays(7))
|
||||||
val lessons = api.getTimetable(
|
val lessons = api.getTimetable(
|
||||||
key = key,
|
key = key,
|
||||||
from = startDate.toISOFormat(),
|
from = startDate.toISOFormat(),
|
||||||
to = endDate?.toISOFormat(),
|
to = defaultEndDate?.toISOFormat(),
|
||||||
).map { lesson ->
|
).map { lesson ->
|
||||||
Lesson(
|
Lesson(
|
||||||
number = 0,
|
number = 0,
|
||||||
|
@ -325,11 +327,32 @@ internal class StudentPlusRepository(
|
||||||
)
|
)
|
||||||
}.sortedBy { it.start }
|
}.sortedBy { it.start }
|
||||||
|
|
||||||
|
val headers = api.getTimetableFreeDays(
|
||||||
|
key = key,
|
||||||
|
from = startDate.toISOFormat(),
|
||||||
|
to = endDate?.toISOFormat(),
|
||||||
|
)
|
||||||
|
val days = (startDate.toEpochDay()..defaultEndDate.toEpochDay()).map(LocalDate::ofEpochDay)
|
||||||
|
val processedHeaders = days.mapNotNull { processedDate ->
|
||||||
|
val exactMatch = headers.find {
|
||||||
|
it.dataOd.toLocalDate() == processedDate && it.dataDo.toLocalDate() == processedDate
|
||||||
|
}
|
||||||
|
val rangeMatch = headers.find {
|
||||||
|
processedDate in it.dataOd.toLocalDate()..it.dataDo.toLocalDate()
|
||||||
|
}
|
||||||
|
(exactMatch ?: rangeMatch)?.let {
|
||||||
|
TimetableDayHeader(
|
||||||
|
date = processedDate,
|
||||||
|
content = it.nazwa,
|
||||||
|
)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
return Timetable(
|
return Timetable(
|
||||||
lessons = lessons,
|
lessons = lessons,
|
||||||
|
headers = processedHeaders,
|
||||||
// todo
|
// todo
|
||||||
additional = emptyList(),
|
additional = emptyList(),
|
||||||
headers = emptyList(),
|
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -17,6 +17,7 @@ import io.github.wulkanowy.sdk.scrapper.register.AuthorizePermissionPlusRequest
|
||||||
import io.github.wulkanowy.sdk.scrapper.register.ContextResponse
|
import io.github.wulkanowy.sdk.scrapper.register.ContextResponse
|
||||||
import io.github.wulkanowy.sdk.scrapper.timetable.CompletedLesson
|
import io.github.wulkanowy.sdk.scrapper.timetable.CompletedLesson
|
||||||
import io.github.wulkanowy.sdk.scrapper.timetable.LessonPlus
|
import io.github.wulkanowy.sdk.scrapper.timetable.LessonPlus
|
||||||
|
import io.github.wulkanowy.sdk.scrapper.timetable.TimetablePlusHeader
|
||||||
import retrofit2.Response
|
import retrofit2.Response
|
||||||
import retrofit2.http.Body
|
import retrofit2.http.Body
|
||||||
import retrofit2.http.GET
|
import retrofit2.http.GET
|
||||||
|
@ -126,6 +127,13 @@ internal interface StudentPlusService {
|
||||||
@Query("zakresDanych") data: Int = 2,
|
@Query("zakresDanych") data: Int = 2,
|
||||||
): List<LessonPlus>
|
): List<LessonPlus>
|
||||||
|
|
||||||
|
@GET("api/DniWolne")
|
||||||
|
suspend fun getTimetableFreeDays(
|
||||||
|
@Query("key") key: String,
|
||||||
|
@Query("dataOd") from: String,
|
||||||
|
@Query("dataDo") to: String?,
|
||||||
|
): List<TimetablePlusHeader>
|
||||||
|
|
||||||
@GET("api/Uwagi")
|
@GET("api/Uwagi")
|
||||||
suspend fun getNotes(@Query("key") key: String): List<Note>
|
suspend fun getNotes(@Query("key") key: String): List<Note>
|
||||||
}
|
}
|
||||||
|
|
|
@ -0,0 +1,20 @@
|
||||||
|
package io.github.wulkanowy.sdk.scrapper.timetable
|
||||||
|
|
||||||
|
import io.github.wulkanowy.sdk.scrapper.adapter.CustomDateAdapter
|
||||||
|
import kotlinx.serialization.SerialName
|
||||||
|
import kotlinx.serialization.Serializable
|
||||||
|
import java.time.LocalDateTime
|
||||||
|
|
||||||
|
@Serializable
|
||||||
|
internal data class TimetablePlusHeader(
|
||||||
|
@SerialName("dataDo")
|
||||||
|
@Serializable(with = CustomDateAdapter::class)
|
||||||
|
val dataDo: LocalDateTime,
|
||||||
|
|
||||||
|
@SerialName("dataOd")
|
||||||
|
@Serializable(with = CustomDateAdapter::class)
|
||||||
|
val dataOd: LocalDateTime,
|
||||||
|
|
||||||
|
@SerialName("nazwa")
|
||||||
|
val nazwa: String,
|
||||||
|
)
|
|
@ -7,9 +7,12 @@ import org.junit.Test
|
||||||
|
|
||||||
class TimetablePlusTest : BaseLocalTest() {
|
class TimetablePlusTest : BaseLocalTest() {
|
||||||
|
|
||||||
private val timetable by lazy {
|
private val timetableFull by lazy {
|
||||||
runBlocking {
|
runBlocking {
|
||||||
getStudentPlusRepo(TimetablePlusTest::class.java, "PlanZajec.json")
|
getStudentPlusRepo {
|
||||||
|
it.enqueue("PlanZajec.json", TimetablePlusTest::class.java)
|
||||||
|
it.enqueue("DniWolne.json", TimetablePlusTest::class.java)
|
||||||
|
}
|
||||||
.getTimetable(
|
.getTimetable(
|
||||||
startDate = getLocalDate(2024, 3, 18),
|
startDate = getLocalDate(2024, 3, 18),
|
||||||
endDate = getLocalDate(2024, 3, 25),
|
endDate = getLocalDate(2024, 3, 25),
|
||||||
|
@ -17,18 +20,43 @@ class TimetablePlusTest : BaseLocalTest() {
|
||||||
diaryId = 2,
|
diaryId = 2,
|
||||||
unitId = 3,
|
unitId = 3,
|
||||||
)
|
)
|
||||||
.lessons
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
private val lessons = timetableFull.lessons
|
||||||
|
private val headers = timetableFull.headers
|
||||||
|
|
||||||
|
@Test
|
||||||
|
fun getAllTest() {
|
||||||
|
assertEquals(9, lessons.size)
|
||||||
|
assertEquals(5, headers.size)
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
fun getTimetableHeaderRange() {
|
||||||
|
listOf(0, 1, 2).forEach {
|
||||||
|
with(headers[it]) {
|
||||||
|
assertEquals(getLocalDate(2024, 3, 21 + it), date)
|
||||||
|
assertEquals("Wiosenna przerwa świąteczna", content)
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
fun getAllTest() {
|
fun getTimetableHeaderDay() {
|
||||||
assertEquals(9, timetable.size)
|
with(headers[3]) {
|
||||||
|
assertEquals(getLocalDate(2024, 3, 24), date)
|
||||||
|
assertEquals("Wielkanoc", content)
|
||||||
|
}
|
||||||
|
with(headers[4]) {
|
||||||
|
assertEquals(getLocalDate(2024, 3, 25), date)
|
||||||
|
assertEquals("Poniedziałek Wielkanocny", content)
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
fun getSimpleLesson() {
|
fun getSimpleLesson() {
|
||||||
with(timetable[0]) {
|
with(lessons[0]) {
|
||||||
assertEquals(0, number)
|
assertEquals(0, number)
|
||||||
assertEquals(getLocalDateTime(2024, 3, 18, 8, 0, 0), start)
|
assertEquals(getLocalDateTime(2024, 3, 18, 8, 0, 0), start)
|
||||||
assertEquals(getLocalDateTime(2024, 3, 18, 8, 45, 0), end)
|
assertEquals(getLocalDateTime(2024, 3, 18, 8, 45, 0), end)
|
||||||
|
@ -49,7 +77,7 @@ class TimetablePlusTest : BaseLocalTest() {
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
fun getLessonWithGroup() {
|
fun getLessonWithGroup() {
|
||||||
with(timetable[1]) {
|
with(lessons[1]) {
|
||||||
assertEquals(0, number)
|
assertEquals(0, number)
|
||||||
assertEquals(getLocalDateTime(2024, 3, 20, 8, 0, 0), start)
|
assertEquals(getLocalDateTime(2024, 3, 20, 8, 0, 0), start)
|
||||||
assertEquals(getLocalDateTime(2024, 3, 20, 8, 45, 0), end)
|
assertEquals(getLocalDateTime(2024, 3, 20, 8, 45, 0), end)
|
||||||
|
@ -70,7 +98,7 @@ class TimetablePlusTest : BaseLocalTest() {
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
fun getLessonWhenTeacherAbsent() {
|
fun getLessonWhenTeacherAbsent() {
|
||||||
with(timetable[2]) {
|
with(lessons[2]) {
|
||||||
assertEquals(0, number)
|
assertEquals(0, number)
|
||||||
assertEquals(getLocalDateTime(2024, 3, 20, 8, 50, 0), start)
|
assertEquals(getLocalDateTime(2024, 3, 20, 8, 50, 0), start)
|
||||||
assertEquals(getLocalDateTime(2024, 3, 20, 9, 35, 0), end)
|
assertEquals(getLocalDateTime(2024, 3, 20, 9, 35, 0), end)
|
||||||
|
@ -91,7 +119,7 @@ class TimetablePlusTest : BaseLocalTest() {
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
fun getCancelledLesson() {
|
fun getCancelledLesson() {
|
||||||
with(timetable[3]) {
|
with(lessons[3]) {
|
||||||
assertEquals(0, number)
|
assertEquals(0, number)
|
||||||
assertEquals(getLocalDateTime(2024, 3, 20, 9, 40, 0), start)
|
assertEquals(getLocalDateTime(2024, 3, 20, 9, 40, 0), start)
|
||||||
assertEquals(getLocalDateTime(2024, 3, 20, 10, 25, 0), end)
|
assertEquals(getLocalDateTime(2024, 3, 20, 10, 25, 0), end)
|
||||||
|
@ -112,7 +140,7 @@ class TimetablePlusTest : BaseLocalTest() {
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
fun getExchangeLesson() {
|
fun getExchangeLesson() {
|
||||||
with(timetable[5]) {
|
with(lessons[5]) {
|
||||||
assertEquals(0, number)
|
assertEquals(0, number)
|
||||||
assertEquals(getLocalDateTime(2024, 3, 20, 10, 30, 0), start)
|
assertEquals(getLocalDateTime(2024, 3, 20, 10, 30, 0), start)
|
||||||
assertEquals(getLocalDateTime(2024, 3, 20, 11, 15, 0), end)
|
assertEquals(getLocalDateTime(2024, 3, 20, 11, 15, 0), end)
|
||||||
|
@ -133,7 +161,7 @@ class TimetablePlusTest : BaseLocalTest() {
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
fun getMovedLessonFrom() {
|
fun getMovedLessonFrom() {
|
||||||
with(timetable[6]) {
|
with(lessons[6]) {
|
||||||
assertEquals(0, number)
|
assertEquals(0, number)
|
||||||
assertEquals(getLocalDateTime(2024, 3, 20, 11, 30, 0), start)
|
assertEquals(getLocalDateTime(2024, 3, 20, 11, 30, 0), start)
|
||||||
assertEquals(getLocalDateTime(2024, 3, 20, 12, 15, 0), end)
|
assertEquals(getLocalDateTime(2024, 3, 20, 12, 15, 0), end)
|
||||||
|
@ -154,7 +182,7 @@ class TimetablePlusTest : BaseLocalTest() {
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
fun getLessonMovedWithReplacementToTest() {
|
fun getLessonMovedWithReplacementToTest() {
|
||||||
with(timetable[4]) {
|
with(lessons[4]) {
|
||||||
assertEquals(0, number)
|
assertEquals(0, number)
|
||||||
assertEquals(getLocalDateTime(2024, 3, 20, 9, 40, 0), start)
|
assertEquals(getLocalDateTime(2024, 3, 20, 9, 40, 0), start)
|
||||||
assertEquals(getLocalDateTime(2024, 3, 20, 10, 25, 0), end)
|
assertEquals(getLocalDateTime(2024, 3, 20, 10, 25, 0), end)
|
||||||
|
@ -178,7 +206,7 @@ class TimetablePlusTest : BaseLocalTest() {
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
fun getLessonMovedWithReplacementFromTest() {
|
fun getLessonMovedWithReplacementFromTest() {
|
||||||
with(timetable[7]) {
|
with(lessons[7]) {
|
||||||
assertEquals(0, number)
|
assertEquals(0, number)
|
||||||
assertEquals(getLocalDateTime(2024, 3, 20, 12, 30, 0), start)
|
assertEquals(getLocalDateTime(2024, 3, 20, 12, 30, 0), start)
|
||||||
assertEquals(getLocalDateTime(2024, 3, 20, 13, 15, 0), end)
|
assertEquals(getLocalDateTime(2024, 3, 20, 13, 15, 0), end)
|
||||||
|
@ -199,7 +227,7 @@ class TimetablePlusTest : BaseLocalTest() {
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
fun getMovedLessonTo() {
|
fun getMovedLessonTo() {
|
||||||
with(timetable[8]) {
|
with(lessons[8]) {
|
||||||
assertEquals(0, number)
|
assertEquals(0, number)
|
||||||
assertEquals(getLocalDateTime(2024, 3, 20, 14, 10, 0), start)
|
assertEquals(getLocalDateTime(2024, 3, 20, 14, 10, 0), start)
|
||||||
assertEquals(getLocalDateTime(2024, 3, 20, 14, 55, 0), end)
|
assertEquals(getLocalDateTime(2024, 3, 20, 14, 55, 0), end)
|
||||||
|
|
|
@ -0,0 +1,17 @@
|
||||||
|
[
|
||||||
|
{
|
||||||
|
"dataOd": "2024-03-21T00:00:00+01:00",
|
||||||
|
"dataDo": "2024-03-26T00:00:00+02:00",
|
||||||
|
"nazwa": "Wiosenna przerwa świąteczna"
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"dataOd": "2024-03-24T00:00:00+01:00",
|
||||||
|
"dataDo": "2024-03-24T00:00:00+01:00",
|
||||||
|
"nazwa": "Wielkanoc"
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"dataOd": "2024-03-25T00:00:00+02:00",
|
||||||
|
"dataDo": "2024-03-25T00:00:00+02:00",
|
||||||
|
"nazwa": "Poniedziałek Wielkanocny"
|
||||||
|
}
|
||||||
|
]
|
Loading…
Reference in a new issue