moved to logic from api to lib
All checks were successful
FarmMaps.Develop/CarbonLib/pipeline/head This commit looks good

This commit is contained in:
2021-06-21 10:25:05 +02:00
parent 28dbf4d098
commit bd98adc4cb
49 changed files with 60894 additions and 0 deletions

97
Models/CarbonRequest.cs Normal file
View File

@@ -0,0 +1,97 @@
using NetTopologySuite.Geometries;
using Newtonsoft.Json;
using Newtonsoft.Json.Converters;
using System;
using System.Collections.Generic;
using System.ComponentModel.DataAnnotations;
using System.Linq;
using System.Runtime.Serialization;
using System.Threading.Tasks;
namespace CarbonService.Models
{
public class CarbonRequest
{
public Geometry geometry { get; set; }
[Required]
public int PostalCode { get; set; }
public List<CropField> CropFields { get; set; }
//public List<OrgManureApplied> OrgManureApplied { get; set; }
}
public class CropField
{
[Required]
public string Name { get; set; }
[Required]
public double Area { get; set; }
[Required]
public string SoilType { get; set; }
[Required]
public SoilProperty SoilProperty { get; set; }
[Required]
public List<HistoricalCropData> HistoricalCropData { get; set; }
public List<GreenManure> GreenManures { get; set; }
}
public class SoilProperty
{
public double? OM_Const { get; set; }
public double? Clay_Content { get; set; }
}
public class OrgManureApplied
{
[Required]
public string Crop { get; set; }
public List<OrganicManureType> OrganicManures { get; set; }
public int? CropYield { get; set; }
public bool CropRes { get; set; }
}
public class OrganicManureType
{
[Required]
public string Type { get; set; }
[Required]
public double Quantity { get; set; }
}
public class HistoricalCropData
{
[Required]
public int Year { get; set; }
//[Required]
//public List<string> Crops { get; set; }
[Required]
public List<OrgManureApplied> Crops { get; set; }
}
public class GreenManure
{
[Required]
public int Year { get; set; }
[Required]
public List<GreenManureType> GreenManureTypes { get; set; }
}
public class GreenManureType
{
[Required]
public string Type { get; set; }
//public string Quality { get; set; }
[JsonConverter(typeof(StringEnumConverter))]
public Quality Quality { get; set; }
}
public enum Quality
{
[EnumMember(Value = "Goed")]
Good,
[EnumMember(Value = "Matig")]
Average,
[EnumMember(Value = "Slecht")]
Bad
}
}

83
Models/CarbonSummary.cs Normal file
View File

@@ -0,0 +1,83 @@
using Newtonsoft.Json;
using System;
using System.Collections.Generic;
using System.Text;
namespace FarmMapsAPI.Carbon.Models
{
public class CarbonSummary
{
[JsonProperty("cropField")]
public List<CropFieldSummary> CropField { get; set; }
[JsonProperty("farmSummary")]
public List<FarmYearSummary> FarmSummary { get; set; }
}
public class CropFieldSummary
{
[JsonProperty("name")]
public string Name { get; set; }
[JsonProperty("summary")]
public List<YearSummary> Summary { get; set; }
}
public class YearSummary
{
[JsonProperty("year")]
public int Year { get; set; }
[JsonProperty("bulk_Density")]
public double Bulk_Density { get; set; }
[JsonProperty("total_crop_area")]
public double Total_crop_area { get; set; }
[JsonProperty("balance")]
public double Balance { get; set; }
[JsonProperty("initial")]
public double Initial { get; set; }
[JsonProperty("iniCcontent")]
public double IniCcontent { get; set; }
[JsonProperty("oM_ini")]
public double OM_ini { get; set; }
[JsonProperty("cO2seq")]
public double CO2seq { get; set; }
[JsonProperty("soC_CarbonCompost")]
public double SOC_CarbonCompost { get; set; }
[JsonProperty("soC_CarbonGreenManure")]
public double SOC_CarbonGreenManure { get; set; }
[JsonProperty("soC_CarbonResidues")]
public double SOC_CarbonResidues { get; set; }
[JsonProperty("soC_CarbonManure")]
public double SOC_CarbonManure { get; set; }
[JsonProperty("emision")]
public double Emision { get; set; }
}
public class FarmYearSummary
{
[JsonProperty("year")]
public int Year { get; set; }
[JsonProperty("total_crop_area")]
public double Total_crop_area { get; set; }
[JsonProperty("balance")]
public double Balance { get; set; }
[JsonProperty("initial")]
public double Initial { get; set; }
[JsonProperty("iniCcontent")]
public double IniCcontent { get; set; }
[JsonProperty("oM_ini")]
public double OM_ini { get; set; }
[JsonProperty("cO2seq")]
public double CO2seq { get; set; }
[JsonProperty("cO2seq_total")]
public double CO2seq_total { get; set; }
[JsonProperty("soC_CarbonCompost")]
public double SOC_CarbonCompost { get; set; }
[JsonProperty("soC_CarbonGreenManure")]
public double SOC_CarbonGreenManure { get; set; }
[JsonProperty("soC_CarbonResidues")]
public double SOC_CarbonResidues { get; set; }
[JsonProperty("soC_CarbonManure")]
public double SOC_CarbonManure { get; set; }
[JsonProperty("emision")]
public double Emision { get; set; }
}
}

