Add remediation scores for syllables and words (only the data structure for now)

This commit is contained in:
Adrien Ufferte
2025-06-18 17:41:30 +02:00
parent ab8efbcbf3
commit a74217e6aa
3 changed files with 98 additions and 13 deletions
+95 -9
View File
@@ -7,19 +7,18 @@ signal score_changed()
const MIN_SCORE: int = -3
# Defines the maximal score a GP can get, it doesn't go above that point
const MAX_SCORE: int = 0
# Defines the score from which the GP should be presented for remediation
const REMEDIATION_SCORE: int = -2
# Defines the score for each GP
#region GP Scores
# Key is the ID of the GP
# Value is the score of the GP
@export
var gps_scores: Dictionary[int, int] = {}
@export
var last_modified: String = ""
var gp_last_modified: String = ""
# Gets the score of a GP if it is below or equals to the remediation score
func get_gp_score(id: int) -> int:
@@ -27,8 +26,7 @@ func get_gp_score(id: int) -> int:
return gps_scores[id] if gps_scores[id] <= REMEDIATION_SCORE else 0
return 0
# Updates the global scores from a minigame scores
# Updates the gp scores from a minigame scores
func update_gp_scores(minigame_scores: Dictionary) -> void:
if not minigame_scores:
return
@@ -44,11 +42,99 @@ func update_gp_scores(minigame_scores: Dictionary) -> void:
else:
gps_scores[id] = maxi(MIN_SCORE, new_gp_score)
last_modified = Time.get_datetime_string_from_system(true)
gp_last_modified = Time.get_datetime_string_from_system(true)
score_changed.emit()
func set_gp_scores(new_scores: Dictionary[int, int]) -> void:
gps_scores = new_scores
func set_last_modified(new_date: String) -> void:
last_modified = new_date
func set_gp_last_modified(new_date: String) -> void:
gp_last_modified = new_date
#endregion
#region Syllables Scores
# Key is the ID of the syllable
# Value is the score of the syllable
@export
var syllables_scores: Dictionary[int, int] = {}
@export
var syllables_last_modified: String = ""
# Gets the score of a syllable if it is below or equals to the remediation score
func get_syllable_score(id: int) -> int:
if syllables_scores.has(id):
return syllables_scores[id] if syllables_scores[id] <= REMEDIATION_SCORE else 0
return 0
# Updates the syllables scores from a minigame scores
func update_syllables_scores(minigame_scores: Dictionary) -> void:
if not minigame_scores:
return
Logger.trace("UserRemediation: Update Syllable Scores: " + str(minigame_scores))
for id: int in minigame_scores.keys():
var new_syllable_score: int = 0
if syllables_scores.has(id):
new_syllable_score += syllables_scores[id]
new_syllable_score += minigame_scores[id]
if new_syllable_score >= MAX_SCORE:
syllables_scores.erase(id)
else:
syllables_scores[id] = maxi(MIN_SCORE, new_syllable_score)
syllables_last_modified = Time.get_datetime_string_from_system(true)
score_changed.emit()
func set_syllables_scores(new_scores: Dictionary[int, int]) -> void:
syllables_scores = new_scores
func set_syllables_last_modified(new_date: String) -> void:
syllables_last_modified = new_date
#endregion
#region Words Scores
# Key is the ID of the word
# Value is the score of the word
@export
var words_scores: Dictionary[int, int] = {}
@export
var words_last_modified: String = ""
# Gets the score of a word if it is below or equals to the remediation score
func get_word_score(id: int) -> int:
if words_scores.has(id):
return words_scores[id] if words_scores[id] <= REMEDIATION_SCORE else 0
return 0
# Updates the words scores from a minigame scores
func update_words_scores(minigame_scores: Dictionary) -> void:
if not minigame_scores:
return
Logger.trace("UserRemediation: Update Syllable Scores: " + str(minigame_scores))
for id: int in minigame_scores.keys():
var new_word_score: int = 0
if words_scores.has(id):
new_word_score += words_scores[id]
new_word_score += minigame_scores[id]
if new_word_score >= MAX_SCORE:
words_scores.erase(id)
else:
words_scores[id] = maxi(MIN_SCORE, new_word_score)
words_last_modified = Time.get_datetime_string_from_system(true)
score_changed.emit()
func set_words_scores(new_scores: Dictionary[int, int]) -> void:
words_scores = new_scores
func set_words_last_modified(new_date: String) -> void:
words_last_modified = new_date
#endregion
+1 -1
View File
@@ -496,7 +496,7 @@ func set_student_remediation_data(student_code: int, new_scores: Dictionary[int,
var student_remediation: UserRemediation
student_remediation = load(remediation_data_path)
student_remediation.set_gp_scores(new_scores)
student_remediation.set_last_modified(updated_at)
student_remediation.set_gp_last_modified(updated_at)
ResourceSaver.save(student_remediation, remediation_data_path)
func _save_student_remediation() -> void:
@@ -131,8 +131,7 @@ func _determine_students_update(response_body: Dictionary, need_update_user: Upd
# Synchronize student gp remediation
var student_gp_remediation: UserRemediation = UserDataManager.get_student_remediation_data(code_to_check)
if student_gp_remediation != null:
var local_student_gp_remediation_unix_time: int = Time.get_unix_time_from_datetime_string(student_gp_remediation.last_modified)
#server_student_remediation_unix_time
var local_student_gp_remediation_unix_time: int = Time.get_unix_time_from_datetime_string(student_gp_remediation.gp_last_modified)
if local_student_gp_remediation_unix_time == server_student_remediation_unix_time:
Logger.trace("UserDatabaseSynchronizer: Student %d GP remediation data timestamp is the same in local and on server. No synchronization necessary" % code_to_check)
need_update_students[code_to_check] = {"remediation_gp": UpdateNeeded.Nothing}
@@ -225,7 +224,7 @@ func _build_message_to_server(need_update_user: UpdateNeeded, need_update_studen
var tuple_list: Array = []
for key: int in student_remediation.gps_scores.keys():
tuple_list.append([key, student_remediation.gps_scores[key]])
gp_remediation_block = {"score_remediation": tuple_list, "updated_at": student_remediation.last_modified}
gp_remediation_block = {"score_remediation": tuple_list, "updated_at": student_remediation.gp_last_modified}
elif student_entry.remediation_gp == UpdateNeeded.FromServer:
gp_remediation_block = {"need_update": true}
elif student_entry.remediation_gp == UpdateNeeded.DeleteServer: