Skip to content
Snippets Groups Projects
Commit 58e4ab0f authored by Tóth Miklós Tibor's avatar Tóth Miklós Tibor :shrug:
Browse files

Error memes

parent f1ff5401
Branches master
No related tags found
No related merge requests found
Pipeline #31320 passed
......@@ -9,7 +9,7 @@ import pekstuff.trimAsPrinciple
import kotlin.coroutines.resume
import kotlin.coroutines.suspendCoroutine
class GSheet private constructor(sheet: sheets.Spreadsheet, sheetNum: Int = 0): DataSource, NoteDataSource {
class GSheet private constructor(val sheet: sheets.Spreadsheet, sheetNum: Int = 0): DataSource, NoteDataSource {
companion object {
private val filterList = listOf(
"szumma", "színes belépő"
......@@ -18,7 +18,6 @@ class GSheet private constructor(sheet: sheets.Spreadsheet, sheetNum: Int = 0):
suspend fun new(url: String, sheetNum: Int = 0): GSheet {
if (!isSignedIn) throw Error("You must sign in to get gapi.sheets")
val sheet = getSheetFromUrl(url)
window.asDynamic().test = sheet
return GSheet(sheet, sheetNum)
}
......@@ -36,19 +35,19 @@ class GSheet private constructor(sheet: sheets.Spreadsheet, sheetNum: Int = 0):
}
}
private val rows = sheet.sheets!![sheetNum].data!![0].rowData!!
private val rows = sheet.sheets?.get(sheetNum)?.data?.get(0)?.rowData ?: throw SheetException("NullPtrError", this)
private val principleIndexes = rows[0].values!!.mapIndexed { i, data ->
private val principleIndexes = rows[0].values?.mapIndexed { i, data ->
(data.formattedValue?.trimAsPrinciple() ?: "") to i
}.drop(1).filter {
}?.drop(1)?.filter {
filterList.all { filter -> !it.first.lowercase().contains(filter) } &&
it.first.isNotBlank()
}.toMap()
}?.toMap() ?: throw SheetException("NullPtrException principles", this)
override val principles get() = principleIndexes.keys
private val peopleIndexes = rows
.mapIndexed { i, data -> (data.values!![0].formattedValue ?: "") to i }
.mapIndexed { i, data -> (data.values?.get(0)?.formattedValue ?: "") to i }
.drop(1)
.filter { it.first.isNotBlank() }
.toMap()
......@@ -56,14 +55,17 @@ class GSheet private constructor(sheet: sheets.Spreadsheet, sheetNum: Int = 0):
override val people get() = peopleIndexes.keys
override operator fun get(person: String, principle: String): Int {
val pers = peopleIndexes[person]!!
val princ = principleIndexes[principle]!!
return rows[pers].values!![princ].formattedValue!!.toIntOrNull() ?: 0
val pers = peopleIndexes[person] ?: throw Error("person $person")
val princ = principleIndexes[principle] ?: throw Error("principle $principle")
return rows[pers].values?.get(princ)?.formattedValue?.toIntOrNull() ?: 0
}
override fun getNote(person: String, principle: String): String {
val pers = peopleIndexes[person]!!
val princ = principleIndexes[principle]!!
return rows[pers].values!![princ].note ?: ""
val pers = peopleIndexes[person] ?: throw Error("person $person not found")
val princ = principleIndexes[principle] ?: throw Error("principle $principle not found")
return rows[pers].values?.get(princ)?.note ?: ""
}
}
class SheetException(str: String, val sheet: GSheet): Exception(str)
\ No newline at end of file
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment