Skip to content

Commit

Permalink
Merge pull request #14 from Stepania/TestingSystem
Browse files Browse the repository at this point in the history
Fertilizer Input
  • Loading branch information
HamishBrownPFR authored Nov 15, 2023
2 parents 1bb3b41 + de07f42 commit 98f8aa4
Show file tree
Hide file tree
Showing 21 changed files with 538 additions and 469 deletions.
31 changes: 0 additions & 31 deletions .github/workflows/build-solution.yml

This file was deleted.

94 changes: 94 additions & 0 deletions .github/workflows/ubuntodotnet.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,94 @@
# This workflow will build a .NET project
# For more information see: https://docs.github.com/en/actions/automating-builds-and-tests/building-and-testing-net

name: .NET

on: pull_request_target


jobs:
build:

runs-on: ubuntu-latest

permissions:
actions: write
pages: write
id-token: write
contents: write
pull-requests: write
deployments: write

environment:
name: github-pages
url: ${{ steps.change-page-url.outputs.new_page_url }}

defaults:
run:
working-directory: ./modelCsharp

steps:
- uses: actions/checkout@v3
- name: Setup .NET
uses: actions/setup-dotnet@v3
with:
dotnet-version: 6.0.x

- name: Install Python 3
uses: actions/setup-python@v1
with:
python-version: 3.11.6

#installing packages
- name: Install Python pandas
run: python -m pip install --upgrade pip pandas
- name: Install Python aspose
run: python -m pip install --upgrade pip aspose.words
- name: Install Python matplotlib
run: python -m pip install --upgrade pip matplotlib
- name: Install Python pyinstaller
run: python -m pip install --upgrade pip datetime
- name: Install Python datetime
run: pip install pyinstaller

- name: Create a temporary artifact downloads folder for graphs
run: mkdir graphs

- name: Restore dependencies
run: dotnet restore

- name: Build
run: dotnet build --no-restore

- name: run
run: dotnet run --project ConsoleAppSVS-test/ConsoleAppSVS-test.csproj

- name: run python
run: python TestModel/testGraph/testGraph/testGraph.py

- name: moving artfacts to temp folder
run: |
mv index.html graphs
mv index.001.png graphs
- name: Step 3 - Use the Upload Artifact GitHub Action
uses: actions/upload-artifact@v2
with:
name: folder for graphs
path: ./modelCsharp/graphs

- name: Deploy 🚀
uses: actions/upload-pages-artifact@v2
with:
path: ./modelCsharp/graphs

- name: Deploy to GitHub Pages
id: deployment
uses: actions/deploy-pages@v2
with:
repo-token: ${{ secrets.GITHUB_TOKEN }}

- name: Override page_url
id: change-page-url
run: echo "new_page_url=${{ steps.deployment.outputs.page_url }}index.html" >> $GITHUB_OUTPUT

268 changes: 268 additions & 0 deletions Untitled1.ipynb

Large diffs are not rendered by default.

4 changes: 4 additions & 0 deletions modelCsharp/ConsoleAppSVS-test/ConsoleAppSVS-test.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,10 @@
<Nullable>enable</Nullable>
</PropertyGroup>

<ItemGroup>
<PackageReference Include="CommandLineParser" Version="2.9.1" />
</ItemGroup>

<ItemGroup>
<ProjectReference Include="..\SVSModel\SVSModel.csproj" />
<ProjectReference Include="..\TestModel\TestModel\TestModel.csproj" />
Expand Down
18 changes: 15 additions & 3 deletions modelCsharp/ConsoleAppSVS-test/Program.cs
Original file line number Diff line number Diff line change
@@ -1,4 +1,16 @@

using TestModel;
using TestModel;

Test.RunTests(TestConfigData.configDict);
namespace ConsoleApp1
{

internal class Program
{
/// <summary>
/// The main entry point for the application.
/// </summary>
static void Main(string[] args)
{
Test.RunTests(TestConfigData.configDict);
}
}
}
1 change: 1 addition & 0 deletions modelCsharp/SVSModel.Excel/SVSModel.Excel.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
</ItemGroup>

