Simplify CurveData data structures
This commit is contained in:
@@ -199,3 +199,4 @@ weblogs/*
|
|||||||
# ImageProcessor DiskCache
|
# ImageProcessor DiskCache
|
||||||
**/App_Data/cache/
|
**/App_Data/cache/
|
||||||
|
|
||||||
|
WebCms/App_Data/Models/all.dll.path
|
||||||
|
|||||||
@@ -19,7 +19,7 @@ namespace LeafWeb.Core.Tests.Charter
|
|||||||
using (var parser = new LeafGasComparisonParser(fileInfo))
|
using (var parser = new LeafGasComparisonParser(fileInfo))
|
||||||
leafGasComparisons = parser.Parse();
|
leafGasComparisons = parser.Parse();
|
||||||
|
|
||||||
var curves = CurveDataConverter.Convert(leafGasComparisons);
|
var curves = CurveDataConverter.Convert(leafGasComparisons).ToArray();
|
||||||
Assert.That(curves.Count(),Is.EqualTo(1));
|
Assert.That(curves.Count(),Is.EqualTo(1));
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -36,7 +36,7 @@ namespace LeafWeb.Core.Tests.Charter
|
|||||||
}
|
}
|
||||||
|
|
||||||
[Test]
|
[Test]
|
||||||
public void Convert_ThrowsExpectionWhenNotEnoughDataSets()
|
public void Convert_PartialCurveData()
|
||||||
{
|
{
|
||||||
var fileInfo = FileUtility.GetContentFile(ContentDirectory, "leafgascomparison_PartialCurveData.csv");
|
var fileInfo = FileUtility.GetContentFile(ContentDirectory, "leafgascomparison_PartialCurveData.csv");
|
||||||
|
|
||||||
@@ -44,9 +44,10 @@ namespace LeafWeb.Core.Tests.Charter
|
|||||||
using (var parser = new LeafGasComparisonParser(fileInfo))
|
using (var parser = new LeafGasComparisonParser(fileInfo))
|
||||||
leafGasComparisons = parser.Parse();
|
leafGasComparisons = parser.Parse();
|
||||||
|
|
||||||
//var h = CurveDataConverter.Convert(leafGasComparisons).ToArray();
|
//var h = CurveDataConverter.Convert(leafGasComparisons).ToArray();
|
||||||
|
|
||||||
Assert.Throws<ParseException>(() => CurveDataConverter.Convert(leafGasComparisons).ToArray());
|
var curves = CurveDataConverter.Convert(leafGasComparisons).ToArray();
|
||||||
}
|
Assert.That(curves.Count(), Is.EqualTo(1));
|
||||||
}
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
@@ -1,21 +1,11 @@
|
|||||||
using System.ComponentModel;
|
using System.Collections.Generic;
|
||||||
|
|
||||||
namespace LeafWeb.Core.Charter
|
namespace LeafWeb.Core.Charter
|
||||||
{
|
{
|
||||||
public class CurveData
|
public class CurveData
|
||||||
{
|
{
|
||||||
public string CurveId { get; set; }
|
public string CurveId { get; set; }
|
||||||
|
|
||||||
[DisplayName("Internal conductance fixed, compensation point and M-M constants fixed")]
|
public IList<CurveParamSet> ParamSets { get; set; } = new List<CurveParamSet>();
|
||||||
public CurveParamSet FixedCndFixedCmp { get; set; }
|
|
||||||
|
|
||||||
[DisplayName("Internal conductance fixed, compensation point and M-M constants estimated")]
|
|
||||||
public CurveParamSet FixedCndEstimatedCmp { get; set; }
|
|
||||||
|
|
||||||
[DisplayName("Internal conductance estimated, compensation point and M-M constants fixed")]
|
|
||||||
public CurveParamSet EstimatedCndFixedCmp { get; set; }
|
|
||||||
|
|
||||||
[DisplayName("Internal conductance estimated, compensation point and M-M constants estimated")]
|
|
||||||
public CurveParamSet EstimatedCndEstimatedCmp { get; set; }
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -28,18 +28,6 @@ namespace LeafWeb.Core.Charter
|
|||||||
|
|
||||||
foreach (var comparisonGroup in comparisonGroups)
|
foreach (var comparisonGroup in comparisonGroups)
|
||||||
{
|
{
|
||||||
if (comparisonGroup.FitType.Count() != 4)
|
|
||||||
{
|
|
||||||
var missing =
|
|
||||||
from rwp in new[] {true, false}
|
|
||||||
from gamma in new [] {true, false}
|
|
||||||
where !comparisonGroup.FitType.Any(ft => ft.FitRwp == rwp && ft.FitGammaStar == gamma)
|
|
||||||
select $"(FitRwp: {(rwp ? "yes" : "no")}, FitGamma*: {(gamma ? "yes" : "no")})";
|
|
||||||
throw new ParseException(
|
|
||||||
$"Curve data in '{comparisonGroup.CurveID}' requires data sets representing all combinations of FitRwp and FitGamma."
|
|
||||||
+ " Combinations missing are: " + string.Join(", ", missing));
|
|
||||||
}
|
|
||||||
|
|
||||||
var curveData = new CurveData {CurveId = comparisonGroup.CurveID};
|
var curveData = new CurveData {CurveId = comparisonGroup.CurveID};
|
||||||
|
|
||||||
foreach (var fitType in comparisonGroup.FitType)
|
foreach (var fitType in comparisonGroup.FitType)
|
||||||
@@ -52,29 +40,18 @@ namespace LeafWeb.Core.Charter
|
|||||||
// gammastar = chloroplastic CO2 partial pressure photocompensation point = "Cmp"
|
// gammastar = chloroplastic CO2 partial pressure photocompensation point = "Cmp"
|
||||||
|
|
||||||
// put each comparison into the correct curve location
|
// put each comparison into the correct curve location
|
||||||
if (!fitType.FitRwp && !fitType.FitGammaStar)
|
if (!fitType.FitRwp && !fitType.FitGammaStar)
|
||||||
curveData.FixedCndFixedCmp = paramSet;
|
paramSet.CurveType = CurveType.FixedCndFixedCmp;
|
||||||
else if (!fitType.FitRwp && fitType.FitGammaStar)
|
else if (!fitType.FitRwp && fitType.FitGammaStar)
|
||||||
curveData.FixedCndEstimatedCmp = paramSet;
|
paramSet.CurveType = CurveType.FixedCndEstimatedCmp;
|
||||||
else if (fitType.FitRwp && !fitType.FitGammaStar)
|
else if ( fitType.FitRwp && !fitType.FitGammaStar)
|
||||||
curveData.EstimatedCndFixedCmp = paramSet;
|
paramSet.CurveType = CurveType.EstimatedCndFixedCmp;
|
||||||
else if (fitType.FitRwp && fitType.FitGammaStar)
|
else if ( fitType.FitRwp && fitType.FitGammaStar)
|
||||||
curveData.EstimatedCndEstimatedCmp = paramSet;
|
paramSet.CurveType = CurveType.EstimatedCndEstimatedCmp;
|
||||||
|
|
||||||
|
curveData.ParamSets.Add(paramSet);
|
||||||
}
|
}
|
||||||
|
|
||||||
// guarantee all data is present
|
|
||||||
if (curveData.FixedCndFixedCmp == null)
|
|
||||||
throw new ArgumentException(
|
|
||||||
$"{comparisonGroup.CurveID} missing data for {ReflectionExtensions.GetPropertyDisplayName<CurveData>(c=>c.FixedCndFixedCmp)}");
|
|
||||||
if (curveData.FixedCndEstimatedCmp == null)
|
|
||||||
throw new ArgumentException(
|
|
||||||
$"{comparisonGroup.CurveID} missing data for {ReflectionExtensions.GetPropertyDisplayName<CurveData>(c=>c.FixedCndEstimatedCmp)}");
|
|
||||||
if (curveData.EstimatedCndFixedCmp == null)
|
|
||||||
throw new ArgumentException(
|
|
||||||
$"{comparisonGroup.CurveID} missing data for {ReflectionExtensions.GetPropertyDisplayName<CurveData>(c=>c.EstimatedCndFixedCmp)}");
|
|
||||||
if (curveData.EstimatedCndEstimatedCmp == null)
|
|
||||||
throw new ArgumentException(
|
|
||||||
$"{comparisonGroup.CurveID} missing data for {ReflectionExtensions.GetPropertyDisplayName<CurveData>(c=>c.EstimatedCndEstimatedCmp)}");
|
|
||||||
yield return curveData;
|
yield return curveData;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -4,7 +4,9 @@ namespace LeafWeb.Core.Charter
|
|||||||
{
|
{
|
||||||
public class CurveParamSet
|
public class CurveParamSet
|
||||||
{
|
{
|
||||||
public List<XyPoint> AnetMeasChloro1Data { get; } = new List<XyPoint>(); // y=AnetMeas column, x=PCO2c, for PointLimitType=1
|
public CurveType CurveType { get; set; }
|
||||||
|
|
||||||
|
public List<XyPoint> AnetMeasChloro1Data { get; } = new List<XyPoint>(); // y=AnetMeas column, x=PCO2c, for PointLimitType=1
|
||||||
public List<XyPoint> AnetMeasChloro2Data { get; } = new List<XyPoint>(); // y=AnetMeas column, x=PCO2c, for PointLimitType=2
|
public List<XyPoint> AnetMeasChloro2Data { get; } = new List<XyPoint>(); // y=AnetMeas column, x=PCO2c, for PointLimitType=2
|
||||||
public List<XyPoint> AnetMeasChloro3Data { get; } = new List<XyPoint>(); // y=AnetMeas column, x=PCO2c, for PointLimitType=3
|
public List<XyPoint> AnetMeasChloro3Data { get; } = new List<XyPoint>(); // y=AnetMeas column, x=PCO2c, for PointLimitType=3
|
||||||
public List<XyPoint> AnetMeasInter1Data { get; } = new List<XyPoint>(); // y=AnetMeas column, x=PCO2i, for PointLimitType=1
|
public List<XyPoint> AnetMeasInter1Data { get; } = new List<XyPoint>(); // y=AnetMeas column, x=PCO2i, for PointLimitType=1
|
||||||
|
|||||||
@@ -0,0 +1,16 @@
|
|||||||
|
using System.ComponentModel;
|
||||||
|
|
||||||
|
namespace LeafWeb.Core.Charter
|
||||||
|
{
|
||||||
|
public enum CurveType
|
||||||
|
{
|
||||||
|
[Description("Internal conductance fixed, compensation point and M-M constants fixed")]
|
||||||
|
FixedCndFixedCmp,
|
||||||
|
[Description("Internal conductance fixed, compensation point and M-M constants estimated")]
|
||||||
|
FixedCndEstimatedCmp,
|
||||||
|
[Description("Internal conductance estimated, compensation point and M-M constants fixed")]
|
||||||
|
EstimatedCndFixedCmp,
|
||||||
|
[Description("Internal conductance estimated, compensation point and M-M constants estimated")]
|
||||||
|
EstimatedCndEstimatedCmp
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -84,6 +84,7 @@
|
|||||||
<Compile Include="Charter\CurveData.cs" />
|
<Compile Include="Charter\CurveData.cs" />
|
||||||
<Compile Include="Charter\CurveDataConverter.cs" />
|
<Compile Include="Charter\CurveDataConverter.cs" />
|
||||||
<Compile Include="Charter\CurveParamSet.cs" />
|
<Compile Include="Charter\CurveParamSet.cs" />
|
||||||
|
<Compile Include="Charter\CurveType.cs" />
|
||||||
<Compile Include="Charter\XYPoint.cs" />
|
<Compile Include="Charter\XYPoint.cs" />
|
||||||
<Compile Include="DAL\DataService.cs" />
|
<Compile Include="DAL\DataService.cs" />
|
||||||
<Compile Include="DAL\LeafWebContext.cs" />
|
<Compile Include="DAL\LeafWebContext.cs" />
|
||||||
|
|||||||
@@ -10,37 +10,15 @@ namespace LeafWeb.Core.Utility
|
|||||||
{
|
{
|
||||||
public static class ReflectionExtensions
|
public static class ReflectionExtensions
|
||||||
{
|
{
|
||||||
public static string GetPropertyDisplayName<T>(Expression<Func<T, object>> propertyExpression)
|
public static string GetDescription(this Enum value)
|
||||||
{
|
{
|
||||||
var memberInfo = GetPropertyInformation(propertyExpression.Body);
|
return
|
||||||
if (memberInfo == null)
|
value
|
||||||
{
|
.GetType()
|
||||||
throw new ArgumentException("No property reference expression was found.", nameof(propertyExpression));
|
.GetMember(value.ToString())
|
||||||
}
|
.FirstOrDefault()
|
||||||
|
?.GetCustomAttribute<DescriptionAttribute>()
|
||||||
var attr = memberInfo.Attributes<DisplayNameAttribute>().SingleOrDefault();
|
?.Description;
|
||||||
return attr == null ? memberInfo.Name : attr.DisplayName;
|
}
|
||||||
}
|
|
||||||
|
|
||||||
public static MemberInfo GetPropertyInformation(Expression propertyExpression)
|
|
||||||
{
|
|
||||||
Debug.Assert(propertyExpression != null, "propertyExpression != null");
|
|
||||||
var memberExpr = propertyExpression as MemberExpression;
|
|
||||||
if (memberExpr == null)
|
|
||||||
{
|
|
||||||
var unaryExpr = propertyExpression as UnaryExpression;
|
|
||||||
if (unaryExpr != null && unaryExpr.NodeType == ExpressionType.Convert)
|
|
||||||
{
|
|
||||||
memberExpr = unaryExpr.Operand as MemberExpression;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
if (memberExpr != null && memberExpr.Member.MemberType == MemberTypes.Property)
|
|
||||||
{
|
|
||||||
return memberExpr.Member;
|
|
||||||
}
|
|
||||||
|
|
||||||
return null;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -1 +1 @@
|
|||||||
C:\Users\poprhythm\AppData\Local\Temp\Temporary ASP.NET Files\vs\f80e29bb\faae20bf\App_Web_all.generated.cs.8f9494c4.wqlgo3gh.dll
|
C:\Users\poprhythm\AppData\Local\Temp\Temporary ASP.NET Files\vs\f80e29bb\faae20bf\App_Web_all.generated.cs.8f9494c4.u298vp5l.dll
|
||||||
@@ -1,4 +1,5 @@
|
|||||||
using System.Collections.Generic;
|
using System;
|
||||||
|
using System.Collections.Generic;
|
||||||
using System.Drawing;
|
using System.Drawing;
|
||||||
using System.Linq;
|
using System.Linq;
|
||||||
using System.Web.UI.DataVisualization.Charting;
|
using System.Web.UI.DataVisualization.Charting;
|
||||||
@@ -21,15 +22,7 @@ namespace LeafWeb.WebCms.Services
|
|||||||
{
|
{
|
||||||
var curveId = curve.CurveId;
|
var curveId = curve.CurveId;
|
||||||
|
|
||||||
var paramTitles = new[]
|
return curve.ParamSets.SelectMany(item => CurveSeries(curveId, item, item.CurveType.GetDescription()));
|
||||||
{
|
|
||||||
new {param = curve.FixedCndFixedCmp, title = ReflectionExtensions.GetPropertyDisplayName<CurveData>(c => c.FixedCndFixedCmp) },
|
|
||||||
new {param = curve.FixedCndEstimatedCmp, title = ReflectionExtensions.GetPropertyDisplayName<CurveData>(c => c.FixedCndEstimatedCmp) },
|
|
||||||
new {param = curve.EstimatedCndFixedCmp, title = ReflectionExtensions.GetPropertyDisplayName<CurveData>(c => c.EstimatedCndFixedCmp) },
|
|
||||||
new {param = curve.EstimatedCndEstimatedCmp,title = ReflectionExtensions.GetPropertyDisplayName<CurveData>(c => c.EstimatedCndEstimatedCmp) },
|
|
||||||
};
|
|
||||||
|
|
||||||
return paramTitles.SelectMany(item => CurveSeries(curveId, item.param, item.title));
|
|
||||||
}
|
}
|
||||||
|
|
||||||
private static IEnumerable<Chart> CurveSeries(string curveId, CurveParamSet paramSet, string chartTitle)
|
private static IEnumerable<Chart> CurveSeries(string curveId, CurveParamSet paramSet, string chartTitle)
|
||||||
|
|||||||
Reference in New Issue
Block a user