From 44b8c6d3283d9fe332d2394ccca4bf4dab7ff1aa Mon Sep 17 00:00:00 2001 From: Timothy Miller Date: Sun, 2 Jun 2024 10:08:56 +1200 Subject: [PATCH 01/10] fix: broken csv ClassMap --- SVSModel/Models/InterfaceModels.cs | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/SVSModel/Models/InterfaceModels.cs b/SVSModel/Models/InterfaceModels.cs index b0b0fc2..904596a 100644 --- a/SVSModel/Models/InterfaceModels.cs +++ b/SVSModel/Models/InterfaceModels.cs @@ -84,8 +84,8 @@ public CropCoefficientMap() Map(c => c.RootN).Name("Root [N]").Default(0); Map(c => c.StoverN).Name("Stover [N]").Default(0); Map(c => c.ProductN).Name("Product [N]").Default(0); - Map(c => c.TtEmerg).Name("Thermal Time to emerge").Default(0); - Map(c => c.Tbase).Name("Base temperature for growth").Default(0); + Map(c => c.TtEmerg).Name("TtEmerg").Default(0); + Map(c => c.Tbase).Name("Tbase").Default(0); } } From 360b09d65c30023b8f13e44b1a051319c123d449 Mon Sep 17 00:00:00 2001 From: Timothy Miller Date: Sun, 2 Jun 2024 10:09:33 +1200 Subject: [PATCH 02/10] chore: fix some comments and casing/naming --- SVSModel/ModelInterface.cs | 101 ++++++++++++++++++++----------------- 1 file changed, 56 insertions(+), 45 deletions(-) diff --git a/SVSModel/ModelInterface.cs b/SVSModel/ModelInterface.cs index 6d403d4..65b7d45 100644 --- a/SVSModel/ModelInterface.cs +++ b/SVSModel/ModelInterface.cs @@ -4,7 +4,6 @@ using System; using System.Collections.Generic; -using System.Diagnostics; using System.Globalization; using System.IO; using System.Linq; @@ -13,9 +12,7 @@ using CsvHelper; using SVSModel.Configuration; using SVSModel.Models; -using SVSModel.Simulation; using static SVSModel.Configuration.Constants; -using static SVSModel.Configuration.InputCategories; namespace SVSModel { @@ -28,45 +25,59 @@ public interface IModelInterface /// A dictionary of nitrogen test results /// A dictionary of nitrogen applications /// Model config object, all parameters are required - /// A list of objects - List GetDailyNBalance(string weatherStation, Dictionary testResults, - Dictionary nApplied, Config config); - + /// An object containing a list of and an NBalance Graph summary + DailyNBalanceDTO GetDailyNBalance(string weatherStation, Dictionary testResults, Dictionary nApplied, Config config); + /// /// Gets the crop data from the data file /// /// List of s directly from the data file IEnumerable GetCropCoefficients(); - Dictionary GetSoilTestResult(DateTime testDate, double testValue, string depthOfSample, - string typeOfTest, string moistureOfTest, - string categoryOfSoil, string textureOfSoil); - + Dictionary GetSoilTestResult( + DateTime testDate, + double testValue, + string depthOfSample, + string typeOfTest, + string moistureOfTest, + string categoryOfSoil, + string textureOfSoil); } public class ModelInterface : IModelInterface { - public Dictionary GetSoilTestResult(DateTime testDate, double testValue, string depthOfSample, - string typeOfTest, string moistureOfTest, - string categoryOfSoil, string textureOfSoil) + public Dictionary GetSoilTestResult( + DateTime testDate, + double testValue, + string depthOfSample, + string typeOfTest, + string moistureOfTest, + string categoryOfSoil, + string textureOfSoil) { - SoilTestConfig test = new SoilTestConfig(testDate, testValue, depthOfSample, - typeOfTest, moistureOfTest, - categoryOfSoil, textureOfSoil); + var test = new SoilTestConfig( + testDate, + testValue, + depthOfSample, + typeOfTest, + moistureOfTest, + categoryOfSoil, + textureOfSoil); + return test.Result; } - public List GetDailyNBalance(string weatherStation, Dictionary testResults, Dictionary nApplied, Config config) + public DailyNBalanceDTO GetDailyNBalance(string weatherStation, Dictionary testResults, Dictionary nApplied, Config config) { var startDate = config.Prior.EstablishDate.AddDays(-1); var endDate = config.Following.HarvestDate.AddDays(2); var metData = BuildMetDataDictionaries(startDate, endDate, weatherStation, false); - var rawResult = Simulation.Simulation.SimulateField(metData.MeanT, metData.Rain, metData.MeanPET, testResults, nApplied, config, Constants.InitialN); + var rawResult = Simulation.Simulation.SimulateField(metData.MeanT, metData.Rain, metData.MeanPET, testResults, nApplied, config, InitialN); - var result = new List(); + List results = []; - // Convert from the 2d object array that SimulateField returns into something user friendly + // Convert from the 2d object array that SimulateField returns into something user-friendly for (var r = 1; r < rawResult.GetLength(0); r++) { var row = Enumerable.Range(0, rawResult.GetLength(1)) @@ -92,10 +103,12 @@ public List GetDailyNBalance(string weatherStation, Dictionary GetCropCoefficients() @@ -103,16 +116,15 @@ public IEnumerable GetCropCoefficients() var assembly = Assembly.GetExecutingAssembly(); var stream = assembly.GetManifestResourceStream("SVSModel.Data.CropCoefficientTableFull.csv"); - if (stream == null) return Enumerable.Empty(); + if (stream == null) return []; - using (var reader = new StreamReader(stream, Encoding.UTF8)) - using (var csv = new CsvReader(reader, CultureInfo.InvariantCulture)) - { - csv.Context.RegisterClassMap(); + using var reader = new StreamReader(stream, Encoding.UTF8); + using var csv = new CsvReader(reader, CultureInfo.InvariantCulture); + + csv.Context.RegisterClassMap(); - var cropData = csv.GetRecords(); - return cropData.ToList(); - } + var cropData = csv.GetRecords(); + return cropData.ToList(); } private static IEnumerable GetMetData(string weatherStation) @@ -122,26 +134,25 @@ private static IEnumerable GetMetData(string weatherStation) var stream = assembly.GetManifestResourceStream($"SVSModel.Data.Met.{weatherStation}.csv"); if (stream == null) return Enumerable.Empty(); - using (var reader = new StreamReader(stream, Encoding.UTF8)) - using (var csv = new CsvReader(reader, CultureInfo.InvariantCulture)) - { - var data = csv.GetRecords(); - return data.ToList(); - } + using var reader = new StreamReader(stream, Encoding.UTF8); + using var csv = new CsvReader(reader, CultureInfo.InvariantCulture); + + var data = csv.GetRecords(); + return data.ToList(); } + private static IEnumerable GetActualMetData(string weatherStation) { var assembly = Assembly.GetExecutingAssembly(); var stream = assembly.GetManifestResourceStream($"SVSModel.Data.Met.{weatherStation}.csv"); - if (stream == null) return Enumerable.Empty(); + if (stream == null) return []; - using (var reader = new StreamReader(stream, Encoding.UTF8)) - using (var csv = new CsvReader(reader, CultureInfo.InvariantCulture)) - { - var data = csv.GetRecords(); - return data.ToList(); - } + using var reader = new StreamReader(stream, Encoding.UTF8); + using var csv = new CsvReader(reader, CultureInfo.InvariantCulture); + + var data = csv.GetRecords(); + return data.ToList(); } public static MetDataDictionaries BuildMetDataDictionaries(DateTime startDate, DateTime endDate, string weatherStation, bool actualWeather) @@ -190,4 +201,4 @@ public static MetDataDictionaries BuildMetDataDictionaries(DateTime startDate, D return new MetDataDictionaries { MeanT = meanT, Rain = rain, MeanPET = meanPET }; } } -} +} \ No newline at end of file From 3b204260ddf573fecbbaf804d5eb556e6a082887 Mon Sep 17 00:00:00 2001 From: Timothy Miller Date: Sun, 2 Jun 2024 10:09:55 +1200 Subject: [PATCH 03/10] feat: getters are required here for the webapp to function --- SVSModel/Simulation.cs | 18 +++++++++--------- 1 file changed, 9 insertions(+), 9 deletions(-) diff --git a/SVSModel/Simulation.cs b/SVSModel/Simulation.cs index e558b63..e7be7a7 100644 --- a/SVSModel/Simulation.cs +++ b/SVSModel/Simulation.cs @@ -199,18 +199,18 @@ public SimulationType(DateTime[] _simDates, Config _config, public class CropNBalanceSummary { - public double MineralIn; - public double CropIn; - public double ResidueIn; - public double SOMIn; - public double FertiliserIn; + public double MineralIn { get; } + public double CropIn { get; } + public double ResidueIn { get; } + public double SOMIn { get; } + public double FertiliserIn { get; } public double UncharacterisedIn { get { return Math.Max(0, Outs - Ins); } } /// Out - public double MinearlOut; - public double ProductOut; - public double StoverOut; - public double LossesOut; + public double MinearlOut { get; } + public double ProductOut { get; } + public double StoverOut { get; } + public double LossesOut { get; } public double UncharacterisedOut { get { return Math.Max(0,Ins-Outs); } } public double Ins { get { return MineralIn + CropIn + ResidueIn + SOMIn + FertiliserIn; } } From 49f0136a520d37b5e5f2e2720a319c0cc4d32a8e Mon Sep 17 00:00:00 2001 From: Timothy Miller Date: Sun, 2 Jun 2024 10:10:15 +1200 Subject: [PATCH 04/10] chore: general tidy up for clarity --- SVSModel/Configuration/SoilTestConfig.cs | 64 ++++++++++-------------- 1 file changed, 27 insertions(+), 37 deletions(-) diff --git a/SVSModel/Configuration/SoilTestConfig.cs b/SVSModel/Configuration/SoilTestConfig.cs index 17847d9..f50e542 100644 --- a/SVSModel/Configuration/SoilTestConfig.cs +++ b/SVSModel/Configuration/SoilTestConfig.cs @@ -4,28 +4,34 @@ using System; using System.Collections.Generic; -using SVSModel.Models; using static SVSModel.Configuration.Constants; using static SVSModel.Configuration.InputCategories; namespace SVSModel.Configuration; /// -/// Class that stores the configuration information in the correct type for a specific Soil Test . -/// I.e constructor takes all config settings as objects and converts them to appropriates types +/// Class that stores the configuration information in the correct type for a specific Soil Test. +/// I.E. constructor takes all config settings as objects and converts them to appropriates types /// -public class SoilTestConfig +public class SoilTestConfig( + DateTime testDate, + double testValue, + string depthOfSample, + string typeOfTest, + string moistureOfSample, + string categoryOfSoil, + string textureOfSoil) { // Inputs - public DateTime TestDate { get; init; } - public double TestValue { get; init; } - public string DepthOfSample {get; init;} - public string TypeOfTest { get; init; } - public string MoistureOfSample { get; init; } - public string CategoryOfSoil { get; init; } - public string TextureOfSoil { get; init; } + private DateTime TestDate { get; } = testDate; + private double TestValue { get; } = testValue; + private string DepthOfSample {get;} = depthOfSample; + private string TypeOfTest { get; } = typeOfTest; + private string MoistureOfSample { get; } = moistureOfSample; + private string CategoryOfSoil { get; } = categoryOfSoil; + private string TextureOfSoil { get; } = textureOfSoil; - public double BulkDensity + private double BulkDensity { get { return Constants.BulkDensity(CategoryOfSoil, TextureOfSoil); } } @@ -35,31 +41,15 @@ public Dictionary Result get { double soilMF = 1; - if (TypeOfTest.ToString()==TestType.QuickTest.ToString()) - soilMF = Constants.MoistureFactor[TextureOfSoil.ToString()][MoistureOfSample.ToString()]; - double soilDepthFactor = SampleDepthFactor[DepthOfSample]; - double result = TestValue / soilMF * BulkDensity * 3 * soilDepthFactor; - return new Dictionary() { { TestDate, result } }; + if (TypeOfTest == TestType.QuickTest.ToString()) + { + soilMF = MoistureFactor[TextureOfSoil][MoistureOfSample]; + } + + var soilDepthFactor = SampleDepthFactor[DepthOfSample]; + var result = TestValue / soilMF * BulkDensity * 3 * soilDepthFactor; + + return new Dictionary { { TestDate, result } }; } } - - /// - /// Constructor used only by external webapp - /// - public SoilTestConfig() { } - - /// - /// Constructor used only by the Excel model - /// - public SoilTestConfig(DateTime testDate, double testValue, string depthOfSample, - string typeOfTest, string moistureOfSample, string categoryOfSoil, string textureOfSoil) - { - TestDate = testDate; - TestValue = testValue; - DepthOfSample = depthOfSample; - TypeOfTest = typeOfTest; - MoistureOfSample = moistureOfSample; - CategoryOfSoil = categoryOfSoil; - TextureOfSoil = textureOfSoil; - } } From 2b8a3bdbeb1daf1a77ae9c8f5f9f515e97842b7f Mon Sep 17 00:00:00 2001 From: Timothy Miller Date: Sun, 2 Jun 2024 10:11:15 +1200 Subject: [PATCH 05/10] chore: move sample depth variable back to underscore, as its only used internally --- SVSModel.Tests/Configuration/FieldConfigTests.cs | 4 ++-- SVSModel/Configuration/FieldConfig.cs | 10 ++++------ 2 files changed, 6 insertions(+), 8 deletions(-) diff --git a/SVSModel.Tests/Configuration/FieldConfigTests.cs b/SVSModel.Tests/Configuration/FieldConfigTests.cs index 2bb99dc..c774540 100644 --- a/SVSModel.Tests/Configuration/FieldConfigTests.cs +++ b/SVSModel.Tests/Configuration/FieldConfigTests.cs @@ -45,7 +45,7 @@ public void Test_FieldConfig_Excel_Gets_Values_Correctly() Assert.Equal(fieldConfig.Rocks, Rocks / 100); Assert.Equal(fieldConfig.SampleDepthFactor, Constants.SampleDepthFactor[SampleDepth]); Assert.Equal(fieldConfig.BulkDensity, Constants.BulkDensity(SoilCategory, Texture)); - Assert.Equal(fieldConfig.AWC, 3 * Constants.AWCpct[Texture] * (1 - Rocks / 100)); + Assert.Equal(fieldConfig.AWC, 3 * Constants.AWCPercent[Texture] * (1 - Rocks / 100)); Assert.Equal(fieldConfig.PrePlantRainFactor, Constants.PPRainFactors[PrePlantRain]); Assert.Equal(fieldConfig.InCropRainFactor, Constants.ICRainFactors[InCropRain]); Assert.Equal(fieldConfig.IrrigationTrigger, Constants.IrrigationTriggers[Irrigation]); @@ -62,7 +62,7 @@ public void Test_FieldConfig_Both_Constructors_Match() PMN = PMN, Splits = Splits, _rawRocks = Rocks, - SampleDepth = SampleDepth, + _sampleDepth = SampleDepth, _prePlantRain = PrePlantRain, _inCropRain = InCropRain, _irrigation = Irrigation diff --git a/SVSModel/Configuration/FieldConfig.cs b/SVSModel/Configuration/FieldConfig.cs index 621d799..84a8515 100644 --- a/SVSModel/Configuration/FieldConfig.cs +++ b/SVSModel/Configuration/FieldConfig.cs @@ -2,9 +2,7 @@ // Author: Hamish Brown. // Copyright (c) 2024 The New Zealand Institute for Plant and Food Research Limited -using System; using System.Collections.Generic; -using static SVSModel.Configuration.InputCategories; namespace SVSModel.Configuration { @@ -21,16 +19,16 @@ public class FieldConfig public double PMN { get; init; } public int Splits { get; init; } public double _rawRocks { internal get; init; } - public string SampleDepth { internal get; init; } + public string _sampleDepth { internal get; init; } public string _prePlantRain { internal get; init; } public string _inCropRain { internal get; init; } public string _irrigation { internal get; init; } // Calculated fields public double Rocks => _rawRocks / 100; - public double SampleDepthFactor => Constants.SampleDepthFactor[SampleDepth]; public double BulkDensity => Constants.BulkDensity(Category, Texture); - public double AWC => 3 * Constants.AWCpct[Texture] * (1 - Rocks); + public double AWC => 3 * Constants.AWCPercent[Texture] * (1 - Rocks); + public double SampleDepthFactor => Constants.SampleDepthFactor[_sampleDepth]; public double PrePlantRainFactor => Constants.PPRainFactors[_prePlantRain]; public double InCropRainFactor => Constants.ICRainFactors[_inCropRain]; public double IrrigationTrigger => Constants.IrrigationTriggers[_irrigation]; @@ -54,7 +52,7 @@ public FieldConfig(Dictionary c) Splits = int.Parse(c["Splits"].ToString()); _rawRocks = Functions.Num(c["Rocks"]); - SampleDepth = c["SampleDepth"].ToString(); + _sampleDepth = c["SampleDepth"].ToString(); _prePlantRain = c["PrePlantRain"].ToString(); _inCropRain = c["InCropRain"].ToString(); _irrigation = c["Irrigation"].ToString(); From eea65f603c730d5280ce12f67e6b8cf75028dc8a Mon Sep 17 00:00:00 2001 From: Timothy Miller Date: Sun, 2 Jun 2024 10:11:48 +1200 Subject: [PATCH 06/10] feat: new return model for GetDailyNBalance --- SVSModel/Models/DailyNBalanceDTO.cs | 15 +++++++++++++++ 1 file changed, 15 insertions(+) create mode 100644 SVSModel/Models/DailyNBalanceDTO.cs diff --git a/SVSModel/Models/DailyNBalanceDTO.cs b/SVSModel/Models/DailyNBalanceDTO.cs new file mode 100644 index 0000000..301ea41 --- /dev/null +++ b/SVSModel/Models/DailyNBalanceDTO.cs @@ -0,0 +1,15 @@ +// FieldNBalance is a program that estimates the N balance and provides N fertilizer recommendations for cultivated crops. +// Author: Hamish Brown. +// Copyright (c) 2024 The New Zealand Institute for Plant and Food Research Limited + +using System.Collections.Generic; +using SVSModel.Simulation; + +namespace SVSModel.Models +{ + public class DailyNBalanceDTO + { + public List Results { get; set; } = []; + public CropNBalanceSummary NBalance { get; set; } + } +} \ No newline at end of file From 08d326b9539ff69ea6a81183554b8c23b1d1b06d Mon Sep 17 00:00:00 2001 From: Timothy Miller Date: Sun, 2 Jun 2024 10:12:33 +1200 Subject: [PATCH 07/10] chore: casing/naming quick tidy --- SVSModel/Configuration/Constants.cs | 48 ++++++++++++++--------------- SVSModel/Models/Crop.cs | 11 +++---- 2 files changed, 27 insertions(+), 32 deletions(-) diff --git a/SVSModel/Configuration/Constants.cs b/SVSModel/Configuration/Constants.cs index 820236e..188d9f5 100644 --- a/SVSModel/Configuration/Constants.cs +++ b/SVSModel/Configuration/Constants.cs @@ -3,8 +3,6 @@ // Copyright (c) 2024 The New Zealand Institute for Plant and Food Research Limited using System.Collections.Generic; -using System.ComponentModel; -using static SVSModel.Configuration.InputCategories; namespace SVSModel.Configuration { @@ -14,7 +12,7 @@ public static class Constants public const double InitialN = 50; /// Dictionary containing values for the proportion of maximum DM that occurs at each predefined crop stage - public static readonly Dictionary PropnMaxDM = new() + public static readonly Dictionary PropNMaxDM = new() { { "Seed", 0.004 }, { "Seedling", 0.011 }, @@ -26,8 +24,8 @@ public static class Constants { "Late", 0.9995 } }; - /// Dictionary containing values for the proportion of thermal time to maturity that has accumulate at each predefined crop stage - public static readonly Dictionary PropnTt = new() + /// Dictionary containing values for the proportion of thermal time to maturity that has accumulated at each predefined crop stage + public static readonly Dictionary PropNTt = new() { { "Seed", -0.0517 }, { "Seedling", 0.050 }, @@ -47,7 +45,7 @@ public static class Constants { "kg/head", 1.0 } }; - /// Dictionary containing conversion from specified residue treatments to proportoins returned + /// Dictionary containing conversion from specified residue treatments to proportions returned public static readonly Dictionary ResidueFactRetained = new() { { "None removed", 1.0 }, @@ -57,7 +55,7 @@ public static class Constants { "All removed", 0.0 } }; - /// Dictionary containing conversion from specified residue treatments to proportoins returned + /// Dictionary containing conversion from specified residue treatments to proportions returned public static readonly Dictionary ResidueIncorporation = new() { { "None (Surface)", 0.0 }, @@ -101,7 +99,7 @@ public static class Constants { "Full", 0.9 } }; - /// Sample depth factor to adjust measurments to equivelent of 30cm measure + /// Sample depth factor to adjust measurements to equivalent of 30cm measure public static readonly Dictionary SampleDepthFactor = new() { { "Top15cm", 0.75 }, @@ -111,7 +109,7 @@ public static class Constants }; /// Available water capacity % - public static readonly Dictionary AWCpct = new() + public static readonly Dictionary AWCPercent = new() { { "Sand", 8 }, { "LoamySand", 18 }, @@ -127,7 +125,7 @@ public static class Constants { "Clay", 18 }, }; - /// The porocity (mm3 pores/mm3 soil volume) of different soil texture classes + /// The porosity (mm3 pores/mm3 soil volume) of different soil texture classes public static readonly Dictionary Porosity = new() { { "Sand", 0.5 }, @@ -148,28 +146,28 @@ public static class Constants public static readonly Dictionary ParticleDensity = new() { { "Sedimentary", 2.65 }, - { "Volcanic", 1.9 }, + { "Volcanic", 1.9 } }; public static double BulkDensity(string soilCategory, string soilTexture) { - return Constants.ParticleDensity[soilCategory] * (1 - Constants.Porosity[soilTexture]); + return ParticleDensity[soilCategory] * (1 - Porosity[soilTexture]); } - public static readonly Dictionary> MoistureFactor = new Dictionary>() + public static readonly Dictionary> MoistureFactor = new() { - {"Clay", new Dictionary() { { "Dry", 1.8}, { "Moist", 1.5},{ "Wet", 1.3} } }, - {"ClayLoam", new Dictionary() { { "Dry", 1.7}, { "Moist", 1.4},{ "Wet", 1.3} } }, - {"Loam", new Dictionary() { { "Dry", 2.0}, { "Moist", 1.5},{ "Wet", 1.3} } }, - {"LoamySand", new Dictionary() { { "Dry", 1.8}, { "Moist", 1.5},{ "Wet", 1.4} } }, - {"Sand", new Dictionary() { { "Dry", 1.8}, { "Moist", 1.5},{ "Wet", 1.4} } }, - {"SandyClay", new Dictionary() { { "Dry", 1.8}, { "Moist", 1.4},{ "Wet", 1.3} } }, - {"SandyClayLoam", new Dictionary() { { "Dry", 1.9}, { "Moist", 1.6},{ "Wet", 1.4} } }, - {"SandyLoam", new Dictionary() { { "Dry", 2.1}, { "Moist", 1.8},{ "Wet", 1.5} } }, - {"Silt", new Dictionary() { { "Dry", 1.9}, { "Moist", 1.4},{ "Wet", 1.3} } }, - {"SiltLoam", new Dictionary() { { "Dry", 1.7}, { "Moist", 1.4},{ "Wet", 1.3} } }, - {"SiltyClay", new Dictionary() { { "Dry", 1.9}, { "Moist", 1.6},{ "Wet", 1.4} } }, - {"SiltyClayLoam", new Dictionary() { { "Dry", 1.9}, { "Moist", 1.5},{ "Wet", 1.4} } }, + { "Clay", new Dictionary { { "Dry", 1.8}, { "Moist", 1.5}, { "Wet", 1.3} } }, + { "ClayLoam", new Dictionary { { "Dry", 1.7}, { "Moist", 1.4}, { "Wet", 1.3} } }, + { "Loam", new Dictionary { { "Dry", 2.0}, { "Moist", 1.5}, { "Wet", 1.3} } }, + { "LoamySand", new Dictionary { { "Dry", 1.8}, { "Moist", 1.5}, { "Wet", 1.4} } }, + { "Sand", new Dictionary { { "Dry", 1.8}, { "Moist", 1.5}, { "Wet", 1.4} } }, + { "SandyClay", new Dictionary { { "Dry", 1.8}, { "Moist", 1.4}, { "Wet", 1.3} } }, + { "SandyClayLoam", new Dictionary { { "Dry", 1.9}, { "Moist", 1.6}, { "Wet", 1.4} } }, + { "SandyLoam", new Dictionary { { "Dry", 2.1}, { "Moist", 1.8}, { "Wet", 1.5} } }, + { "Silt", new Dictionary { { "Dry", 1.9}, { "Moist", 1.4}, { "Wet", 1.3} } }, + { "SiltLoam", new Dictionary { { "Dry", 1.7}, { "Moist", 1.4}, { "Wet", 1.3} } }, + { "SiltyClay", new Dictionary { { "Dry", 1.9}, { "Moist", 1.6}, { "Wet", 1.4} } }, + { "SiltyClayLoam", new Dictionary { { "Dry", 1.9}, { "Moist", 1.5}, { "Wet", 1.4} } } }; } } diff --git a/SVSModel/Models/Crop.cs b/SVSModel/Models/Crop.cs index b4e2a1f..53074a9 100644 --- a/SVSModel/Models/Crop.cs +++ b/SVSModel/Models/Crop.cs @@ -4,13 +4,10 @@ using System; using System.Collections.Generic; -using System.Collections.Immutable; using System.IO; using System.Linq; using System.Reflection; -using System.Runtime.InteropServices.ComTypes; using Microsoft.Data.Analysis; -using SVSModel; using SVSModel.Configuration; using SVSModel.Simulation; @@ -44,19 +41,19 @@ public static CropType Grow(Dictionary meanT, thisCrop.TtSowToEmerg = cropParams.TtSowtoEmerge; } - double PropnTt_EstToHarv = Constants.PropnTt[cf.HarvestStage] - Math.Max(Constants.PropnTt[cf.EstablishStage], 0); //Constants.PropnTt["Emergence"]); + double PropnTt_EstToHarv = Constants.PropNTt[cf.HarvestStage] - Math.Max(Constants.PropNTt[cf.EstablishStage], 0); //Constants.PropNTt["Emergence"]); thisCrop.TtEmergToMat = (thisCrop.TtEstabToHarv - thisCrop.TtSowToEmerg) * 1 / PropnTt_EstToHarv; thisCrop.TtEmergToSeedling = 0; if (cf.EstablishStage == "Seedling") { - thisCrop.TtEmergToSeedling = thisCrop.TtEmergToMat * Constants.PropnTt["Seedling"]; + thisCrop.TtEmergToSeedling = thisCrop.TtEmergToMat * Constants.PropNTt["Seedling"]; } thisCrop.Xo_Biomass = thisCrop.TtEmergToMat * 0.5; thisCrop.b_Biomass = thisCrop.Xo_Biomass * .2; - thisCrop.T_maxRD = Constants.PropnTt["EarlyReproductive"] * thisCrop.TtEmergToMat; - thisCrop.T_sen = Constants.PropnTt["MidReproductive"] * thisCrop.TtEmergToMat; + thisCrop.T_maxRD = Constants.PropNTt["EarlyReproductive"] * thisCrop.TtEmergToMat; + thisCrop.T_sen = Constants.PropNTt["MidReproductive"] * thisCrop.TtEmergToMat; thisCrop.Xo_cov = thisCrop.Xo_Biomass * 0.4 / cropParams.rCover; thisCrop.b_cov = thisCrop.Xo_cov * 0.2; if (cropParams.TypicalYieldUnits == "kg/head") From 41a283d01d9cf36011d6d78199f9bcd6a9a833de Mon Sep 17 00:00:00 2001 From: Timothy Miller Date: Sun, 2 Jun 2024 10:12:44 +1200 Subject: [PATCH 08/10] feat: update nuget package version --- SVSModel/README.md | 2 +- SVSModel/SVSModel.csproj | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/SVSModel/README.md b/SVSModel/README.md index f6c69c1..26f49a3 100644 --- a/SVSModel/README.md +++ b/SVSModel/README.md @@ -6,5 +6,5 @@ $ dotnet pack SVSModel/SVSModel.csproj ``` ```bash -$ dotnet nuget push SVSModel/bin/Release/SVSModel.1.1.8.nupkg --source "https://pkgs.dev.azure.com/rezaresystems/48ae16c6-5f20-44a0-ad41-e047c311de0a/_packaging/svs-model-calculator/nuget/v3/index.json" --api-key az --interactive +$ dotnet nuget push SVSModel/bin/Release/SVSModel.1.1.16.nupkg --source "https://pkgs.dev.azure.com/rezaresystems/48ae16c6-5f20-44a0-ad41-e047c311de0a/_packaging/svs-model-calculator/nuget/v3/index.json" --api-key az --interactive ``` \ No newline at end of file diff --git a/SVSModel/SVSModel.csproj b/SVSModel/SVSModel.csproj index 9ad0001..ce9cca6 100644 --- a/SVSModel/SVSModel.csproj +++ b/SVSModel/SVSModel.csproj @@ -2,7 +2,7 @@ netstandard2.0 SVSModel - 1.1.8 + 1.1.16 PotatoesNZ A wrapper of the SVS Model code 12 From 5e0a126b38cb2cf5ae97eefb8d268f0762226ed1 Mon Sep 17 00:00:00 2001 From: Timothy Miller Date: Mon, 3 Jun 2024 11:27:45 +1200 Subject: [PATCH 09/10] fix: bad naming pattern on these constants --- SVSModel/Configuration/Constants.cs | 4 ++-- SVSModel/Models/Crop.cs | 11 +++++------ 2 files changed, 7 insertions(+), 8 deletions(-) diff --git a/SVSModel/Configuration/Constants.cs b/SVSModel/Configuration/Constants.cs index 188d9f5..df53257 100644 --- a/SVSModel/Configuration/Constants.cs +++ b/SVSModel/Configuration/Constants.cs @@ -12,7 +12,7 @@ public static class Constants public const double InitialN = 50; /// Dictionary containing values for the proportion of maximum DM that occurs at each predefined crop stage - public static readonly Dictionary PropNMaxDM = new() + public static readonly Dictionary ProportionMaxDM = new() { { "Seed", 0.004 }, { "Seedling", 0.011 }, @@ -25,7 +25,7 @@ public static class Constants }; /// Dictionary containing values for the proportion of thermal time to maturity that has accumulated at each predefined crop stage - public static readonly Dictionary PropNTt = new() + public static readonly Dictionary ProportionTt = new() { { "Seed", -0.0517 }, { "Seedling", 0.050 }, diff --git a/SVSModel/Models/Crop.cs b/SVSModel/Models/Crop.cs index 53074a9..2226b8f 100644 --- a/SVSModel/Models/Crop.cs +++ b/SVSModel/Models/Crop.cs @@ -21,8 +21,7 @@ public class Crop /// An array containing the accumulated thermal time for the duration of the crop /// A specific class that holds all the simulation configuration data in the correct types for use in the model /// A 2D array of crop model outputs - public static CropType Grow(Dictionary meanT, - CropConfig cf) + public static CropType Grow(Dictionary meanT, CropConfig cf) { CropType thisCrop = new CropType(); @@ -41,19 +40,19 @@ public static CropType Grow(Dictionary meanT, thisCrop.TtSowToEmerg = cropParams.TtSowtoEmerge; } - double PropnTt_EstToHarv = Constants.PropNTt[cf.HarvestStage] - Math.Max(Constants.PropNTt[cf.EstablishStage], 0); //Constants.PropNTt["Emergence"]); + double PropnTt_EstToHarv = Constants.ProportionTt[cf.HarvestStage] - Math.Max(Constants.ProportionTt[cf.EstablishStage], 0); //Constants.PropNTt["Emergence"]); thisCrop.TtEmergToMat = (thisCrop.TtEstabToHarv - thisCrop.TtSowToEmerg) * 1 / PropnTt_EstToHarv; thisCrop.TtEmergToSeedling = 0; if (cf.EstablishStage == "Seedling") { - thisCrop.TtEmergToSeedling = thisCrop.TtEmergToMat * Constants.PropNTt["Seedling"]; + thisCrop.TtEmergToSeedling = thisCrop.TtEmergToMat * Constants.ProportionTt["Seedling"]; } thisCrop.Xo_Biomass = thisCrop.TtEmergToMat * 0.5; thisCrop.b_Biomass = thisCrop.Xo_Biomass * .2; - thisCrop.T_maxRD = Constants.PropNTt["EarlyReproductive"] * thisCrop.TtEmergToMat; - thisCrop.T_sen = Constants.PropNTt["MidReproductive"] * thisCrop.TtEmergToMat; + thisCrop.T_maxRD = Constants.ProportionTt["EarlyReproductive"] * thisCrop.TtEmergToMat; + thisCrop.T_sen = Constants.ProportionTt["MidReproductive"] * thisCrop.TtEmergToMat; thisCrop.Xo_cov = thisCrop.Xo_Biomass * 0.4 / cropParams.rCover; thisCrop.b_cov = thisCrop.Xo_cov * 0.2; if (cropParams.TypicalYieldUnits == "kg/head") From 096d1bba3d4c6e3e6c71270b301e547c56cdcc40 Mon Sep 17 00:00:00 2001 From: Timothy Miller Date: Mon, 3 Jun 2024 11:32:14 +1200 Subject: [PATCH 10/10] feat: release new nuget version --- SVSModel/README.md | 2 +- SVSModel/SVSModel.csproj | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/SVSModel/README.md b/SVSModel/README.md index 26f49a3..f700c57 100644 --- a/SVSModel/README.md +++ b/SVSModel/README.md @@ -6,5 +6,5 @@ $ dotnet pack SVSModel/SVSModel.csproj ``` ```bash -$ dotnet nuget push SVSModel/bin/Release/SVSModel.1.1.16.nupkg --source "https://pkgs.dev.azure.com/rezaresystems/48ae16c6-5f20-44a0-ad41-e047c311de0a/_packaging/svs-model-calculator/nuget/v3/index.json" --api-key az --interactive +$ dotnet nuget push SVSModel/bin/Release/SVSModel.1.1.17.nupkg --source "https://pkgs.dev.azure.com/rezaresystems/48ae16c6-5f20-44a0-ad41-e047c311de0a/_packaging/svs-model-calculator/nuget/v3/index.json" --api-key az --interactive ``` \ No newline at end of file diff --git a/SVSModel/SVSModel.csproj b/SVSModel/SVSModel.csproj index ce9cca6..d15d42b 100644 --- a/SVSModel/SVSModel.csproj +++ b/SVSModel/SVSModel.csproj @@ -2,7 +2,7 @@ netstandard2.0 SVSModel - 1.1.16 + 1.1.17 PotatoesNZ A wrapper of the SVS Model code 12