<ItemGroup>
<PackageReference Include="CommandLineParser" Version="2.9.1" />
<PackageReference Include="ExcelDna.AddIn" Version="1.7.0-rc1" />
</ItemGroup>

Expand Down
1 change: 1 addition & 0 deletions modelCsharp/SVSModel/SVSModel.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -114,6 +114,7 @@
</ItemGroup>

<ItemGroup>
<PackageReference Include="CommandLineParser" Version="2.9.1" />
<PackageReference Include="CsvHelper" Version="30.0.1" />
<PackageReference Include="Microsoft.Data.Analysis" Version="0.20.0" />
</ItemGroup>
Expand Down
Binary file added modelCsharp/TestModel/Observed/SoilMineralN.xlsx
Binary file not shown.
File renamed without changes.
23 changes: 23 additions & 0 deletions modelCsharp/TestModel/TestModel/FertiliserData.csv
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
Site,Date,Nitrogen
8,2020-09-24,46
8,2020-09-24,22
8,2020-11-15,22
8,2020-11-15,16
8,2020-11-21,24
8,2020-11-20,0.75
8,2020-11-24,33.28
8,2020-11-26,54
8,2020-11-26,0.75
8,2020-12-01,24
8,2020-12-04,32
8,2020-12-12,38.4
8,2020-12-12,0.75
8,2021-04-21,8.4
8,2021-07-03,4.2
8,2021-09-10,76
8,2021-09-26,76
8,2021-10-11,76
8,2022-09-29,0.125
8,2022-09-29,0.63
8,2022-11-30,0.39
8,2022-11-30,0.1
89 changes: 73 additions & 16 deletions modelCsharp/TestModel/TestModel/Test.cs
Original file line number Diff line number Diff line change
Expand Up @@ -12,48 +12,62 @@
using System;
using static System.Net.Mime.MediaTypeNames;
using System.Text.Json.Serialization;
//using ServiceStack;
//using ServiceStack.Text;
using System.Collections.Generic;
//using Nancy.Routing.Constraints;
using IronPython.Hosting;
using Microsoft.Scripting.Hosting;
using Microsoft.Scripting;
using static IronPython.Modules._ast;
using System.IO;
using CommandLine;
using static IronPython.Modules.PythonDateTime;
using System.Text.RegularExpressions;
using System.Net.Http.Json;
using Microsoft.VisualBasic;
using static IronPython.SQLite.PythonSQLite;


