From 9d1d38db9002435b0d059dc125bec4ac7596a675 Mon Sep 17 00:00:00 2001 From: Jaap Marsman Date: Sun, 13 Nov 2022 16:53:49 +0800 Subject: [PATCH] fixed floating point conversion in percentages for results page --- godot/ObservationWindow.gd | 15 +++++++++++++++ godot/Results.gd | 12 ------------ godot/global_ints.gd | 20 ++++++++++---------- 3 files changed, 25 insertions(+), 22 deletions(-) diff --git a/godot/ObservationWindow.gd b/godot/ObservationWindow.gd index 651f34d..764e1b2 100644 --- a/godot/ObservationWindow.gd +++ b/godot/ObservationWindow.gd @@ -23,6 +23,19 @@ func _process(_delta): $"Panel/BehaviourButtons".visible = true +func calculate_percentages(): + global_ints.total_observed_time = global_ints.total_behaviours / 3 + + global_ints.one_behaviour_percent = int((float(global_ints.one_behaviour_score) / global_ints.total_behaviours) * 100) + + global_ints.two_behaviour_percent = int((float(global_ints.two_behaviour_score) / global_ints.total_behaviours) * 100) + + global_ints.three_behaviour_percent = int((float(global_ints.three_behaviour_score) / global_ints.total_behaviours) * 100) + + global_ints.four_behaviour_percent = int((float(global_ints.four_behaviour_score) / global_ints.total_behaviours) * 100) + + global_ints.five_behaviour_percent = int((float(global_ints.five_behaviour_score) / global_ints.total_behaviours) * 100) + func on_interval_moment(): print("Timer reaches 0 - Let's check if buttons have been pressed and count something") toggle_observation = false @@ -57,6 +70,7 @@ func _on_TwentySecondTimer_timeout(): $"TwentySecondTimer".stop() global_ints.generate_results = true + calculate_percentages() $"../Results".visible = true if global_ints.locked_observations_intervals_remaining > 1: @@ -115,4 +129,5 @@ func _on_Button_pressed(): $"TwentySecondTimer".stop() global_ints.generate_results = true + calculate_percentages() $"../Results".visible = true diff --git a/godot/Results.gd b/godot/Results.gd index 0f79ca5..95a8682 100644 --- a/godot/Results.gd +++ b/godot/Results.gd @@ -87,18 +87,6 @@ func _on_Results_visibility_changed(): if global_ints.generate_results == true: global_ints.generate_results = false - global_ints.total_observed_time = global_ints.total_behaviours / 3 - - global_ints.one_behaviour_percent = (global_ints.one_behaviour_score / global_ints.total_behaviours) * 100 - - global_ints.two_behaviour_percent = (global_ints.two_behaviour_score / global_ints.total_behaviours) * 100 - - global_ints.three_behaviour_percent = (global_ints.three_behaviour_score / global_ints.total_behaviours) * 100 - - global_ints.four_behaviour_percent = (global_ints.four_behaviour_score / global_ints.total_behaviours) * 100 - - global_ints.five_behaviour_percent = (global_ints.five_behaviour_score / global_ints.total_behaviours) * 100 - var result_text : String result_text = str("Date: " , global_ints.ddmmyyyy , "\nTime: ", global_ints.observation_start_time , " to " , global_ints.observation_end_time , "\n \nThis Time Sampling Form (TSF) observation was completed by " , global_ints.observer_person_name , ". " , global_ints.observed_person_name , " was observed for " , global_ints.total_observed_time , " minute(s) during " , global_ints.observed_activity , ". \n \nDuring the observation, The ", global_ints.one_behaviour," behaviour was observed ", global_ints.one_behaviour_score, " out of ",global_ints.total_behaviours," times, resulting in ",global_ints.one_behaviour_percent,"%. The ",global_ints.two_behaviour," behaviour was observed ",global_ints.two_behaviour_score," out of ",global_ints.total_behaviours," times, resulting in ",global_ints.two_behaviour_percent,"%. The ",global_ints.three_behaviour," behaviour was observed ",global_ints.three_behaviour_score," out of ",global_ints.total_behaviours," times, resulting in ",global_ints.three_behaviour_percent,"%. The ", global_ints.four_behaviour," behaviour was observed ",global_ints.four_behaviour_score," out of ",global_ints.total_behaviours," times, resulting in ",global_ints.four_behaviour_percent,"%. The ",global_ints.five_behaviour," behaviour was observed ",global_ints.five_behaviour_score," out of ",global_ints.total_behaviours," times, resulting in ",global_ints.five_behaviour_percent,"%. ",global_ints.six_behaviour_score," intervals were not scored.") diff --git a/godot/global_ints.gd b/godot/global_ints.gd index 779dc6c..34a9b3e 100644 --- a/godot/global_ints.gd +++ b/godot/global_ints.gd @@ -55,11 +55,11 @@ var four_behaviour_score : int var five_behaviour_score : int var six_behaviour_score : int -var one_behaviour_percent : int -var two_behaviour_percent : int -var three_behaviour_percent : int -var four_behaviour_percent : int -var five_behaviour_percent : int +var one_behaviour_percent : float +var two_behaviour_percent : float +var three_behaviour_percent : float +var four_behaviour_percent : float +var five_behaviour_percent : float func reset_all_vars(): observation_minutes = 15 @@ -104,11 +104,11 @@ func reset_all_vars(): five_behaviour_score = 0 six_behaviour_score = 0 - one_behaviour_percent = 0 - two_behaviour_percent = 0 - three_behaviour_percent = 0 - four_behaviour_percent = 0 - five_behaviour_percent = 0 + one_behaviour_percent = 0.0 + two_behaviour_percent = 0.0 + three_behaviour_percent = 0.0 + four_behaviour_percent = 0.0 + five_behaviour_percent = 0.0 observation_start_time = "" observation_end_time = ""