Use SQL queries to remove doubles

This commit is contained in:
BimDav
2023-03-15 14:49:52 +01:00
parent 59fc8671d0
commit 216623bf8f
2 changed files with 12 additions and 16 deletions
+2 -2
View File
@@ -57,8 +57,8 @@ func _setup_minigame() -> void:
# Find the stimuli and distractions of the minigame.
func _find_stimuli_and_distractions() -> void:
stimuli = Database.copy_without_double_graphemes(Database.get_GP_for_lesson(lesson_nb))
distractions = Database.copy_without_double_graphemes(Database.get_GP_before_lesson(lesson_nb))
stimuli = Database.get_GP_for_lesson(lesson_nb, true)
distractions = Database.get_GP_before_lesson(lesson_nb, true)
# Launch the minigame
+10 -14
View File
@@ -24,13 +24,19 @@ func _exit_tree() -> void:
db.close_db()
func get_GP_for_lesson(lesson_nb: int) -> Array:
db.query_with_bindings("Select Grapheme, Phoneme, LessonNb FROM GPs INNER JOIN Lessons ON Lessons.GPID = GPs.ID AND Lessons.LessonNb == ?", [lesson_nb])
func get_GP_for_lesson(lesson_nb: int, distinct: bool) -> Array:
var query: = "Select Grapheme, Phoneme, LessonNb FROM GPs INNER JOIN Lessons ON Lessons.GPID = GPs.ID AND Lessons.LessonNb == ?"
if distinct:
query += "GROUP BY Grapheme"
db.query_with_bindings(query, [lesson_nb])
return db.query_result
func get_GP_before_lesson(lesson_nb: int) -> Array:
db.query_with_bindings("Select Grapheme, Phoneme, LessonNb FROM GPs INNER JOIN Lessons ON Lessons.GPID = GPs.ID AND Lessons.LessonNb < ?", [lesson_nb])
func get_GP_before_lesson(lesson_nb: int, distinct: bool) -> Array:
var query: = "Select Grapheme, Phoneme, LessonNb FROM GPs INNER JOIN Lessons ON Lessons.GPID = GPs.ID AND Lessons.LessonNb < ?"
if distinct:
query += "GROUP BY Grapheme"
db.query_with_bindings(query, [lesson_nb])
return db.query_result
@@ -54,16 +60,6 @@ func get_distractors_for_grapheme(grapheme: String, lesson_nb: int) -> Array:
return db.query_result
func copy_without_double_graphemes(input: Array) -> Array:
var output: = []
var graphemes: = {}
for val in input:
if not graphemes.has(val.Grapheme):
output.append(val)
graphemes[val.Grapheme] = true
return output
func get_audio_stream_for_word(word: String) -> AudioStream:
var GPs: = get_GP_from_word(word)
var file_name: = _phoneme_to_string(GPs[0].Phoneme)