Skip to content

Commit

Permalink
Add template project
Browse files Browse the repository at this point in the history
  • Loading branch information
holos-aafc committed Aug 20, 2024
1 parent dc8235f commit 4404de4
Show file tree
Hide file tree
Showing 15 changed files with 375 additions and 23 deletions.
14 changes: 7 additions & 7 deletions H.Core/Calculators/Climate/ClimateNormalCalculator.cs
Original file line number Diff line number Diff line change
Expand Up @@ -226,21 +226,21 @@ public Dictionary<MonthlyNormalTypes, Dictionary<Months, double>> GetNormalsForA
int startYear = customTimeFrameStart;
int endYear = customTimeFrameEnd;

//Precipitation}
// Precipitation
var precipNormal = new Dictionary<Months, double>();
var listOfPrecips = new List<SpecificClimateValueType>();

//Temperature
// Temperature
var temperatureNormals = new Dictionary<Months, double>();
var listOfTemperatures = new List<SpecificClimateValueType>();

//Evapotranspiration
// Evapotranspiration
var evapotransNormals = new Dictionary<Months, double>();
var listOfEvapotrans = new List<SpecificClimateValueType>();

foreach (var item in customClimateDatas)
{
//precip values
// Precipitation values
var precip = new SpecificClimateValueType()
{
ClimateNormalType = ClimateType.Precipitation,
Expand All @@ -250,7 +250,7 @@ public Dictionary<MonthlyNormalTypes, Dictionary<Months, double>> GetNormalsForA
};
listOfPrecips.Add(precip);

//temperature values
// Temperature values
var temperature = new SpecificClimateValueType()
{
ClimateNormalType = ClimateType.Temperature,
Expand All @@ -260,7 +260,7 @@ public Dictionary<MonthlyNormalTypes, Dictionary<Months, double>> GetNormalsForA
};
listOfTemperatures.Add(temperature);

//evapotrans value
// Evapotranspiration values
var evapotrans = new SpecificClimateValueType()
{
ClimateNormalType = ClimateType.Evapotranspiration,
Expand All @@ -271,7 +271,7 @@ public Dictionary<MonthlyNormalTypes, Dictionary<Months, double>> GetNormalsForA
listOfEvapotrans.Add(evapotrans);
}

//Get the normals for each month
// Get the normals for each month
foreach (var months in Enum.GetValues(typeof(Months)).Cast<Months>())
{
var m = GetStartandEndJulianDays(months);
Expand Down
1 change: 1 addition & 0 deletions H.Core/Calculators/Climate/ClimateService.cs
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
using System.Diagnostics;
using System;
using System.Linq;
using H.Core.Services.Initialization.Climate;

namespace H.Core.Calculators.Climate
{
Expand Down
1 change: 0 additions & 1 deletion H.Core/Enumerations/CropTypeExtensions.cs
Original file line number Diff line number Diff line change
Expand Up @@ -419,7 +419,6 @@ public static IOrderedEnumerable<CropType> GetValidCropTypes()
{
return new List<CropType>
{
//CropType.NotSelected,
CropType.Barley,
CropType.BarleySilage,
CropType.BeansDryField,
Expand Down
4 changes: 4 additions & 0 deletions H.Core/H.Core.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -663,6 +663,8 @@
<Compile Include="Services\Initialization\Animals\AnimalInitializationService.Sheep.cs" />
<Compile Include="Services\Initialization\Animals\AnimalInitializationService.Diet.cs" />
<Compile Include="Services\Initialization\Animals\IAnimalInitializationService.cs" />
<Compile Include="Services\Initialization\Climate\ClimateInitializationService.cs" />
<Compile Include="Services\Initialization\Climate\IClimateInitializationService.cs" />
<Compile Include="Services\Initialization\Crops\CropInitializationService.cs" />
<Compile Include="Services\Initialization\Crops\CropInitializationService.Carbon.cs" />
<Compile Include="Services\Initialization\Crops\CropInitializationService.Yield.cs" />
Expand All @@ -681,6 +683,8 @@
<Compile Include="Services\Initialization\Crops\CropInitializationService.Grazing.cs" />
<Compile Include="Services\Initialization\Crops\CropInitializationService.CoverCrops.cs" />
<Compile Include="Services\Initialization\Crops\ICropInitializationService.cs" />
<Compile Include="Services\Initialization\Geography\GeographyInitializationService.cs" />
<Compile Include="Services\Initialization\Geography\IGeographyInitializationService.cs" />
<Compile Include="Services\Initialization\IInitializationService.cs" />
<Compile Include="Services\Initialization\InitializationService.cs" />
<Compile Include="Services\LandManagement\FieldResultsService.DetailViewItems.cs" />
Expand Down
3 changes: 3 additions & 0 deletions H.Core/Models/Farm.cs
Original file line number Diff line number Diff line change
Expand Up @@ -231,6 +231,9 @@ public ObservableCollection<DefaultManureCompositionData> DefaultManureCompositi

public ObservableCollection<Table_30_Default_Bedding_Material_Composition_Data> DefaultsCompositionOfBeddingMaterials { get; set; }

/// <summary>
/// Indicates the location of the farm
/// </summary>
public int PolygonId
{
get { return _polygonId; }
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,56 @@
using System.Collections.ObjectModel;
using System.Linq;
using H.Core.Calculators.Climate;
using H.Core.Models;
using H.Core.Providers.Climate;

namespace H.Core.Services.Initialization.Climate
{
public class ClimateInitializationService : IClimateInitializationService
{
#region Fields

private readonly NasaClimateProvider _nasaClimateProvider;
private readonly ClimateNormalCalculator _climateNormalCalculator;

#endregion

#region Constructors

public ClimateInitializationService()
{
_nasaClimateProvider = new NasaClimateProvider();
_climateNormalCalculator = new ClimateNormalCalculator();
}

#endregion

#region Public Methods

public void InitializeClimate(Farm farm)
{
var dailyClimateData = _nasaClimateProvider.GetCustomClimateData(farm.Latitude, farm.Longitude);

var startYear = dailyClimateData.Min(x => x.Date.Year);
var endYear = dailyClimateData.Max(x => x.Date.Year);

this.InitializeClimate(farm, startYear, endYear);
}

public void InitializeClimate(Farm farm, int startYear, int endYear)
{
var dailyClimateData = _nasaClimateProvider.GetCustomClimateData(farm.Latitude, farm.Longitude);
var climateForPeriod = dailyClimateData.Where(x => x.Date.Year >= startYear && x.Date.Year <= endYear).ToList();
var temperatureNormals = _climateNormalCalculator.GetTemperatureDataByDailyValues(climateForPeriod, startYear, endYear);
var precipitationNormals = _climateNormalCalculator.GetPrecipitationDataByDailyValues(climateForPeriod, startYear, endYear);
var evapotranspirationNormals = _climateNormalCalculator.GetEvapotranspirationDataByDailyValues(climateForPeriod, startYear, endYear);

farm.ClimateData.DailyClimateData.AddRange(climateForPeriod);
farm.ClimateData.EvapotranspirationData = evapotranspirationNormals;
farm.ClimateData.PrecipitationData = precipitationNormals;
farm.ClimateData.TemperatureData = temperatureNormals;
}

#endregion
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
using H.Core.Models;

namespace H.Core.Services.Initialization.Climate
{
public interface IClimateInitializationService
{
void InitializeClimate(Farm farm);
void InitializeClimate(Farm farm, int startYear, int endYear);
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
using H.Core.Models;
using H.Core.Providers;
using H.Core.Providers.Soil;

namespace H.Core.Services.Initialization.Geography
{
public class GeographyInitializationService : IGeographyInitializationService
{
#region Fields

private readonly IGeographicDataProvider _geographicDataProvider;

#endregion

#region Constructors

public GeographyInitializationService()
{
_geographicDataProvider = new GeographicDataProvider();
_geographicDataProvider.Initialize();
}

#endregion

#region Public Methods

public void InitializeGeography(Farm farm)
{
var geographicData = _geographicDataProvider.GetGeographicalData(farm.PolygonId);
if (geographicData.DefaultSoilData == null)
{
geographicData.DefaultSoilData = new SoilData();
}

farm.GeographicData = geographicData;
}

#endregion
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
using H.Core.Models;

namespace H.Core.Services.Initialization.Geography
{
public interface IGeographyInitializationService
{
void InitializeGeography(Farm farm);
}
}
6 changes: 3 additions & 3 deletions H.Core/Services/LandManagement/FieldResultsService.cs
Original file line number Diff line number Diff line change
Expand Up @@ -75,14 +75,14 @@ public partial class FieldResultsService : IFieldResultsService
#region Constructors

public FieldResultsService(
ICBMSoilCarbonCalculator icbmSoilCarbonCalculator,
IPCCTier2SoilCarbonCalculator ipccTier2SoilCarbonCalculator,
ICBMSoilCarbonCalculator icbmSoilCarbonCalculator,
IPCCTier2SoilCarbonCalculator ipccTier2SoilCarbonCalculator,
N2OEmissionFactorCalculator n2OEmissionFactorCalculator,
IInitializationService initializationService)
{
if (initializationService != null)
{
_initializationService = initializationService;
_initializationService = initializationService;
}
else
{
Expand Down
21 changes: 9 additions & 12 deletions H.Integration/Hay LCI/HayLCIIntegrationTest.cs
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,8 @@
using H.Core.Providers.Soil;
using H.Core.Calculators.Carbon;
using H.Core.Calculators.Nitrogen;
using H.Core.Services.Initialization.Climate;
using H.Core.Services.Initialization.Geography;
using H.Core.Test;

namespace H.Integration.Hay_LCI
Expand Down Expand Up @@ -87,6 +89,8 @@ class Table3Item
private string _baseOutputDirectory;
private bool _usingIrrigation;
private List<Table3Item> _slcList;
private IClimateInitializationService _climateInitializationService;
private IGeographyInitializationService _geographyInitializationService;

#endregion

Expand Down Expand Up @@ -126,7 +130,7 @@ public void TestInitialize()

_fertilizerBlendConverter = new FertilizerBlendConverter();


var iCBMSoilCarbonCalculator = new ICBMSoilCarbonCalculator(_climateProvider, _n2OEmissionFactorCalculator);
var n2oEmissionFactorCalculator = new N2OEmissionFactorCalculator(_climateProvider);
var ipcc = new IPCCTier2SoilCarbonCalculator(_climateProvider, n2oEmissionFactorCalculator);
Expand All @@ -137,6 +141,9 @@ public void TestInitialize()

var manureCompositionProvider = new Table_6_Manure_Types_Default_Composition_Provider();
_manureCompositionTypes = manureCompositionProvider.ManureCompositionData;

_climateInitializationService = new ClimateInitializationService();
_geographyInitializationService = new GeographyInitializationService();
}

[TestCleanup]
Expand Down Expand Up @@ -615,17 +622,7 @@ private void AssignClimateData(List<Farm> farms)

foreach (var farm in farms)
{
var nasaClimate = _nasaClimateProvider.GetCustomClimateData(farm.Latitude, farm.Longitude);
var climateForPeriod = nasaClimate.Where(x => x.Date.Year >= startYear && x.Date.Year <= endYear).ToList();
var temperatureNormalsForPeriod = _climateNormalCalculator.GetTemperatureDataByDailyValues(climateForPeriod, startYear, endYear);
var precipitationNormalsForPeriod = _climateNormalCalculator.GetPrecipitationDataByDailyValues(climateForPeriod, startYear, endYear);
var evapotranspirationNormalsForPeriod = _climateNormalCalculator.GetEvapotranspirationDataByDailyValues(climateForPeriod, startYear, endYear);

farm.ClimateData.DailyClimateData.AddRange(climateForPeriod);

farm.ClimateData.EvapotranspirationData = evapotranspirationNormalsForPeriod;
farm.ClimateData.PrecipitationData = precipitationNormalsForPeriod;
farm.ClimateData.TemperatureData = temperatureNormalsForPeriod;
_climateInitializationService.InitializeClimate(farm, startYear, endYear);

currentCount++;

Expand Down
64 changes: 64 additions & 0 deletions H.Template/H.Template.csproj
Original file line number Diff line number Diff line change
@@ -0,0 +1,64 @@
<?xml version="1.0" encoding="utf-8"?>
<Project ToolsVersion="15.0" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
<Import Project="$(MSBuildExtensionsPath)\$(MSBuildToolsVersion)\Microsoft.Common.props" Condition="Exists('$(MSBuildExtensionsPath)\$(MSBuildToolsVersion)\Microsoft.Common.props')" />
<PropertyGroup>
<Configuration Condition=" '$(Configuration)' == '' ">Debug</Configuration>
<Platform Condition=" '$(Platform)' == '' ">AnyCPU</Platform>
<ProjectGuid>{D8488FC4-6BD1-471A-9B82-DA6785492316}</ProjectGuid>
<OutputType>Exe</OutputType>
<RootNamespace>H.Template</RootNamespace>
<AssemblyName>H.Template</AssemblyName>
<TargetFrameworkVersion>v4.8.1</TargetFrameworkVersion>
<FileAlignment>512</FileAlignment>
<AutoGenerateBindingRedirects>true</AutoGenerateBindingRedirects>
<Deterministic>true</Deterministic>
<TargetFrameworkProfile />
</PropertyGroup>
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Debug|AnyCPU' ">
<PlatformTarget>AnyCPU</PlatformTarget>
<DebugSymbols>true</DebugSymbols>
<DebugType>full</DebugType>
<Optimize>false</Optimize>
<OutputPath>bin\Debug\</OutputPath>
<DefineConstants>DEBUG;TRACE</DefineConstants>
<ErrorReport>prompt</ErrorReport>
<WarningLevel>4</WarningLevel>
</PropertyGroup>
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Release|AnyCPU' ">
<PlatformTarget>AnyCPU</PlatformTarget>
<DebugType>pdbonly</DebugType>
<Optimize>true</Optimize>
<OutputPath>bin\Release\</OutputPath>
<DefineConstants>TRACE</DefineConstants>
<ErrorReport>prompt</ErrorReport>
<WarningLevel>4</WarningLevel>
</PropertyGroup>
<ItemGroup>
<Reference Include="System" />
<Reference Include="System.Core" />
<Reference Include="System.Xml.Linq" />
<Reference Include="System.Data.DataSetExtensions" />
<Reference Include="Microsoft.CSharp" />
<Reference Include="System.Data" />
<Reference Include="System.Net.Http" />
<Reference Include="System.Xml" />
</ItemGroup>
<ItemGroup>
<Compile Include="Program.cs" />
<Compile Include="Properties\AssemblyInfo.cs" />
</ItemGroup>
<ItemGroup>
<None Include="App.config" />
</ItemGroup>
<ItemGroup>
<ProjectReference Include="..\H.Core\H.Core.csproj">
<Project>{08D833EF-D06E-42F1-B548-89E985DFC26B}</Project>
<Name>H.Core</Name>
</ProjectReference>
<ProjectReference Include="..\H.Infrastructure\H.Infrastructure.csproj">
<Project>{0C9D716E-6579-4EE6-AEA6-5B019563AD95}</Project>
<Name>H.Infrastructure</Name>
</ProjectReference>
</ItemGroup>
<Import Project="$(MSBuildToolsPath)\Microsoft.CSharp.targets" />
</Project>
Loading

0 comments on commit 4404de4

Please sign in to comment.