Example #1
0
        public static LeaderBoardResponse GetLeaderBoard(string centerId)
        {
            List <LeaderBoardItem> leaderBoard = new List <LeaderBoardItem>();
            List <AgentInfo>       agents      = AgentReader.GetAgentsForCenter(centerId);

            int rank = 0;

            foreach (AgentInfo agent in agents.OrderByDescending(a => a.Points))
            {
                leaderBoard.Add(new LeaderBoardItem()
                {
                    Name          = agent.AgentName,
                    TotalPoints   = agent.Points,
                    PhotoFileName = agent.PhotoFileName,
                    Rank          = ++rank
                });

                if (rank >= 10)
                {
                    break;
                }
            }

            return(new LeaderBoardResponse()
            {
                CenterName = AgentReader.GetCenterName(centerId),
                LeaderBoard = leaderBoard
            });
        }
Example #2
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
            });
        }