Skip to content

Commit

Permalink
[FEAT][NMP-670] Calculations for Solid Fertigation (#696)
Browse files Browse the repository at this point in the history
* Fixed validation bug

* WIP

* Added conditional validation to calculate dry fertigation

* WIP

* To decimal

* WIP

* WIP

* WIP

* solubility auto populates

* WIP Still need to properly implement conversions

* feat: Added solid calculations and units
- TODO: unit conversions of amount to dissolve and tank vol
- TODO: general clean up and verification

---------

Co-authored-by: Dallas Richmond <[email protected]>
  • Loading branch information
PaulGarewal and dallascrichmond authored Oct 2, 2024
1 parent 61bdd24 commit 89626bb
Show file tree
Hide file tree
Showing 10 changed files with 501 additions and 53 deletions.
109 changes: 107 additions & 2 deletions app/Agri.Data/SeedData/FertigationData.json
Original file line number Diff line number Diff line change
Expand Up @@ -229,6 +229,92 @@
"StaticDataVersionId": 14
}
],
"DryFertilizerSolubilities":[
{
"Id": 1,
"FertilizerId": 1,
"SolubilityUnitId": 1,
"Value": 1080,
"StaticDataVersionId": 14
},
{
"Id": 2,
"FertilizerId": 1,
"SolubilityUnitId": 2,
"Value": 1.08,
"StaticDataVersionId": 14
},
{
"Id": 3,
"FertilizerId": 1,
"SolubilityUnitId": 3,
"Value": 9.01,
"StaticDataVersionId": 14
},
{
"Id": 4,
"FertilizerId": 6,
"SolubilityUnitId": 1,
"Value": 1900,
"StaticDataVersionId": 14
},
{
"Id": 5,
"FertilizerId": 6,
"SolubilityUnitId": 2,
"Value": 1.9,
"StaticDataVersionId": 14
},
{
"Id": 6,
"FertilizerId": 6,
"SolubilityUnitId": 3,
"Value": 15.86,
"StaticDataVersionId": 14
},
{
"Id": 7,
"FertilizerId": 7,
"SolubilityUnitId": 1,
"Value": 764,
"StaticDataVersionId": 14
},
{
"Id": 8,
"FertilizerId": 7,
"SolubilityUnitId": 2,
"Value": 0.764,
"StaticDataVersionId": 14
},
{
"Id": 9,
"FertilizerId": 7,
"SolubilityUnitId": 3,
"Value": 6.38,
"StaticDataVersionId": 14
},
{
"Id": 10,
"FertilizerId": 29,
"SolubilityUnitId": 1,
"Value": 1444,
"StaticDataVersionId": 14
},
{
"Id": 11,
"FertilizerId": 29,
"SolubilityUnitId": 2,
"Value": 1.444,
"StaticDataVersionId": 14
},
{
"Id": 12,
"FertilizerId": 29,
"SolubilityUnitId": 3,
"Value": 12.03,
"StaticDataVersionId": 14
}
],
"LiquidFertilizerDensities":[
{
"Id": 1,
Expand Down Expand Up @@ -747,8 +833,27 @@
"Name": "Imp. gallon/min",
"StaticDataVersionId": 14
}
]
,
],
"SolubilityUnits": [
{
"Id": 1,
"Name": "g/L",
"ConvFactor": 0.01002,
"StaticDataVersionId": 14
},
{
"Id": 2,
"Name": "kg/L",
"ConvFactor": 10.02,
"StaticDataVersionId": 14
},
{
"Id": 3,
"Name": "lb/imp. gallon",
"ConvFactor": 1,
"StaticDataVersionId": 14
}
],
"FertilizerUnits": [
{
"Id" : 1,
Expand Down
24 changes: 24 additions & 0 deletions app/Agri.Models/Configuration/DryFertilizerSolubility.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
using Newtonsoft.Json;
using System.ComponentModel.DataAnnotations;
using System.Runtime.Serialization;

namespace Agri.Models.Configuration
{
public class DryFertilizerSolubility : Versionable
{
[Key]
public int Id { get; set; }

public int FertilizerId { get; set; }
public int SolubilityUnitId { get; set; }
public decimal Value { get; set; }

[JsonIgnore]
[IgnoreDataMember]
public Fertilizer Fertilizer { get; set; }

[JsonIgnore]
[IgnoreDataMember]
public SolubilityUnit SolubilityUnit { get; set; }
}
}
6 changes: 6 additions & 0 deletions app/Agri.Models/Configuration/Fertigation.cs
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
using System;
using System.Collections.Generic;
using System.ComponentModel.DataAnnotations;
using System.Linq;
Expand All @@ -13,18 +14,23 @@ public Fertigation()

public List<Fertilizer> Fertilizers { get; set; }
public List<LiquidFertilizerDensity> LiquidFertilizerDensities { get; set; }
public List<DryFertilizerSolubility> DryFertilizerSolubilities { get; set; }
public List<LiquidMaterialApplicationUSGallonsPerAcreRateConversion> LiquidMaterialApplicationUsGallonsPerAcreRateConversions { get; set; }
public List<LiquidMaterialsConversionFactor> LiquidMaterialsConversionFactors { get; set; }
public List<FertilizerType> FertilizerTypes { get; set; }
public List<ProductRateUnit> ProductRateUnits { get; set; }
public List<DensityUnit> DensityUnits { get; set; }
public List<SolubilityUnit> SolubilityUnits { get; set; }
public List<InjectionRateUnit> InjectionRateUnits { get; set; }
public List<FertilizerUnit> FertilizerUnit { get; set; }
public List<Scheduling> Schedules { get; set; }

public LiquidFertilizerDensity GetLiquidFertilizerDensity( int id, int densityUnitId){
return LiquidFertilizerDensities.Single(density => density.FertilizerId == id && density.DensityUnitId == densityUnitId);
}
public DryFertilizerSolubility GetDryFertilizerSolubility(int id, int solubilityUnitId){
return DryFertilizerSolubilities.Single(solubility => solubility.FertilizerId == id && solubility.SolubilityUnitId == solubilityUnitId);
}

}
}
17 changes: 17 additions & 0 deletions app/Agri.Models/Configuration/SolubilityUnit.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
using System.Collections.Generic;
using System.ComponentModel.DataAnnotations;

