forked from github/wulkanowy-mirror
Add checking vulcan average from both semesters (#1140)
This commit is contained in:
parent
dd085a14fa
commit
5e3b89636f
@ -86,7 +86,11 @@ class GradeAverageProvider @Inject constructor(
|
|||||||
return@combine firstSemesterGradeSubject
|
return@combine firstSemesterGradeSubject
|
||||||
}
|
}
|
||||||
|
|
||||||
val isAnyAverage = secondSemesterGradeSubject.data.orEmpty().any { it.average != .0 }
|
val isAnyVulcanAverageInFirstSemester =
|
||||||
|
firstSemesterGradeSubject.data.orEmpty().any { it.average != .0 }
|
||||||
|
val isAnyVulcanAverageInSecondSemester =
|
||||||
|
secondSemesterGradeSubject.data.orEmpty().any { it.average != .0 }
|
||||||
|
|
||||||
val updatedData = secondSemesterGradeSubject.data?.map { secondSemesterSubject ->
|
val updatedData = secondSemesterGradeSubject.data?.map { secondSemesterSubject ->
|
||||||
val firstSemesterSubject = firstSemesterGradeSubject.data.orEmpty()
|
val firstSemesterSubject = firstSemesterGradeSubject.data.orEmpty()
|
||||||
.singleOrNull { it.subject == secondSemesterSubject.subject }
|
.singleOrNull { it.subject == secondSemesterSubject.subject }
|
||||||
@ -94,7 +98,7 @@ class GradeAverageProvider @Inject constructor(
|
|||||||
val updatedAverage = if (averageMode == ALL_YEAR) {
|
val updatedAverage = if (averageMode == ALL_YEAR) {
|
||||||
calculateAllYearAverage(
|
calculateAllYearAverage(
|
||||||
student = student,
|
student = student,
|
||||||
isAnyAverage = isAnyAverage,
|
isAnyVulcanAverage = isAnyVulcanAverageInFirstSemester || isAnyVulcanAverageInSecondSemester,
|
||||||
gradeAverageForceCalc = gradeAverageForceCalc,
|
gradeAverageForceCalc = gradeAverageForceCalc,
|
||||||
secondSemesterSubject = secondSemesterSubject,
|
secondSemesterSubject = secondSemesterSubject,
|
||||||
firstSemesterSubject = firstSemesterSubject
|
firstSemesterSubject = firstSemesterSubject
|
||||||
@ -102,7 +106,7 @@ class GradeAverageProvider @Inject constructor(
|
|||||||
} else {
|
} else {
|
||||||
calculateBothSemestersAverage(
|
calculateBothSemestersAverage(
|
||||||
student = student,
|
student = student,
|
||||||
isAnyAverage = isAnyAverage,
|
isAnyVulcanAverage = isAnyVulcanAverageInFirstSemester || isAnyVulcanAverageInSecondSemester,
|
||||||
gradeAverageForceCalc = gradeAverageForceCalc,
|
gradeAverageForceCalc = gradeAverageForceCalc,
|
||||||
secondSemesterSubject = secondSemesterSubject,
|
secondSemesterSubject = secondSemesterSubject,
|
||||||
firstSemesterSubject = firstSemesterSubject
|
firstSemesterSubject = firstSemesterSubject
|
||||||
@ -116,11 +120,11 @@ class GradeAverageProvider @Inject constructor(
|
|||||||
|
|
||||||
private fun calculateAllYearAverage(
|
private fun calculateAllYearAverage(
|
||||||
student: Student,
|
student: Student,
|
||||||
isAnyAverage: Boolean,
|
isAnyVulcanAverage: Boolean,
|
||||||
gradeAverageForceCalc: Boolean,
|
gradeAverageForceCalc: Boolean,
|
||||||
secondSemesterSubject: GradeSubject,
|
secondSemesterSubject: GradeSubject,
|
||||||
firstSemesterSubject: GradeSubject?
|
firstSemesterSubject: GradeSubject?
|
||||||
) = if (!isAnyAverage || gradeAverageForceCalc) {
|
) = if (!isAnyVulcanAverage || gradeAverageForceCalc) {
|
||||||
val updatedSecondSemesterGrades =
|
val updatedSecondSemesterGrades =
|
||||||
secondSemesterSubject.grades.updateModifiers(student)
|
secondSemesterSubject.grades.updateModifiers(student)
|
||||||
val updatedFirstSemesterGrades =
|
val updatedFirstSemesterGrades =
|
||||||
@ -133,20 +137,23 @@ class GradeAverageProvider @Inject constructor(
|
|||||||
|
|
||||||
private fun calculateBothSemestersAverage(
|
private fun calculateBothSemestersAverage(
|
||||||
student: Student,
|
student: Student,
|
||||||
isAnyAverage: Boolean,
|
isAnyVulcanAverage: Boolean,
|
||||||
gradeAverageForceCalc: Boolean,
|
gradeAverageForceCalc: Boolean,
|
||||||
secondSemesterSubject: GradeSubject,
|
secondSemesterSubject: GradeSubject,
|
||||||
firstSemesterSubject: GradeSubject?
|
firstSemesterSubject: GradeSubject?
|
||||||
) = if (!isAnyAverage || gradeAverageForceCalc) {
|
): Double {
|
||||||
val secondSemesterAverage =
|
|
||||||
secondSemesterSubject.grades.updateModifiers(student).calcAverage()
|
|
||||||
val firstSemesterAverage = firstSemesterSubject?.grades?.updateModifiers(student)
|
|
||||||
?.calcAverage() ?: secondSemesterAverage
|
|
||||||
val divider = if (secondSemesterSubject.grades.any { it.weightValue > .0 }) 2 else 1
|
val divider = if (secondSemesterSubject.grades.any { it.weightValue > .0 }) 2 else 1
|
||||||
|
|
||||||
(secondSemesterAverage + firstSemesterAverage) / divider
|
return if (!isAnyVulcanAverage || gradeAverageForceCalc) {
|
||||||
} else {
|
val secondSemesterAverage =
|
||||||
(secondSemesterSubject.average + (firstSemesterSubject?.average ?: secondSemesterSubject.average)) / 2
|
secondSemesterSubject.grades.updateModifiers(student).calcAverage()
|
||||||
|
val firstSemesterAverage = firstSemesterSubject?.grades?.updateModifiers(student)
|
||||||
|
?.calcAverage() ?: secondSemesterAverage
|
||||||
|
|
||||||
|
(secondSemesterAverage + firstSemesterAverage) / divider
|
||||||
|
} else {
|
||||||
|
(secondSemesterSubject.average + (firstSemesterSubject?.average ?: secondSemesterSubject.average)) / divider
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private fun getGradeSubjects(
|
private fun getGradeSubjects(
|
||||||
|
@ -198,6 +198,19 @@ class GradeAverageProviderTest {
|
|||||||
assertEquals(3.5, items.single { it.subject == "Język polski" }.average, .0)
|
assertEquals(3.5, items.single { it.subject == "Język polski" }.average, .0)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
fun `calc both semesters average with no grade in second semester but with average in first semester`() {
|
||||||
|
every { preferencesRepository.gradeAverageForceCalc } returns false
|
||||||
|
every { preferencesRepository.gradeAverageMode } returns GradeAverageMode.BOTH_SEMESTERS
|
||||||
|
|
||||||
|
coEvery { gradeRepository.getGrades(student, semesters[1], false) } returns flowWithResource { secondGradeWithModifier to secondSummariesWithModifier }
|
||||||
|
coEvery { gradeRepository.getGrades(student, semesters[2], false) } returns flowWithResource { emptyList<Grade>() to listOf(getSummary(24, "Język polski", .0))}
|
||||||
|
|
||||||
|
val items = runBlocking { gradeAverageProvider.getGradesDetailsWithAverage(student, semesters[2].semesterId, false).getResult() }
|
||||||
|
|
||||||
|
assertEquals(3.49, items.single { it.subject == "Język polski" }.average, .0)
|
||||||
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
fun `force calc average on no grades`() {
|
fun `force calc average on no grades`() {
|
||||||
every { preferencesRepository.gradeAverageForceCalc } returns true
|
every { preferencesRepository.gradeAverageForceCalc } returns true
|
||||||
|
2
gradle/wrapper/gradle-wrapper.properties
vendored
2
gradle/wrapper/gradle-wrapper.properties
vendored
@ -1,5 +1,5 @@
|
|||||||
distributionBase=GRADLE_USER_HOME
|
distributionBase=GRADLE_USER_HOME
|
||||||
distributionPath=wrapper/dists
|
distributionPath=wrapper/dists
|
||||||
distributionUrl=https\://services.gradle.org/distributions/gradle-6.8.1-all.zip
|
distributionUrl=https\://services.gradle.org/distributions/gradle-6.8.2-all.zip
|
||||||
zipStoreBase=GRADLE_USER_HOME
|
zipStoreBase=GRADLE_USER_HOME
|
||||||
zipStorePath=wrapper/dists
|
zipStorePath=wrapper/dists
|
||||||
|
Loading…
Reference in New Issue
Block a user