Esempio n. 1
0
        // TODO SAM 2009-05-08 Evaluate whether to allow passing in max coefficient value for check
        /// <summary>
        /// Performs specific data checks and returns a list of data that failed the data checks. </summary>
        /// <param name="count"> Index of the data vector currently being checked. </param>
        /// <param name="dataset"> StateCU dataset currently in memory. </param>
        /// <param name="props"> Extra properties to perform checks with. </param>
        /// <returns> List of invalid data. </returns>
        public virtual StateCU_ComponentValidation validateComponent(StateCU_DataSet dataset)
        {
            StateCU_ComponentValidation validation = new StateCU_ComponentValidation();
            string id = getName();     // Name is used for ID because ID used to be numeric

            double[][] kcday = getKcday();
            double[][] kcb   = getKcb();
            // Percent of growth stage
            for (int igs = 0; igs < kcday.Length; igs++)
            {
                for (int ipos = 0; ipos < kcday[igs].Length; ipos++)
                {
                    if ((kcday[igs][ipos] < 0.0) || (kcday[igs][ipos] > 100.0))
                    {
                        validation.add(new StateCU_ComponentValidationProblem(this, "Crop \"" + id + "\" percent of growth stage (" + kcday[igs][ipos] + ") is invalid.", "Specify as 0 to 100."));
                    }
                    if ((kcb[igs][ipos] < 0) || (kcb[igs][ipos] > 3.0))
                    {
                        validation.add(new StateCU_ComponentValidationProblem(this, "Crop \"" + id + "\" coefficient (" + kcb[igs][ipos] + ") is invalid.", "Specify as 0 to 3.0 (upper limit may vary by location)."));
                    }
                }
            }

            return(validation);
        }
