mirror of
https://github.com/szkolny-eu/szkolny-android.git
synced 2024-11-24 19:04:38 -06:00
[API/Podlasie] Add getting grades proposals.
This commit is contained in:
parent
b13257cb78
commit
4389dc9d79
@ -0,0 +1,121 @@
|
||||
/*
|
||||
* Copyright (c) Kacper Ziubryniewicz 2020-5-13
|
||||
*/
|
||||
|
||||
package pl.szczodrzynski.edziennik.data.api.edziennik.podlasie.data.api
|
||||
|
||||
import com.google.gson.JsonObject
|
||||
import pl.szczodrzynski.edziennik.data.api.edziennik.podlasie.DataPodlasie
|
||||
import pl.szczodrzynski.edziennik.data.api.models.DataRemoveModel
|
||||
import pl.szczodrzynski.edziennik.data.db.entity.Grade
|
||||
import pl.szczodrzynski.edziennik.data.db.entity.Grade.Companion.TYPE_SEMESTER1_FINAL
|
||||
import pl.szczodrzynski.edziennik.data.db.entity.Grade.Companion.TYPE_SEMESTER1_PROPOSED
|
||||
import pl.szczodrzynski.edziennik.data.db.entity.Grade.Companion.TYPE_SEMESTER2_FINAL
|
||||
import pl.szczodrzynski.edziennik.data.db.entity.Grade.Companion.TYPE_SEMESTER2_PROPOSED
|
||||
import pl.szczodrzynski.edziennik.data.db.entity.Grade.Companion.TYPE_YEAR_FINAL
|
||||
import pl.szczodrzynski.edziennik.data.db.entity.Grade.Companion.TYPE_YEAR_PROPOSED
|
||||
import pl.szczodrzynski.edziennik.data.db.entity.Metadata
|
||||
import pl.szczodrzynski.edziennik.getLong
|
||||
import pl.szczodrzynski.edziennik.getString
|
||||
|
||||
class PodlasieApiFinalGrades(val data: DataPodlasie, val rows: List<JsonObject>) {
|
||||
init { data.profile?.also { profile ->
|
||||
rows.forEach { grade ->
|
||||
val id = grade.getLong("ExternalId") ?: return@forEach
|
||||
val mark = grade.getString("Mark") ?: return@forEach
|
||||
val proposedMark = grade.getString("ProposedMark") ?: "0"
|
||||
val name = data.app.gradesManager.getGradeNumberName(mark)
|
||||
val value = data.app.gradesManager.getGradeValue(name)
|
||||
val semester = grade.getString("TermShortcut")?.length ?: return@forEach
|
||||
|
||||
val typeName = grade.getString("Type") ?: return@forEach
|
||||
val type = when (typeName) {
|
||||
"S" -> if (semester == 1) TYPE_SEMESTER1_FINAL else TYPE_SEMESTER2_FINAL
|
||||
"Y", "R" -> TYPE_YEAR_FINAL
|
||||
else -> return@forEach
|
||||
}
|
||||
|
||||
val subjectName = grade.getString("SchoolSubject") ?: return@forEach
|
||||
val subject = data.getSubject(subjectName)
|
||||
|
||||
val addedDate = if (profile.empty) profile.getSemesterStart(semester).inMillis
|
||||
else System.currentTimeMillis()
|
||||
|
||||
val gradeObject = Grade(
|
||||
profileId = data.profileId,
|
||||
id = id,
|
||||
name = name,
|
||||
type = type,
|
||||
value = value,
|
||||
weight = 0f,
|
||||
color = -1,
|
||||
category = null,
|
||||
description = null,
|
||||
comment = null,
|
||||
semester = semester,
|
||||
teacherId = -1,
|
||||
subjectId = subject.id,
|
||||
addedDate = addedDate
|
||||
)
|
||||
|
||||
data.gradeList.add(gradeObject)
|
||||
data.metadataList.add(
|
||||
Metadata(
|
||||
data.profileId,
|
||||
Metadata.TYPE_GRADE,
|
||||
id,
|
||||
profile.empty,
|
||||
profile.empty
|
||||
))
|
||||
|
||||
if (proposedMark != "0") {
|
||||
val proposedName = data.app.gradesManager.getGradeNumberName(proposedMark)
|
||||
val proposedValue = data.app.gradesManager.getGradeValue(proposedName)
|
||||
|
||||
val proposedType = when (typeName) {
|
||||
"S" -> if (semester == 1) TYPE_SEMESTER1_PROPOSED else TYPE_SEMESTER2_PROPOSED
|
||||
"Y", "R" -> TYPE_YEAR_PROPOSED
|
||||
else -> return@forEach
|
||||
}
|
||||
|
||||
val proposedGradeObject = Grade(
|
||||
profileId = data.profileId,
|
||||
id = id * (-1),
|
||||
name = proposedName,
|
||||
type = proposedType,
|
||||
value = proposedValue,
|
||||
weight = 0f,
|
||||
color = -1,
|
||||
category = null,
|
||||
description = null,
|
||||
comment = null,
|
||||
semester = semester,
|
||||
teacherId = -1,
|
||||
subjectId = subject.id,
|
||||
addedDate = addedDate
|
||||
)
|
||||
|
||||
data.gradeList.add(proposedGradeObject)
|
||||
data.metadataList.add(
|
||||
Metadata(
|
||||
data.profileId,
|
||||
Metadata.TYPE_GRADE,
|
||||
proposedGradeObject.id,
|
||||
profile.empty,
|
||||
profile.empty
|
||||
))
|
||||
}
|
||||
}
|
||||
|
||||
data.toRemove.addAll(listOf(
|
||||
TYPE_SEMESTER1_FINAL,
|
||||
TYPE_SEMESTER1_PROPOSED,
|
||||
TYPE_SEMESTER2_FINAL,
|
||||
TYPE_SEMESTER2_PROPOSED,
|
||||
TYPE_YEAR_FINAL,
|
||||
TYPE_YEAR_PROPOSED
|
||||
).map {
|
||||
DataRemoveModel.Grades.allWithType(it)
|
||||
})
|
||||
}}
|
||||
}
|
@ -25,6 +25,7 @@ class PodlasieApiMain(override val data: DataPodlasie,
|
||||
|
||||
json.getJsonArray("Timetable")?.asJsonObjectList()?.let { PodlasieApiTimetable(data, it) }
|
||||
json.getJsonArray("Marks")?.asJsonObjectList()?.let { PodlasieApiGrades(data, it) }
|
||||
json.getJsonArray("MarkFinal")?.asJsonObjectList()?.let { PodlasieApiFinalGrades(data, it) }
|
||||
|
||||
data.setSyncNext(ENDPOINT_PODLASIE_API_MAIN, SYNC_ALWAYS)
|
||||
onSuccess(ENDPOINT_PODLASIE_API_MAIN)
|
||||
|
@ -208,6 +208,30 @@ class GradesManager(val app: App) : CoroutineScope {
|
||||
}
|
||||
}
|
||||
|
||||
fun getGradeNumberName(name: String): String {
|
||||
return when(name.toLowerCase()){
|
||||
"niedostateczny", "f" -> "1"
|
||||
"niedostateczny plus", "f+" -> "1+"
|
||||
"niedostateczny minus", "f-" -> "1-"
|
||||
"dopuszczający", "e" -> "2"
|
||||
"dopuszczający plus", "e+" -> "2+"
|
||||
"dopuszczający minus", "e-" -> "2-"
|
||||
"dostateczny", "d" -> "3"
|
||||
"dostateczny plus", "d+" -> "3+"
|
||||
"dostateczny minus", "d-" -> "3-"
|
||||
"dobry", "c" -> "4"
|
||||
"dobry plus", "c+" -> "4+"
|
||||
"dobry minus", "c-" -> "4-"
|
||||
"bardzo dobry", "b" -> "5"
|
||||
"bardzo dobry plus", "b+" -> "5+"
|
||||
"bardzo dobry minus", "b-" -> "5-"
|
||||
"celujący", "a" -> "6"
|
||||
"celujący plus", "a+" -> "6+"
|
||||
"celujący minus", "a-" -> "6-"
|
||||
else -> name
|
||||
}
|
||||
}
|
||||
|
||||
/* _ _ _____ _____ _ __ _
|
||||
| | | |_ _| / ____| (_)/ _(_)
|
||||
| | | | | | | (___ _ __ ___ ___ _| |_ _ ___
|
||||
|
Loading…
Reference in New Issue
Block a user