Fuse all functions to retrieve GPs inside the database class

This commit is contained in:
Dylan Sarrazyn
2024-03-19 15:03:43 +01:00
committed by BimDav
parent 5f05e3bcd1
commit 95146c7696
6 changed files with 26 additions and 45 deletions
+1 -1
View File
@@ -42,7 +42,7 @@ func _ready() -> void:
func setup() -> void:
gp_list = Database.get_GP_for_lesson(lesson_nb, true)
gp_list = Database.get_GP_for_lesson(lesson_nb, true, true)
grapheme_label.text = ""
for gp in gp_list:
@@ -29,8 +29,8 @@ func _find_stimuli_and_distractions() -> void:
var current_lesson_stimuli = []
var previous_lesson_stimuli = []
var all_GPs = Database.get_GP_before_and_for_lesson(lesson_nb, false, true, true)
var all_syllables = Database.get_syllables_for_lesson(lesson_nb, false)
var all_GPs: = Database.get_GP_for_lesson(lesson_nb, false, false, true, true)
var all_syllables: = Database.get_syllables_for_lesson(lesson_nb, false)
# Find the GPs for current lesson
for gp in all_GPs:
@@ -85,9 +85,6 @@ func _find_stimuli_and_distractions() -> void:
else:
stimuli.append_array(previous_lesson_stimuli)
print("--------------- WITH PREVIOUS LESSON STIMULI :")
print(stimuli)
# If there are not enough stimuli, fill the rest with current lesson
while stimuli.size() < max_progression:
stimuli.append(current_lesson_stimuli.pick_random())
@@ -95,7 +92,7 @@ func _find_stimuli_and_distractions() -> void:
# Shuffle the stimuli
stimuli.shuffle()
print("--------------- COMPLETE SHUFFLED STIMULI :")
print("--------------- ALL STIMULI :")
print(stimuli)
# For each stimuli get the distractors
@@ -109,7 +106,7 @@ func _find_stimuli_and_distractions() -> void:
# Difficulty 1
# Any previously learned item w/ all letters different
for gp in all_GPs:
if gp.Grapheme != stimulus.Grapheme and gp.Phoneme != stimulus.Phoneme and (not gp.OtherPhoneme or not gp.OtherPhoneme.has(stimulus.Phoneme)):
if gp.Grapheme != stimulus.Grapheme and gp.Phoneme != stimulus.Phoneme and (not gp.OtherPhonemes or not gp.OtherPhonemes.has(stimulus.Phoneme)):
stimulus_distractors.append(gp)
if GPs:
for syllable in all_syllables:
+1 -1
View File
@@ -22,7 +22,7 @@ scale = Vector2(2, 2)
sprite_frames = ExtResource("2_k0dcm")
animation = &"idle_front_blink"
autoplay = "idle_front"
frame_progress = 0.68306
frame_progress = 0.71793
offset = Vector2(2.08165e-12, -82)
[node name="Label" type="Label" parent="."]
@@ -94,7 +94,7 @@ func _setup_minigame() -> void:
# Find the stimuli and distractions of the minigame.
func _find_stimuli_and_distractions() -> void:
stimuli = Database.get_GP_before_and_for_lesson(lesson_nb, true)
stimuli = Database.get_GP_for_lesson(lesson_nb, true)
func _start() -> void:
@@ -2,9 +2,9 @@
[ext_resource type="PackedScene" uid="uid://8awe4usnucyv" path="res://sources/minigames/base/base_minigame.tscn" id="1_oeg4r"]
[ext_resource type="Script" path="res://sources/minigames/parakeets/parakeets_minigame.gd" id="2_x6xn5"]
[ext_resource type="AudioStream" uid="uid://csbrl2rxli4tp" path="res://language_resources/fr/minigames/parakeets/audio/kalulu/kalulu_intro_parakeets_language.mp3" id="3_ofxb4"]
[ext_resource type="AudioStream" uid="uid://csbrl2rxli4tp" path="res://language_resources/pt/minigames/parakeets/audio/kalulu/kalulu_intro_parakeets_language.mp3" id="3_ofxb4"]
[ext_resource type="Texture2D" uid="uid://dv1ombj8eolb1" path="res://assets/minigames/parakeets/graphic/background.png" id="3_xjvte"]
[ext_resource type="AudioStream" uid="uid://c58a2q8b26vpn" path="res://language_resources/fr/minigames/parakeets/audio/kalulu/kalulu_end_parakeets_language.mp3" id="4_01e28"]
[ext_resource type="AudioStream" uid="uid://c58a2q8b26vpn" path="res://language_resources/pt/minigames/parakeets/audio/kalulu/kalulu_end_parakeets_language.mp3" id="4_01e28"]
[ext_resource type="AudioStream" uid="uid://comucfkvgwnsv" path="res://language_resources/fr/minigames/parakeets/audio/kalulu/kalulu_help_parakeets_language.mp3" id="4_nosoh"]
[ext_resource type="Texture2D" uid="uid://clvh07xfgjmri" path="res://assets/minigames/parakeets/graphic/tree_trunk.png" id="4_unuga"]
[ext_resource type="Texture2D" uid="uid://d3n327me83on7" path="res://assets/minigames/parakeets/graphic/tree_branch.png" id="5_46kss"]
@@ -15,9 +15,9 @@
[node name="Parakeets" instance=ExtResource("1_oeg4r")]
script = ExtResource("2_x6xn5")
difficulty = 4
lesson_nb = 4
fly_duration = 3.0
lesson_nb = 4
difficulty = 4
max_number_of_lives = 5
intro_kalulu_speech = ExtResource("3_ofxb4")
help_kalulu_speech = ExtResource("4_nosoh")
+15 -31
View File
@@ -40,6 +40,10 @@ var additional_word_list: Dictionary
@onready var db: = SQLite.new()
func _exit_tree() -> void:
db.close_db()
func _init_db() -> void:
# load_additional_word_list()
# db_path = db_path
@@ -71,45 +75,23 @@ func load_additional_word_list() -> void:
file.close()
func _exit_tree() -> void:
db.close_db()
func get_GP_for_lesson(lesson_nb: int, distinct: bool) -> Array:
var query: = "Select Grapheme, Phoneme, Type, LessonNb FROM GPs
INNER JOIN GPsInLessons ON GPsInLessons.GPID = GPs.ID
INNER JOIN Lessons ON Lessons.ID = GPsInLessons.LessonID 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, distinct: bool) -> Array:
var query: = "Select Grapheme, Phoneme, Type, LessonNb FROM GPs
INNER JOIN GPsInLessons ON GPsInLessons.GPID = GPs.ID
INNER JOIN Lessons ON Lessons.ID = GPsInLessons.LessonID AND Lessons.LessonNb < ?"
if distinct:
query += "GROUP BY Grapheme"
db.query_with_bindings(query, [lesson_nb])
return db.query_result
func get_GP_before_and_for_lesson(lesson_nb: int, distinct: bool, only_vowels: bool = false, with_other_phonemes: bool = false) -> Array:
func get_GP_for_lesson(lesson_nb: int, distinct: bool, only_new: bool = false, only_vowels: bool = false, with_other_phonemes: bool = false) -> Array:
var parameters := []
var symbol: = "<=" if not only_new else "=="
var query: = "SELECT Grapheme, Phoneme, "
if with_other_phonemes:
query += "(SELECT group_concat(Phoneme) FROM GPs g2
INNER JOIN GPsInLessons ON GPsInLessons.GPID = g2.ID
INNER JOIN Lessons ON Lessons.ID = GPsInLessons.LessonID AND Lessons.LessonNb <= ?
INNER JOIN Lessons ON Lessons.ID = GPsInLessons.LessonID AND Lessons.LessonNb " + symbol + " ?
WHERE g.Grapheme = g2.Grapheme AND g.Phoneme != g2.Phoneme)
AS OtherPhoneme, "
AS OtherPhonemes, "
parameters.append(lesson_nb)
query += "Type, LessonNb FROM GPs g
INNER JOIN GPsInLessons ON GPsInLessons.GPID = g.ID
INNER JOIN Lessons ON Lessons.ID = GPsInLessons.LessonID AND Lessons.LessonNb <= ?"
INNER JOIN Lessons ON Lessons.ID = GPsInLessons.LessonID AND Lessons.LessonNb " + symbol + " ?"
parameters.append(lesson_nb)
if only_vowels:
@@ -118,14 +100,16 @@ func get_GP_before_and_for_lesson(lesson_nb: int, distinct: bool, only_vowels: b
if distinct:
query += " GROUP BY Grapheme"
query += " ORDER BY LessonNb ASC"
db.query_with_bindings(query, parameters)
var result = db.query_result
if with_other_phonemes:
for GP in result:
if GP.OtherPhoneme:
GP.OtherPhoneme = GP.OtherPhoneme.split(",")
if GP.OtherPhonemes:
GP.OtherPhonemes = GP.OtherPhonemes.split(",")
return result
@@ -173,6 +157,7 @@ GROUP BY sID"
syllable.GPs = syllable.GPs.split(".")
return result
func get_words_for_lesson(lesson_nb: int, only_new: = false) -> Array:
var query: = "SELECT * FROM Words
INNER JOIN
@@ -438,7 +423,7 @@ func _import_syllables() -> void:
GPID = GP_id,
Position = i,
})
func _import_words() -> void:
var file = FileAccess.open("res://data3/words_list.json", FileAccess.READ)
@@ -496,7 +481,6 @@ func _remove_unusable_words() -> void:
if not db.query_result.is_empty():
var word_id = db.query_result[0]["ID"]
db.delete_rows("Words", "ID=%s" % word_id)
func _import_words_csv() -> void: