コード例 #1
0
        public static CenterViewResponse GetCenterView(string centerId)
        {
            List <KPIItem>      centerView = new List <KPIItem>();
            List <AgentKPIInfo> allKPIs    = KPIReader.GetAgentKPI();
            List <KPIInfo>      kpiNames   = KPIReader.GetAllKPIInfo();

            List <SupervisorInfo> supervisors = AgentReader.GetSupervisorsForCenter(centerId);

            foreach (var supervisor in supervisors)
            {
                List <KPIItem> supervisorKPI = GetSupervisorView(supervisor.SupervisorId).SupervisorView;

                if (supervisorKPI.Count > 0)
                {
                    List <AgentInfo> agents = AgentReader.GetAgentsForSupervisor(supervisor.SupervisorId);
                    var agentKPIs           = from allK in allKPIs
                                              join a in agents on allK.AgentId equals a.AgentId
                                              group allK by allK.KpiId into g
                                              select new { KpiId = g.First().KpiId, KpiTotal = g.Average(a => a.KpiValue) };

                    string topKpiString    = string.Empty;
                    string bottomKpiString = string.Empty;

                    var topKPI = agentKPIs.OrderByDescending(a => a.KpiTotal).Take(2);
                    foreach (var row in topKPI)
                    {
                        string kpiName = kpiNames.Where(k => k.KpiId.Equals(row.KpiId)).FirstOrDefault().KpiName;
                        topKpiString += string.Format("{0}: {1};", kpiName, row.KpiTotal);
                    }

                    var bottomKPI = agentKPIs.OrderBy(a => a.KpiTotal).Take(2);
                    foreach (var row in bottomKPI)
                    {
                        string kpiName = kpiNames.Where(k => k.KpiId.Equals(row.KpiId)).FirstOrDefault().KpiName;
                        bottomKpiString += string.Format("{0}: {1};", kpiName, row.KpiTotal);
                    }

                    double avgScore = supervisorKPI.Average(a => a.Score);

                    centerView.Add(new KPIItem()
                    {
                        AgentId   = supervisor.SupervisorId,
                        AgentName = supervisor.SupervisorName,
                        Score     = Convert.ToInt32(avgScore),
                        TopKPI    = topKpiString,
                        BottomKPI = bottomKpiString
                    });
                }
            }

            return(new CenterViewResponse()
            {
                CenterName = AgentReader.GetCenterName(centerId),
                CenterView = centerView
            });
        }
コード例 #2
0
        public static HeatMapViewResponse GetHeatMapView(string supervisorId)
        {
            var heatMapItems = new List <Dictionary <string, string> >();

            List <KPIInfo>      kpis      = KPIReader.GetAllKPIInfo();
            List <AgentKPIInfo> agentKpis = KPIReader.GetAgentKPI();
            List <AgentInfo>    agents    = AgentReader.GetAgentsForSupervisor(supervisorId);

            string           centerId     = AgentReader.GetCenterIdForSupervisor(supervisorId);
            List <AgentInfo> centerAgents = AgentReader.GetAgentsForCenter(centerId);

            var result = from k in kpis
                         join ak in agentKpis on k.KpiId equals ak.KpiId
                         join a in agents on ak.AgentId equals a.AgentId
                         orderby k.Category, k.KpiId, a.AgentName
                select new { a.AgentId, a.AgentName, a.Date, k.KpiId, k.KpiName, ak.KpiValue, k.Category };

            var kpiGroups = result.GroupBy(a => a.KpiName).Select(g => g.FirstOrDefault());

            foreach (var kpiGroup in kpiGroups)
            {
                var kpiRows = from a in result
                              where a.KpiName.Equals(kpiGroup.KpiName)
                              group a by a.AgentName into g
                              select g.OrderByDescending(i => i.Date).FirstOrDefault();

                var item = new Dictionary <string, string>();
                item.Add("..Category", kpiGroup.Category);
                item.Add(".Behavior Attribute", kpiGroup.KpiName);

                var centerResult = from ak in agentKpis
                                   join ca in centerAgents on ak.AgentId equals ca.AgentId
                                   where ak.KpiId == kpiGroup.KpiId
                                   group ak by ak.KpiId into g
                                   select new { CenterAverage = g.Average(a => a.KpiValue) };

                var sdResult = from ak in agentKpis
                               join ca in centerAgents on ak.AgentId equals ca.AgentId
                               where ak.KpiId == kpiGroup.KpiId
                               select new { ak.KpiValue };
                List <double> sdList = new List <double>();
                foreach (var row in sdResult)
                {
                    sdList.Add(row.KpiValue);
                }

                double centerAverage = Convert.ToInt32(centerResult.First().CenterAverage);
                item.Add(".Center Average", centerAverage.ToString("F"));

                double standardDeviation = StatisticsHelper.GetStandardDeviation(sdList);
                item.Add(".Standard Deviation", standardDeviation.ToString("F"));

                foreach (var row in kpiRows)
                {
                    item.Add(row.AgentName, row.KpiValue.ToString("F"));
                }

                heatMapItems.Add(item);
            }

            return(new HeatMapViewResponse()
            {
                SupervisorName = AgentReader.GetSupervisorName(supervisorId),
                HeatMapView = heatMapItems
            });
        }