Exemple #1
0
        public async Task <ActionResult> GetUserTimeSpendOnTask(string fromDateUserWorks, string toDateUserWorks)
        {
            var      accessToken    = Session["MicrosoftAccessToken"] as string;
            var      externalUserId = Session["UserId"] as string;
            DateTime fromDateUsr    = DateTime.Parse(fromDateUserWorks);
            DateTime toDateUsr      = DateTime.Parse(toDateUserWorks);
            TaskSubitemWorkService taskSubitemWorkService = new TaskSubitemWorkService(accessToken);
            UserService            userService            = new UserService(accessToken);
            var userWorks =
                await
                taskSubitemWorkService.GetUserTaskSubitemWorks(
                    await userService.GetUserId(externalUserId, UserDomainEnum.Microsoft), fromDateUsr, toDateUsr);

            var userWorksGroupByDay = userWorks.GroupBy(w => w.EndDateTime.Value.Date);
            Dictionary <DateTime, double> valuesForUser = new Dictionary <DateTime, double>();

            foreach (var item in userWorksGroupByDay)
            {
                TimeSpan totalTimeSpan = new TimeSpan();
                foreach (TaskSubitemWork work in item)
                {
                    totalTimeSpan += work.EndDateTime.Value - work.StartDateTime;
                }
                valuesForUser.Add(item.Key, totalTimeSpan.Minutes);
            }

            var userDict = valuesForUser.OrderBy(i => i.Key).ToDictionary(pair => pair.Key.ToString("dd-MM-yyyy"), pair => pair.Value);

            int    width      = 600;
            int    height     = 50;
            string chartTitle = "In this period you did not spend time on the tasks.";

            if (userDict.Any())
            {
                width      = 1024;
                height     = 700;
                chartTitle = "Your time spent on task subitems";
            }
            var key = new Chart(width: width, height: height)
                      .AddSeries(
                chartType: "column",
                legend: "group",
                xValue: userDict.Keys,
                yValues: userDict.Values).AddTitle(chartTitle).Write();

            return(null);
        }
Exemple #2
0
        public async Task <ActionResult> GetWorksLineChart(string fromDateWorks, string toDateWorks, string groupId)
        {
            string      accessToken            = Session["MicrosoftAccessToken"] as string;
            var         taskSubitemWorkService = new TaskSubitemWorkService(accessToken);
            UserService userService            = new UserService(accessToken);
            var         userId = await userService.GetUserId(Session["UserId"] as string, UserDomainEnum.Microsoft);

            DateTime fromDate  = DateTime.Parse(fromDateWorks);
            DateTime toDate    = DateTime.Parse(toDateWorks);
            var      userWorks = await taskSubitemWorkService.GetGroupTaskSubitemWorksForUser(userId, groupId, fromDate, toDate);

            var groupWorks = await taskSubitemWorkService.GetGroupTaskSubitemWorks(groupId, fromDate, toDate);

            var userWorksGroupByDay  = userWorks.GroupBy(w => w.EndDateTime.Value.Date);
            var groupWorksGroupByDay = groupWorks.GroupBy(w => w.EndDateTime.Value.Date);

            Dictionary <DateTime, double> valuesForGroup = new Dictionary <DateTime, double>();

            foreach (var item in groupWorksGroupByDay)
            {
                TimeSpan totalTimeSpan = new TimeSpan();
                foreach (TaskSubitemWork work in item)
                {
                    totalTimeSpan += work.EndDateTime.Value - work.StartDateTime;
                }
                valuesForGroup.Add(item.Key, totalTimeSpan.Minutes);
            }

            Dictionary <DateTime, double> valuesForUser = new Dictionary <DateTime, double>();

            foreach (var item in userWorksGroupByDay)
            {
                TimeSpan totalTimeSpan = new TimeSpan();
                foreach (TaskSubitemWork work in item)
                {
                    totalTimeSpan += work.EndDateTime.Value - work.StartDateTime;
                }
                valuesForUser.Add(item.Key, totalTimeSpan.Minutes);
            }

            var groupDictDt = valuesForGroup.OrderBy(i => i.Key).ToDictionary(pair => pair.Key, pair => pair.Value);
            var userDictDt  = valuesForUser.OrderBy(i => i.Key).ToDictionary(pair => pair.Key, pair => pair.Value);

            foreach (var g in groupDictDt)
            {
                if (!userDictDt.ContainsKey(g.Key))
                {
                    userDictDt.Add(g.Key, 0);
                }
            }

            var groupDict = groupDictDt.OrderBy(i => i.Key).ToDictionary(pair => pair.Key.ToString("dd-MM-yyyy"), pair => pair.Value);
            var userDict  = userDictDt.OrderBy(i => i.Key).ToDictionary(pair => pair.Key.ToString("dd-MM-yyyy"), pair => pair.Value);

            int    width      = 600;
            int    height     = 50;
            string chartTitle = "In this period nobody spend time on the tasks in this group.";

            if (groupDict.Any() || userDict.Any())
            {
                width      = 1024;
                height     = 700;
                chartTitle = "Minutes spent on task subitems";
            }
            var key = new Chart(width: width, height: height)
                      .AddSeries(
                chartType: "column",
                legend: "group",
                xValue: groupDict.Keys,
                yValues: groupDict.Values)
                      .AddSeries(
                chartType: "column",
                legend: "user",
                xValue: userDict.Keys,
                yValues: userDict.Values).AddTitle(chartTitle)
                      .Write();

            return(null);
        }