Skip to content

Commit

Permalink
centralizing how number format should be done
Browse files Browse the repository at this point in the history
  • Loading branch information
Rogerio Gasi committed Apr 16, 2024
1 parent 7c88f7c commit 487a4be
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 12 deletions.
31 changes: 21 additions & 10 deletions AR_Project/Assets/Scripts/Output/CSV/Calculation/OutputData.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -15,8 +16,6 @@ public class OutputData : ICsvData
public string avatar;
public List<GameType> game_order;

public const string DecimalPrecision = "0.###";

public float age_year()
{
var birthdate = DateTime.ParseExact(birth, "dd/MM/yyyy", CultureInfo.InvariantCulture);
Expand All @@ -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<string> ToList()
{
var usCulture = new CultureInfo("en-US");
var sequenceTasks = "";
foreach (var gt in game_order)
{
Expand Down Expand Up @@ -69,8 +80,8 @@ public List<string> 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
Expand All @@ -81,7 +92,7 @@ public List<string> 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());
Expand All @@ -94,19 +105,19 @@ public List<string> 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<string>
(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)
Expand All @@ -128,7 +139,7 @@ public List<string> ToList()

for (int i = 0; i < orderedChooseTime.Count; i++)
{
list.Add(orderedChooseTime[i].ToString(DecimalPrecision, usCulture).Replace(",", ""));
list.Add(ConvertNumber(orderedChooseTime[i]));
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -75,8 +75,7 @@ public static float GetMaximumPossibleSV()

public List<string> ToList()
{
var usCulture = new CultureInfo("en-US");
return values.ConvertAll<string>(x => x.ToString(OutputData.DecimalPrecision,usCulture).Replace(",",""));
return values.ConvertAll<string>(OutputData.ConvertNumber);
}

public List<float> GetValues()
Expand Down

0 comments on commit 487a4be

Please sign in to comment.