Merge branch 'hotfix/all-year-average' into develop

This commit is contained in:
Mikołaj Pich 2021-04-18 20:43:29 +02:00
commit 6855296de4
5 changed files with 113 additions and 40 deletions

View File

@ -22,8 +22,8 @@ android {
testApplicationId "io.github.tests.wulkanowy" testApplicationId "io.github.tests.wulkanowy"
minSdkVersion 21 minSdkVersion 21
targetSdkVersion 30 targetSdkVersion 30
versionCode 90 versionCode 91
versionName "1.1.4" versionName "1.1.5"
testInstrumentationRunner "androidx.test.runner.AndroidJUnitRunner" testInstrumentationRunner "androidx.test.runner.AndroidJUnitRunner"
vectorDrawables.useSupportLibrary = true vectorDrawables.useSupportLibrary = true
@ -137,7 +137,7 @@ play {
serviceAccountCredentials = file('key.p12') serviceAccountCredentials = file('key.p12')
defaultToAppBundles = false defaultToAppBundles = false
track = 'production' track = 'production'
updatePriority = 3 updatePriority = 1
} }
huaweiPublish { huaweiPublish {
@ -161,7 +161,7 @@ ext {
} }
dependencies { dependencies {
implementation "io.github.wulkanowy:sdk:877b9135" implementation "io.github.wulkanowy:sdk:07a21c1"
coreLibraryDesugaring 'com.android.tools:desugar_jdk_libs:1.1.5' coreLibraryDesugaring 'com.android.tools:desugar_jdk_libs:1.1.5'

View File

@ -70,7 +70,7 @@ class GradeAverageProvider @Inject constructor(
forceRefresh: Boolean, forceRefresh: Boolean,
averageMode: GradeAverageMode averageMode: GradeAverageMode
): Flow<Resource<List<GradeSubject>>> { ): Flow<Resource<List<GradeSubject>>> {
val gradeAverageForceCalc = preferencesRepository.gradeAverageForceCalc val isGradeAverageForceCalc = preferencesRepository.gradeAverageForceCalc
val selectedSemester = semesters.single { it.semesterId == semesterId } val selectedSemester = semesters.single { it.semesterId == semesterId }
val firstSemester = val firstSemester =
semesters.single { it.diaryId == selectedSemester.diaryId && it.semesterName == 1 } semesters.single { it.diaryId == selectedSemester.diaryId && it.semesterName == 1 }
@ -80,8 +80,7 @@ class GradeAverageProvider @Inject constructor(
if (selectedSemester == firstSemester) return selectedSemesterGradeSubjects if (selectedSemester == firstSemester) return selectedSemesterGradeSubjects
val firstSemesterGradeSubjects = val firstSemesterGradeSubjects = getGradeSubjects(student, firstSemester, forceRefresh)
getGradeSubjects(student, firstSemester, forceRefresh)
return selectedSemesterGradeSubjects.combine(firstSemesterGradeSubjects) { secondSemesterGradeSubject, firstSemesterGradeSubject -> return selectedSemesterGradeSubjects.combine(firstSemesterGradeSubjects) { secondSemesterGradeSubject, firstSemesterGradeSubject ->
if (firstSemesterGradeSubject.status == Status.ERROR) { if (firstSemesterGradeSubject.status == Status.ERROR) {
@ -89,9 +88,9 @@ class GradeAverageProvider @Inject constructor(
} }
val isAnyVulcanAverageInFirstSemester = val isAnyVulcanAverageInFirstSemester =
firstSemesterGradeSubject.data.orEmpty().any { it.average != .0 } firstSemesterGradeSubject.data.orEmpty().any { it.isVulcanAverage }
val isAnyVulcanAverageInSecondSemester = val isAnyVulcanAverageInSecondSemester =
secondSemesterGradeSubject.data.orEmpty().any { it.average != .0 } secondSemesterGradeSubject.data.orEmpty().any { it.isVulcanAverage }
val updatedData = secondSemesterGradeSubject.data?.map { secondSemesterSubject -> val updatedData = secondSemesterGradeSubject.data?.map { secondSemesterSubject ->
val firstSemesterSubject = firstSemesterGradeSubject.data.orEmpty() val firstSemesterSubject = firstSemesterGradeSubject.data.orEmpty()
@ -101,7 +100,7 @@ class GradeAverageProvider @Inject constructor(
calculateAllYearAverage( calculateAllYearAverage(
student = student, student = student,
isAnyVulcanAverage = isAnyVulcanAverageInFirstSemester || isAnyVulcanAverageInSecondSemester, isAnyVulcanAverage = isAnyVulcanAverageInFirstSemester || isAnyVulcanAverageInSecondSemester,
gradeAverageForceCalc = gradeAverageForceCalc, isGradeAverageForceCalc = isGradeAverageForceCalc,
secondSemesterSubject = secondSemesterSubject, secondSemesterSubject = secondSemesterSubject,
firstSemesterSubject = firstSemesterSubject firstSemesterSubject = firstSemesterSubject
) )
@ -109,7 +108,7 @@ class GradeAverageProvider @Inject constructor(
calculateBothSemestersAverage( calculateBothSemestersAverage(
student = student, student = student,
isAnyVulcanAverage = isAnyVulcanAverageInFirstSemester || isAnyVulcanAverageInSecondSemester, isAnyVulcanAverage = isAnyVulcanAverageInFirstSemester || isAnyVulcanAverageInSecondSemester,
gradeAverageForceCalc = gradeAverageForceCalc, isGradeAverageForceCalc = isGradeAverageForceCalc,
secondSemesterSubject = secondSemesterSubject, secondSemesterSubject = secondSemesterSubject,
firstSemesterSubject = firstSemesterSubject firstSemesterSubject = firstSemesterSubject
) )
@ -123,10 +122,10 @@ class GradeAverageProvider @Inject constructor(
private fun calculateAllYearAverage( private fun calculateAllYearAverage(
student: Student, student: Student,
isAnyVulcanAverage: Boolean, isAnyVulcanAverage: Boolean,
gradeAverageForceCalc: Boolean, isGradeAverageForceCalc: Boolean,
secondSemesterSubject: GradeSubject, secondSemesterSubject: GradeSubject,
firstSemesterSubject: GradeSubject? firstSemesterSubject: GradeSubject?
) = if (!isAnyVulcanAverage || gradeAverageForceCalc) { ) = if (!isAnyVulcanAverage || isGradeAverageForceCalc) {
val updatedSecondSemesterGrades = val updatedSecondSemesterGrades =
secondSemesterSubject.grades.updateModifiers(student) secondSemesterSubject.grades.updateModifiers(student)
val updatedFirstSemesterGrades = val updatedFirstSemesterGrades =
@ -140,13 +139,13 @@ class GradeAverageProvider @Inject constructor(
private fun calculateBothSemestersAverage( private fun calculateBothSemestersAverage(
student: Student, student: Student,
isAnyVulcanAverage: Boolean, isAnyVulcanAverage: Boolean,
gradeAverageForceCalc: Boolean, isGradeAverageForceCalc: Boolean,
secondSemesterSubject: GradeSubject, secondSemesterSubject: GradeSubject,
firstSemesterSubject: GradeSubject? firstSemesterSubject: GradeSubject?
): Double { ): Double {
val divider = if (secondSemesterSubject.grades.any { it.weightValue > .0 }) 2 else 1 val divider = if (secondSemesterSubject.grades.any { it.weightValue > .0 }) 2 else 1
return if (!isAnyVulcanAverage || gradeAverageForceCalc) { return if (!isAnyVulcanAverage || isGradeAverageForceCalc) {
val secondSemesterAverage = val secondSemesterAverage =
secondSemesterSubject.grades.updateModifiers(student).calcAverage(isOptionalArithmeticAverage) secondSemesterSubject.grades.updateModifiers(student).calcAverage(isOptionalArithmeticAverage)
val firstSemesterAverage = firstSemesterSubject?.grades?.updateModifiers(student) val firstSemesterAverage = firstSemesterSubject?.grades?.updateModifiers(student)
@ -163,7 +162,7 @@ class GradeAverageProvider @Inject constructor(
semester: Semester, semester: Semester,
forceRefresh: Boolean forceRefresh: Boolean
): Flow<Resource<List<GradeSubject>>> { ): Flow<Resource<List<GradeSubject>>> {
val gradeAverageForceCalc = preferencesRepository.gradeAverageForceCalc val isGradeAverageForceCalc = preferencesRepository.gradeAverageForceCalc
return gradeRepository.getGrades(student, semester, forceRefresh = forceRefresh) return gradeRepository.getGrades(student, semester, forceRefresh = forceRefresh)
.map { res -> .map { res ->
@ -172,20 +171,21 @@ class GradeAverageProvider @Inject constructor(
val allGrades = details.orEmpty().groupBy { it.subject } val allGrades = details.orEmpty().groupBy { it.subject }
val items = summaries?.emulateEmptySummaries( val items = summaries?.emulateEmptySummaries(
student, student = student,
semester, semester = semester,
allGrades.toList(), grades = allGrades.toList(),
isAnyAverage calcAverage = isAnyAverage
)?.map { summary -> )?.map { summary ->
val grades = allGrades[summary.subject].orEmpty() val grades = allGrades[summary.subject].orEmpty()
GradeSubject( GradeSubject(
subject = summary.subject, subject = summary.subject,
average = if (!isAnyAverage || gradeAverageForceCalc) { average = if (!isAnyAverage || isGradeAverageForceCalc) {
grades.updateModifiers(student).calcAverage(isOptionalArithmeticAverage) grades.updateModifiers(student).calcAverage(isOptionalArithmeticAverage)
} else summary.average, } else summary.average,
points = summary.pointsSum, points = summary.pointsSum,
summary = summary, summary = summary,
grades = grades grades = grades,
isVulcanAverage = isAnyAverage
) )
} }

View File

@ -8,5 +8,6 @@ data class GradeSubject(
val average: Double, val average: Double,
val points: String, val points: String,
val summary: GradeSummary, val summary: GradeSummary,
val grades: List<Grade> val grades: List<Grade>,
val isVulcanAverage: Boolean
) )

View File

@ -1,11 +1,5 @@
Wersja 1.1.4 Wersja 1.1.5
Oprócz tego naprawiliśmy: Naprawiliśmy liczenie średniej wszystkich ocen z całego roku
- rzadkie problemy ze stabilnością przy logowaniu i w innych miejscach
- brakujące awatary przy zmianie konta z poziomu widżetu
- wysyłanie wiadomości gdy w aplikacji jest zalogowany jednocześnie uczeń i rodzic
Ta wersja jest ostatnią, która będzie działać na starszych urządzeniach z Androidem 4.
Od tej pory do końca roku bedziemy dla nich udostępniać wyłącznie krytyczne poprawki błędów
Pełna lista zmian: https://github.com/wulkanowy/wulkanowy/releases Pełna lista zmian: https://github.com/wulkanowy/wulkanowy/releases

View File

@ -495,15 +495,71 @@ class GradeAverageProviderTest {
) )
} }
val items = runBlocking { gradeAverageProvider.getGradesDetailsWithAverage(student, semesters[2].semesterId, true).getResult() } val items = runBlocking {
gradeAverageProvider.getGradesDetailsWithAverage(
student,
semesters[2].semesterId,
true
).getResult()
}
assertEquals(2, items.size) assertEquals(2, items.size)
assertEquals(3.0, items.single { it.subject == "Matematyka" }.average, .0) // (from details): 3,5 + 2,5 → 3,0 assertEquals(
assertEquals(3.25, items.single { it.subject == "Fizyka" }.average, .0) // (from details): 3,5 + 3,0 → 3,25 3.0,
items.single { it.subject == "Matematyka" }.average,
.0
) // (from details): 3,5 + 2,5 → 3,0
assertEquals(
3.25,
items.single { it.subject == "Fizyka" }.average,
.0
) // (from details): 3,5 + 3,0 → 3,25
} }
@Test @Test
fun `calc full year average when current is second with load from cache sequence`() { fun `calc all year average`() {
every { preferencesRepository.gradeAverageMode } returns GradeAverageMode.ALL_YEAR
every { preferencesRepository.gradeAverageForceCalc } returns false
coEvery {
gradeRepository.getGrades(
student,
semesters[1],
true
)
} returns flowWithResource {
firstGrades to listOf(
getSummary(22, "Matematyka", .0),
getSummary(22, "Fizyka", .0)
)
}
coEvery {
gradeRepository.getGrades(
student,
semesters[2],
true
)
} returns flowWithResource {
secondGrades to listOf(
getSummary(22, "Matematyka", .0),
getSummary(22, "Fizyka", .0)
)
}
val items = runBlocking {
gradeAverageProvider.getGradesDetailsWithAverage(
student,
semesters[2].semesterId,
true
).getResult()
}
assertEquals(2, items.size)
assertEquals(3.0, items.single { it.subject == "Matematyka" }.average, .0)
assertEquals(3.25, items.single { it.subject == "Fizyka" }.average, .0)
}
@Test
fun `force calc full year average when current is second with load from cache sequence`() {
every { preferencesRepository.gradeAverageForceCalc } returns true every { preferencesRepository.gradeAverageForceCalc } returns true
every { preferencesRepository.isOptionalArithmeticAverage } returns false every { preferencesRepository.isOptionalArithmeticAverage } returns false
every { preferencesRepository.gradeAverageMode } returns GradeAverageMode.ALL_YEAR every { preferencesRepository.gradeAverageMode } returns GradeAverageMode.ALL_YEAR
@ -546,18 +602,40 @@ class GradeAverageProviderTest {
} }
@Test @Test
fun `calc both semesters average when no summaries`() { fun `force calc both semesters average when no summaries`() {
every { preferencesRepository.gradeAverageForceCalc } returns true every { preferencesRepository.gradeAverageForceCalc } returns true
every { preferencesRepository.isOptionalArithmeticAverage } returns false every { preferencesRepository.isOptionalArithmeticAverage } returns false
every { preferencesRepository.gradeAverageMode } returns GradeAverageMode.BOTH_SEMESTERS every { preferencesRepository.gradeAverageMode } returns GradeAverageMode.BOTH_SEMESTERS
coEvery { gradeRepository.getGrades(student, semesters[1], true) } returns flowWithResource { firstGrades to emptyList() } coEvery {
coEvery { gradeRepository.getGrades(student, semesters[2], true) } returns flowWithResource { secondGrades to emptyList() } gradeRepository.getGrades(
student,
semesters[1],
true
)
} returns flowWithResource { firstGrades to emptyList() }
coEvery {
gradeRepository.getGrades(
student,
semesters[2],
true
)
} returns flowWithResource { secondGrades to emptyList() }
val items = runBlocking { gradeAverageProvider.getGradesDetailsWithAverage(student, semesters[2].semesterId, true).getResult() } val items = runBlocking {
gradeAverageProvider.getGradesDetailsWithAverage(
student,
semesters[2].semesterId,
true
).getResult()
}
assertEquals(2, items.size) assertEquals(2, items.size)
assertEquals(3.0, items.single { it.subject == "Matematyka" }.average, .0) // (from details): 3,5 + 2,5 → 3,0 assertEquals(
3.0,
items.single { it.subject == "Matematyka" }.average,
.0
) // (from details): 3,5 + 2,5 → 3,0
assertEquals(3.25, items.single { it.subject == "Fizyka" }.average, .0) // (from details): 3,5 + 3,0 → 3,25 assertEquals(3.25, items.single { it.subject == "Fizyka" }.average, .0) // (from details): 3,5 + 3,0 → 3,25
} }