Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Set culture on test outputs to get consistent date format #42

Closed
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion TestComponents/Test.cs
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@
}
else
{
root = Environment.GetEnvironmentVariable("GITHUB_WORKSPACE");

Check warning on line 45 in TestComponents/Test.cs

View workflow job for this annotation

GitHub Actions / build

Converting null literal or possible null value to non-nullable type.

Check warning on line 45 in TestComponents/Test.cs

View workflow job for this annotation

GitHub Actions / build

Converting null literal or possible null value to non-nullable type.
path = Path.Join(root, "TestComponents", "TestSets");
}

Expand All @@ -63,7 +63,7 @@
foreach (string s in sets)
{
//Make config file in format that .NET DataTable is able to import
runPythonScript(root, Path.Join("TestGraphs", "MakeConfigs", $"{s}.py"));

Check warning on line 66 in TestComponents/Test.cs

View workflow job for this annotation

GitHub Actions / build

Possible null reference argument for parameter 'path' in 'void Test.runPythonScript(string path, string pyProg)'.

Check warning on line 66 in TestComponents/Test.cs

View workflow job for this annotation

GitHub Actions / build

Possible null reference argument for parameter 'path' in 'void Test.runPythonScript(string path, string pyProg)'.
//Run each test
runTestSet(path, s);
//Make graphs associated with each test
Expand All @@ -85,11 +85,11 @@

var assembly = Assembly.GetExecutingAssembly();
string testConfig = "TestComponents.TestSets." + set + ".FieldConfigs.csv";
Stream configcsv = assembly.GetManifestResourceStream(testConfig);

Check warning on line 88 in TestComponents/Test.cs

View workflow job for this annotation

GitHub Actions / build

Converting null literal or possible null value to non-nullable type.

Check warning on line 88 in TestComponents/Test.cs

View workflow job for this annotation

GitHub Actions / build

Converting null literal or possible null value to non-nullable type.
DataFrame allTests = DataFrame.LoadCsv(configcsv);

string fertData = "TestComponents.TestSets." + set + ".FertiliserData.csv";
Stream fertcsv = assembly.GetManifestResourceStream(fertData);

Check warning on line 92 in TestComponents/Test.cs

View workflow job for this annotation

GitHub Actions / build

Converting null literal or possible null value to non-nullable type.

Check warning on line 92 in TestComponents/Test.cs

View workflow job for this annotation

GitHub Actions / build

Converting null literal or possible null value to non-nullable type.
DataFrame allFert = new DataFrame();
if (fertcsv != null)
{
Expand All @@ -100,7 +100,7 @@

foreach (DataFrameRow row in allTests.Rows)
{
Tests.Add(row[0].ToString());

Check warning on line 103 in TestComponents/Test.cs

View workflow job for this annotation

GitHub Actions / build

Possible null reference argument for parameter 'item' in 'void List<string>.Add(string item)'.

Check warning on line 103 in TestComponents/Test.cs

View workflow job for this annotation

GitHub Actions / build

Possible null reference argument for parameter 'item' in 'void List<string>.Add(string item)'.
}
//Tests.Add("LincolnRot2_N4_Irr2_PakChoi");

Expand All @@ -117,9 +117,9 @@
Dictionary<System.DateTime, double> testResults = new Dictionary<System.DateTime, double>();
Dictionary<System.DateTime, double> nApplied = fertDict(test, allFert);

string weatherStation = allTests["WeatherStation"][testRow].ToString();

Check warning on line 120 in TestComponents/Test.cs

View workflow job for this annotation

GitHub Actions / build

Converting null literal or possible null value to non-nullable type.

Check warning on line 120 in TestComponents/Test.cs

View workflow job for this annotation

GitHub Actions / build

Converting null literal or possible null value to non-nullable type.

bool actualWeather = weatherStation.Contains("Actual");

Check warning on line 122 in TestComponents/Test.cs

View workflow job for this annotation

GitHub Actions / build

Dereference of a possibly null reference.

Check warning on line 122 in TestComponents/Test.cs

View workflow job for this annotation

GitHub Actions / build

Dereference of a possibly null reference.

MetDataDictionaries metData = ModelInterface.BuildMetDataDictionaries(_config.Prior.EstablishDate, _config.Following.HarvestDate.AddDays(1), weatherStation, actualWeather);

Expand All @@ -129,7 +129,7 @@
List<string> OutPutHeaders = new List<string>();
for (int i = 0; i < output.GetLength(1); i += 1)
{
OutPutHeaders.Add(output[0, i].ToString());

Check warning on line 132 in TestComponents/Test.cs

View workflow job for this annotation

GitHub Actions / build

Possible null reference argument for parameter 'item' in 'void List<string>.Add(string item)'.

Check warning on line 132 in TestComponents/Test.cs

View workflow job for this annotation

GitHub Actions / build

Possible null reference argument for parameter 'item' in 'void List<string>.Add(string item)'.
if (i == 0)
{
columns[i] = new PrimitiveDataFrameColumn<System.DateTime>(output[0, i].ToString());
Expand Down Expand Up @@ -159,8 +159,9 @@
System.IO.Directory.CreateDirectory("OutputFiles");
}

CultureInfo cult = new CultureInfo("en-NZ");
DataFrame.SaveCsv(
newDataframe, Path.Join(path, set, "Outputs", $"{test}.csv")
newDataframe, Path.Join(path, set, "Outputs", $"{test}.csv"), cultureInfo : cult
);
}
}
Expand Down Expand Up @@ -284,7 +285,7 @@
if (Environment.GetEnvironmentVariable("GITHUB_WORKSPACE") != null)
{
//Need to parse date like this in GitHub
date = DateTime.ParseExact(row[1].ToString(), "d/MM/yyyy", CultureInfo.InvariantCulture);

Check warning on line 288 in TestComponents/Test.cs

View workflow job for this annotation

GitHub Actions / build

Possible null reference argument for parameter 's' in 'DateTime DateTime.ParseExact(string s, string format, IFormatProvider? provider)'.

Check warning on line 288 in TestComponents/Test.cs

View workflow job for this annotation

GitHub Actions / build

Possible null reference argument for parameter 's' in 'DateTime DateTime.ParseExact(string s, string format, IFormatProvider? provider)'.
}
else
{
Expand All @@ -299,7 +300,7 @@
}
if (date == last) //If alread fertiliser added for that date add it to existing total
{
fert[last] += Double.Parse(row[2].ToString());

Check warning on line 303 in TestComponents/Test.cs

View workflow job for this annotation

GitHub Actions / build

Possible null reference argument for parameter 's' in 'double double.Parse(string s)'.

Check warning on line 303 in TestComponents/Test.cs

View workflow job for this annotation

GitHub Actions / build

Possible null reference argument for parameter 's' in 'double double.Parse(string s)'.
}
else //add it to a new date
{
Expand Down
Loading