mirror of
https://github.com/szkolny-eu/szkolny-android.git
synced 2025-01-18 21:06:44 -06:00
[API/Librus] Implement behaviour grades with types. Use optional "Phrase" in text grades.
This commit is contained in:
parent
d00963b53d
commit
0b186a754a
@ -27,6 +27,17 @@ class LibrusApiBehaviourGrades(override val data: DataLibrus,
|
|||||||
|
|
||||||
private val nameFormat by lazy { DecimalFormat("#.##") }
|
private val nameFormat by lazy { DecimalFormat("#.##") }
|
||||||
|
|
||||||
|
private val types by lazy {
|
||||||
|
mapOf(
|
||||||
|
1 to ("wz" to "wzorowe"),
|
||||||
|
2 to ("bdb" to "bardzo dobre"),
|
||||||
|
3 to ("db" to "dobre"),
|
||||||
|
4 to ("popr" to "poprawne"),
|
||||||
|
5 to ("ndp" to "nieodpowiednie"),
|
||||||
|
6 to ("ng" to "naganne")
|
||||||
|
)
|
||||||
|
}
|
||||||
|
|
||||||
init { data.profile?.also { profile ->
|
init { data.profile?.also { profile ->
|
||||||
apiGet(TAG, "BehaviourGrades/Points") { json ->
|
apiGet(TAG, "BehaviourGrades/Points") { json ->
|
||||||
|
|
||||||
@ -95,8 +106,12 @@ class LibrusApiBehaviourGrades(override val data: DataLibrus,
|
|||||||
val addedDate = grade.getString("AddDate")?.let { Date.fromIso(it) }
|
val addedDate = grade.getString("AddDate")?.let { Date.fromIso(it) }
|
||||||
?: System.currentTimeMillis()
|
?: System.currentTimeMillis()
|
||||||
|
|
||||||
|
val text = grade.getString("Text")
|
||||||
|
val type = grade.getJsonObject("BehaviourGrade")?.getInt("Id")?.let { types[it] }
|
||||||
|
|
||||||
val name = when {
|
val name = when {
|
||||||
value != null -> (if (value >= 0) "+" else "") + nameFormat.format(value)
|
type != null -> type.first
|
||||||
|
value != null -> (if (value > 0) "+" else "") + nameFormat.format(value)
|
||||||
shortName != null -> shortName
|
shortName != null -> shortName
|
||||||
else -> return@forEach
|
else -> return@forEach
|
||||||
}
|
}
|
||||||
@ -115,14 +130,14 @@ class LibrusApiBehaviourGrades(override val data: DataLibrus,
|
|||||||
|
|
||||||
val categoryName = category?.text ?: ""
|
val categoryName = category?.text ?: ""
|
||||||
|
|
||||||
val description = grade.getJsonArray("Comments")?.asJsonObjectList()?.let { comments ->
|
val comments = grade.getJsonArray("Comments")
|
||||||
if (comments.isNotEmpty()) {
|
?.asJsonObjectList()
|
||||||
data.gradeCategories.singleOrNull {
|
?.mapNotNull { comment ->
|
||||||
it.type == GradeCategory.TYPE_BEHAVIOUR_COMMENT
|
val cId = comment.getLong("Id") ?: return@mapNotNull null
|
||||||
&& it.categoryId == comments[0].asJsonObject.getLong("Id")
|
data.gradeCategories[cId]?.text
|
||||||
}?.text
|
} ?: listOf()
|
||||||
} else null
|
|
||||||
} ?: ""
|
val description = listOfNotNull(type?.second) + comments
|
||||||
|
|
||||||
val valueFrom = value ?: category?.valueFrom ?: 0f
|
val valueFrom = value ?: category?.valueFrom ?: 0f
|
||||||
val valueTo = category?.valueTo ?: 0f
|
val valueTo = category?.valueTo ?: 0f
|
||||||
@ -136,8 +151,8 @@ class LibrusApiBehaviourGrades(override val data: DataLibrus,
|
|||||||
weight = -1f,
|
weight = -1f,
|
||||||
color = color,
|
color = color,
|
||||||
category = categoryName,
|
category = categoryName,
|
||||||
description = description,
|
description = text ?: description.join(" - "),
|
||||||
comment = null,
|
comment = if (text != null) description.join(" - ") else null,
|
||||||
semester = semester,
|
semester = semester,
|
||||||
teacherId = teacherId,
|
teacherId = teacherId,
|
||||||
subjectId = 1
|
subjectId = 1
|
||||||
|
@ -57,7 +57,7 @@ class LibrusApiTextGrades(override val data: DataLibrus,
|
|||||||
color = category?.color ?: -1,
|
color = category?.color ?: -1,
|
||||||
category = category?.text ?: "",
|
category = category?.text ?: "",
|
||||||
description = description,
|
description = description,
|
||||||
comment = null,
|
comment = grade.getString("Phrase") /* whatever it is */,
|
||||||
semester = semester,
|
semester = semester,
|
||||||
teacherId = teacherId,
|
teacherId = teacherId,
|
||||||
subjectId = subjectId
|
subjectId = subjectId
|
||||||
|
Loading…
x
Reference in New Issue
Block a user