forked from github/wulkanowy-mirror
Add option to change plus and minus modifier separately (#192)
This commit is contained in:
parent
92baecbd0d
commit
900065d758
@ -24,8 +24,11 @@ class PreferencesRepository @Inject constructor(
|
||||
val currentTheme: Int
|
||||
get() = sharedPref.getString(currentThemeKey, "1")?.toInt() ?: 1
|
||||
|
||||
val gradeModifier: Double
|
||||
get() = sharedPref.getString(context.getString(R.string.pref_key_grade_modifier), "0.0")?.toDouble() ?: 0.0
|
||||
val gradePlusModifier: Double
|
||||
get() = sharedPref.getString(context.getString(R.string.pref_key_grade_modifier_plus), "0.0")?.toDouble() ?: 0.0
|
||||
|
||||
val gradeMinusModifier: Double
|
||||
get() = sharedPref.getString(context.getString(R.string.pref_key_grade_modifier_minus), "0.0")?.toDouble() ?: 0.0
|
||||
|
||||
val serviceEnablesKey: String = context.getString(R.string.pref_key_services_enable)
|
||||
val isServiceEnabled: Boolean
|
||||
|
@ -34,7 +34,7 @@ class GradeDetailsPresenter @Inject constructor(
|
||||
disposable.add(studentRepository.getCurrentStudent()
|
||||
.flatMap { semesterRepository.getSemesters(it) }
|
||||
.flatMap { gradeRepository.getGrades(it.first { item -> item.semesterId == semesterId }, forceRefresh) }
|
||||
.map { it.map { item -> item.changeModifier(preferencesRepository.gradeModifier) } }
|
||||
.map { it.map { item -> item.changeModifier(preferencesRepository.gradePlusModifier, preferencesRepository.gradeMinusModifier) } }
|
||||
.map { createGradeItems(it.groupBy { grade -> grade.subject }.toSortedMap()) }
|
||||
.subscribeOn(schedulers.backgroundThread)
|
||||
.observeOn(schedulers.mainThread)
|
||||
|
@ -40,7 +40,7 @@ class GradeSummaryPresenter @Inject constructor(
|
||||
.flatMap { gradesSummary ->
|
||||
gradeRepository.getGrades(it, forceRefresh)
|
||||
.map { grades ->
|
||||
grades.map { item -> item.changeModifier(preferencesRepository.gradeModifier) }
|
||||
grades.map { item -> item.changeModifier(preferencesRepository.gradePlusModifier, preferencesRepository.gradeMinusModifier) }
|
||||
.groupBy { grade -> grade.subject }
|
||||
.mapValues { entry -> entry.value.calcAverage() }
|
||||
.filterValues { value -> value != 0.0 }
|
||||
|
@ -47,9 +47,14 @@ inline val Grade.colorStringId: Int
|
||||
}
|
||||
}
|
||||
|
||||
fun Grade.changeModifier(newModifier: Double): Grade {
|
||||
if (modifier != 0.0 && newModifier != 0.0) {
|
||||
modifier = if (modifier > 0) newModifier else -newModifier
|
||||
fun Grade.changeModifier(plusModifier: Double, minusModifier: Double): Grade {
|
||||
if (modifier != 0.0) {
|
||||
if (plusModifier != 0.0 && modifier > 0) {
|
||||
modifier = plusModifier
|
||||
}
|
||||
if (minusModifier != .0 && modifier < 0) {
|
||||
modifier = -minusModifier
|
||||
}
|
||||
}
|
||||
return this
|
||||
}
|
@ -217,7 +217,8 @@
|
||||
<string name="pref_view_summary">Pokazuj podsumowanie w ocenach</string>
|
||||
<string name="pref_view_present">Pokazuj obecność we frekwencji</string>
|
||||
<string name="pref_view_theme_dark">Ciemny motyw (Beta)</string>
|
||||
<string name="pref_view_grade_modifier">Wartość plusa i minusa</string>
|
||||
<string name="pref_view_grade_modifier_plus">Wartość plusa</string>
|
||||
<string name="pref_view_grade_modifier_minus">Wartość minusa</string>
|
||||
<string name="pref_view_expand_grade">Rozwiń oceny</string>
|
||||
|
||||
<string name="pref_notify_header">Powiadomienia</string>
|
||||
|
@ -3,7 +3,8 @@
|
||||
<string name="pref_key_start_menu">start_menu</string>
|
||||
<string name="pref_key_attendance_present">attendance_present</string>
|
||||
<string name="pref_key_theme">theme</string>
|
||||
<string name="pref_key_grade_modifier">grade_modifier</string>
|
||||
<string name="pref_key_grade_modifier_plus">grade_modifier_plus</string>
|
||||
<string name="pref_key_grade_modifier_minus">grade_modifier_minus</string>
|
||||
<string name="pref_key_expand_grade">expand_grade</string>
|
||||
<string name="pref_key_services_enable">services_enable</string>
|
||||
<string name="pref_key_services_interval">services_interval</string>
|
||||
|
@ -199,7 +199,8 @@
|
||||
<string name="pref_view_summary">Show the summary in the grades</string>
|
||||
<string name="pref_view_present">Show presence in attendance</string>
|
||||
<string name="pref_view_theme_dark">Dark theme (Beta)</string>
|
||||
<string name="pref_view_grade_modifier">Value of the plus and minus</string>
|
||||
<string name="pref_view_grade_modifier_plus">Value of the plus</string>
|
||||
<string name="pref_view_grade_modifier_minus">Value of the minus</string>
|
||||
<string name="pref_view_expand_grade">Expand grades</string>
|
||||
|
||||
<string name="pref_notify_header">Notifications</string>
|
||||
|
@ -34,9 +34,17 @@
|
||||
android:defaultValue="0.0"
|
||||
android:entries="@array/grade_modifier_entries"
|
||||
android:entryValues="@array/grade_modifier_value"
|
||||
android:key="@string/pref_key_grade_modifier"
|
||||
android:key="@string/pref_key_grade_modifier_plus"
|
||||
android:summary="%s"
|
||||
android:title="@string/pref_view_grade_modifier"
|
||||
android:title="@string/pref_view_grade_modifier_plus"
|
||||
app:iconSpaceReserved="false" />
|
||||
<ListPreference
|
||||
android:defaultValue="0.0"
|
||||
android:entries="@array/grade_modifier_entries"
|
||||
android:entryValues="@array/grade_modifier_value"
|
||||
android:key="@string/pref_key_grade_modifier_minus"
|
||||
android:summary="%s"
|
||||
android:title="@string/pref_view_grade_modifier_minus"
|
||||
app:iconSpaceReserved="false" />
|
||||
</PreferenceCategory>
|
||||
<PreferenceCategory
|
||||
|
@ -3,31 +3,30 @@ package io.github.wulkanowy.utils
|
||||
import io.github.wulkanowy.data.db.entities.Grade
|
||||
import io.github.wulkanowy.data.db.entities.GradeSummary
|
||||
import org.junit.Assert.assertEquals
|
||||
import org.junit.Before
|
||||
import org.junit.Test
|
||||
import org.mockito.Mockito.mock
|
||||
import org.mockito.Mock
|
||||
import org.mockito.MockitoAnnotations
|
||||
import org.threeten.bp.LocalDate
|
||||
|
||||
class GradeExtensionTest {
|
||||
|
||||
@Mock
|
||||
lateinit var date: LocalDate
|
||||
|
||||
@Before
|
||||
fun before() {
|
||||
MockitoAnnotations.initMocks(this)
|
||||
}
|
||||
|
||||
@Test
|
||||
fun calcWeightedAverage() {
|
||||
val localDate = mock(LocalDate::class.java)
|
||||
assertEquals(3.47, listOf(
|
||||
Grade(1, 1, "", "", 5, 0.33
|
||||
, "", "", "", "", "",
|
||||
6, localDate, ""),
|
||||
Grade(1, 1, "", "", 5, -0.33
|
||||
, "", "", "", "", "",
|
||||
5, localDate, ""),
|
||||
Grade(1, 1, "", "", 4, 0.0
|
||||
, "", "", "", "", "",
|
||||
1, localDate, ""),
|
||||
Grade(1, 1, "", "", 1, 0.5
|
||||
, "", "", "", "", "",
|
||||
9, localDate, ""),
|
||||
Grade(1, 1, "", "", 0, 0.0
|
||||
, "", "", "", "", "",
|
||||
0, localDate, "")
|
||||
createGrade(5, 6, 0.33),
|
||||
createGrade(5, 5, -0.33),
|
||||
createGrade(4, 1, 0.0),
|
||||
createGrade(1, 9, 0.5),
|
||||
createGrade(0, 0, 0.0)
|
||||
).calcAverage(), 0.005)
|
||||
}
|
||||
|
||||
@ -42,16 +41,39 @@ class GradeExtensionTest {
|
||||
}
|
||||
|
||||
@Test
|
||||
fun changeModifierTest() {
|
||||
val localDate = mock(LocalDate::class.java)
|
||||
assertEquals(0.33, Grade(1, 1, "", "", 5, 0.25
|
||||
, "", "", "", "", "",
|
||||
6, localDate, "").changeModifier(0.33).modifier, 0.0)
|
||||
assertEquals(-0.33, Grade(1, 1, "", "", 5, -0.25
|
||||
, "", "", "", "", "",
|
||||
6, localDate, "").changeModifier(0.33).modifier, 0.0)
|
||||
assertEquals(0.25, Grade(1, 1, "", "", 5, 0.25
|
||||
, "", "", "", "", "",
|
||||
6, localDate, "").changeModifier(0.0).modifier, 0.0)
|
||||
fun changeModifier_default() {
|
||||
assertEquals(.33, createGrade(5, 0, .33).changeModifier(.0, .0).modifier, .0)
|
||||
assertEquals(-.33, createGrade(5, 0, -.33).changeModifier(.0, .0).modifier, .0)
|
||||
}
|
||||
|
||||
@Test
|
||||
fun changeModifier_plus() {
|
||||
assertEquals(.33, createGrade(5, 0, .25).changeModifier(.33, .50).modifier, .0)
|
||||
assertEquals(.25, createGrade(5, 0, .33).changeModifier(.25, .0).modifier, .0)
|
||||
}
|
||||
|
||||
@Test
|
||||
fun changeModifier_minus() {
|
||||
assertEquals(-.33, createGrade(5, 0, -.25).changeModifier(.25, .33).modifier, .0)
|
||||
assertEquals(-.25, createGrade(5, 0, -.33).changeModifier(.0, .25).modifier, .0)
|
||||
}
|
||||
|
||||
private fun createGrade(value: Int, weightValue: Int = 0, modifier: Double = 0.25): Grade {
|
||||
return Grade(
|
||||
semesterId = 1,
|
||||
studentId = 1,
|
||||
subject = "",
|
||||
entry = "",
|
||||
value = value,
|
||||
modifier = modifier,
|
||||
comment = "",
|
||||
color = "",
|
||||
gradeSymbol = "",
|
||||
description = "",
|
||||
weight = "",
|
||||
weightValue = weightValue,
|
||||
date = date,
|
||||
teacher = ""
|
||||
)
|
||||
}
|
||||
}
|
||||
|
Loading…
x
Reference in New Issue
Block a user