namespace TestModel
{
public class Test
{
private static void runPythonScript()
/* private static void runPythonScript()
{
//that is new with james
//string progToRun = dir + @"/../TestModel/testGraph/testGraph/testGraph.py";
string dir = Directory.GetCurrentDirectory();
string newPath = Path.GetFullPath(Path.Combine(dir, @"..\..\..\..\"));
string progToRun = newPath+ @"TestModel\testGraph\testGraph\testGraph.py";
string progToRun = newPath + @"TestModel\testGraph\testGraph\testGraph.py";
Process proc = new Process();
proc.StartInfo.FileName = "python.exe";
proc.StartInfo.RedirectStandardOutput = true;
proc.StartInfo.UseShellExecute = false;
proc.StartInfo.Arguments =progToRun;
proc.StartInfo.UseShellExecute = false;
proc.StartInfo.Arguments = progToRun;
proc.Start();
StreamReader sReader = proc.StandardOutput;
proc.WaitForExit();
Console.ReadLine();

}
}*/
public static void RunTests(Dictionary<string, object> _configDict)

{
string dir = Directory.GetCurrentDirectory();
//DataFrame testConfigs = Crop.LoadCoefficients("SVSModel.Data.TestConfig.csv");
string resourceName = "TestModel.actualDataConfig.csv";

// new line
string resourceFertiliser = "TestModel.FertiliserData.csv";

string resourceName = "TestModel.TestConfig.csv";
var assembly = Assembly.GetExecutingAssembly();
Stream csv = assembly.GetManifestResourceStream(resourceName);

//new line
Stream csvFertiliser = assembly.GetManifestResourceStream(resourceFertiliser);

DataFrame allTests = DataFrame.LoadCsv(csv);

//new line
DataFrame fertiliser = DataFrame.LoadCsv(csvFertiliser);

List<string> Tests = new List<string>();

foreach (DataFrameRow row in allTests.Rows)
Expand All @@ -69,6 +83,40 @@ public static void RunTests(Dictionary<string, object> _configDict)

Dictionary<DateTime, double> testResults = new Dictionary<DateTime, double>();
Dictionary<DateTime, double> nApplied = new Dictionary<DateTime, double>();

int siteNumber = Int32.Parse(Regex.Match(test, @"\d+").Value);

foreach (DataFrameRow row in fertiliser.Rows)
{

int firstElement = Int32.Parse(row[0].ToString());

DateTime fertDate = Convert.ToDateTime(row[1].ToString());

if (firstElement == siteNumber)

if ((fertDate > _config.Current.EstablishDate) && (fertDate <= _config.Current.HarvestDate))

try
{

if (!nApplied.ContainsKey((DateTime)row[1]))
{
nApplied.Add(fertDate, (Single)row[2]);
}
else
{
nApplied[fertDate]+= (Single)row[2];
}

}

catch (Exception e)
{
Trace.WriteLine(e+"something is not working properly in fertiliser department");

}
}

string weatherStation = allTests["WeatherStation"][testRow].ToString();

Expand Down Expand Up @@ -102,14 +150,24 @@ public static void RunTests(Dictionary<string, object> _configDict)
}
newDataframe.Append(nextRow, true);
}
string folderName = "OutputFiles";

string fertiliserFolder = "NitrogenApplied";

if (!Directory.Exists(folderName) && !Directory.Exists(fertiliserFolder))
{
System.IO.Directory.CreateDirectory("OutputFiles");

}

DataFrame.SaveCsv(newDataframe, dir + "\\OutputFiles\\" + test + ".csv");
//DataFrame.SaveCsv(newDataframe, dir + "\\OutputFiles\\" + test + ".csv");
DataFrame.SaveCsv(newDataframe, test + ".csv");

}
runPythonScript();
// uncomment it if run is on local machine
//runPythonScript();

}

