Beispiel #1
0
    public static void UpdateMetricWithData(List <ProfileMetric> lst, DataTable dt, DataRow dr)
    {
        foreach (ProfileMetric pm in lst)
        {
            if (dt.Columns.Contains(pm.columnname + "_Current") &&
                dt.Columns.Contains(pm.columnname + "_Previous") &&
                dt.Columns.Contains(pm.columnname + "_Difference"))
            {
                //If YTD Threshold is defined
                MetricThreshold mt = pm.thresholds.Find(mtemp => mtemp.ThresholdType == MetricThreshold.ThresholdTypes.YTD);
                if (mt != null)
                {
                    pm.currentvalue  = new MetricValue(dr[pm.columnname + "_Current"], mt, pm.percentage, pm.displayformatstring);
                    pm.previousvalue = new MetricValue(dr[pm.columnname + "_Previous"], mt, pm.percentage, pm.displayformatstring);

                    /*mt.InControl = (!pm.currentvalue.incontrol.HasValue || pm.currentvalue.incontrol.Value) &&
                     *          (!pm.previousvalue.incontrol.HasValue || pm.previousvalue.incontrol.Value);*/
                    mt.InControl = (!pm.currentvalue.incontrol.HasValue || pm.currentvalue.incontrol.Value);
                }
                else
                {
                    pm.currentvalue  = new MetricValue(dr[pm.columnname + "_Current"], null, pm.percentage, pm.displayformatstring);
                    pm.previousvalue = new MetricValue(dr[pm.columnname + "_Previous"], null, pm.percentage, pm.displayformatstring);
                }

                //If YoY Threshold is defined
                mt            = pm.thresholds.Find(mtemp => mtemp.ThresholdType == MetricThreshold.ThresholdTypes.YoY);
                pm.difference = new MetricValue(dr[pm.columnname + "_Difference"], mt, true, string.Empty);
                if (mt != null)
                {
                    mt.InControl = (!pm.difference.incontrol.HasValue || pm.difference.incontrol.Value);
                }

                mt = pm.thresholds.Find(mtemp => mtemp.ThresholdType == MetricThreshold.ThresholdTypes.InControl);
                if (mt != null)
                {
                    mt.InControl = (dr[pm.columnname + "_In_Control"] == System.DBNull.Value) ? false : (bool)dr[pm.columnname + "_In_Control"];
                }

                //InControl Threshold is defined
                //reverse logic: s/b == true but bit values in database are switched for true/false
                pm.incontrolrule1 = (dt.Columns.Contains(pm.columnname + "ControlRule1") &&
                                     (dr[pm.columnname + "ControlRule1"] != System.DBNull.Value &&
                                      bool.Parse(dr[pm.columnname + "ControlRule1"].ToString()) == false)
                                     );

                pm.incontrolrule2 = (dt.Columns.Contains(pm.columnname + "ControlRule2") &&
                                     (dr[pm.columnname + "ControlRule2"] != System.DBNull.Value &&
                                      bool.Parse(dr[pm.columnname + "ControlRule2"].ToString()) == false)
                                     );

                pm.incontrolrule3 = (dt.Columns.Contains(pm.columnname + "ControlRule3") &&
                                     (dr[pm.columnname + "ControlRule3"] != System.DBNull.Value &&
                                      bool.Parse(dr[pm.columnname + "ControlRule3"].ToString()) == false)
                                     );

                pm.incontrolrule = pm.incontrolrule1 && pm.incontrolrule2 && pm.incontrolrule3;
            }
        }
    }
Beispiel #2
0
        public override int GetHashCode()
        {
            var hashCode = -1095595053;

            hashCode = hashCode * -1521134295 + MetricThreshold.GetHashCode();
            hashCode = hashCode * -1521134295 + TextualThreshold.GetHashCode();
            foreach (var filter in Filters)
            {
                hashCode = hashCode * -1521134295 + filter.GetHashCode();
            }

            return(hashCode);
        }
Beispiel #3
0
        public MetricValue(object val, MetricThreshold thresh, bool perc, string displayformatstring)
        {
            this.value = val;

            if (displayformatstring != null && displayformatstring.Trim() != string.Empty)
            {
                try
                {
                    //this.displayvalue = val.ToString(); //NOTE: uncomment this line for quick load
                    this.displayvalue = (perc && val != System.DBNull.Value) ? string.Format(displayformatstring, val) + "%" : string.Format(displayformatstring, (decimal)val);

                    //NOTE: The above line, specifically the decimal cast, is causing many firstchance exceptions which is causing a longer load time.
                    //The displayformatstring is what gives us a currency value, which is assigned in the PVT_Threshold_Filters table i.e. {0:C}.
                    //Basically, what the float values coming through are giving us a problem with being casted to strings.
                    //TEST: float.TryParse("0.58", NumberStyles.Any, CultureInfo.InvariantCulture, out f);
                }
                catch { this.displayvalue = (perc && val != System.DBNull.Value) ? val.ToString() + "%" : val.ToString(); }
                //NOTE: We're taking in large float types, so this exception will be thrown but then handled.
            }
            else
            {
                this.displayvalue = (perc && val != System.DBNull.Value) ? val.ToString() + "%" : val.ToString();
            }

            this.threshold = thresh;

            if (this.threshold != null)
            {
                decimal tempval = 0.0m;

                decimal.TryParse(val.ToString(), out tempval);

                if (tempval < 0)
                {
                    tempval = -1 * tempval;
                }

                if (threshold.ThresholdOperatorType == MetricThreshold.ThresholdOperatorTypes.GTE)
                {
                    this.incontrol = (tempval >= threshold.Threshold);
                }
                else if (threshold.ThresholdOperatorType == MetricThreshold.ThresholdOperatorTypes.LTE)
                {
                    this.incontrol = (tempval <= threshold.Threshold);
                }
            }
        }
 public void Init()
 {
     instance = new MetricThreshold();
 }