Datos: queries de estadisticas y diario

getIDAnimeFromIDF, getAnimeFrasesStats (vistas/total por anime),
getSeenStatsSelected (vistas/total de los animes seleccionados) y
getSeenFrases (vistas en orden cronologico, filtrable por anime).
This commit is contained in:
kprkpr committed 2026-10-21 09:52:17 +00:00
1 parent b36bbd46f2
commit 13aac8f959
2 files changed
+45

No files matched your search

@@ -263,6 +263,51 @@ class SQLiteHelper(ctx: Context) : SQLiteOpenHelper(ctx, "app.sqlite", null, 1)
return intList(appDb, "SELECT IDFrase FROM FRASESFAV").toTypedArray() return intList(appDb, "SELECT IDFrase FROM FRASESFAV").toTypedArray()
} }
/* ---------------- Estadísticas y Diario (rediseño 2026-10) ---------------- */
/** IDAnime del catálogo al que pertenece [IDFrase] (-1 si la frase no es válida) */
fun getIDAnimeFromIDF(IDFrase: Int): Int {
if (IDFrase <= 0) return -1
val c = catalog().rawQuery("SELECT IDAnime FROM FRASES WHERE IDFrase = '$IDFrase'", null)
val ret = if (c.moveToFirst()) c.getInt(0) else -1
c.close()
return ret
}
/** (vistas, total) de las frases de un anime: vistas = frases de ese anime que
* ya salieron en algún día; total = frases existentes del anime en el catálogo */
fun getAnimeFrasesStats(idAnime: Int): Pair<Int, Int> {
val total = intList(catalog(), "SELECT IDFrase FROM FRASES WHERE IDAnime = '$idAnime'")
val seen = if (total.isEmpty()) 0
else appDb.rawQuery("SELECT COUNT(*) FROM FRASESVI WHERE IDFrase IN (${total.joinToString(",")})", null).use {
it.moveToFirst(); it.getInt(0)
}
return Pair(seen, total.size)
}
/** (vistas, total) entre los animes seleccionados: vistas = frases ya vistas de
* los animes seleccionados; total = frases existentes de esos animes */
fun getSeenStatsSelected(): Pair<Int, Int> {
val animesOn = intList(appDb, "SELECT IDAnime FROM ANIMESON")
if (animesOn.isEmpty()) return Pair(0, 0)
val inAnimes = animesOn.joinToString(",")
val ids = intList(catalog(), "SELECT IDFrase FROM FRASES WHERE IDAnime IN ($inAnimes)")
val seen = if (ids.isEmpty()) 0
else appDb.rawQuery("SELECT COUNT(*) FROM FRASESVI WHERE IDFrase IN (${ids.joinToString(",")})", null).use {
it.moveToFirst(); it.getInt(0)
}
return Pair(seen, ids.size)
}
/** Frases ya vistas (IDFrase) en orden cronológico por día visto.
* @param idAnime: si no es null, sólo las de ese anime (Diario filtrado) */
fun getSeenFrases(idAnime: Int? = null): List<Int> {
val seen = intList(appDb, "SELECT IDFrase FROM FRASESVI WHERE IDFrase > 0 ORDER BY TDay ASC")
if (idAnime == null) return seen
val ofAnime = intList(catalog(), "SELECT IDFrase FROM FRASES WHERE IDAnime = '$idAnime'").toHashSet()
return seen.filter { ofAnime.contains(it) }
}
fun getAllAnimeIDs(): Array<Int>{ fun getAllAnimeIDs(): Array<Int>{
return intList(catalog(), "SELECT IDAnime FROM ANIMES ORDER BY Name ASC").toTypedArray() return intList(catalog(), "SELECT IDAnime FROM ANIMES ORDER BY Name ASC").toTypedArray()
} }
Binary file not shown.

Before

Width:  |  Height:  |  Size: 215 KiB