removed 0.54 factor; fix farm totals; added miterra crop input
All checks were successful
FarmMaps.Develop/CarbonLib/pipeline/head This commit looks good

This commit is contained in:
2021-06-29 14:56:27 +02:00
parent 6554e059df
commit 110815f7ea
2 changed files with 40 additions and 26 deletions

View File

@@ -146,30 +146,46 @@ namespace FarmMapsAPI.Carbon
{
foreach (var cropYear in crops.Crops)
{
var cropMapping = mappingCropFarmmapsMiterraRothC.FirstOrDefault(x => x.CropCode == cropYear.CropCode);
if (cropMapping != null)
if (!string.IsNullOrEmpty(cropYear.MiterraCropName))
{
var orgManure = new List<OrganicManureType>();
if (cropYear.OrganicManures != null)
mappedCropData.Add(new HistoricalCropData
{
foreach (var manure in cropYear.OrganicManures)
{
orgManure.Add(new OrganicManureType { Type = manure.Type, Quantity = manure.Quantity });
}
}
var crop = mappedCropData.SingleOrDefault(x => x.Year == crops.Year);
if (crop == null)
{
mappedCropData.Add(new HistoricalCropData { Year = crops.Year, Crops = new List<OrgManureApplied> { new OrgManureApplied { Crop = cropMapping.MiterraRothCCrop, OrganicManures = orgManure, CropYield = cropYear.CropYield } } });
}
else
{
crop.Crops.Add(new OrgManureApplied { Crop = cropMapping.MiterraRothCCrop, OrganicManures = orgManure, CropYield = cropYear.CropYield, CropRes = cropYear.CropRes });
}
Year = crops.Year,
Crops = new List<OrgManureApplied> {
new OrgManureApplied {
Crop = cropYear.MiterraCropName,
OrganicManures =
cropYear.OrganicManures.Select(x => new OrganicManureType { Type = x.Type, Quantity = x.Quantity }).ToList(),
CropYield = cropYear.CropYield } }
});
}
else
{
mappedCropData.Add(new HistoricalCropData { Year = crops.Year, Crops = new List<OrgManureApplied> { new OrgManureApplied { Crop = cropYear.CropCode, OrganicManures = null, CropYield = cropYear.CropYield } } });
var cropMapping = mappingCropFarmmapsMiterraRothC.FirstOrDefault(x => x.CropCode == cropYear.CropCode);
if (cropMapping != null)
{
var orgManure = new List<OrganicManureType>();
if (cropYear.OrganicManures != null)
{
foreach (var manure in cropYear.OrganicManures)
{
orgManure.Add(new OrganicManureType { Type = manure.Type, Quantity = manure.Quantity });
}
}
var crop = mappedCropData.SingleOrDefault(x => x.Year == crops.Year);
if (crop == null)
{
mappedCropData.Add(new HistoricalCropData { Year = crops.Year, Crops = new List<OrgManureApplied> { new OrgManureApplied { Crop = cropMapping.MiterraRothCCrop, OrganicManures = orgManure, CropYield = cropYear.CropYield } } });
}
else
{
crop.Crops.Add(new OrgManureApplied { Crop = cropMapping.MiterraRothCCrop, OrganicManures = orgManure, CropYield = cropYear.CropYield, CropRes = cropYear.CropRes });
}
}
else
{
mappedCropData.Add(new HistoricalCropData { Year = crops.Year, Crops = new List<OrgManureApplied> { new OrgManureApplied { Crop = cropYear.CropCode, OrganicManures = null, CropYield = cropYear.CropYield } } });
}
}
}
@@ -1493,10 +1509,6 @@ namespace FarmMapsAPI.Carbon
sumCarbonGreenManure += item.Value.SingleOrDefault(x => x.Key == "CarbonGreenManure")?.Value ?? 0;
sumCarbonCompost += item.Value.SingleOrDefault(x => x.Key == "CarbonCompost")?.Value ?? 0;
}
sumCarbonManure = sumCarbonManure / 0.54;
sumCarbonResidues = sumCarbonResidues / 0.54;
sumCarbonGreenManure = sumCarbonGreenManure / 0.54;
sumCarbonCompost = sumCarbonCompost / 0.54;
soc_Summary[(fieldLoop, yLoop)].Add(new ColumnValue("SOC_CarbonManure", sumCarbonManure));
soc_Summary[(fieldLoop, yLoop)].Add(new ColumnValue("SOC_CarbonResidues", sumCarbonResidues));
soc_Summary[(fieldLoop, yLoop)].Add(new ColumnValue("SOC_CarbonGreenManure", sumCarbonGreenManure));
@@ -1518,7 +1530,7 @@ namespace FarmMapsAPI.Carbon
var crpField = cropFieldSummary.Single(x => x.Name == item.Key.Item1);
var summary = crpField.Summary.Single(x => x.Year == item.Key.Item2);
summary.Balance = sum / 0.54;
summary.Balance = sum;
}
foreach (var item in socIni)
@@ -1639,13 +1651,14 @@ namespace FarmMapsAPI.Carbon
foreach (var item in soc_Summary.Where(x=>x.Key.Item2 == farm.Key.Item2))
{
var cropfieldArea = item.Value.SingleOrDefault(x => x.Key == "Total_crop_area")?.Value ?? 0;
sumCarbonMan += item.Value.SingleOrDefault(x => x.Key == "SOC_CarbonManure")?.Value ?? 0;
sumCarbonRes += item.Value.SingleOrDefault(x => x.Key == "SOC_CarbonResidues")?.Value ?? 0;
sumCarbonGreenMan += item.Value.SingleOrDefault(x => x.Key == "SOC_CarbonGreenManure")?.Value ?? 0;
sumCarbonCom += item.Value.SingleOrDefault(x => x.Key == "SOC_CarbonCompost")?.Value ?? 0;
sumEmision += item.Value.SingleOrDefault(x => x.Key == "Emision")?.Value ?? 0;
sumBal += item.Value.SingleOrDefault(x => x.Key == "Balance")?.Value / 0.54 ?? 0;
sumBal += item.Value.SingleOrDefault(x => x.Key == "Balance")?.Value * cropfieldArea ?? 0;
sumIni += item.Value.SingleOrDefault(x => x.Key == "Initial")?.Value ?? 0;
sumInicc += item.Value.SingleOrDefault(x => x.Key == "IniCcontent")?.Value ?? 0;
}
@@ -1708,7 +1721,7 @@ namespace FarmMapsAPI.Carbon
var soilPropertiesField = new Dictionary<string, SoilPropertyType>();
foreach (var field in farmInput.CropFields)
{
soilPropertiesField.Add(field.Name, new SoilPropertyType { OM_Cont = field.SoilProperty.OM_Const.Value, Clay_Content = field.SoilProperty.Clay_Content.Value, OM_Corr = field.SoilProperty.OM_Const.Value });
soilPropertiesField.Add(field.Name, new SoilPropertyType { OM_Cont = field.SoilProperty.OM_Const.Value, Clay_Content = field.SoilProperty.Clay_Content.Value, OM_Corr = field.SoilProperty.OM_Const.Value <= 20 ? field.SoilProperty.OM_Const.Value : 0 });
}
return soilPropertiesField;