Example #1
0
 /// <summary>
 ///     Construct an analyzed field.
 /// </summary>
 /// <param name="theScript">The script being analyzed.</param>
 /// <param name="name">The name of the field.</param>
 public AnalyzedField(AnalystScript theScript, String name) : base(name)
 {
     _classMap  = new Dictionary <String, AnalystClassItem>();
     _instances = 0;
     _script    = theScript;
     _fmt       = _script.DetermineFormat();
 }
        /// <summary>
        ///     Perform a pass one analysis of this field.
        /// </summary>
        /// <param name="str">The current value.</param>
        public void Analyze1(String v)
        {
            bool   accountedFor = false;
            string str          = v.Trim();

            if (str.Trim().Length == 0 || str.Equals("?"))
            {
                Complete = false;
                return;
            }

            _instances++;

            if (Real)
            {
                try
                {
                    double d = _script.DetermineFormat().Parse(str);
                    Max          = Math.Max(d, Max);
                    Min          = Math.Min(d, Min);
                    _total      += d;
                    accountedFor = true;
                }
                catch (FormatException)
                {
                    Real = false;
                    if (!Integer)
                    {
                        Max = 0;
                        Min = 0;
                        StandardDeviation = 0;
                    }
                }
            }

            if (Integer)
            {
                try
                {
                    int i = Int32.Parse(str);
                    Max = Math.Max(i, Max);
                    Min = Math.Min(i, Min);
                    if (!accountedFor)
                    {
                        _total += i;
                    }
                }
                catch (FormatException)
                {
                    Integer = false;
                    if (!Real)
                    {
                        Max = 0;
                        Min = 0;
                        StandardDeviation = 0;
                    }
                }
            }

            if (Class)
            {
                AnalystClassItem item;

                // is this a new class?
                if (!_classMap.ContainsKey(str))
                {
                    item           = new AnalystClassItem(str, str, 1);
                    _classMap[str] = item;

                    // do we have too many different classes?
                    int max = _script.Properties.GetPropertyInt(
                        ScriptProperties.SetupConfigMaxClassCount);
                    if (_classMap.Count > max)
                    {
                        Class = false;
                    }
                }
                else
                {
                    item = _classMap[str];
                    item.IncreaseCount();
                }
            }
        }