mirror of
https://github.com/wulkanowy/wulkanowy.git
synced 2025-01-18 21:36:49 -06:00
Fix calc vulcan average in second semester (#1779)
This commit is contained in:
parent
18568c86be
commit
edd1c9442e
@ -10,9 +10,7 @@ import io.github.wulkanowy.data.repositories.GradeRepository
|
||||
import io.github.wulkanowy.data.repositories.PreferencesRepository
|
||||
import io.github.wulkanowy.data.repositories.SemesterRepository
|
||||
import io.github.wulkanowy.sdk.Sdk
|
||||
import io.github.wulkanowy.ui.modules.grade.GradeAverageMode.ALL_YEAR
|
||||
import io.github.wulkanowy.ui.modules.grade.GradeAverageMode.BOTH_SEMESTERS
|
||||
import io.github.wulkanowy.ui.modules.grade.GradeAverageMode.ONE_SEMESTER
|
||||
import io.github.wulkanowy.ui.modules.grade.GradeAverageMode.*
|
||||
import io.github.wulkanowy.utils.calcAverage
|
||||
import io.github.wulkanowy.utils.changeModifier
|
||||
import io.github.wulkanowy.utils.flowWithResourceIn
|
||||
@ -144,20 +142,20 @@ class GradeAverageProvider @Inject constructor(
|
||||
isGradeAverageForceCalc: Boolean,
|
||||
secondSemesterSubject: GradeSubject,
|
||||
firstSemesterSubject: GradeSubject?
|
||||
): Double {
|
||||
): Double = if (!isAnyVulcanAverage || isGradeAverageForceCalc) {
|
||||
val divider = if (secondSemesterSubject.grades.any { it.weightValue > .0 }) 2 else 1
|
||||
|
||||
return if (!isAnyVulcanAverage || isGradeAverageForceCalc) {
|
||||
val secondSemesterAverage =
|
||||
secondSemesterSubject.grades.updateModifiers(student)
|
||||
val secondSemesterAverage = secondSemesterSubject.grades.updateModifiers(student)
|
||||
.calcAverage(isOptionalArithmeticAverage)
|
||||
val firstSemesterAverage = firstSemesterSubject?.grades?.updateModifiers(student)
|
||||
?.calcAverage(isOptionalArithmeticAverage) ?: secondSemesterAverage
|
||||
|
||||
(secondSemesterAverage + firstSemesterAverage) / divider
|
||||
} else {
|
||||
(secondSemesterSubject.average + (firstSemesterSubject?.average ?: secondSemesterSubject.average)) / divider
|
||||
}
|
||||
val divider = if (secondSemesterSubject.average > 0) 2 else 1
|
||||
|
||||
(secondSemesterSubject.average + (firstSemesterSubject?.average
|
||||
?: secondSemesterSubject.average)) / divider
|
||||
}
|
||||
|
||||
private fun getGradeSubjects(
|
||||
|
@ -859,12 +859,51 @@ class GradeAverageProviderTest {
|
||||
) to listOf(getSummary(semesterId = 23, subject = "Fizyka", average = .0))
|
||||
}
|
||||
|
||||
val items = runBlocking { gradeAverageProvider.getGradesDetailsWithAverage(student, semesters[2].semesterId, true).getResult() }
|
||||
|
||||
assertEquals(5.5555, items.single { it.subject == "Fizyka" }.average, .0001) // (from details): 5.72727272 + 4,8 → .average()
|
||||
val items = runBlocking {
|
||||
gradeAverageProvider.getGradesDetailsWithAverage(
|
||||
student,
|
||||
semesters[2].semesterId,
|
||||
true
|
||||
).getResult()
|
||||
}
|
||||
|
||||
private fun getGrade(semesterId: Int, subject: String, value: Double, modifier: Double = 0.0, weight: Double = 1.0, entry: String = ""): Grade {
|
||||
assertEquals(
|
||||
5.5555,
|
||||
items.single { it.subject == "Fizyka" }.average,
|
||||
.0001
|
||||
) // (from details): 5.72727272 + 4,8 → .average()
|
||||
}
|
||||
|
||||
@Test
|
||||
fun `calc both semesters average when both summary have same average from vulcan and second semester has no grades`() {
|
||||
every { preferencesRepository.gradeAverageForceCalc } returns false
|
||||
every { preferencesRepository.gradeAverageMode } returns GradeAverageMode.BOTH_SEMESTERS
|
||||
every { preferencesRepository.isOptionalArithmeticAverage } returns false
|
||||
|
||||
coEvery { gradeRepository.getGrades(student, semesters[1], true) } returns
|
||||
flowWithResource { firstGrades to firstSummaries }
|
||||
coEvery { gradeRepository.getGrades(student, semesters[2], true) } returns
|
||||
flowWithResource { listOf<Grade>() to firstSummaries }
|
||||
|
||||
val items = runBlocking {
|
||||
gradeAverageProvider.getGradesDetailsWithAverage(
|
||||
student,
|
||||
semesters[2].semesterId,
|
||||
true
|
||||
).getResult()
|
||||
}
|
||||
|
||||
assertEquals(3.1, items.single { it.subject == "Fizyka" }.average, .0001)
|
||||
}
|
||||
|
||||
private fun getGrade(
|
||||
semesterId: Int,
|
||||
subject: String,
|
||||
value: Double,
|
||||
modifier: Double = 0.0,
|
||||
weight: Double = 1.0,
|
||||
entry: String = ""
|
||||
): Grade {
|
||||
return Grade(
|
||||
studentId = 101,
|
||||
semesterId = semesterId,
|
||||
|
Loading…
x
Reference in New Issue
Block a user