From 487a4be25df0bbe7f2a899e251f48b0168fb899f Mon Sep 17 00:00:00 2001 From: Rogerio Gasi Date: Tue, 16 Apr 2024 12:17:42 -0700 Subject: [PATCH] centralizing how number format should be done --- .../Output/CSV/Calculation/OutputData.cs | 31 +++++++++++++------ .../CSV/Calculation/SubjectiveValueData.cs | 3 +- 2 files changed, 22 insertions(+), 12 deletions(-) diff --git a/AR_Project/Assets/Scripts/Output/CSV/Calculation/OutputData.cs b/AR_Project/Assets/Scripts/Output/CSV/Calculation/OutputData.cs index d380836..a6cf529 100644 --- a/AR_Project/Assets/Scripts/Output/CSV/Calculation/OutputData.cs +++ b/AR_Project/Assets/Scripts/Output/CSV/Calculation/OutputData.cs @@ -2,6 +2,7 @@ using System.Collections.Generic; using System.Globalization; using System.Linq; +using System.Threading; using AR_Project.Savers; namespace Output.CSV.Calculation @@ -15,8 +16,6 @@ public class OutputData : ICsvData public string avatar; public List game_order; - public const string DecimalPrecision = "0.###"; - public float age_year() { var birthdate = DateTime.ParseExact(birth, "dd/MM/yyyy", CultureInfo.InvariantCulture); @@ -38,10 +37,22 @@ public int age_month() }; public float total_points; + public const string NumberFormat = "#0.###"; + + public static string ConvertNumber(float number) + { + string formattedNumber = number.ToString(NumberFormat, CultureInfo.InvariantCulture); + return formattedNumber; + } + + public static string ConvertNumber(double number) + { + string formattedNumber = number.ToString(NumberFormat, CultureInfo.InvariantCulture); + return formattedNumber; + } public List ToList() { - var usCulture = new CultureInfo("en-US"); var sequenceTasks = ""; foreach (var gt in game_order) { @@ -69,8 +80,8 @@ public List ToList() name, date_application, birth, - age_year().ToString(DecimalPrecision, usCulture).Replace(",",""), - age_month().ToString(DecimalPrecision, usCulture).Replace(",",""), + ConvertNumber(age_year()), + ConvertNumber(age_month()), gender, avatar, sequenceTasks @@ -81,7 +92,7 @@ public List ToList() foreach(var data in orderedData) list.AddRange(data.points.ToList()); - list.Add(total_points.ToString(usCulture).Replace(",","")); + list.Add(ConvertNumber(total_points)); foreach(var data in orderedData) data.subjectiveValueData.Calculate(data.points.GetSequencePoints()); @@ -94,19 +105,19 @@ public List ToList() { var auc = Math.GetAreaUnderCurve(data.subjectiveValueData.GetValues()); aucValues.Add(auc); - list.Add(auc.ToString(DecimalPrecision, usCulture).Replace(",", "")); + list.Add(ConvertNumber(auc)); } // Subjective Values normalized foreach (var data in orderedData) { list.AddRange(Math.GetNormalizedValues(data.subjectiveValueData).ConvertAll - (x => x.ToString(DecimalPrecision,usCulture).Replace(",",""))); + (ConvertNumber)); } //AUC normalized foreach (var auc in aucValues) { - list.Add((auc / maxAUC).ToString(DecimalPrecision, usCulture).Replace(",", "")); + list.Add(ConvertNumber(auc / maxAUC)); } foreach (var data in orderedData) @@ -128,7 +139,7 @@ public List ToList() for (int i = 0; i < orderedChooseTime.Count; i++) { - list.Add(orderedChooseTime[i].ToString(DecimalPrecision, usCulture).Replace(",", "")); + list.Add(ConvertNumber(orderedChooseTime[i])); } } diff --git a/AR_Project/Assets/Scripts/Output/CSV/Calculation/SubjectiveValueData.cs b/AR_Project/Assets/Scripts/Output/CSV/Calculation/SubjectiveValueData.cs index 496a562..df7f563 100644 --- a/AR_Project/Assets/Scripts/Output/CSV/Calculation/SubjectiveValueData.cs +++ b/AR_Project/Assets/Scripts/Output/CSV/Calculation/SubjectiveValueData.cs @@ -75,8 +75,7 @@ public static float GetMaximumPossibleSV() public List ToList() { - var usCulture = new CultureInfo("en-US"); - return values.ConvertAll(x => x.ToString(OutputData.DecimalPrecision,usCulture).Replace(",","")); + return values.ConvertAll(OutputData.ConvertNumber); } public List GetValues()