20
Models/ClimateVariable.cs Normal file
View File

@@ -0,0 +1,20 @@
using System;
using System.Collections.Generic;
using System.Text;
namespace FarmMapsAPI.Carbon.Models
{
public class ClimateVariable
{
public double Temperature { get; set; }
public double Precipitation { get; set; }
public double Evapotranspiration { get; set; }
public ClimateVariable(double temperature, double precipitation, double evapoTranspiration)
{
Temperature = temperature;
Precipitation = precipitation;
Evapotranspiration = evapoTranspiration;
}
}
}

30
Models/ColumnValue.cs Normal file
View File

@@ -0,0 +1,30 @@
using System;
using System.Collections.Generic;
using System.Text;
namespace FarmMapsAPI.Carbon.Models
{
public class ColumnValue
{
public string Key { get; set; }
public double Value { get; set; }
public ColumnValue(string key, double value)
{
Key = key;
Value = value;
}
}
public class YearColumnValue
{
public int Key { get; set; }
public double Value { get; set; }
public YearColumnValue(int key, double value)
{
Key = key;
Value = value;
}
}
}

View File

@@ -0,0 +1,12 @@
using System;
using System.Collections.Generic;
using System.Text;
namespace FarmMapsAPI.Carbon.Models
{
public class CropCoverMonthsModel
{
public string CropName { get; set; }
public List<string> CoverMonths { get; set; }
}
}

View File

@@ -0,0 +1,16 @@
using System;
using System.Collections.Generic;
using System.Text;
namespace FarmMapsAPI.Carbon.Models
{
public class CropPropertyModel
{
public string Name { get; set; }
public double DM_content { get; set; }
public double FracR { get; set; }
public double C_input_CropRes { get; set; }
public double HarvestIndex { get; set; }
}
}

19
Models/CropSets.cs Normal file
View File

@@ -0,0 +1,19 @@
using System;
using System.Collections.Generic;
using System.Text;
namespace FarmMapsAPI.Carbon.Models
{
public class StrawCrp
{
public string StrawCrop { get; set; }
public double DM_Content { get; set; }
}
public class CropSets
{
public List<StrawCrp> StrawCrops { get; set; }
public List<string> GreenManureType { get; set; }
public List<string> Perennial { get; set; }
}
}

24
Models/CropYieldModel.cs Normal file
View File

@@ -0,0 +1,24 @@
using System;
using System.Collections.Generic;
using System.Text;
namespace FarmMapsAPI.Carbon.Models
{
public class YearData
{
public int Year { get; set; }
public double YieldValue { get; set; }
}
public class Yield
{
public string ProvinceCode { get; set; }
public List<YearData> YearData { get; set; }
}
public class CropYieldModel
{
public string CropName { get; set; }
public List<Yield> Yields { get; set; }
}
}

View File

@@ -0,0 +1,25 @@
using System;
using System.Collections.Generic;
using System.Text;
namespace FarmMapsAPI.Carbon.Models
{
public class ManureSourcesLiv
{
public string ManureSource_liv { get; set; }
public string Description { get; set; }
}
public class Compost
{
public string compost { get; set; }
public string Description { get; set; }
}
public class FarmInputsetsModel
{
public List<ManureSourcesLiv> ManureSources_liv { get; set; }
public List<Compost> composts { get; set; }
public List<string> CarbonSource { get; set; }
}
}

