mirror of
https://github.com/wulkanowy/wulkanowy.git
synced 2025-01-19 02:56:45 -06:00
Fix calculating average with optional arithmetic average on and no grade with average in second semester (#2448)
This commit is contained in:
parent
ccba31f2e8
commit
f2d26453ed
@ -159,7 +159,7 @@ class GradeAverageProvider @Inject constructor(
|
|||||||
?.updateModifiers(student, config).orEmpty()
|
?.updateModifiers(student, config).orEmpty()
|
||||||
|
|
||||||
(updatedSecondSemesterGrades + updatedFirstSemesterGrades).calcAverage(
|
(updatedSecondSemesterGrades + updatedFirstSemesterGrades).calcAverage(
|
||||||
config.isOptionalArithmeticAverage
|
isOptionalArithmeticAverage = config.isOptionalArithmeticAverage,
|
||||||
)
|
)
|
||||||
} else {
|
} else {
|
||||||
secondSemesterSubject.average
|
secondSemesterSubject.average
|
||||||
@ -173,13 +173,21 @@ class GradeAverageProvider @Inject constructor(
|
|||||||
config: AverageCalcParams,
|
config: AverageCalcParams,
|
||||||
): Double {
|
): Double {
|
||||||
return if (!isAnyVulcanAverage || config.forceAverageCalc) {
|
return if (!isAnyVulcanAverage || config.forceAverageCalc) {
|
||||||
val divider = if (secondSemesterSubject.grades.any { it.weightValue > .0 }) 2 else 1
|
val isSecondSemesterHasWeightGrade = secondSemesterSubject.grades
|
||||||
|
.any { it.weightValue > .0 }
|
||||||
|
val isSecondSemesterHasArithmeticGrade = secondSemesterSubject.grades
|
||||||
|
.all { it.weightValue == .0 } && config.isOptionalArithmeticAverage
|
||||||
|
val isSecondSemesterHaveAverage =
|
||||||
|
isSecondSemesterHasWeightGrade || isSecondSemesterHasArithmeticGrade
|
||||||
|
|
||||||
|
val divider = if (isSecondSemesterHaveAverage) 2 else 1
|
||||||
val secondSemesterAverage = secondSemesterSubject.grades
|
val secondSemesterAverage = secondSemesterSubject.grades
|
||||||
.updateModifiers(student, config)
|
.updateModifiers(student, config)
|
||||||
.calcAverage(config.isOptionalArithmeticAverage)
|
.calcAverage(isOptionalArithmeticAverage = config.isOptionalArithmeticAverage)
|
||||||
val firstSemesterAverage = firstSemesterSubject?.grades
|
val firstSemesterAverage = firstSemesterSubject?.grades
|
||||||
?.updateModifiers(student, config)
|
?.updateModifiers(student, config)
|
||||||
?.calcAverage(config.isOptionalArithmeticAverage) ?: secondSemesterAverage
|
?.calcAverage(isOptionalArithmeticAverage = config.isOptionalArithmeticAverage)
|
||||||
|
?: secondSemesterAverage
|
||||||
|
|
||||||
(secondSemesterAverage + firstSemesterAverage) / divider
|
(secondSemesterAverage + firstSemesterAverage) / divider
|
||||||
} else {
|
} else {
|
||||||
@ -225,7 +233,7 @@ class GradeAverageProvider @Inject constructor(
|
|||||||
subject = summary.subject,
|
subject = summary.subject,
|
||||||
average = if (!isAnyAverage || params.forceAverageCalc) {
|
average = if (!isAnyAverage || params.forceAverageCalc) {
|
||||||
grades.updateModifiers(student, params)
|
grades.updateModifiers(student, params)
|
||||||
.calcAverage(params.isOptionalArithmeticAverage)
|
.calcAverage(isOptionalArithmeticAverage = params.isOptionalArithmeticAverage)
|
||||||
} else summary.average,
|
} else summary.average,
|
||||||
points = summary.pointsSum,
|
points = summary.pointsSum,
|
||||||
summary = summary,
|
summary = summary,
|
||||||
@ -286,8 +294,13 @@ class GradeAverageProvider @Inject constructor(
|
|||||||
proposedPoints = "",
|
proposedPoints = "",
|
||||||
finalPoints = "",
|
finalPoints = "",
|
||||||
pointsSum = "",
|
pointsSum = "",
|
||||||
average = if (calcAverage) details.updateModifiers(student, params)
|
average = when {
|
||||||
.calcAverage(params.isOptionalArithmeticAverage) else .0
|
calcAverage -> details
|
||||||
|
.updateModifiers(student, params)
|
||||||
|
.calcAverage(isOptionalArithmeticAverage = params.isOptionalArithmeticAverage)
|
||||||
|
|
||||||
|
else -> .0
|
||||||
|
}
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -25,6 +25,7 @@ import kotlinx.coroutines.flow.flow
|
|||||||
import kotlinx.coroutines.flow.flowOf
|
import kotlinx.coroutines.flow.flowOf
|
||||||
import kotlinx.coroutines.flow.toList
|
import kotlinx.coroutines.flow.toList
|
||||||
import kotlinx.coroutines.runBlocking
|
import kotlinx.coroutines.runBlocking
|
||||||
|
import kotlinx.coroutines.test.runTest
|
||||||
import org.junit.Assert.assertEquals
|
import org.junit.Assert.assertEquals
|
||||||
import org.junit.Before
|
import org.junit.Before
|
||||||
import org.junit.Test
|
import org.junit.Test
|
||||||
@ -112,8 +113,8 @@ class GradeAverageProviderTest {
|
|||||||
|
|
||||||
private val secondGradeWithModifier = listOf(
|
private val secondGradeWithModifier = listOf(
|
||||||
// avg: 3.375
|
// avg: 3.375
|
||||||
getGrade(24, "Język polski", 3.0, -0.50),
|
getGrade(24, "Język polski", 3.0, -0.50, entry = "3-"),
|
||||||
getGrade(24, "Język polski", 4.0, 0.25)
|
getGrade(24, "Język polski", 4.0, 0.25, entry = "4+")
|
||||||
)
|
)
|
||||||
|
|
||||||
private val secondSummariesWithModifier = listOf(
|
private val secondSummariesWithModifier = listOf(
|
||||||
@ -122,8 +123,8 @@ class GradeAverageProviderTest {
|
|||||||
|
|
||||||
private val noWeightGrades = listOf(
|
private val noWeightGrades = listOf(
|
||||||
// standard: 0.0, arithmetic: 4.0
|
// standard: 0.0, arithmetic: 4.0
|
||||||
getGrade(22, "Matematyka", 5.0, 0.0, 0.0),
|
getGrade(22, "Matematyka", 5.0, 0.0, 0.0, "5"),
|
||||||
getGrade(22, "Matematyka", 3.0, 0.0, 0.0),
|
getGrade(22, "Matematyka", 3.0, 0.0, 0.0, "3"),
|
||||||
getGrade(22, "Matematyka", 1.0, 0.0, 0.0, "np.")
|
getGrade(22, "Matematyka", 1.0, 0.0, 0.0, "np.")
|
||||||
)
|
)
|
||||||
|
|
||||||
@ -132,7 +133,7 @@ class GradeAverageProviderTest {
|
|||||||
)
|
)
|
||||||
|
|
||||||
private val noWeightGradesArithmeticSummary = listOf(
|
private val noWeightGradesArithmeticSummary = listOf(
|
||||||
getSummary(23, "Matematyka", 4.0)
|
getSummary(23, "Matematyka", .0)
|
||||||
)
|
)
|
||||||
|
|
||||||
@Before
|
@Before
|
||||||
@ -211,6 +212,51 @@ class GradeAverageProviderTest {
|
|||||||
) // from summary: 4,0
|
) // from summary: 4,0
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
fun `calc current semester arithmetic average with no weights in second semester`() = runTest {
|
||||||
|
every { preferencesRepository.gradeAverageForceCalcFlow } returns flowOf(false)
|
||||||
|
every { preferencesRepository.isOptionalArithmeticAverageFlow } returns flowOf(true)
|
||||||
|
every { preferencesRepository.gradeAverageModeFlow } returns flowOf(GradeAverageMode.BOTH_SEMESTERS)
|
||||||
|
coEvery {
|
||||||
|
gradeRepository.getGrades(
|
||||||
|
student = student,
|
||||||
|
semester = semesters[1],
|
||||||
|
forceRefresh = true,
|
||||||
|
)
|
||||||
|
} returns resourceFlow {
|
||||||
|
Triple(
|
||||||
|
first = noWeightGrades,
|
||||||
|
second = noWeightGradesArithmeticSummary,
|
||||||
|
third = emptyList(),
|
||||||
|
)
|
||||||
|
}
|
||||||
|
coEvery {
|
||||||
|
gradeRepository.getGrades(
|
||||||
|
student = student,
|
||||||
|
semester = semesters[2],
|
||||||
|
forceRefresh = true,
|
||||||
|
)
|
||||||
|
} returns resourceFlow {
|
||||||
|
Triple(
|
||||||
|
first = noWeightGrades,
|
||||||
|
second = noWeightGradesArithmeticSummary,
|
||||||
|
third = emptyList(),
|
||||||
|
)
|
||||||
|
}
|
||||||
|
|
||||||
|
val items = gradeAverageProvider.getGradesDetailsWithAverage(
|
||||||
|
student = student,
|
||||||
|
semesterId = semesters[2].semesterId,
|
||||||
|
forceRefresh = true
|
||||||
|
).getResult()
|
||||||
|
|
||||||
|
assertEquals(
|
||||||
|
4.0,
|
||||||
|
items.single { it.subject == "Matematyka" }.average,
|
||||||
|
.0
|
||||||
|
) // from summary: 4,0
|
||||||
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
fun `calc current semester average with load from cache sequence`() {
|
fun `calc current semester average with load from cache sequence`() {
|
||||||
every { preferencesRepository.gradeAverageForceCalcFlow } returns flowOf(true)
|
every { preferencesRepository.gradeAverageForceCalcFlow } returns flowOf(true)
|
||||||
|
Loading…
x
Reference in New Issue
Block a user