Convert mappers to expresssion body

This commit is contained in:
Mikołaj Pich 2020-07-25 20:37:03 +02:00
parent cca8c74b8f
commit 71571826d4
24 changed files with 637 additions and 745 deletions

View file

@ -4,7 +4,6 @@ import io.github.wulkanowy.sdk.scrapper.toLocalDate
import java.time.LocalDate
fun List<ExamResponse>.mapExamsList(startDate: LocalDate, endDate: LocalDate?): List<Exam> {
val end = endDate ?: startDate.plusDays(4)
return asSequence().map { weeks ->
weeks.weeks.map { day ->

View file

@ -8,88 +8,78 @@ private val pointGradeRegex = "\\d+\\.?\\d+/\\d+".toRegex()
private fun String.isEntryContainsCommentWithGrade() = isGradeValid(removeSurrounding("(", ")"))
fun GradesResponse.mapGradesList(): List<Grade> {
return gradesWithSubjects.map { gradesSubject ->
gradesSubject.grades.map { grade ->
val values = getGradeValueWithModifier(grade.entry)
val gradeEntryWithoutComment = grade.entry.substringBefore(" (")
fun GradesResponse.mapGradesList() = gradesWithSubjects.map { gradesSubject ->
gradesSubject.grades.map { grade ->
val values = getGradeValueWithModifier(grade.entry)
val gradeEntryWithoutComment = grade.entry.substringBefore(" (")
Grade().apply {
subject = gradesSubject.name
entry = gradeEntryWithoutComment.run {
when {
isPoints && matches(pointGradeRegex) -> getGradePointPercent()
isEntryContainsCommentWithGrade() -> this // getGrade_onlyGradeInCommentEntry
removeSurrounding("(", ")").length > 4 -> "..." // getGrade_onlyCommentEntry
else -> removeSurrounding("(", ")")
}
Grade().apply {
subject = gradesSubject.name
entry = gradeEntryWithoutComment.run {
when {
isPoints && matches(pointGradeRegex) -> getGradePointPercent()
isEntryContainsCommentWithGrade() -> this // getGrade_onlyGradeInCommentEntry
removeSurrounding("(", ")").length > 4 -> "..." // getGrade_onlyCommentEntry
else -> removeSurrounding("(", ")")
}
comment = gradeEntryWithoutComment.run {
when {
length > 4 -> grade.entry
startsWith("(") && endsWith(")") -> "" // getGrade_onlyGradeInCommentEntry
else -> grade.entry.substringBeforeLast(")").substringAfter(" (")
}
}
comment = gradeEntryWithoutComment.run {
when {
length > 4 -> grade.entry
startsWith("(") && endsWith(")") -> "" // getGrade_onlyGradeInCommentEntry
else -> grade.entry.substringBeforeLast(")").substringAfter(" (")
}
if (comment.removeSurrounding("(", ")") == entry) comment = "" // getGrade_onlyCommentEntry
value = values.first
modifier = values.second
color = if ("0" == grade.color) "000000" else grade.color.toInt().toString(16).toUpperCase()
symbol = grade.symbol.orEmpty()
description = grade.description.orEmpty()
weight = String.format(Locale.FRANCE, "%.2f", grade.weightValue)
weightValue = if (isGradeValid(gradeEntryWithoutComment)) grade.weightValue else .0
date = grade.privateDate
teacher = grade.teacher
}
if (comment.removeSurrounding("(", ")") == entry) comment = "" // getGrade_onlyCommentEntry
value = values.first
modifier = values.second
color = if ("0" == grade.color) "000000" else grade.color.toInt().toString(16).toUpperCase()
symbol = grade.symbol.orEmpty()
description = grade.description.orEmpty()
weight = String.format(Locale.FRANCE, "%.2f", grade.weightValue)
weightValue = if (isGradeValid(gradeEntryWithoutComment)) grade.weightValue else .0
date = grade.privateDate
teacher = grade.teacher
}
}.flatten().sortedByDescending { it.date }
}
fun GradesResponse.mapGradesSummary(): List<GradeSummary> {
return gradesWithSubjects.map { subject ->
GradeSummary().apply {
visibleSubject = subject.visibleSubject
order = subject.order
name = subject.name
average = subject.average
predicted = getGradeShortValue(subject.proposed)
final = getGradeShortValue(subject.annual)
pointsSum = subject.pointsSum.takeIf { it != "-" }.orEmpty()
proposedPoints = subject.proposedPoints.orEmpty()
finalPoints = subject.finalPoints.orEmpty()
}
}.sortedBy { it.name }.toList()
}
fun List<GradesStatisticsResponse.Annual>.mapGradesStatisticsAnnual(semesterId: Int): List<GradeStatistics> {
return map { annualSubject ->
annualSubject.items?.reversed()?.mapIndexed { index, item ->
item.apply {
this.semesterId = semesterId
gradeValue = index + 1
grade = item.gradeValue.toString()
subject = annualSubject.subject
}
}.orEmpty()
}.flatten().reversed()
}
fun List<GradesStatisticsResponse.Partial>.mapGradesStatisticsPartial(semesterId: Int): List<GradeStatistics> {
return map { partialSubject ->
partialSubject.classSeries.items?.reversed()?.mapIndexed { index, item ->
item.apply {
this.semesterId = semesterId
gradeValue = index + 1
grade = item.gradeValue.toString()
subject = partialSubject.subject
}
}?.reversed().orEmpty()
}.flatten()
}
fun List<GradePointsSummary>.mapGradesStatisticsPoints(semesterId: Int): List<GradePointsSummary> {
return map {
it.copy(semesterId = semesterId)
}
}.flatten().sortedByDescending { it.date }
fun GradesResponse.mapGradesSummary() = gradesWithSubjects.map { subject ->
GradeSummary().apply {
visibleSubject = subject.visibleSubject
order = subject.order
name = subject.name
average = subject.average
predicted = getGradeShortValue(subject.proposed)
final = getGradeShortValue(subject.annual)
pointsSum = subject.pointsSum.takeIf { it != "-" }.orEmpty()
proposedPoints = subject.proposedPoints.orEmpty()
finalPoints = subject.finalPoints.orEmpty()
}
}.sortedBy { it.name }.toList()
fun List<GradesStatisticsResponse.Annual>.mapGradesStatisticsAnnual(semesterId: Int) = map { annualSubject ->
annualSubject.items?.reversed()?.mapIndexed { index, item ->
item.apply {
this.semesterId = semesterId
gradeValue = index + 1
grade = item.gradeValue.toString()
subject = annualSubject.subject
}
}.orEmpty()
}.flatten().reversed()
fun List<GradesStatisticsResponse.Partial>.mapGradesStatisticsPartial(semesterId: Int) = map { partialSubject ->
partialSubject.classSeries.items?.reversed()?.mapIndexed { index, item ->
item.apply {
this.semesterId = semesterId
gradeValue = index + 1
grade = item.gradeValue.toString()
subject = partialSubject.subject
}
}?.reversed().orEmpty()
}.flatten()
fun List<GradePointsSummary>.mapGradesStatisticsPoints(semesterId: Int) = map {
it.copy(semesterId = semesterId)
}

View file

@ -2,14 +2,12 @@ package io.github.wulkanowy.sdk.scrapper.school
import io.github.wulkanowy.sdk.scrapper.getEmptyIfDash
fun SchoolAndTeachersResponse.mapToTeachers(): List<Teacher> {
return teachers.map { item ->
item.name.split(",").map { namePart ->
item.copy(
name = namePart.substringBefore(" [").getEmptyIfDash().trim(),
short = namePart.substringAfter("[").substringBefore("]").getEmptyIfDash(),
subject = item.subject.trim()
)
}.asReversed()
}.flatten().sortedWith(compareBy({ it.subject }, { it.name }))
}
fun SchoolAndTeachersResponse.mapToTeachers() = teachers.map { item ->
item.name.split(",").map { namePart ->
item.copy(
name = namePart.substringBefore(" [").getEmptyIfDash().trim(),
short = namePart.substringAfter("[").substringBefore("]").getEmptyIfDash(),
subject = item.subject.trim()
)
}.asReversed()
}.flatten().sortedWith(compareBy({ it.subject }, { it.name }))

View file

@ -11,22 +11,20 @@ import io.github.wulkanowy.sdk.scrapper.toLocalDate
import org.jsoup.Jsoup
import java.time.LocalDate
fun TimetableResponse.mapTimetableList(startDate: LocalDate, endDate: LocalDate?): List<Timetable> {
return rows2api.flatMap { lessons ->
lessons.drop(1).mapIndexed { i, it ->
val times = lessons[0].split("<br />")
TimetableResponse.TimetableRow.TimetableCell().apply {
date = headers.union(_headersOld).drop(1)[i].date.split("<br />")[1].toDate("dd.MM.yyyy")
start = "${date.toLocalDate().toFormat("yyyy-MM-dd")} ${times[1]}".toDate("yyyy-MM-dd HH:mm")
end = "${date.toLocalDate().toFormat("yyyy-MM-dd")} ${times[2]}".toDate("yyyy-MM-dd HH:mm")
number = times[0].toInt()
td = Jsoup.parse(it)
}
}.mapNotNull { TimetableParser().getTimetable(it) }
}.asSequence().filter {
it.date.toLocalDate() >= startDate && it.date.toLocalDate() <= endDate ?: startDate.plusDays(4)
}.sortedWith(compareBy({ it.date }, { it.number })).toList()
}
fun TimetableResponse.mapTimetableList(startDate: LocalDate, endDate: LocalDate?) = rows2api.flatMap { lessons ->
lessons.drop(1).mapIndexed { i, it ->
val times = lessons[0].split("<br />")
TimetableResponse.TimetableRow.TimetableCell().apply {
date = headers.union(_headersOld).drop(1)[i].date.split("<br />")[1].toDate("dd.MM.yyyy")
start = "${date.toLocalDate().toFormat("yyyy-MM-dd")} ${times[1]}".toDate("yyyy-MM-dd HH:mm")
end = "${date.toLocalDate().toFormat("yyyy-MM-dd")} ${times[2]}".toDate("yyyy-MM-dd HH:mm")
number = times[0].toInt()
td = Jsoup.parse(it)
}
}.mapNotNull { TimetableParser().getTimetable(it) }
}.asSequence().filter {
it.date.toLocalDate() >= startDate && it.date.toLocalDate() <= endDate ?: startDate.plusDays(4)
}.sortedWith(compareBy({ it.date }, { it.number })).toList()
fun ApiResponse<*>.mapCompletedLessonsList(start: LocalDate, endDate: LocalDate?, gson: GsonBuilder): List<CompletedLesson> {
return (data as LinkedTreeMap<*, *>).map { list ->

View file

@ -11,69 +11,61 @@ import io.github.wulkanowy.sdk.scrapper.attendance.Absent as ScrapperAbsent
import io.github.wulkanowy.sdk.scrapper.attendance.Attendance as ScrapperAttendance
import io.github.wulkanowy.sdk.scrapper.attendance.AttendanceSummary as ScrapperAttendanceSummary
fun List<ApiAttendance>.mapAttendance(dictionaries: Dictionaries): List<Attendance> {
return map {
val category = dictionaries.attendanceCategories.singleOrNull { cat -> cat.id == it.categoryId }
Attendance(
number = it.number,
name = category?.name?.capitalize() ?: "Nieznany",
subject = it.subjectName,
date = it.date.toLocalDate(),
timeId = -1,
absence = category?.absence ?: false,
categoryId = it.categoryId,
presence = category?.presence ?: false,
lateness = category?.lateness ?: false,
exemption = category?.exemption ?: false,
excused = category?.excused ?: false,
excusable = false, //
deleted = category?.deleted ?: false,
excuseStatus = null
)
}
fun List<ApiAttendance>.mapAttendance(dictionaries: Dictionaries) = map {
val category = dictionaries.attendanceCategories.singleOrNull { cat -> cat.id == it.categoryId }
Attendance(
number = it.number,
name = category?.name?.capitalize() ?: "Nieznany",
subject = it.subjectName,
date = it.date.toLocalDate(),
timeId = -1,
absence = category?.absence ?: false,
categoryId = it.categoryId,
presence = category?.presence ?: false,
lateness = category?.lateness ?: false,
exemption = category?.exemption ?: false,
excused = category?.excused ?: false,
excusable = false, //
deleted = category?.deleted ?: false,
excuseStatus = null
)
}
fun List<ScrapperAttendance>.mapAttendance(): List<Attendance> {
return map {
Attendance(
number = it.number,
name = it.name,
subject = it.subject,
date = it.date.toLocalDate(),
timeId = it.timeId,
absence = it.absence,
categoryId = it.categoryId,
deleted = it.deleted,
excusable = it.excusable,
excused = it.excused,
exemption = it.exemption,
lateness = it.lateness,
presence = it.presence,
excuseStatus = it.excuseStatus
)
}
fun List<ScrapperAttendance>.mapAttendance() = map {
Attendance(
number = it.number,
name = it.name,
subject = it.subject,
date = it.date.toLocalDate(),
timeId = it.timeId,
absence = it.absence,
categoryId = it.categoryId,
deleted = it.deleted,
excusable = it.excusable,
excused = it.excused,
exemption = it.exemption,
lateness = it.lateness,
presence = it.presence,
excuseStatus = it.excuseStatus
)
}
fun List<ScrapperAttendanceSummary>.mapAttendanceSummary(): List<AttendanceSummary> {
return map {
AttendanceSummary(
month = it.month,
presence = it.presence,
absence = it.absence,
absenceExcused = it.absenceExcused,
absenceForSchoolReasons = it.absenceForSchoolReasons,
lateness = it.lateness,
latenessExcused = it.latenessExcused,
exemption = it.exemption
)
}
fun List<ScrapperAttendanceSummary>.mapAttendanceSummary() = map {
AttendanceSummary(
month = it.month,
presence = it.presence,
absence = it.absence,
absenceExcused = it.absenceExcused,
absenceForSchoolReasons = it.absenceForSchoolReasons,
lateness = it.lateness,
latenessExcused = it.latenessExcused,
exemption = it.exemption
)
}
fun List<Absent>.mapToScrapperAbsent(): List<ScrapperAbsent> {
return map {
ScrapperAbsent(
date = it.date,
timeId = it.timeId
)
}
fun List<Absent>.mapToScrapperAbsent() = map {
ScrapperAbsent(
date = it.date,
timeId = it.timeId
)
}

View file

@ -7,37 +7,33 @@ import io.github.wulkanowy.sdk.toLocalDate
import io.github.wulkanowy.sdk.mobile.exams.Exam as ApiExam
import io.github.wulkanowy.sdk.scrapper.exams.Exam as ScrapperExam
fun List<ApiExam>.mapExams(dict: Dictionaries): List<Exam> {
return map { exam ->
Exam(
date = exam.date.toLocalDate(),
entryDate = exam.date.toLocalDate(),
description = exam.description,
group = exam.divideName.orEmpty(),
teacher = dict.teachers.singleOrNull { it.id == exam.employeeId }?.run { "$name $surname" }.orEmpty(),
subject = dict.subjects.singleOrNull { it.id == exam.subjectId }?.name.orEmpty(),
teacherSymbol = dict.teachers.singleOrNull { it.id == exam.employeeId }?.code.orEmpty(),
type = when (exam.typeNumber) {
1 -> "Sprawdzian"
2 -> "Kartkówka"
3 -> "Praca klasowa"
else -> "Nieznany"
}
)
}
fun List<ApiExam>.mapExams(dict: Dictionaries) = map { exam ->
Exam(
date = exam.date.toLocalDate(),
entryDate = exam.date.toLocalDate(),
description = exam.description,
group = exam.divideName.orEmpty(),
teacher = dict.teachers.singleOrNull { it.id == exam.employeeId }?.run { "$name $surname" }.orEmpty(),
subject = dict.subjects.singleOrNull { it.id == exam.subjectId }?.name.orEmpty(),
teacherSymbol = dict.teachers.singleOrNull { it.id == exam.employeeId }?.code.orEmpty(),
type = when (exam.typeNumber) {
1 -> "Sprawdzian"
2 -> "Kartkówka"
3 -> "Praca klasowa"
else -> "Nieznany"
}
)
}
fun List<ScrapperExam>.mapExams(): List<Exam> {
return map {
Exam(
date = it.date.toLocalDate(),
entryDate = it.entryDate.toLocalDate(),
description = it.description,
group = it.group,
teacherSymbol = it.teacherSymbol,
teacher = it.teacher,
subject = it.subject,
type = it.type
)
}
fun List<ScrapperExam>.mapExams() = map {
Exam(
date = it.date.toLocalDate(),
entryDate = it.entryDate.toLocalDate(),
description = it.description,
group = it.group,
teacherSymbol = it.teacherSymbol,
teacher = it.teacher,
subject = it.subject,
type = it.type
)
}

View file

@ -5,22 +5,18 @@ import io.github.wulkanowy.sdk.pojo.GovernmentUnit
import io.github.wulkanowy.sdk.scrapper.home.GovernmentMember as ScrapperGovernmentMember
import io.github.wulkanowy.sdk.scrapper.home.GovernmentUnit as ScrapperGovernmentUnit
fun List<ScrapperGovernmentUnit>.mapToUnits(): List<GovernmentUnit> {
return map {
GovernmentUnit(
unitName = it.unitName,
people = it.people.mapToMembers()
)
}
fun List<ScrapperGovernmentUnit>.mapToUnits() = map {
GovernmentUnit(
unitName = it.unitName,
people = it.people.mapToMembers()
)
}
fun List<ScrapperGovernmentMember>.mapToMembers(): List<GovernmentMember> {
return map {
GovernmentMember(
name = it.name,
division = it.division,
position = it.position,
id = it.id
)
}
fun List<ScrapperGovernmentMember>.mapToMembers() = map {
GovernmentMember(
name = it.name,
division = it.division,
position = it.position,
id = it.id
)
}

View file

@ -11,46 +11,44 @@ import io.github.wulkanowy.sdk.mobile.grades.Grade as ApiGrade
import io.github.wulkanowy.sdk.scrapper.grades.Grade as ScrapperGrade
import io.github.wulkanowy.sdk.scrapper.grades.GradeSummary as ScrapperGradeSummary
fun List<ApiGrade>.mapGradesDetails(dict: Dictionaries): List<Grade> {
return map { grade ->
Grade(
subject = dict.subjects.singleOrNull { it.id == grade.subjectId }?.name.orEmpty(),
description = grade.description,
symbol = dict.gradeCategories.singleOrNull { it.id == grade.categoryId }?.code.orEmpty(),
comment = grade.comment.orEmpty(),
date = grade.creationDate.toLocalDate(),
teacher = dict.teachers.singleOrNull { it.id == grade.employeeIdD }?.let { "${it.name} ${it.surname}" }.orEmpty(),
entry = if (grade.entry.isNotBlank()) grade.entry else "...",
weightValue = if (isGradeValid(grade.entry)) grade.gradeWeight else .0,
modifier = grade.modificationWeight ?: .0,
value = grade.value,
weight = grade.weight,
color = "0"
)
}
fun List<ApiGrade>.mapGradesDetails(dict: Dictionaries) = map { grade ->
Grade(
subject = dict.subjects.singleOrNull { it.id == grade.subjectId }?.name.orEmpty(),
description = grade.description,
symbol = dict.gradeCategories.singleOrNull { it.id == grade.categoryId }?.code.orEmpty(),
comment = grade.comment.orEmpty(),
date = grade.creationDate.toLocalDate(),
teacher = dict.teachers.singleOrNull { it.id == grade.employeeIdD }?.let { "${it.name} ${it.surname}" }.orEmpty(),
entry = if (grade.entry.isNotBlank()) grade.entry else "...",
weightValue = if (isGradeValid(grade.entry)) grade.gradeWeight else .0,
modifier = grade.modificationWeight ?: .0,
value = grade.value,
weight = grade.weight,
color = "0"
)
}
fun List<ScrapperGrade>.mapGradesDetails(): List<Grade> {
return map {
Grade(
subject = it.subject,
description = it.description.orEmpty(),
symbol = it.symbol.orEmpty(),
comment = it.comment,
date = it.date.toLocalDate(),
teacher = it.teacher,
entry = it.entry,
weight = it.weight,
weightValue = it.weightValue,
color = it.color,
value = it.value.toDouble(),
modifier = it.modifier
)
}
fun List<ScrapperGrade>.mapGradesDetails() = map {
Grade(
subject = it.subject,
description = it.description.orEmpty(),
symbol = it.symbol.orEmpty(),
comment = it.comment,
date = it.date.toLocalDate(),
teacher = it.teacher,
entry = it.entry,
weight = it.weight,
weightValue = it.weightValue,
color = it.color,
value = it.value.toDouble(),
modifier = it.modifier
)
}
fun GradesSummaryResponse.mapGradesSummary(dict: Dictionaries): List<GradeSummary> {
return average.union(predicted).union(evaluative).map { it.subjectId }.distinct().sorted().map { subjectId ->
fun GradesSummaryResponse.mapGradesSummary(dict: Dictionaries) = average
.union(predicted)
.union(evaluative)
.map { it.subjectId }.distinct().sorted().map { subjectId ->
GradeSummary(
name = dict.subjects.singleOrNull { it.id == subjectId }?.name.orEmpty(),
predicted = predicted.singleOrNull { it.subjectId == subjectId }?.entry.orEmpty(),
@ -61,26 +59,19 @@ fun GradesSummaryResponse.mapGradesSummary(dict: Dictionaries): List<GradeSummar
finalPoints = ""
)
}
fun List<ScrapperGradeSummary>.mapGradesSummary() = map {
GradeSummary(
name = it.name,
finalPoints = it.finalPoints,
proposedPoints = it.proposedPoints,
pointsSum = it.pointsSum,
average = it.average,
final = it.final,
predicted = it.predicted
)
}
fun List<ScrapperGradeSummary>.mapGradesSummary(): List<GradeSummary> {
return map {
GradeSummary(
name = it.name,
finalPoints = it.finalPoints,
proposedPoints = it.proposedPoints,
pointsSum = it.pointsSum,
average = it.average,
final = it.final,
predicted = it.predicted
)
}
}
fun Pair<List<ScrapperGrade>, List<ScrapperGradeSummary>>.mapGrades() = first.mapGradesDetails() to second.mapGradesSummary()
fun Pair<List<ScrapperGrade>, List<ScrapperGradeSummary>>.mapGrades(): Pair<List<Grade>, List<GradeSummary>> {
return first.mapGradesDetails() to second.mapGradesSummary()
}
fun Pair<List<ApiGrade>, GradesSummaryResponse>.mapGrades(dict: Dictionaries): Pair<List<Grade>, List<GradeSummary>> {
return first.mapGradesDetails(dict) to second.mapGradesSummary(dict)
}
fun Pair<List<ApiGrade>, GradesSummaryResponse>.mapGrades(dict: Dictionaries) = first.mapGradesDetails(dict) to second.mapGradesSummary(dict)

View file

@ -5,25 +5,21 @@ import io.github.wulkanowy.sdk.pojo.GradeStatistics
import io.github.wulkanowy.sdk.scrapper.grades.GradePointsSummary
import io.github.wulkanowy.sdk.scrapper.grades.GradeStatistics as ScrapperGradeStatistics
fun List<ScrapperGradeStatistics>.mapGradeStatistics(): List<GradeStatistics> {
return map {
GradeStatistics(
semesterId = it.semesterId,
subject = it.subject,
grade = it.grade,
gradeValue = it.gradeValue,
amount = it.amount ?: 0
)
}
fun List<ScrapperGradeStatistics>.mapGradeStatistics() = map {
GradeStatistics(
semesterId = it.semesterId,
subject = it.subject,
grade = it.grade,
gradeValue = it.gradeValue,
amount = it.amount ?: 0
)
}
fun List<GradePointsSummary>.mapGradePointsStatistics(): List<GradePointsStatistics> {
return map {
GradePointsStatistics(
semesterId = it.semesterId,
subject = it.subject,
student = it.student,
others = it.others
)
}
fun List<GradePointsSummary>.mapGradePointsStatistics() = map {
GradePointsStatistics(
semesterId = it.semesterId,
subject = it.subject,
student = it.student,
others = it.others
)
}

View file

@ -8,33 +8,29 @@ import io.github.wulkanowy.sdk.toLocalDate
import io.github.wulkanowy.sdk.mobile.homework.Homework as ApiHomework
import io.github.wulkanowy.sdk.scrapper.homework.Homework as ScrapperHomework
fun List<ApiHomework>.mapHomework(dictionaries: Dictionaries): List<Homework> {
return map {
val employee = dictionaries.employees.singleOrNull { employee -> employee.id == it.employeeId }
Homework(
date = it.date.toLocalDate(),
entryDate = it.date.toLocalDate(),
subject = dictionaries.subjects.singleOrNull { subject -> subject.id == it.subjectId }?.name.orEmpty(),
content = it.content,
teacherSymbol = employee?.code.orEmpty(),
teacher = employee?.run { "$name $surname" }.orEmpty(),
attachments = emptyList()
)
}
fun List<ApiHomework>.mapHomework(dictionaries: Dictionaries) = map {
val employee = dictionaries.employees.singleOrNull { employee -> employee.id == it.employeeId }
Homework(
date = it.date.toLocalDate(),
entryDate = it.date.toLocalDate(),
subject = dictionaries.subjects.singleOrNull { subject -> subject.id == it.subjectId }?.name.orEmpty(),
content = it.content,
teacherSymbol = employee?.code.orEmpty(),
teacher = employee?.run { "$name $surname" }.orEmpty(),
attachments = emptyList()
)
}
fun List<ScrapperHomework>.mapHomework(): List<Homework> {
return map {
Homework(
date = it.date.toLocalDate(),
teacher = it.teacher,
teacherSymbol = it.teacherSymbol,
content = it.content,
subject = it.subject,
entryDate = it.entryDate.toLocalDate(),
attachments = it._attachments.map { (url, name) ->
HomeworkAttachment(url, name)
}
)
}
fun List<ScrapperHomework>.mapHomework() = map {
Homework(
date = it.date.toLocalDate(),
teacher = it.teacher,
teacherSymbol = it.teacherSymbol,
content = it.content,
subject = it.subject,
entryDate = it.entryDate.toLocalDate(),
attachments = it._attachments.map { (url, name) ->
HomeworkAttachment(url, name)
}
)
}

View file

@ -3,12 +3,10 @@ package io.github.wulkanowy.sdk.mapper
import io.github.wulkanowy.sdk.pojo.LuckyNumber
import io.github.wulkanowy.sdk.scrapper.home.LuckyNumber as ScrapperLuckyNumber
fun List<ScrapperLuckyNumber>.mapLuckyNumbers(): List<LuckyNumber> {
return map {
LuckyNumber(
unitName = it.unitName,
school = it.school,
number = it.number
)
}
fun List<ScrapperLuckyNumber>.mapLuckyNumbers() = map {
LuckyNumber(
unitName = it.unitName,
school = it.school,
number = it.number
)
}

View file

@ -10,63 +10,57 @@ import io.github.wulkanowy.sdk.mobile.messages.Message as ApiMessage
import io.github.wulkanowy.sdk.scrapper.messages.Message as ScrapperMessage
@JvmName("mapApiMessages")
fun List<ApiMessage>.mapMessages(dictionaries: Dictionaries): List<Message> {
return map {
Message(
id = it.messageId,
unreadBy = it.unread?.toInt(),
unread = it.folder == "Odebrane" && it.readDateTime == null,
sender = it.senderName ?: dictionaries.employees.singleOrNull { employee -> employee.id == it.senderId }?.let { e -> "${e.name} ${e.surname}" },
senderId = it.senderId,
removed = it.status == "Usunieta",
recipient = it.recipients?.joinToString(", ") { recipient -> recipient.name.normalizeRecipient() },
readBy = it.read?.toInt(),
messageId = it.messageId,
folderId = when (it.folder) {
"Odebrane" -> 1
"Wyslane" -> 2
else -> 1
},
content = it.content,
date = it.sentDateTime.toLocalDateTime(),
subject = it.subject,
hasAttachments = false
)
}
}
fun List<ScrapperMessage>.mapMessages(): List<Message> {
return map {
Message(
id = it.id,
subject = it.subject,
date = it.date?.toLocalDateTime(),
content = it.content,
folderId = it.folderId,
messageId = it.messageId,
readBy = it.readBy,
recipient = it.recipient,
removed = it.removed,
sender = it.sender,
senderId = it.senderId,
unread = it.unread,
unreadBy = it.unreadBy,
hasAttachments = it.hasAttachments
)
}
}
fun ScrapperMessage.mapScrapperMessage(): MessageDetails {
return MessageDetails(
content = requireNotNull(content),
attachments = attachments?.map {
MessageAttachment(
id = it.id,
messageId = it.messageId,
oneDriveId = it.oneDriveId,
url = it.url,
filename = it.filename
)
} ?: emptyList()
fun List<ApiMessage>.mapMessages(dictionaries: Dictionaries) = map {
Message(
id = it.messageId,
unreadBy = it.unread?.toInt(),
unread = it.folder == "Odebrane" && it.readDateTime == null,
sender = it.senderName ?: dictionaries.employees.singleOrNull { employee -> employee.id == it.senderId }?.let { e -> "${e.name} ${e.surname}" },
senderId = it.senderId,
removed = it.status == "Usunieta",
recipient = it.recipients?.joinToString(", ") { recipient -> recipient.name.normalizeRecipient() },
readBy = it.read?.toInt(),
messageId = it.messageId,
folderId = when (it.folder) {
"Odebrane" -> 1
"Wyslane" -> 2
else -> 1
},
content = it.content,
date = it.sentDateTime.toLocalDateTime(),
subject = it.subject,
hasAttachments = false
)
}
fun List<ScrapperMessage>.mapMessages() = map {
Message(
id = it.id,
subject = it.subject,
date = it.date?.toLocalDateTime(),
content = it.content,
folderId = it.folderId,
messageId = it.messageId,
readBy = it.readBy,
recipient = it.recipient,
removed = it.removed,
sender = it.sender,
senderId = it.senderId,
unread = it.unread,
unreadBy = it.unreadBy,
hasAttachments = it.hasAttachments
)
}
fun ScrapperMessage.mapScrapperMessage() = MessageDetails(
content = requireNotNull(content),
attachments = attachments?.map {
MessageAttachment(
id = it.id,
messageId = it.messageId,
oneDriveId = it.oneDriveId,
url = it.url,
filename = it.filename
)
}.orEmpty()
)

View file

@ -7,23 +7,19 @@ import io.github.wulkanowy.sdk.toLocalDateTime
import java.time.LocalDateTime.now
import io.github.wulkanowy.sdk.scrapper.mobile.Device as ScrapperDevice
fun TokenResponse.mapToken(): Token {
return Token(
token = token,
symbol = symbol,
pin = pin,
qrCodeImage = qrCodeImage
fun TokenResponse.mapToken() = Token(
token = token,
symbol = symbol,
pin = pin,
qrCodeImage = qrCodeImage
)
fun List<ScrapperDevice>.mapDevices() = map {
Device(
id = it.id,
deviceId = it.deviceId.orEmpty(),
name = it.name.orEmpty(),
createDate = it.createDate?.toLocalDateTime() ?: now(),
modificationDate = it.modificationDate?.toLocalDateTime()
)
}
fun List<ScrapperDevice>.mapDevices(): List<Device> {
return map {
Device(
id = it.id,
deviceId = it.deviceId.orEmpty(),
name = it.name.orEmpty(),
createDate = it.createDate?.toLocalDateTime() ?: now(),
modificationDate = it.modificationDate?.toLocalDateTime()
)
}
}

View file

@ -7,32 +7,28 @@ import io.github.wulkanowy.sdk.toLocalDate
import io.github.wulkanowy.sdk.mobile.notes.Note as ApiNote
import io.github.wulkanowy.sdk.scrapper.notes.Note as ScrapperNote
fun List<ApiNote>.mapNotes(dictionaries: Dictionaries): List<Note> {
return map {
Note(
date = it.entryDate.toLocalDate(),
content = it.content,
teacherSymbol = dictionaries.teachers.singleOrNull { teacher -> teacher.id == it.employeeId }?.code.orEmpty(),
teacher = "${it.employeeName} ${it.employeeSurname}",
category = dictionaries.noteCategories.singleOrNull { cat -> cat.id == it.noteCategoryId }?.name.orEmpty(),
categoryType = ScrapperNote.CategoryType.UNKNOWN,
showPoints = false,
points = 0
)
}
fun List<ApiNote>.mapNotes(dictionaries: Dictionaries) = map {
Note(
date = it.entryDate.toLocalDate(),
content = it.content,
teacherSymbol = dictionaries.teachers.singleOrNull { teacher -> teacher.id == it.employeeId }?.code.orEmpty(),
teacher = "${it.employeeName} ${it.employeeSurname}",
category = dictionaries.noteCategories.singleOrNull { cat -> cat.id == it.noteCategoryId }?.name.orEmpty(),
categoryType = ScrapperNote.CategoryType.UNKNOWN,
showPoints = false,
points = 0
)
}
fun List<ScrapperNote>.mapNotes(): List<Note> {
return map {
Note(
date = it.date.toLocalDate(),
teacher = it.teacher,
teacherSymbol = it.teacherSymbol,
category = it.category,
categoryType = ScrapperNote.CategoryType.getByValue(it.categoryType),
showPoints = it.showPoints,
points = it.points.toIntOrNull() ?: 0,
content = it.content
)
}
fun List<ScrapperNote>.mapNotes() = map {
Note(
date = it.date.toLocalDate(),
teacher = it.teacher,
teacherSymbol = it.teacherSymbol,
category = it.category,
categoryType = ScrapperNote.CategoryType.getByValue(it.categoryType),
showPoints = it.showPoints,
points = it.points.toIntOrNull() ?: 0,
content = it.content
)
}

View file

@ -5,72 +5,62 @@ import io.github.wulkanowy.sdk.pojo.Recipient
import io.github.wulkanowy.sdk.mobile.messages.Recipient as MobileRecipient
import io.github.wulkanowy.sdk.scrapper.messages.Recipient as ScrapperRecipient
fun List<ScrapperRecipient>.mapRecipients(): List<Recipient> {
return map {
Recipient(
id = it.id,
hash = it.hash,
loginId = it.loginId,
name = it.name,
reportingUnitId = it.reportingUnitId,
role = it.role,
shortName = it.shortName.orEmpty()
)
}
fun List<ScrapperRecipient>.mapRecipients() = map {
Recipient(
id = it.id,
hash = it.hash,
loginId = it.loginId,
name = it.name,
reportingUnitId = it.reportingUnitId,
role = it.role,
shortName = it.shortName.orEmpty()
)
}
fun List<Recipient>.mapFromRecipientsToScraper(): List<ScrapperRecipient> {
return map {
ScrapperRecipient(
id = it.id,
hash = it.hash,
loginId = it.loginId,
name = it.name,
reportingUnitId = it.reportingUnitId,
role = it.role,
shortName = it.shortName
)
}
fun List<Recipient>.mapFromRecipientsToScraper() = map {
ScrapperRecipient(
id = it.id,
hash = it.hash,
loginId = it.loginId,
name = it.name,
reportingUnitId = it.reportingUnitId,
role = it.role,
shortName = it.shortName
)
}
fun List<Recipient>.mapFromRecipientsToMobile(): List<MobileRecipient> {
return map {
MobileRecipient(
// id = it.id,
// hash = it.hash,
loginId = it.loginId,
name = it.name
// reportingUnitId = it.reportingUnitId,
// role = it.role,
// shortName = it.shortName
)
}
fun List<Recipient>.mapFromRecipientsToMobile() = map {
MobileRecipient(
// id = it.id,
// hash = it.hash,
loginId = it.loginId,
name = it.name
// reportingUnitId = it.reportingUnitId,
// role = it.role,
// shortName = it.shortName
)
}
fun List<MobileRecipient>.mapFromMobileToRecipients(): List<Recipient> {
return map {
Recipient(
id = "",
loginId = it.loginId,
hash = "",
name = it.name,
reportingUnitId = 0,
role = 0,
shortName = ""
)
}
fun List<MobileRecipient>.mapFromMobileToRecipients() = map {
Recipient(
id = "",
loginId = it.loginId,
hash = "",
name = it.name,
reportingUnitId = 0,
role = 0,
shortName = ""
)
}
fun List<Teacher>.mapRecipients(reportingUnitId: Int): List<Recipient> {
return map {
Recipient(
id = it.loginId.toString(),
shortName = it.code,
role = 2,
reportingUnitId = reportingUnitId,
name = "${it.name} ${it.surname}",
loginId = it.loginId,
hash = "NIE UŻYWAJ NADAWCÓW POBRANYCH W TRYBIE API DO WYSYŁANIA WIADOMOŚCI W TRYBIE SCRAPPER ANI ODWROTNIE" // TODO: throw exception then
)
}
fun List<Teacher>.mapRecipients(reportingUnitId: Int) = map {
Recipient(
id = it.loginId.toString(),
shortName = it.code,
role = 2,
reportingUnitId = reportingUnitId,
name = "${it.name} ${it.surname}",
loginId = it.loginId,
hash = "NIE UŻYWAJ NADAWCÓW POBRANYCH W TRYBIE API DO WYSYŁANIA WIADOMOŚCI W TRYBIE SCRAPPER ANI ODWROTNIE" // TODO: throw exception then
)
}

View file

@ -4,26 +4,22 @@ import io.github.wulkanowy.sdk.mobile.register.Student
import io.github.wulkanowy.sdk.pojo.ReportingUnit
import io.github.wulkanowy.sdk.scrapper.messages.ReportingUnit as ScrapperReportingUnit
fun List<ScrapperReportingUnit>.mapReportingUnits(): List<ReportingUnit> {
return map {
ReportingUnit(
id = it.id,
roles = it.roles,
senderId = it.senderId,
senderName = it.senderName,
short = it.short
)
}
fun List<ScrapperReportingUnit>.mapReportingUnits() = map {
ReportingUnit(
id = it.id,
roles = it.roles,
senderId = it.senderId,
senderName = it.senderName,
short = it.short
)
}
fun List<Student>.mapReportingUnits(studentId: Int): List<ReportingUnit> {
return filter { studentId == it.loginId }.map {
ReportingUnit(
id = it.reportingUnitId,
short = it.reportingUnitShortcut,
senderName = it.name,
senderId = it.id,
roles = emptyList()
)
}
fun List<Student>.mapReportingUnits(studentId: Int) = filter { studentId == it.loginId }.map {
ReportingUnit(
id = it.reportingUnitId,
short = it.reportingUnitShortcut,
senderName = it.name,
senderId = it.id,
roles = emptyList()
)
}

View file

@ -3,12 +3,10 @@ package io.github.wulkanowy.sdk.mapper
import io.github.wulkanowy.sdk.pojo.School
import io.github.wulkanowy.sdk.scrapper.school.School as ScrapperSchool
fun ScrapperSchool.mapSchool(): School {
return School(
name = name,
address = address,
contact = contact,
headmaster = headmaster,
pedagogue = pedagogue
)
}
fun ScrapperSchool.mapSchool() = School(
name = name,
address = address,
contact = contact,
headmaster = headmaster,
pedagogue = pedagogue
)

View file

@ -9,37 +9,33 @@ import java.time.Month
import io.github.wulkanowy.sdk.scrapper.register.Semester as ScrapperSemester
@JvmName("mapScrapperSemesters")
fun List<ScrapperSemester>.mapSemesters(): List<Semester> {
return map {
Semester(
diaryId = it.diaryId,
diaryName = it.diaryName,
schoolYear = it.schoolYear,
semesterId = it.semesterId,
semesterNumber = it.semesterNumber,
start = it.start,
end = it.end,
classId = it.classId,
unitId = it.unitId
)
}
fun List<ScrapperSemester>.mapSemesters() = map {
Semester(
diaryId = it.diaryId,
diaryName = it.diaryName,
schoolYear = it.schoolYear,
semesterId = it.semesterId,
semesterNumber = it.semesterNumber,
start = it.start,
end = it.end,
classId = it.classId,
unitId = it.unitId
)
}
fun List<Student>.mapSemesters(studentId: Int): List<Semester> {
return filter { it.id == studentId }.map {
Semester(
diaryId = 0,
diaryName = it.classSymbol,
schoolYear = it.periodDateFrom.toLocalDate().let { start -> if (start.month == Month.SEPTEMBER) start.year else start.year - 1 },
semesterId = it.classificationPeriodId,
semesterNumber = it.periodNumber,
start = it.periodDateFrom.toLocalDate(),
end = it.periodDateTo.toLocalDate(),
classId = it.classId,
unitId = it.reportingUnitId
)
}.mockSecondSemester()
}
fun List<Student>.mapSemesters(studentId: Int) = filter { it.id == studentId }.map {
Semester(
diaryId = 0,
diaryName = it.classSymbol,
schoolYear = it.periodDateFrom.toLocalDate().let { start -> if (start.month == Month.SEPTEMBER) start.year else start.year - 1 },
semesterId = it.classificationPeriodId,
semesterNumber = it.periodNumber,
start = it.periodDateFrom.toLocalDate(),
end = it.periodDateTo.toLocalDate(),
classId = it.classId,
unitId = it.reportingUnitId
)
}.mockSecondSemester()
private fun List<Semester>.mockSecondSemester(): List<Semester> {
if (size != 1) throw VulcanException("Expected semester list size 1, get $size")

View file

@ -5,31 +5,27 @@ import io.github.wulkanowy.sdk.pojo.Sender
import io.github.wulkanowy.sdk.pojo.SentMessage
import io.github.wulkanowy.sdk.scrapper.messages.SentMessage as ScrapperSentMessage
fun ScrapperSentMessage.mapSentMessage(): SentMessage {
return SentMessage(
recipients = recipients.mapRecipients(),
id = id,
content = content,
isWelcomeMessage = isWelcomeMessage,
sender = Sender(
id = sender.id,
role = sender.role,
reportingUnitId = sender.reportingUnitId,
name = sender.name,
loginId = sender.loginId,
hash = sender.hash
),
subject = subject
)
}
fun ScrapperSentMessage.mapSentMessage() = SentMessage(
recipients = recipients.mapRecipients(),
id = id,
content = content,
isWelcomeMessage = isWelcomeMessage,
sender = Sender(
id = sender.id,
role = sender.role,
reportingUnitId = sender.reportingUnitId,
name = sender.name,
loginId = sender.loginId,
hash = sender.hash
),
subject = subject
)
fun Message.mapSentMessage(loginId: Int): SentMessage {
return SentMessage(
recipients = recipients.orEmpty().mapFromMobileToRecipients(),
subject = subject,
content = content,
sender = Sender(senderId.toString(), senderName, loginId, -1, -2, "-3"),
id = messageId,
isWelcomeMessage = false
)
}
fun Message.mapSentMessage(loginId: Int) = SentMessage(
recipients = recipients.orEmpty().mapFromMobileToRecipients(),
subject = subject,
content = content,
sender = Sender(senderId.toString(), senderName, loginId, -1, -2, "-3"),
id = messageId,
isWelcomeMessage = false
)

View file

@ -4,35 +4,33 @@ import io.github.wulkanowy.sdk.pojo.StudentInfo
import io.github.wulkanowy.sdk.scrapper.toLocalDate
import io.github.wulkanowy.sdk.scrapper.student.StudentInfo as ScrapperStudentInfo
fun ScrapperStudentInfo.mapStudent(): StudentInfo {
return StudentInfo(
student = StudentInfo.Student(
fullName = student.fullName,
address = student.address,
birthDate = student.birthDate.toLocalDate(),
birthPlace = student.birthPlace,
cellPhoneNumber = student.cellPhoneNumber,
correspondenceAddress = student.correspondenceAddress,
email = student.email,
familyName = student.familyName,
firstName = student.firstName,
gender = student.gender,
parentsNames = student.parentsNames,
pesel = student.pesel,
phoneNumber = student.phoneNumber,
polishCitizenship = student.polishCitizenship,
registeredAddress = student.registeredAddress,
secondName = student.secondName,
surname = student.surname
),
family = family.map {
StudentInfo.FamilyMember(
fullName = it.fullName,
email = it.email,
address = it.address,
kinship = it.kinship,
phones = it.phones
)
}
)
}
fun ScrapperStudentInfo.mapStudent() = StudentInfo(
student = StudentInfo.Student(
fullName = student.fullName,
address = student.address,
birthDate = student.birthDate.toLocalDate(),
birthPlace = student.birthPlace,
cellPhoneNumber = student.cellPhoneNumber,
correspondenceAddress = student.correspondenceAddress,
email = student.email,
familyName = student.familyName,
firstName = student.firstName,
gender = student.gender,
parentsNames = student.parentsNames,
pesel = student.pesel,
phoneNumber = student.phoneNumber,
polishCitizenship = student.polishCitizenship,
registeredAddress = student.registeredAddress,
secondName = student.secondName,
surname = student.surname
),
family = family.map {
StudentInfo.FamilyMember(
fullName = it.fullName,
email = it.email,
address = it.address,
kinship = it.kinship,
phones = it.phones
)
}
)

View file

@ -5,50 +5,46 @@ import io.github.wulkanowy.sdk.pojo.Student
import io.github.wulkanowy.sdk.mobile.register.Student as ApiStudent
import io.github.wulkanowy.sdk.scrapper.register.Student as ScrapperStudent
fun List<ApiStudent>.mapStudents(symbol: String): List<Student> {
return map {
Student(
email = it.userLogin,
isParent = it.userRole != "uczeń",
symbol = symbol,
studentId = it.id,
userLoginId = it.userLoginId,
classId = it.classId,
className = it.classCode.orEmpty(),
studentName = "${it.name} ${it.surname}",
schoolSymbol = it.reportingUnitSymbol,
schoolShortName = it.reportingUnitShortcut,
schoolName = it.reportingUnitName,
loginType = Sdk.ScrapperLoginType.STANDARD,
loginMode = Sdk.Mode.API,
scrapperBaseUrl = "",
mobileBaseUrl = it.mobileBaseUrl,
privateKey = it.privateKey,
certificateKey = it.certificateKey
)
}
fun List<ApiStudent>.mapStudents(symbol: String) = map {
Student(
email = it.userLogin,
isParent = it.userRole != "uczeń",
symbol = symbol,
studentId = it.id,
userLoginId = it.userLoginId,
classId = it.classId,
className = it.classCode.orEmpty(),
studentName = "${it.name} ${it.surname}",
schoolSymbol = it.reportingUnitSymbol,
schoolShortName = it.reportingUnitShortcut,
schoolName = it.reportingUnitName,
loginType = Sdk.ScrapperLoginType.STANDARD,
loginMode = Sdk.Mode.API,
scrapperBaseUrl = "",
mobileBaseUrl = it.mobileBaseUrl,
privateKey = it.privateKey,
certificateKey = it.certificateKey
)
}
fun List<ScrapperStudent>.mapStudents(): List<Student> {
return map {
Student(
email = it.email,
isParent = it.isParent,
className = it.className,
classId = it.classId,
studentId = it.studentId,
userLoginId = 0,
symbol = it.symbol,
loginType = Sdk.ScrapperLoginType.valueOf(it.loginType.name),
schoolName = it.schoolName,
schoolShortName = it.schoolShortName,
schoolSymbol = it.schoolSymbol,
studentName = it.studentName,
loginMode = Sdk.Mode.SCRAPPER,
scrapperBaseUrl = it.baseUrl,
mobileBaseUrl = "",
certificateKey = "",
privateKey = ""
)
}
fun List<ScrapperStudent>.mapStudents() = map {
Student(
email = it.email,
isParent = it.isParent,
className = it.className,
classId = it.classId,
studentId = it.studentId,
userLoginId = 0,
symbol = it.symbol,
loginType = Sdk.ScrapperLoginType.valueOf(it.loginType.name),
schoolName = it.schoolName,
schoolShortName = it.schoolShortName,
schoolSymbol = it.schoolSymbol,
studentName = it.studentName,
loginMode = Sdk.Mode.SCRAPPER,
scrapperBaseUrl = it.baseUrl,
mobileBaseUrl = "",
certificateKey = "",
privateKey = ""
)
}

View file

@ -5,20 +5,16 @@ import io.github.wulkanowy.sdk.mobile.dictionaries.Subject as ApiSubject
import io.github.wulkanowy.sdk.scrapper.attendance.Subject as ScrapperSubject
@JvmName("mapApiSubjects")
fun List<ApiSubject>.mapSubjects(): List<Subject> {
return listOf(Subject(-1, "Wszystkie")) + filter { it.active }.map {
Subject(
id = it.id,
name = it.name
)
}
fun List<ApiSubject>.mapSubjects() = listOf(Subject(-1, "Wszystkie")) + filter { it.active }.map {
Subject(
id = it.id,
name = it.name
)
}
fun List<ScrapperSubject>.mapSubjects(): List<Subject> {
return map {
Subject(
id = it.value,
name = it.name
)
}
fun List<ScrapperSubject>.mapSubjects() = map {
Subject(
id = it.value,
name = it.name
)
}

View file

@ -5,24 +5,20 @@ import io.github.wulkanowy.sdk.pojo.Teacher
import io.github.wulkanowy.sdk.mobile.school.Teacher as ApiTeacher
import io.github.wulkanowy.sdk.scrapper.school.Teacher as ScrapperTeacher
fun List<ApiTeacher>.mapTeachers(dictionaries: Dictionaries): List<Teacher> {
return mapNotNull { teacher ->
val item = dictionaries.employees.singleOrNull { it.id == teacher.employeeId }
if (item?.name == null) return@mapNotNull null
Teacher(
name = "${item.name} ${item.surname}",
short = item.code,
subject = dictionaries.subjects.singleOrNull { it.id == teacher.subjectId }?.name ?: teacher.role
)
}
fun List<ApiTeacher>.mapTeachers(dictionaries: Dictionaries) = mapNotNull { teacher ->
val item = dictionaries.employees.singleOrNull { it.id == teacher.employeeId }
if (item?.name == null) return@mapNotNull null
Teacher(
name = "${item.name} ${item.surname}",
short = item.code,
subject = dictionaries.subjects.singleOrNull { it.id == teacher.subjectId }?.name ?: teacher.role
)
}
fun List<ScrapperTeacher>.mapTeachers(): List<Teacher> {
return map {
Teacher(
name = it.name,
short = it.short,
subject = it.subject
)
}
fun List<ScrapperTeacher>.mapTeachers() = map {
Teacher(
name = it.name,
short = it.short,
subject = it.subject
)
}

View file

@ -10,74 +10,68 @@ import io.github.wulkanowy.sdk.mobile.timetable.Lesson as ApiTimetable
import io.github.wulkanowy.sdk.scrapper.timetable.CompletedLesson as ScrapperCompletedLesson
import io.github.wulkanowy.sdk.scrapper.timetable.Timetable as ScrapperTimetable
fun List<ApiTimetable>.mapTimetable(dictionaries: Dictionaries): List<Timetable> {
return map {
val teacher = dictionaries.employees.singleOrNull { employee -> employee.id == it.employeeId }
val teacherOld = dictionaries.employees.singleOrNull { employee -> employee.id == it.employeeOldId }
val time = dictionaries.lessonTimes.single { time -> time.id == it.lessonTimeId }
Timetable(
canceled = it.overriddenName,
changes = it.boldName || (!it.annotationAboutChange.isNullOrBlank() && !it.overriddenName),
date = it.day.toLocalDate(),
start = "${it.dayText} ${time.startText}".toLocalDateTime("yyyy-MM-dd HH:mm"),
end = "${it.dayText} ${time.endText}".toLocalDateTime("yyyy-MM-dd HH:mm"),
group = it.divisionShort.orEmpty(),
info = it.annotationAboutChange?.substringAfter("(")?.substringBefore(")").orEmpty(),
number = it.lessonNumber,
room = it.room.orEmpty(),
roomOld = "",
subject = it.subjectName,
subjectOld = "",
studentPlan = it.studentPlan,
teacher = teacher?.run { "$name $surname" }.orEmpty(),
teacherOld = teacherOld?.run { "$name $surname" }.orEmpty()
)
}.groupBy { Triple(it.date, it.number, it.studentPlan) }.map { (_, lessons) ->
if (lessons.size > 1 && lessons.any { !it.canceled } && lessons.any { it.canceled }) {
val canceled = lessons.first { it.canceled }
listOf(lessons.first { !it.canceled }.copy(
subjectOld = canceled.subject,
teacherOld = canceled.teacher,
roomOld = canceled.room
))
} else lessons
}.flatten()
fun List<ApiTimetable>.mapTimetable(dictionaries: Dictionaries) = map {
val teacher = dictionaries.employees.singleOrNull { employee -> employee.id == it.employeeId }
val teacherOld = dictionaries.employees.singleOrNull { employee -> employee.id == it.employeeOldId }
val time = dictionaries.lessonTimes.single { time -> time.id == it.lessonTimeId }
Timetable(
canceled = it.overriddenName,
changes = it.boldName || (!it.annotationAboutChange.isNullOrBlank() && !it.overriddenName),
date = it.day.toLocalDate(),
start = "${it.dayText} ${time.startText}".toLocalDateTime("yyyy-MM-dd HH:mm"),
end = "${it.dayText} ${time.endText}".toLocalDateTime("yyyy-MM-dd HH:mm"),
group = it.divisionShort.orEmpty(),
info = it.annotationAboutChange?.substringAfter("(")?.substringBefore(")").orEmpty(),
number = it.lessonNumber,
room = it.room.orEmpty(),
roomOld = "",
subject = it.subjectName,
subjectOld = "",
studentPlan = it.studentPlan,
teacher = teacher?.run { "$name $surname" }.orEmpty(),
teacherOld = teacherOld?.run { "$name $surname" }.orEmpty()
)
}.groupBy { Triple(it.date, it.number, it.studentPlan) }.map { (_, lessons) ->
if (lessons.size > 1 && lessons.any { !it.canceled } && lessons.any { it.canceled }) {
val canceled = lessons.first { it.canceled }
listOf(lessons.first { !it.canceled }.copy(
subjectOld = canceled.subject,
teacherOld = canceled.teacher,
roomOld = canceled.room
))
} else lessons
}.flatten()
fun List<ScrapperTimetable>.mapTimetable() = map {
Timetable(
canceled = it.canceled,
changes = it.changes,
date = it.date.toLocalDate(),
end = it.end.toLocalDateTime(),
group = it.group,
info = it.info,
number = it.number,
room = it.room,
roomOld = it.roomOld,
start = it.start.toLocalDateTime(),
subject = it.subject,
subjectOld = it.subjectOld,
studentPlan = true,
teacher = it.teacher,
teacherOld = it.teacherOld
)
}
fun List<ScrapperTimetable>.mapTimetable(): List<Timetable> {
return map {
Timetable(
canceled = it.canceled,
changes = it.changes,
date = it.date.toLocalDate(),
end = it.end.toLocalDateTime(),
group = it.group,
info = it.info,
number = it.number,
room = it.room,
roomOld = it.roomOld,
start = it.start.toLocalDateTime(),
subject = it.subject,
subjectOld = it.subjectOld,
studentPlan = true,
teacher = it.teacher,
teacherOld = it.teacherOld
)
}
}
fun List<ScrapperCompletedLesson>.mapCompletedLessons(): List<CompletedLesson> {
return map {
CompletedLesson(
date = it.date.toLocalDate(),
number = it.number,
subject = it.subject,
topic = it.topic,
teacher = it.teacher,
teacherSymbol = it.teacherSymbol,
substitution = it.substitution,
absence = it.absence,
resources = it.resources
)
}
fun List<ScrapperCompletedLesson>.mapCompletedLessons() = map {
CompletedLesson(
date = it.date.toLocalDate(),
number = it.number,
subject = it.subject,
topic = it.topic,
teacher = it.teacher,
teacherSymbol = it.teacherSymbol,
substitution = it.substitution,
absence = it.absence,
resources = it.resources
)
}