View File

@@ -0,0 +1,93 @@
//using CarbonService.Models;
using NetTopologySuite.Geometries;
using Newtonsoft.Json.Converters;
using System;
using System.Collections.Generic;
using System.ComponentModel.DataAnnotations;
using System.Linq;
using System.Runtime.Serialization;
using System.Text.Json.Serialization;
using System.Threading.Tasks;
namespace FarmMapsAPI.Carbon.Models
{
public class FarmMapsCarbonRequest
{
public int PostalCode { get; set; }
public List<CropFieldFarmMaps> CropFields { get; set; }
//added
public int CalculateUntil { get; set; }
}
public class CropFieldFarmMaps
{
[Required]
public string Name { get; set; }
[Required]
public double Area { get; set; }
[Required]
public string SoilType { get; set; }
[Required]
public SoilPropertyFarmMaps SoilProperty { get; set; }
[Required]
public List<HistoricalCropDataFarmMaps> HistoricalCropData { get; set; }
}
public class HistoricalCropDataFarmMaps
{
[Required]
public int Year { get; set; }
[Required]
public List<CropData> Crops { get; set; }
public List<GreenManureTypeFarmMaps> GreenManures { get; set; }
public bool Rotation { get; set; }
public HistoricalCropDataFarmMaps DeepCopy()
{
HistoricalCropDataFarmMaps other = (HistoricalCropDataFarmMaps)this.MemberwiseClone();
return other;
}
}
public class CropData
{
[Required]
public string CropCode { get; set; }
public List<OrganicManureFarmMaps> OrganicManures { get; set; }
public int? CropYield { get; set; }
public bool CropRes { get; set; }
}
public class OrganicManureFarmMaps
{
[Required]
public string Type { get; set; }
[Required]
public double Quantity { get; set; }
}
public class SoilPropertyFarmMaps
{
public double? OM_Const { get; set; }
public double? Clay_Content { get; set; }
}
public class GreenManureTypeFarmMaps
{
public string CropCode { get; set; }
[JsonConverter(typeof(StringEnumConverter))]
public QualityFarmMaps? Quality { get; set; }
}
public enum QualityFarmMaps
{
[EnumMember(Value = "Goed")]
Good,
[EnumMember(Value = "Matig")]
Average,
[EnumMember(Value = "Slecht")]
Bad
}
}

15
Models/GIS_Soils_Sets.cs Normal file
View File

@@ -0,0 +1,15 @@
using System;
using System.Collections.Generic;
using System.Text;
namespace FarmMapsAPI.Carbon.Models
{
public class GIS_Soils_Sets
{
public List<string> SoilType { get; set; }
public List<string> MineralSoils { get; set; }
public List<string> Months { get; set; }
public List<string> AllMonths { get; set; }
public List<string> ClimateVar { get; set; }
}
}

62
Models/GamsParameter.cs Normal file
View File

@@ -0,0 +1,62 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
namespace FarmMapsAPI.Carbon.Models
{
public class GamsThreeKeyParameter
{
//field, year, crop
public Dictionary<(string,int,string), List<ColumnValue>> TrippleKeyParam { get; set; }
public GamsThreeKeyParameter()
{
TrippleKeyParam = new Dictionary<(string, int, string), List<ColumnValue>>();
}
public void AddValue((string, int, string)key, string column, double value)
{
if (TrippleKeyParam.ContainsKey(key))
{
if (TrippleKeyParam[key].Any(x => x.Key == column))
{
throw new Exception("key allready exists");
}
else
{
TrippleKeyParam[key].Add(new ColumnValue(column, value));
}
}
else
{
TrippleKeyParam.Add(key, new List<ColumnValue> { new ColumnValue(column, value) });
}
}
public void AddValueSkipIfColumnExists((string, int, string) key, string column, double value)
{
if (TrippleKeyParam.ContainsKey(key))
{
if (TrippleKeyParam[key].Any(x => x.Key == column))
{
return;
}
else
{
TrippleKeyParam[key].Add(new ColumnValue(column, value));
}
}
else
{
TrippleKeyParam.Add(key, new List<ColumnValue> { new ColumnValue(column, value) });
}
}
public List<(string, int, string)> KeysWhereCropKeyExists(int year, string crop)
{
//return TrippleKeyParam.Where(x => x.Value.Any(y => y.Key == column)).Select(s=>s.Key).ToList();
return TrippleKeyParam.Where(x => x.Key.Item2 == year && x.Key.Item3.ToLower() == crop.ToLower()).Select(s=>s.Key).ToList();
}
}
}

