Example #1
0
        /// <summary>
        /// Retrieve graph data of the primary metric of a KPI for a month in an year
        /// </summary>
        /// <param name="scorecardId">Scorecard Id</param>
        /// <param name="kpiId">KPI Id</param>
        /// <param name="yearId">Identifier of the year</param>
        /// <param name="month">Month</param>
        /// <returns>Graph data</returns>
        public KPIGraphData GetScorecardKPIGraphData(int scorecardId,
                                                     int kpiId, int yearId, int month)
        {
            KPIGraphData kpiGraphData = null;

            //get the year in which month belongs
            Year     year          = yearRepository.Get(yearId);
            int      requestedYear = CalendarUtility.GetYearOfTheMonth(year, month);
            DateTime requestDate   = new DateTime(requestedYear, month, 1);
            // Get the primary metrics active for a KPI in a calendar year
            var primaryMetricTargets = targetRepository.GetAll().Where(x =>
                                                                       x.ScorecardId == scorecardId && x.KPIId == kpiId && x.CalendarYearId == yearId &&
                                                                       x.MetricType == MetricType.Primary && x.IsActive);
            //get the metric which is active in the selected month by
            //comparing target start date (set day as 1) and target end date (set day as last day of the month)
            var primaryMetricTarget = primaryMetricTargets.ToList().FirstOrDefault(x =>
                                                                                   requestDate >= new DateTime(x.EffectiveStartDate.Year, x.EffectiveStartDate.Month, 1) &&
                                                                                   requestDate <= new DateTime(x.EffectiveEndDate.Year, x.EffectiveEndDate.Month,
                                                                                                               DateTime.DaysInMonth(x.EffectiveEndDate.Year, x.EffectiveEndDate.Month)));

            if (primaryMetricTarget != null)
            {
                kpiGraphData       = new KPIGraphData();
                kpiGraphData.KpiId = kpiId;
                //if metrics tracking method is monthly, get the monthly graph details
                if (primaryMetricTarget.TrackingMethodId == Constants.TrackingMethodMonthly)
                {
                    IEnumerable <MonthItem> monthsInYear = CalendarUtility.
                                                           GetMonthsBetweenDates(year.StartDate, year.EndDate);
                    kpiGraphData.MonthlyGraphData = GetMonthlyGraphData(primaryMetricTarget, monthsInYear);
                    if (kpiGraphData.MonthlyGraphData != null)
                    {
                        kpiGraphData = GetMinandMaxValueForMonthlyGraphData(kpiGraphData);
                    }
                }
                //else get daily graph details
                else
                {
                    kpiGraphData.DailyGraphData = GetDailyGraphData(
                        primaryMetricTarget, month, requestedYear);
                    if (kpiGraphData.DailyGraphData != null)
                    {
                        kpiGraphData = GetMinandMaxValueForDailyGraphData(kpiGraphData);
                    }
                }
            }

            return(kpiGraphData);
        }
Example #2
0
        /// <summary>
        /// Retrieve graph data of the primary metric of all KPIs in a scorecard
        /// for a month in an year
        /// </summary>
        /// <param name="scorecardId">Scorecard Id</param>
        /// <param name="yearId">Identifier of the year</param>
        /// <param name="month">Month</param>
        /// <returns>Graph data</returns>
        public IEnumerable <KPIGraphData> GetScorecardGraphData(int scorecardId,
                                                                int yearId, int month)
        {
            List <KPIGraphData> scorecardKPIsGraphData = new List <KPIGraphData>();
            Scorecard           scorecard = scorecardRepository.Get(scorecardId);

            if (scorecard != null)
            {
                foreach (var kpi in scorecard.KPIs)
                {
                    KPIGraphData kpiGraphData = GetScorecardKPIGraphData(scorecardId,
                                                                         kpi.Id, yearId, month);
                    scorecardKPIsGraphData.Add(kpiGraphData);
                }
            }

            return(scorecardKPIsGraphData);
        }
Example #3
0
        /// <summary>
        /// Method to get min value of actual and goal from daily graph data
        /// </summary>
        /// <param name="kpiGraphData">graph data</param>
        /// <returns>graph data with the values set</returns>
        private KPIGraphData GetMinandMaxValueForDailyGraphData(KPIGraphData kpiGraphData)
        {
            //get min values of actual and goal
            List <decimal?> minValues = new List <decimal?>();

            minValues.Add(kpiGraphData.DailyGraphData.Min(x => x.ActualValue));
            minValues.Add(kpiGraphData.DailyGraphData.Min(x => x.GoalValue));
            minValues.Add(kpiGraphData.DailyGraphData.Min(x => x.StretchGoalValue));
            //get max values of actual and goal
            List <decimal?> maxValues = new List <decimal?>();

            maxValues.Add(kpiGraphData.DailyGraphData.Max(x => x.ActualValue));
            maxValues.Add(kpiGraphData.DailyGraphData.Max(x => x.GoalValue));
            maxValues.Add(kpiGraphData.DailyGraphData.Max(x => x.StretchGoalValue));
            //set min and max among actual, goal and stretch goal to graph data
            kpiGraphData.MinValue = minValues.Min();
            kpiGraphData.MaxValue = maxValues.Max();

            return(kpiGraphData);
        }
Example #4
0
        /// <summary>
        /// Gets the scorecard kpi graph data for selected metric.
        /// </summary>
        /// <param name="metricTargetId">The metric target identifier.</param>
        /// <param name="kpiId">The kpi identifier.</param>
        /// <param name="yearId">The year identifier.</param>
        /// <param name="month">The month.</param>
        /// <returns>
        /// The graph data
        /// </returns>
        public KPIGraphData GetScorecardMetricKPIGraphData(int metricTargetId, int kpiId, int yearId, int month)
        {
            KPIGraphData graphData = null;
            //get the year in which month belongs
            Year     year          = yearRepository.Get(yearId);
            int      requestedYear = CalendarUtility.GetYearOfTheMonth(year, month);
            DateTime requestDate   = new DateTime(requestedYear, month, 1);
            // Get the metric target details for a KPI in a calendar year
            var metricTarget = targetRepository.Get(metricTargetId);

            if (metricTarget != null && metricTarget.IsActive && metricTarget.GraphPlottingMethod != null)
            {
                graphData       = new KPIGraphData();
                graphData.KpiId = kpiId;
                //if metrics tracking method is monthly, get the monthly graph details
                if (metricTarget.TrackingMethodId == Constants.TrackingMethodMonthly)
                {
                    IEnumerable <MonthItem> monthsInYear = CalendarUtility.
                                                           GetMonthsBetweenDates(year.StartDate, year.EndDate);
                    graphData.MonthlyGraphData = GetMonthlyGraphData(metricTarget, monthsInYear);
                    if (graphData.MonthlyGraphData != null)
                    {
                        graphData = GetMinandMaxValueForMonthlyGraphData(graphData);
                    }
                }
                //else get daily graph details
                else if (metricTarget.TrackingMethodId == Constants.TrackingMethodDaily)
                {
                    graphData.DailyGraphData = GetDailyGraphData(
                        metricTarget, month, requestedYear);
                    if (graphData.DailyGraphData != null)
                    {
                        graphData = GetMinandMaxValueForDailyGraphData(graphData);
                    }
                }
            }

            return(graphData);
        }