namespace Agri.Models.Configuration
{
public class SolubilityUnit : SelectOption
{
public SolubilityUnit()
{
DryFertilizerSolubilities = new List<DryFertilizerSolubility>();
}

public decimal ConvFactor { get; set; }

public List<DryFertilizerSolubility> DryFertilizerSolubilities { get; set; }
}
}
1 change: 1 addition & 0 deletions app/Agri.Models/Farm/NutrientFertilizer.cs
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ public class NutrientFertilizer
public decimal fertK2o { get; set; }
public decimal liquidDensity { get; set; }
public int liquidDensityUnitId { get; set; }
public int solInWaterUnitId { get; set; }
public int eventsPerSeason { get; set; }
public bool isFertigation { get; set; }
public decimal injectionRate { get; set; }
Expand Down
32 changes: 32 additions & 0 deletions app/Server/src/SERVERAPI/Attributes/RequiredIfAttribute.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
using System;
using System.ComponentModel.DataAnnotations;
using System.Linq;

namespace SERVERAPI.Attributes
{
public class RequiredIfAttribute : RequiredAttribute
{
private string PropertyName { get; set; }
private object[] DesiredValues { get; set; }

public RequiredIfAttribute(string propertyName, params object[] desiredValues)
{
PropertyName = propertyName;
DesiredValues = desiredValues;
}

protected override ValidationResult IsValid(object value, ValidationContext context)
{
object instance = context.ObjectInstance;
Type type = instance.GetType();
object propertyValue = type.GetProperty(PropertyName).GetValue(instance, null);

if (DesiredValues.Contains(propertyValue))
{
return base.IsValid(value, context);
}

return ValidationResult.Success;
}
}
}
Loading

0 comments on commit 89626bb

Please sign in to comment.