Esempio n. 2
0
        // TODO SAM 2009-05-08 Evaluate whether to allow passing in max coefficient value for check
        /// <summary>
        /// Performs specific data checks and returns a list of data that failed the data checks. </summary>
        /// <param name="count"> Index of the data vector currently being checked. </param>
        /// <param name="dataset"> StateCU dataset currently in memory. </param>
        /// <param name="props"> Extra properties to perform checks with. </param>
        /// <returns> List of invalid data. </returns>
        public virtual StateCU_ComponentValidation validateComponent(StateCU_DataSet dataset)
        {
            StateCU_ComponentValidation validation = new StateCU_ComponentValidation();
            string id = getName();     // Name is used for ID because ID used to be numeric

            int[] nckca = getNckca();
            int[] nckcp = getNckcp();
            if (((nckca == null) || (nckca.Length == 0)) && ((nckcp == null) || (nckcp.Length == 0)))
            {
                validation.add(new StateCU_ComponentValidationProblem(this, "Crop \"" + id + "\" data are neither specified as day of year or percent of season.", "Specify coefficients for day of year OR percent of season."));
            }
            else if (((nckca != null) && (nckca.Length > 0)) && ((nckcp != null) && (nckcp.Length > 0)))
            {
                validation.add(new StateCU_ComponentValidationProblem(this, "Crop \"" + id + "\" data are specified as day of year and percent of season.", "Specify coefficients for day of year OR percent of season."));
            }
            else if (isAnnualCrop())
            {
                // Annual - percent of season
                double[] ckca = getCkca();
                for (int i = 0; i < nckca.Length; i++)
                {
                    if ((nckca[i] < 0) || (nckca[i] > 100))
                    {
                        validation.add(new StateCU_ComponentValidationProblem(this, "Crop \"" + id + "\" percent of season (" + nckca[i] + ") is invalid.", "Specify as 0 to 100."));
                    }
                    if ((ckca[i] < 0) || (ckca[i] > 3.0))
                    {
                        validation.add(new StateCU_ComponentValidationProblem(this, "Crop \"" + id + "\" coefficient (" + ckca[i] + ") is invalid.", "Specify as 0 to 3.0 (upper limit may vary by location)."));
                    }
                }
            }
            else
            {
                // Perennial - day of year
                double[] ckcp = getCkcp();
                for (int i = 0; i < nckcp.Length; i++)
                {
                    if ((nckcp[i] < 1) || (nckcp[i] > 366))
                    {
                        validation.add(new StateCU_ComponentValidationProblem(this, "Crop \"" + id + "\" day of year (" + nckcp[i] + ") is invalid.", "Specify as 1 to 366."));
                    }
                    if ((ckcp[i] < 0) || (ckcp[i] > 3.0))
                    {
                        validation.add(new StateCU_ComponentValidationProblem(this, "Crop \"" + id + "\" coefficient (" + ckcp[i] + ") is invalid.", "Specify as 0 to 3.0 (upper limit may vary by location)."));
                    }
                }
            }
            // Check method
            int ktsw = getKtsw();

            if ((ktsw < 0) || (ktsw > 4))
            {
                validation.add(new StateCU_ComponentValidationProblem(this, "Crop \"" + id + "\" Blaney-Criddle method (" + ktsw + ") is invalid.", "Specify as 0 to 4 (refer to StateCU documentation)."));
            }

            return(validation);
        }
        /// <summary>
        /// Performs specific data checks and returns a list of data that failed the data checks. </summary>
        /// <param name="dataset"> StateCU dataset currently in memory. </param>
        /// <returns> Validation results. </returns>
        public virtual StateCU_ComponentValidation validateComponent(StateCU_DataSet dataset)
        {
            StateCU_ComponentValidation validation = new StateCU_ComponentValidation();
            string id       = getID();
            double latitude = getLatitude();

            if (!((latitude >= -90.0) && (latitude <= 90.0)))
            {
                validation.add(new StateCU_ComponentValidationProblem(this, "Climate station \"" + id + "\" latitude (" + latitude + ") is invalid.", "Specify a latitude -90 to 90."));
            }
            double elevation = getElevation();

            if (!((elevation >= 0.0) && (elevation <= 15000.00)))
            {
                validation.add(new StateCU_ComponentValidationProblem(this, "Climate station \"" + id + "\" elevation (" + elevation + ") is invalid.", "Specify an elevation 0 to 15000 FT (maximum varies by location)."));
            }
            string name = getName();

            if ((string.ReferenceEquals(name, null)) || name.Trim().Length == 0)
            {
                validation.add(new StateCU_ComponentValidationProblem(this, "Climate station \"" + id + "\" name is blank - may cause confusion.", "Specify the station name or use the ID for the name."));
            }
            string region1 = getRegion1();

            if ((string.ReferenceEquals(region1, null)) || region1.Trim().Length == 0)
            {
                validation.add(new StateCU_ComponentValidationProblem(this, "Climate station \"" + id + "\" region1 is blank - may cause region lookups to fail for other data.", "Specify as county or other region indicator."));
            }
            double zh = getZh();

            if (!(zh >= 0.0))
            {
                validation.add(new StateCU_ComponentValidationProblem(this, "Climate station \"" + id + "\" zh (" + zh + ") is invalid.", "Specify a zh >= 0."));
            }
            double zm = getZm();

            if (!(zm >= 0.0))
            {
                validation.add(new StateCU_ComponentValidationProblem(this, "Climate station \"" + id + "\" zm (" + zm + ") is invalid.", "Specify a zm >= 0."));
            }
            return(validation);
        }
        /// <summary>
        /// Performs specific data checks for a component.  The
        /// intelligence and checks are stored in the component itself. </summary>
        /// <param name="data"> List of data objects to check. </param>
        /// <returns> List of data that failed the data checks. </returns>
        private System.Collections.IList doSpecificDataChecks(IList <StateCU_ComponentValidator> data, PropList props)
        {
            System.Collections.IList checks = new List <object>();
            if (data == null)
            {
                return(checks);
            }
            // Check each component object by calling the
            // checkComponentData() method.  Each component
            // needs to implement this method and extend from
            // the StateMod_Component interface
            StateCU_ComponentValidator comp = null;

            for (int i = 0; i < data.Count; i++)
            {
                comp = data[i];
                StateCU_ComponentValidation validation = comp.validateComponent(__dataset);
                if (validation.size() > 0)
                {
                    checks.Add(validation.getAll());
                }
            }
            return(checks);
        }