Skip to content

Commit

Permalink
Dont read in fertiliser dates that are outside of simulation date range
Browse files Browse the repository at this point in the history
  • Loading branch information
HamishBrownPFR committed Jun 22, 2024
1 parent 9a6a3ed commit c9309a1
Showing 1 changed file with 12 additions and 8 deletions.
20 changes: 12 additions & 8 deletions TestComponents/Test.cs
Original file line number Diff line number Diff line change
Expand Up @@ -115,7 +115,7 @@ public static void runTestSet(string path, string set)
double initialN = _testData.Item2;

Dictionary<System.DateTime, double> testResults = new Dictionary<System.DateTime, double>();
Dictionary<System.DateTime, double> nApplied = fertDict(test, allFert);
Dictionary<System.DateTime, double> nApplied = fertDict(test, allFert, _config);

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.

Expand Down Expand Up @@ -272,7 +272,7 @@ private static int getTestRow(string test, DataFrame allTests)
return testRow;
}

private static Dictionary<System.DateTime, double> fertDict(string test, DataFrame allFert)
private static Dictionary<System.DateTime, double> fertDict(string test, DataFrame allFert, Config _config)
{
Dictionary<System.DateTime, double> fert = new Dictionary<System.DateTime, double>();
foreach (DataFrameRow row in allFert.Rows)
Expand All @@ -292,18 +292,22 @@ private static int getTestRow(string test, DataFrame allTests)
date = (DateTime)row[1];
}


DateTime last = new DateTime();
if (fert.Keys.Count > 0)
{
last = fert.Keys.Last();
}
if (date == last) //If alread fertiliser added for that date add it to existing total
{
fert[last] += Double.Parse(row[2].ToString());
}
else //add it to a new date
if ((date >= _config.StartDate) && (date <= _config.StartDate))
{
fert.Add(date, Double.Parse(row[2].ToString()));
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 305 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
{
fert.Add(date, Double.Parse(row[2].ToString()));
}
}
}
}
Expand Down

0 comments on commit c9309a1

Please sign in to comment.