예제 #1
0
        public void InvokeCDIStrategy()
        {
            // calculate the percentiles for the client metrics
            List <Metrics> clientIntervals = new List <Metrics>();

            foreach (Client client in _clients)
            {
                Metrics current = client.GetCDIIntervalData();
                if (current != null)
                {
                    clientIntervals.Add(current);
                }
            }
            _percentiles = new MetricPercentiles(clientIntervals);

            // construct the customer strategy
            //_iCdiStrategy = new CustomerPercentileStrategy(clientIntervals, Callback);
            //_iCdiStrategy.CalculateCDI();    // customer CDI not used

            // calculate the CDI for each client
            linq.CDI_Settings settings = GetCDISettings(_organizationAnalysis.ParentID);
            foreach (Client client in _clients)
            {
                client.InvokeCDIStrategy(_percentiles, settings);
            }
        }
        public void FindOptimalMix()
        {
            int    maxCombination = 0;
            double maxCorrelation = 0;

            double[] maxRSquared = null;

            int MaxMask = ((int)EMetrics.SentimentClosed) << 1;

            for (int mask = 1; mask < MaxMask; ++mask)
            {
                _weights = new linq.CDI_Settings();
                _weights.SetEqualWeights(mask);

                int i = 0;
                foreach (Client client in _clients)
                {
                    client.InvokeCDIStrategy(_percentiles, _weights);
                    _cdi[i++] = client._iCdiStrategy.CDI.Value;
                }

                double[] rSquared = new double[MetricCount];  // magic n
                for (int m = 0; m < MetricCount; ++m)
                {
                    rSquared[m] = Statistics.RSquared(_normalizedIntervals[m], _cdi);
                }

                double sumAbsCorrelation = rSquared.Sum();
                if (sumAbsCorrelation > maxCorrelation)
                {
                    maxCombination = mask;
                    maxCorrelation = sumAbsCorrelation;
                    maxRSquared    = rSquared;
                }
                //CDIEventLog.Instance.WriteLine("{0}\t{1}", mask, sumAbsCorrelation);
            }

            StringBuilder builder = new StringBuilder();

            if (maxRSquared != null)
            {
                foreach (double value in maxRSquared)
                {
                    builder.AppendFormat("\t{0:0.00}", value);
                }
            }

            if (_writeHeader)
            {
                CDIEventLog.Instance.WriteLine("OrganizationID\tMetrics\tSumR^2\tNew30\tOpen\tDaysOpen\tTotalTickets\tClosed30\tDaysToClose\tActionCount\tSeverity\tSentiment");
                _writeHeader = false;
            }
            char[] charArray = Convert.ToString(maxCombination, 2).ToCharArray();   // convert to base 2 and reverse the bits
            Array.Reverse(charArray);
            CDIEventLog.Instance.WriteLine("{0}\t{1}\t{2:0.00}{3}", _customer.OrganizationID, new string(charArray), maxCorrelation, builder.ToString());
        }
예제 #3
0
        public linq.CDI_Settings GetCDISettings(int organizationID)
        {
            if (_weights != null)
            {
                return(_weights);
            }

            try
            {
                string connectionString = ConfigurationManager.AppSettings.Get("ConnectionString");
                using (SqlConnection connection = new SqlConnection(connectionString))
                    using (DataContext db = new DataContext(connection))
                    {
                        //db.Log = CDIEventLog.Instance;
                        db.ObjectTrackingEnabled = false; // read-only
                        Table <CDI_Settings> table = db.GetTable <CDI_Settings>();
                        _weights = table.Where(s => s.OrganizationID == organizationID).FirstOrDefault();
                    }
            }
            catch (Exception e)
            {
                CDIEventLog.Instance.WriteEntry("CDI_Settings Read failed", e);
            }

            if ((_weights == null) ||
                !_weights.TotalTicketsWeight.HasValue ||
                !_weights.OpenTicketsWeight.HasValue ||
                !_weights.Last30Weight.HasValue ||
                !_weights.AvgDaysOpenWeight.HasValue ||
                !_weights.AvgDaysToCloseWeight.HasValue)
            {
                const float equalWeight = 0.2f;
                _weights = new linq.CDI_Settings()
                {
                    TotalTicketsWeight   = equalWeight,
                    OpenTicketsWeight    = equalWeight,
                    Last30Weight         = equalWeight,
                    AvgDaysOpenWeight    = equalWeight,
                    AvgDaysToCloseWeight = equalWeight
                };
            }

            return(_weights);
        }
예제 #4
0
        /// <summary> CDI1 </summary>
        public void InvokeCDIStrategy(MetricPercentiles clientPercentiles, linq.CDI_Settings weights)
        {
            _normalizedMetrics = clientPercentiles.Normalize(_rawMetrics);

            double result = 0;

            foreach (EMetrics metric in Enum.GetValues(typeof(EMetrics)))
            {
                double?value  = _normalizedMetrics.GetAsCDIPercentile(metric);
                double?weight = weights.GetWeight(metric);
                if (value.HasValue && weight.HasValue)
                {
                    result += value.Value * weight.Value;
                }
            }

            // square it to get a better distribution?
            _normalizedMetrics.CDI = _rawMetrics.CDI = (int)Math.Round(result);
        }
예제 #5
0
 public void InvokeCDIStrategy(MetricPercentiles clientPercentiles, linq.CDI_Settings weights)
 {
     _iCdiStrategy.InvokeCDIStrategy(clientPercentiles, weights);
 }