From 1999cd6eafb8a87b8b27d187b0aac36befcc6e39 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Miko=C5=82aj=20Pich?= Date: Sun, 26 Jan 2020 01:26:06 +0100 Subject: [PATCH] Visual enhancement of displaying grades point stats (#665) --- app/build.gradle | 2 +- .../wulkanowy/data/db/migrations/Migration20.kt | 9 +++++++++ .../gradestatistics/GradeStatisticsLocal.kt | 7 ++++--- .../grade/statistics/GradeStatisticsFragment.kt | 11 +++++++++++ .../grade/statistics/GradeStatisticsPresenter.kt | 2 +- .../java/io/github/wulkanowy/utils/NumberExtension.kt | 7 +++++++ 6 files changed, 33 insertions(+), 5 deletions(-) create mode 100644 app/src/main/java/io/github/wulkanowy/utils/NumberExtension.kt diff --git a/app/build.gradle b/app/build.gradle index 819ed4f4c..b6857a0c8 100644 --- a/app/build.gradle +++ b/app/build.gradle @@ -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" diff --git a/app/src/main/java/io/github/wulkanowy/data/db/migrations/Migration20.kt b/app/src/main/java/io/github/wulkanowy/data/db/migrations/Migration20.kt index 4f7cdd03f..2fcfc183d 100644 --- a/app/src/main/java/io/github/wulkanowy/data/db/migrations/Migration20.kt +++ b/app/src/main/java/io/github/wulkanowy/data/db/migrations/Migration20.kt @@ -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") + } } diff --git a/app/src/main/java/io/github/wulkanowy/data/repositories/gradestatistics/GradeStatisticsLocal.kt b/app/src/main/java/io/github/wulkanowy/data/repositories/gradestatistics/GradeStatisticsLocal.kt index d636b91ac..279e2959d 100644 --- a/app/src/main/java/io/github/wulkanowy/data/repositories/gradestatistics/GradeStatisticsLocal.kt +++ b/app/src/main/java/io/github/wulkanowy/data/repositories/gradestatistics/GradeStatisticsLocal.kt @@ -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() 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) } diff --git a/app/src/main/java/io/github/wulkanowy/ui/modules/grade/statistics/GradeStatisticsFragment.kt b/app/src/main/java/io/github/wulkanowy/ui/modules/grade/statistics/GradeStatisticsFragment.kt index a65cab9c9..1c54f387e 100644 --- a/app/src/main/java/io/github/wulkanowy/ui/modules/grade/statistics/GradeStatisticsFragment.kt +++ b/app/src/main/java/io/github/wulkanowy/ui/modules/grade/statistics/GradeStatisticsFragment.kt @@ -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()) diff --git a/app/src/main/java/io/github/wulkanowy/ui/modules/grade/statistics/GradeStatisticsPresenter.kt b/app/src/main/java/io/github/wulkanowy/ui/modules/grade/statistics/GradeStatisticsPresenter.kt index bea70ea42..833782619 100644 --- a/app/src/main/java/io/github/wulkanowy/ui/modules/grade/statistics/GradeStatisticsPresenter.kt +++ b/app/src/main/java/io/github/wulkanowy/ui/modules/grade/statistics/GradeStatisticsPresenter.kt @@ -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 { diff --git a/app/src/main/java/io/github/wulkanowy/utils/NumberExtension.kt b/app/src/main/java/io/github/wulkanowy/utils/NumberExtension.kt new file mode 100644 index 000000000..12350a42a --- /dev/null +++ b/app/src/main/java/io/github/wulkanowy/utils/NumberExtension.kt @@ -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) +}