public static SVSModel.Configuration.Config SetConfigFromDataFrame(string test, DataFrame allTests)
{
int testRow = getTestRow(test, allTests);
Expand Down Expand Up @@ -184,7 +242,6 @@ public static SVSModel.Configuration.Config SetConfigFromDataFrame(string test,

return ret;
}

private static int getTestRow(string test, DataFrame allTests)
{
int testRow = 0;
Expand Down
4 changes: 0 additions & 4 deletions modelCsharp/TestModel/TestModel/TestConfig.csv

This file was deleted.

9 changes: 8 additions & 1 deletion modelCsharp/TestModel/TestModel/TestModel.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -8,11 +8,16 @@
</PropertyGroup>

<ItemGroup>
<None Remove="actualDataConfig.csv" />
<None Remove="fert.csv" />
<None Remove="Fertiliser.csv" />
<None Remove="FertiliserData.csv" />
<None Remove="TestConfig.csv" />
</ItemGroup>

<ItemGroup>
<EmbeddedResource Include="TestConfig.csv" />
<EmbeddedResource Include="actualDataConfig.csv" />
<EmbeddedResource Include="FertiliserData.csv" />
</ItemGroup>


Expand All @@ -21,7 +26,9 @@
</ItemGroup>

<ItemGroup>
<PackageReference Include="CommandLineParser" Version="2.9.1" />
<PackageReference Include="IronPython" Version="3.4.1" />
<PackageReference Include="Newtonsoft.Json" Version="13.0.3" />
</ItemGroup>

<ItemGroup>
Expand Down
4 changes: 4 additions & 0 deletions modelCsharp/TestModel/TestModel/actualDataConfig.csv
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
Property,InitialN,SoilOrder,SampleDepth,BulkDensity,PMNtype,PMN,Trigger,Efficiency,Splits,AWC,PrePlantRain,InCropRain,Irrigation,PriorCropNameFull,PriorSaleableYield,PriorFieldLoss,PriorDressingLoss,PriorMoistureContent,PriorEstablishDate,PriorEstablishYear,PriorEstablishMonth,PriorEstablishDay,PriorEstablishStage,PriorHarvestDate,PriorHarvestYear,PriorHarvestMonth,PriorHarvestDay,PriorHarvestStage,PriorResidueRemoval,PriorResidueIncorporation,CurrentCropNameFull,CurrentSaleableYield,CurrentFieldLoss,CurrentDressingLoss,CurrentMoistureContent,CurrentEstablishDate,CurrentEstablishYear,CurrentEstablishMonth,CurrentEstablishDay,CurrentEstablishStage,CurrentHarvestDate,CurrentHarvestYear,CurrentHarvestMonth,CurrentHarvestDay,CurrentHarvestStage,CurrentResidueRemoval,CurrentResidueIncorporation,FollowingCropNameFull,FollowingSaleableYield,FollowingFieldLoss,FollowingDressingLoss,FollowingMoistureContent,FollowingEstablishDate,FollowingEstablishYear,FollowingEstablishMonth,FollowingEstablishDay,FollowingEstablishStage,FollowingHarvestDate,FollowingHarvestYear,FollowingHarvestMonth,FollowingHarvestDay,FollowingHarvestStage,FollowingResidueRemoval,FollowingResidueIncorporation,WeatherStation
8Wheat,50,Immature Pallic,0-30cm,1.07,PMN,160,30,80,3,148,Typical,Very Dry,Full,Potato Vegetable General,88.4,0,0,30,24/09/2020,2020,9,24,Seed,17/03/2021,2021,3,21,LateReproductive,None removed,Full (Plough),Wheat Grain General,12.7,0,0,30,21/04/2021,2021,4,21,Seed,26/01/2022,2022,1,26,Maturity,Baled,Full (Plough),Pea Grain General,4.7,0,0,30,27/09/2022,2022,9,27,Seed,25/01/2023,2023,1,25,Maturity,None removed,Full (Plough),ashburton
8Peas,50,Immature Pallic,0-30cm,1.22,PMN,120,30,80,3,148,Typical,Very Dry,Full,Wheat Grain General,12.7,0,0,30,21/04/2021,2021,4,21,Seed,26/01/2022,2022,1,26,Maturity,Baled,Full (Plough),Pea Grain General,4.7,0,0,30,27/09/2022,2022,9,27,Seed,25/01/2023,2023,1,25,Maturity,None removed,Full (Plough),Oat Fodder General,10,0,0,40,10/04/2023,2023,4,10,Seed,4/08/2023,2023,8,4,Maturity,None removed,Full (Plough),ashburton
8Oat,50,Immature Pallic,0-30cm,1.31,PMN,80,30,80,3,148,Typical,Very Dry,Full,Pea Grain General,4.7,0,0,30,27/09/2022,2022,9,27,Seed,25/01/2023,2023,1,25,Maturity,None removed,Full (Plough),Oat Fodder General,10,0,0,40,10/04/2023,2023,4,10,Seed,4/08/2023,2023,8,4,Maturity,None removed,Full (Plough),Oat Fodder General,10,0,0,0,1/09/2023,2023,9,1,Seed,1/10/2023,2023,10,1,EarlyReproductive,None removed,Full (Plough),ashburton
Loading

0 comments on commit 98f8aa4

Please sign in to comment.