12
Models/ManCcontModel.cs Normal file
View File

@@ -0,0 +1,12 @@
using System;
using System.Collections.Generic;
using System.Text;
namespace FarmMapsAPI.Carbon.Models
{
public class ManCcontModel
{
public string ManCcont { get; set; }
public double Value { get; set; }
}
}

View File

@@ -0,0 +1,16 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Threading.Tasks;
namespace FarmMapsAPI.Carbon.Models
{
public class MappingCropFarmmapsMiterraRothC
{
public string CropCode { get; set; }
public string CropName { get; set; }
public string PurposeCode { get; set; }
public string PurposeName { get; set; }
public string MiterraRothCCrop { get; set; }
}
}

View File

@@ -0,0 +1,16 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Threading.Tasks;
namespace FarmMapsAPI.Carbon.Models
{
public class MappingGreenManureFarmmapsMiterraRothC
{
public string CropCode { get; set; }
public string CropName { get; set; }
public string PurposeCode { get; set; }
public string PurposeName { get; set; }
public string MiterraRothCCrop { get; set; }
}
}

18
Models/ParameterSet.cs Normal file
View File

@@ -0,0 +1,18 @@
using System;
using System.Collections.Generic;
using System.Text;
namespace FarmMapsAPI.Carbon.Models
{
public class ParameterSet
{
public double LayerDepth { get; set; }
public double kDPM { get; set; }
public double kRPM { get; set; }
public double kBIO { get; set; }
public double kHUM { get; set; }
public double StubbleFraction { get; set; }
public double CarbonBiomass { get; set; }
public double FracBelowGroundCinput { get; set; }
}
}

View File

@@ -0,0 +1,24 @@
using System;
using System.Collections.Generic;
using System.Text;
namespace FarmMapsAPI.Carbon.Models
{
public class KNMIZoneReg
{
public string KNMI_zone { get; set; }
public List<int> Reg { get; set; }
}
public class NUTS0NUTSII
{
public string prov { get; set; }
public List<int> reg { get; set; }
}
public class SetsForDataTransformation
{
public List<KNMIZoneReg> KNMI_zone_Reg { get; set; }
public List<NUTS0NUTSII> NUTS0NUTSII { get; set; }
}
}

View File

@@ -0,0 +1,12 @@
using System;
using System.Collections.Generic;
using System.Text;
namespace FarmMapsAPI.Carbon.Models
{
public class SoilBulkDensityType
{
public double Clay { get; set; }
public double Sand { get; set; }
}
}

View File

@@ -0,0 +1,39 @@
using System;
using System.Collections.Generic;
using System.Text;
namespace FarmMapsAPI.Carbon.Models
{
public class SoilPropertyType
{
public double OM_Cont { get; set; }
public double OM_Corr { get; set; }
public double Bulk_Density { get; set; }
public double Clay_Content { get; set; }
public double Depth { get; set; }
}
struct SoilTypePropertyKey
{
public string SoilType { get; set; }
public string SoilProperty{ get; set; }
public override int GetHashCode()
{
return SoilType.GetHashCode() ^ SoilProperty.GetHashCode();
}
public override bool Equals(object obj)
{
if (obj is SoilTypePropertyKey)
{
SoilTypePropertyKey compositeKey = (SoilTypePropertyKey)obj;
return ((this.SoilType == compositeKey.SoilType) &&
(this.SoilProperty == compositeKey.SoilProperty));
}
return false;
}
}
}

View File

@@ -0,0 +1,14 @@
using System;
using System.Collections.Generic;
using System.Text;
namespace FarmMapsAPI.Carbon.Models
{
public class YieldGreenManureModel
{
public string ManureName { get; set; }
public double GoodQuality { get; set; }
public double AverageQuality { get; set; }
public double BadQuality { get; set; }
}
}