-
Notifications
You must be signed in to change notification settings - Fork 22
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
dc8235f
commit 4404de4
Showing
15 changed files
with
375 additions
and
23 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
56 changes: 56 additions & 0 deletions
56
H.Core/Services/Initialization/Climate/ClimateInitializationService.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 | ||
} | ||
} |
10 changes: 10 additions & 0 deletions
10
H.Core/Services/Initialization/Climate/IClimateInitializationService.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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); | ||
} | ||
} |
40 changes: 40 additions & 0 deletions
40
H.Core/Services/Initialization/Geography/GeographyInitializationService.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 | ||
} | ||
} |
9 changes: 9 additions & 0 deletions
9
H.Core/Services/Initialization/Geography/IGeographyInitializationService.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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> |
Oops, something went wrong.