sort grades from cache by semester
continuous-integration/drone/push Build is passing Details

This commit is contained in:
Jannik 2020-08-30 01:38:45 +02:00
parent cb1f43ec66
commit f12873fe00
Signed by: Seil0
GPG Key ID: E8459F3723C52C24
6 changed files with 145 additions and 13 deletions

View File

@ -0,0 +1,41 @@
/**
* ProjectLaogai
*
* Copyright 2019-2020 <seil0@mosad.xyz>
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston,
* MA 02110-1301, USA.
*
*/
package org.mosad.seil0.projectlaogai.controller
import org.mosad.seil0.projectlaogai.util.GradeSubject
class GradesController {
/**
* show the difference between 2 grades sets
*/
fun diffGrades(mapA: HashMap<String, ArrayList<GradeSubject>>, mapB: HashMap<String, ArrayList<GradeSubject>>): Int {
// TODO compare
// TODO return diff
return 1
}
}

View File

@ -110,10 +110,10 @@ class QISPOSParser(val context: Context) {
}
// return the sorted map
return gradesMap.toSortedMap(compareBy<String>{
val oText = it.substringAfter(" ")
// if WS, substring before / and add 0.5 to compareBy
if (oText.contains("/")) {
oText.substringBefore("/").toInt() + 0.5
} else {

View File

@ -315,7 +315,7 @@ class CacheController(cont: Context) {
}
coursesList = FileReader(file).use {
GsonBuilder().create().fromJson(BufferedReader(it).readLine(), CoursesList().javaClass).courses
GsonBuilder().create().fromJson(it, CoursesList().javaClass).courses
}
}
@ -333,7 +333,7 @@ class CacheController(cont: Context) {
}
mensaMenu = FileReader(file).use {
GsonBuilder().create().fromJson(BufferedReader(it).readLine(), MensaMenu().javaClass)
GsonBuilder().create().fromJson(it, MensaMenu().javaClass)
}
}
@ -394,14 +394,14 @@ class CacheController(cont: Context) {
FileReader(fileLessons).use {
TimetableController.lessonMap.putAll(
GsonBuilder().create()
.fromJson(BufferedReader(it).readLine(), object : TypeToken<HashMap<String, Lesson>>() {}.type)
.fromJson(it, object : TypeToken<HashMap<String, Lesson>>() {}.type)
)
}
FileReader(fileSubjects).use {
TimetableController.subjectMap.putAll(
GsonBuilder().create()
.fromJson(BufferedReader(it).readLine(), HashMap<String, ArrayList<String>>().javaClass)
.fromJson(it, HashMap<String, ArrayList<String>>().javaClass)
)
}
@ -415,9 +415,9 @@ class CacheController(cont: Context) {
/**
* read the encrypted grades file, don't keep them
* in CacheController for security reasons
* @return the grades as HashMap if the file exists, else a empty HashMap
* @return the grades as SortedMap if the file exists, else a empty SortedMap
*/
fun readGrades(): HashMap<String, ArrayList<GradeSubject>> {
fun readGrades(): SortedMap<String, java.util.ArrayList<GradeSubject>> {
val file = File(context.filesDir, "grades_encrypted")
// if the file does not exit, try creating it
@ -436,16 +436,24 @@ class CacheController(cont: Context) {
EncryptedFile.FileEncryptionScheme.AES256_GCM_HKDF_4KB
).build()
return encryptedFile.openFileInput().bufferedReader().use {
val map: HashMap<String, ArrayList<GradeSubject>> = encryptedFile.openFileInput().bufferedReader().use {
GsonBuilder().create()
.fromJson(
it.readLine(),
object : TypeToken<HashMap<String, ArrayList<GradeSubject>>>() {}.type
)
.fromJson(it, object : TypeToken<HashMap<String, ArrayList<GradeSubject>>>() {}.type)
}
// same sorting as qispos parser
return map.toSortedMap(compareBy<String>{
val oText = it.substringAfter(" ")
if (oText.contains("/")) {
oText.substringBefore("/").toInt() + 0.5
} else {
oText.toDouble()
}
}.thenBy { it })
}
return HashMap()
return sortedMapOf()
}
}

View File

@ -0,0 +1,53 @@
/**
* ProjectLaogai
*
* Copyright 2019-2020 <seil0@mosad.xyz>
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston,
* MA 02110-1301, USA.
*
*/
package org.mosad.seil0.projectlaogai
import com.google.gson.GsonBuilder
import com.google.gson.reflect.TypeToken
import org.junit.Assert
import org.junit.Test
import org.mosad.seil0.projectlaogai.controller.GradesController
import org.mosad.seil0.projectlaogai.util.GradeSubject
import java.io.File
import java.io.FileReader
class GradesControllerTest {
@Test
fun diffGrades_isCorrect() {
val origFile = File(GradesControllerTest::class.java.getResource("/grades_orig.json")?.path!!)
val diffFile = File(GradesControllerTest::class.java.getResource("/grades_diff.json")?.path!!)
val mapA: HashMap<String, ArrayList<GradeSubject>> = FileReader(origFile).use {
GsonBuilder().create().fromJson(it, object : TypeToken<HashMap<String, ArrayList<GradeSubject>>>() {}.type)
}
val mapB: HashMap<String, ArrayList<GradeSubject>> = FileReader(diffFile).use {
GsonBuilder().create().fromJson(it, object : TypeToken<HashMap<String, ArrayList<GradeSubject>>>() {}.type)
}
val ret = GradesController().diffGrades(mapA, mapB)
Assert.assertEquals(1, ret)
}
}

View File

@ -0,0 +1,16 @@
{
"WiSe 17/18":[
{"credits":"4,0","grade":"1,0","id":"AI-1020","name":"Grundlagen der Elektronik","semester":"WiSe 17/18"},
{"credits":"2,0","grade":"2,3","id":"AI-1040","name":"Prozedurale Programmierung","semester":"WiSe 17/18"}
],
"SoSe 18":[
{"credits":"4,0","grade":"1,7","id":"AI-2010","name":"Technische Informatik","semester":"SoSe 18"},
{"credits":"1,0","grade":"bestanden","id":"AI-2015","name":"Praktikum Technische Informatik","semester":"SoSe 18"}
],
"WiSe 18/19":[
{"credits":"2,0","grade":"2,7","id":"AI-3010","name":"Computernetze","semester":"WiSe 18/19"},
{"credits":"3,0","grade":"bestanden","id":"AI-3015","name":"Praktikum Computernetze","semester":"WiSe 18/19"},
{"credits":"2,0","grade":"1,7","id":"AI-3020","name":"Datenbanksysteme 1","semester":"WiSe 18/19"},
{"credits":"3,0","grade":"bestanden","id":"AI-3025","name":"Praktikum Datenbanksysteme","semester":"WiSe 18/19"}
]
}

View File

@ -0,0 +1,14 @@
{
"WiSe 17/18":[
{"credits":"4,0","grade":"1,0","id":"AI-1020","name":"Grundlagen der Elektronik","semester":"WiSe 17/18"},
{"credits":"2,0","grade":"2,3","id":"AI-1040","name":"Prozedurale Programmierung","semester":"WiSe 17/18"}
],
"SoSe 18":[
{"credits":"4,0","grade":"1,7","id":"AI-2010","name":"Technische Informatik","semester":"SoSe 18"},
{"credits":"1,0","grade":"bestanden","id":"AI-2015","name":"Praktikum Technische Informatik","semester":"SoSe 18"}
],
"WiSe 18/19":[
{"credits":"2,0","grade":"2,7","id":"AI-3010","name":"Computernetze","semester":"WiSe 18/19"},
{"credits":"3,0","grade":"bestanden","id":"AI-3015","name":"Praktikum Computernetze","semester":"WiSe 18/19"}
]
}