Clean code naming convention V4
This commit is contained in:
@@ -104,7 +104,7 @@ func get_exercice_for_lesson(lesson_nb: int) -> Array[int]:
|
||||
return result
|
||||
|
||||
|
||||
func get_GP_for_lesson(lesson_nb: int, distinct: bool, only_new: bool = false, only_vowels: bool = false, with_other_phonemes: bool = false, include_exceptions: bool = false) -> Array:
|
||||
func get_gps_for_lesson(lesson_nb: int, distinct: bool, only_new: bool = false, only_vowels: bool = false, with_other_phonemes: bool = false, include_exceptions: bool = false) -> Array:
|
||||
|
||||
var parameters: Array = []
|
||||
var symbol: String = "<=" if not only_new else "=="
|
||||
@@ -150,7 +150,7 @@ func get_GP_for_lesson(lesson_nb: int, distinct: bool, only_new: bool = false, o
|
||||
return result
|
||||
|
||||
|
||||
func get_GPs_from_syllable(syllable_ID: int) -> Array[Dictionary]:
|
||||
func get_gps_from_syllable(syllable_ID: int) -> Array[Dictionary]:
|
||||
db.query_with_bindings("SELECT GPs.ID, GPs.Grapheme, GPs.Phoneme, GPs.Type FROM Syllables INNER JOIN GPsInSyllables ON Syllables.ID = GPsInSyllables.SyllableID AND Syllables.ID=? INNER JOIN GPs WHERE GPs.ID = GPsInSyllables.GPID ORDER BY Position", [syllable_ID])
|
||||
return db.query_result
|
||||
|
||||
@@ -160,7 +160,7 @@ func get_gp_from_word(ID: int) -> Array:
|
||||
return db.query_result
|
||||
|
||||
|
||||
func get_GPs_from_sentence(sentenceID: int) -> Array[Dictionary]:
|
||||
func get_gps_from_sentence(sentenceID: int) -> Array[Dictionary]:
|
||||
db.query_with_bindings("SELECT GPs.ID, GPs.Grapheme, GPs.Phoneme, GPs.Type, GPsInWords.WordID, GPsInWords.Position AS GPPosition, WordsInSentences.Position AS WordPosition FROM GPs
|
||||
INNER JOIN GPsInWords ON GPsInWords.GPID = GPs.ID
|
||||
INNER JOIN WordsInSentences ON WordsInSentences.WordID = GPsInWords.WordID
|
||||
@@ -198,7 +198,7 @@ func get_syllables_for_lesson(lesson_nb: int, only_new: bool = false) -> Array[D
|
||||
|
||||
var res: Array[Dictionary] = db.query_result
|
||||
for syllable: Dictionary in res:
|
||||
syllable.GPs = get_GPs_from_syllable(syllable.ID as int)
|
||||
syllable.GPs = get_gps_from_syllable(syllable.ID as int)
|
||||
var phonemes: Array[String] = []
|
||||
for gp: Dictionary in syllable.GPs:
|
||||
phonemes.append(gp.Phoneme)
|
||||
@@ -244,11 +244,11 @@ FROM Words
|
||||
|
||||
# Parse the GPs IDs
|
||||
for word: Dictionary in res:
|
||||
var word_GPs: Array = []
|
||||
var word_gps: Array = []
|
||||
var word_gps_id: String = word.GPs_IDs
|
||||
for GPID: String in word_gps_id.split(","):
|
||||
word_GPs.append({ID = int(GPID)})
|
||||
word.GPs = word_GPs
|
||||
for gp_id: String in word_gps_id.split(","):
|
||||
word_gps.append({ID = int(gp_id)})
|
||||
word.GPs = word_gps
|
||||
word.erase("GPs_IDs")
|
||||
|
||||
return res
|
||||
@@ -346,7 +346,7 @@ WHERE Sentences.Exception = 0
|
||||
return db.query_result
|
||||
|
||||
|
||||
func get_sentences_for_lesson_with_silent_GPs(lesson_nb: int, min_length: int = 2, max_length:int = 5) -> Array[Dictionary]:
|
||||
func get_sentences_for_lesson_with_silent_gps(lesson_nb: int, min_length: int = 2, max_length:int = 5) -> Array[Dictionary]:
|
||||
var query: String = "SELECT Sentences.*, VerifiedCount.MaxLessonNb AS LessonNb FROM Sentences
|
||||
INNER JOIN
|
||||
(SELECT SentenceID, count() as WordsCount FROM WordsInSentences
|
||||
|
||||
@@ -132,7 +132,7 @@ func check_internet_access() -> bool:
|
||||
return false
|
||||
|
||||
|
||||
func _create_URI_with_parameters(URI: String, params: Dictionary) -> String:
|
||||
func _create_uri_with_parameters(URI: String, params: Dictionary) -> String:
|
||||
var is_first_param: bool = true
|
||||
for key: String in params.keys():
|
||||
if is_first_param:
|
||||
@@ -170,13 +170,13 @@ func _response() -> Dictionary:
|
||||
|
||||
|
||||
func _get_request(URI: String, params: Dictionary) -> void:
|
||||
resetResult()
|
||||
reset_result()
|
||||
var headers: PackedStringArray = _create_request_headers()
|
||||
if params.has("password"):
|
||||
Logger.trace("ServerManager Sending GET request.\n URI = %s\n Parameters not logged because it contains a password." % URI)
|
||||
else:
|
||||
Logger.trace("ServerManager Sending GET request.\n URI = %s\n Parameters = %s" % [URI, params])
|
||||
if http_request.request(_create_URI_with_parameters(environment_url + URI, params), headers) == OK:
|
||||
if http_request.request(_create_uri_with_parameters(environment_url + URI, params), headers) == OK:
|
||||
await request_completed
|
||||
else:
|
||||
Logger.error("ServerManager Error sending GET request")
|
||||
@@ -185,8 +185,8 @@ func _get_request(URI: String, params: Dictionary) -> void:
|
||||
|
||||
|
||||
func _post_request(URI: String, params: Dictionary) -> void:
|
||||
resetResult()
|
||||
var url: String = _create_URI_with_parameters(environment_url + URI, params)
|
||||
reset_result()
|
||||
var url: String = _create_uri_with_parameters(environment_url + URI, params)
|
||||
var headers: PackedStringArray = _create_request_headers()
|
||||
if params.has("password"):
|
||||
Logger.trace("ServerManager Sending POST request.\n URI = %s\n Parameters not logged because it contains a password." % URI)
|
||||
@@ -201,7 +201,7 @@ func _post_request(URI: String, params: Dictionary) -> void:
|
||||
|
||||
|
||||
func _post_json_request(URI: String, data: Dictionary) -> void:
|
||||
resetResult()
|
||||
reset_result()
|
||||
var req: String = environment_url + URI
|
||||
var headers: PackedStringArray = _create_request_headers(true)
|
||||
if data.has("password"):
|
||||
@@ -217,8 +217,8 @@ func _post_json_request(URI: String, data: Dictionary) -> void:
|
||||
|
||||
|
||||
func _delete_request(URI: String, params: Dictionary = {}) -> void:
|
||||
resetResult()
|
||||
var req: String = _create_URI_with_parameters(environment_url + URI, params)
|
||||
reset_result()
|
||||
var req: String = _create_uri_with_parameters(environment_url + URI, params)
|
||||
var headers: PackedStringArray = _create_request_headers()
|
||||
Logger.trace("ServerManager Sending DELETE request.\n URI = %s\n Parameters = %s" % [URI, params])
|
||||
if http_request.request(req, headers, HTTPClient.METHOD_DELETE, "") == OK:
|
||||
@@ -238,8 +238,8 @@ func _on_http_request_request_completed(result_code: int, response_code: int, _h
|
||||
Logger.trace("ServerManager Request Completed. Response code = %d" % response_code)
|
||||
if body:
|
||||
Logger.trace("Body received = %s" % body.get_string_from_utf8())
|
||||
var strBody: String = body.get_string_from_utf8()
|
||||
var result: Variant = JSON.parse_string(strBody)
|
||||
var str_body: String = body.get_string_from_utf8()
|
||||
var result: Variant = JSON.parse_string(str_body)
|
||||
if result != null:
|
||||
json = result
|
||||
else:
|
||||
@@ -260,7 +260,7 @@ func _on_internet_check_request_completed(result_code: int, response_code: int,
|
||||
internet_check_completed.emit(success)
|
||||
|
||||
|
||||
func resetResult() -> void:
|
||||
func reset_result() -> void:
|
||||
success = false
|
||||
code = 0
|
||||
json = {}
|
||||
|
||||
@@ -95,13 +95,13 @@ func synchronize() -> void:
|
||||
var students_timestamps: Array[Dictionary] = []
|
||||
for item: Dictionary in response_body.students:
|
||||
students_timestamps.append(item)
|
||||
for studentDic: Dictionary in students_timestamps:
|
||||
if not studentDic.has("code"):
|
||||
for student_dic: Dictionary in students_timestamps:
|
||||
if not student_dic.has("code"):
|
||||
continue
|
||||
var code_to_check: int = studentDic.code
|
||||
var serverStudentUnixTime: int = -1
|
||||
if studentDic.has("updated_at"):
|
||||
serverStudentUnixTime = Time.get_unix_time_from_datetime_string(studentDic.updated_at as String)
|
||||
var code_to_check: int = student_dic.code
|
||||
var server_student_unix_time: int = -1
|
||||
if student_dic.has("updated_at"):
|
||||
server_student_unix_time = Time.get_unix_time_from_datetime_string(student_dic.updated_at as String)
|
||||
else:
|
||||
Logger.warn("UserDataBaseSynchronizer: Student %d received from server has no timestamp" % code_to_check)
|
||||
var found: bool = false
|
||||
@@ -109,11 +109,11 @@ func synchronize() -> void:
|
||||
var students_in_device: Array[StudentData] = UserDataManager.teacher_settings.students[device]
|
||||
for student_data: StudentData in students_in_device:
|
||||
if student_data.code == code_to_check:
|
||||
var localStudentUnixTime: int = Time.get_unix_time_from_datetime_string(student_data.last_modified)
|
||||
if localStudentUnixTime == serverStudentUnixTime:
|
||||
var local_student_unix_time: int = Time.get_unix_time_from_datetime_string(student_data.last_modified)
|
||||
if local_student_unix_time == server_student_unix_time:
|
||||
Logger.trace("UserDataBaseSynchronizer: Student %d data timestamp is the same in local and on server. No synchronization necessary" % code_to_check)
|
||||
need_update_students[code_to_check] = UpdateNeeded.Nothing
|
||||
elif localStudentUnixTime > serverStudentUnixTime:
|
||||
elif local_student_unix_time > server_student_unix_time:
|
||||
need_update_students[code_to_check] = UpdateNeeded.FromLocal
|
||||
else: # localStudentUnixTime < serverStudentUnixTime
|
||||
need_update_students[code_to_check] = UpdateNeeded.FromServer
|
||||
|
||||
Reference in New Issue
Block a user