示例#1
0
        private static bool FindDependValue(ref GuidelineCalculationRequestViewModel data,
                                            IEnumerable <GuidelineCalculationRequestViewModel> dataset,
                                            string dependAnalyteName, Func <double, GuidelineCalculationRequestViewModel, GuidelineCalculationRequestViewModel> callback)
        {
            if (dependAnalyteName == Constants.MathE)
            {
                data = callback(Math.E, data);
                return(true);
            }

            var pointToMatch = data;

            if (dependAnalyteName == Constants.PH_AnalyteName)
            {
                return(pointToMatch.PH.HasValue);
            }
            if (dependAnalyteName == Constants.Hardness_AnalyteName)
            {
                return(pointToMatch.Hardness.HasValue);
            }
            if (dependAnalyteName == Constants.Chloride_AnalyteName)
            {
                return(pointToMatch.Chloride.HasValue);
            }
            //var depend = dataset.FirstOrDefault(x => x.DateTime.Date == pointToMatch.DateTime.Date &&
            //                                        x.Site == pointToMatch.Site &&
            //                                        String.Compare(x.Analyte, dependAnalyteName, true) == 0);

            //if (depend == null || depend.Value == null)
            //{
            //    return false;
            //}
            //data = callback(depend.Value.Value, data);
            return(true);
        }
        public AnalyteGuidelineValue CalculateGuidelineValue(
            GuidelineCalculationRequestViewModel data,
            AnalyteGuideline guideline)
        {
            if (String.IsNullOrEmpty(guideline.GuidelineValue))
            {
                throw new ArgumentNullException("System fail to calculate guideline value for " + guideline.AnalyteName);
            }

            if (guideline.ValueType == Constants.DoubleValueType || guideline.ValueType == Constants.RangeValueType)
            {
                return(this.CalculateStaticGuidelineValue(guideline));
            }
            else if (guideline.ValueType == Constants.EquationValueType)
            {
                double?parsedValue = EvaluateEquation(guideline.GuidelineValue, data.ToEquationParameters());

                return(new SimpleGuidelineValue(guideline.Guideline.Name, guideline.AnalyteName, guideline.ValueType, guideline.Unit, parsedValue));
            }
            else if (guideline.ValueType == Constants.AmmoniaLookupTableValueType)
            {
                var    ammoniaGuidelineCalculator = new AmmoniaGuidelineValueCalculator();
                double?parsedValue = ammoniaGuidelineCalculator.CalculateGuidelineValue(guideline.GuidelineValue, data.Value.Value, data.ToEquationParameters());

                return(new SimpleGuidelineValue(guideline.Guideline.Name, guideline.AnalyteName, guideline.ValueType, guideline.Unit, parsedValue));
            }
            else
            {
                throw new ArgumentException(guideline.ValueType + " is not a supported value type for standard value calculator.");
            }
        }
示例#3
0
        public static bool Decide(
            ref GuidelineCalculationRequestViewModel data,
            IEnumerable <GuidelineCalculationRequestViewModel> dataset,
            DependentDecision decision,
            AnalyteGuideline guideline)
        {
            if (decision == DependentDecision.ExistingValue)
            {
                return(true);
            }

            if (guideline.ValueType == Constants.EquationValueType)
            {
                foreach (var analyte in ExtractDependAnalyteNames(guideline.GuidelineValue))
                {
                    var result = FindDependValue(
                        ref data, dataset,
                        analyte,
                        dic[analyte]
                        );
                    if (!result)
                    {
                        return(false);
                    }
                }


                return(true);
            }

            return(true);
        }