Visual enhancement of displaying grades point stats (#665)

This commit is contained in:
Mikołaj Pich 2020-01-26 01:26:06 +01:00 committed by Rafał Borcz
parent 1e5269c22c
commit 1999cd6eaf
6 changed files with 33 additions and 5 deletions

View File

@ -122,7 +122,7 @@ configurations.all {
}
dependencies {
implementation "io.github.wulkanowy:sdk:8ad4480"
implementation "io.github.wulkanowy:sdk:cfda961"
implementation "org.jetbrains.kotlin:kotlin-stdlib-jdk8:$kotlin_version"
implementation "androidx.core:core-ktx:1.2.0-rc01"

View File

@ -6,6 +6,11 @@ import androidx.sqlite.db.SupportSQLiteDatabase
class Migration20 : Migration(19, 20) {
override fun migrate(database: SupportSQLiteDatabase) {
migrateTimetable(database)
truncateSubjects(database)
}
private fun migrateTimetable(database: SupportSQLiteDatabase) {
database.execSQL("DROP TABLE Timetable")
database.execSQL("""
CREATE TABLE IF NOT EXISTS `Timetable` (
@ -30,4 +35,8 @@ class Migration20 : Migration(19, 20) {
)
""")
}
private fun truncateSubjects(database: SupportSQLiteDatabase) {
database.execSQL("DELETE FROM Subjects")
}
}

View File

@ -5,6 +5,7 @@ import io.github.wulkanowy.data.db.dao.GradeStatisticsDao
import io.github.wulkanowy.data.db.entities.GradePointsStatistics
import io.github.wulkanowy.data.db.entities.GradeStatistics
import io.github.wulkanowy.data.db.entities.Semester
import io.github.wulkanowy.utils.roundToDecimalPlaces
import io.reactivex.Maybe
import javax.inject.Inject
import javax.inject.Singleton
@ -40,9 +41,9 @@ class GradeStatisticsLocal @Inject constructor(
"Wszystkie" -> gradePointsStatisticsDb.loadAll(semester.semesterId, semester.studentId).flatMap { list ->
if (list.isEmpty()) return@flatMap Maybe.empty<GradePointsStatistics>()
Maybe.just(GradePointsStatistics(semester.studentId, semester.semesterId, subjectName,
list.fold(.0) { acc, e -> acc + e.others },
list.fold(.0) { acc, e -> acc + e.student })
)
(list.fold(.0) { acc, e -> acc + e.others } / list.size).roundToDecimalPlaces(2),
(list.fold(.0) { acc, e -> acc + e.student } / list.size).roundToDecimalPlaces(2)
))
}
else -> gradePointsStatisticsDb.loadSubject(semester.semesterId, semester.studentId, subjectName)
}

View File

@ -108,6 +108,17 @@ class GradeStatisticsFragment : BaseFragment(), GradeStatisticsView, GradeView.G
animateXY(1000, 1000)
legend.textColor = context.getThemeAttrColor(android.R.attr.textColorPrimary)
with(axisLeft) {
axisMinimum = 0f
axisMaximum = 100f
labelCount = 11
}
with(axisRight) {
axisMinimum = 0f
axisMaximum = 100f
labelCount = 11
}
}
subjectsAdapter = ArrayAdapter(requireContext(), android.R.layout.simple_spinner_item, mutableListOf())

View File

@ -95,7 +95,7 @@ class GradeStatisticsPresenter @Inject constructor(
}
fun onTypeChange() {
val type = view?.let { it.currentType } ?: ViewType.POINTS
val type = view?.currentType ?: ViewType.POINTS
Timber.i("Select grade stats semester: $type")
disposable.clear()
view?.run {

View File

@ -0,0 +1,7 @@
package io.github.wulkanowy.utils
import kotlin.math.round
fun Double.roundToDecimalPlaces(places: Int = 2): Double {
return round(this * 10 * places) / (10 * places)
}