diff --git a/CarbonCalculation.cs b/CarbonCalculation.cs index 707d264..c48f6c1 100644 --- a/CarbonCalculation.cs +++ b/CarbonCalculation.cs @@ -568,9 +568,9 @@ namespace FarmMapsAPI.Carbon var valueList = new List(); foreach (var stubbleKeyValue in stubbleC.Value) { - var dmYieldValue = dm_Yield_Field[stubbleC.Key].Single(s => s.Key == stubbleKeyValue.Key); - var strawYieldValue = strawYield[stubbleC.Key].Single(s => s.Key == stubbleKeyValue.Key); - var dmContentStraw = cropSet.StrawCrops.Single(s => s.StrawCrop == stubbleKeyValue.Key); + var dmYieldValue = dm_Yield_Field[stubbleC.Key].Single(s => s.Key.ToLower() == stubbleKeyValue.Key.ToLower()); + var strawYieldValue = strawYield[stubbleC.Key].Single(s => s.Key.ToLower() == stubbleKeyValue.Key.ToLower()); + var dmContentStraw = cropSet.StrawCrops.Single(s => s.StrawCrop.ToLower() == stubbleKeyValue.Key.ToLower()); var result = ((dmYieldValue.Value + ((stubbleKeyValue.Value + strawYieldValue.Value) * dmContentStraw.DM_Content)) * parameterSet.CarbonBiomass) / ((1 / parameterSet.FracBelowGroundCinput) - 1); valueList.Add(new ColumnValue(stubbleKeyValue.Key, result)); @@ -613,7 +613,7 @@ namespace FarmMapsAPI.Carbon { result = 12000; } - carbonInputs.AddValue((cropArea.Key.Item1, cropArea.Key.Item2, crop.Key), "CarbonResidues", result); + carbonInputs.AddOrUpdateValue((cropArea.Key.Item1, cropArea.Key.Item2, crop.Key), "CarbonResidues", result); } } } diff --git a/Models/GamsParameter.cs b/Models/GamsParameter.cs index 48a69d0..5d98372 100644 --- a/Models/GamsParameter.cs +++ b/Models/GamsParameter.cs @@ -34,6 +34,25 @@ namespace FarmMapsAPI.Carbon.Models } } + public void AddOrUpdateValue((string, int, string) key, string column, double value) + { + if (TrippleKeyParam.ContainsKey(key)) + { + if (TrippleKeyParam[key].Any(x => x.Key == column)) + { + TrippleKeyParam[key].Single(x => x.Key == column).Value = value; + } + else + { + TrippleKeyParam[key].Add(new ColumnValue(column, value)); + } + } + else + { + TrippleKeyParam.Add(key, new List { new ColumnValue(column, value) }); + } + } + public void AddValueSkipIfColumnExists((string, int, string) key, string column, double value) { if (TrippleKeyParam.ContainsKey(key)) diff --git a/config/CropSets.json b/config/CropSets.json index 3bbc864..52b6d11 100644 --- a/config/CropSets.json +++ b/config/CropSets.json @@ -4,6 +4,10 @@ "StrawCrop": "Maize", "DM_Content": 0.7 }, + { + "StrawCrop": "Fodder_maize", + "DM_Content": 0.85 + }, { "StrawCrop": "Corn_cob_mix", "DM_Content": 0.7