示例#1
0
        /// <summary>
        /// Creates the user completed days charts.
        /// </summary>
        /// <returns></returns>
        public ChartModel CreateUserCompletedDaysChart()
        {
            using (var dbContext = GetDatabaseContext())
            {
                // Initial blank filter model.
                TaskFilterModel filterModel = new TaskFilterModel
                {
                    OriginalCreationDateFrom = DateTime.Now.AddDays(-14),
                    OriginalCreationDateTo   = DateTime.Now,
                    ActualFinishDateFrom     = DateTime.Now.AddDays(-14),
                    ActualFinishDateTo       = DateTime.Now,
                    StartedDate   = DateTime.Now.AddDays(-14),
                    AllUsers      = dbContext.Users.ToList(),
                    CreatedUserId = "",
                    TaskPriority  = -1
                };

                ChartModel chartModel = new ChartModel
                {
                    Type = "bar"
                };

                ChartDataModel chartDataModel = new ChartDataModel
                {
                    Labels = new List <string>()
                };

                int index = 0;
                foreach (User user in dbContext.Users.ToList())
                {
                    chartDataModel.Labels.Add(user.UserName);
                }

                ChartDatasetModel chartDatasetModel = new ChartDatasetModel
                {
                    Data            = new int[dbContext.Users.Count()],
                    BackgroundColor = new string[] { "#FF69B4" },
                    BorderColor     = new string[] { "#FFFFFF" },
                };

                IEnumerable <User> users = dbContext.Users.ToList();
                index = 0;
                foreach (User user in users.Where(user => user.AssignedTasks != null))
                {
                    int totalCompletedDays = user.AssignedTasks.Where(task => task.TaskStateId == 3 && task.ActualFinishDate >= filterModel.ActualFinishDateFrom &&
                                                                      task.ActualFinishDate <= filterModel.ActualFinishDateTo).Sum(task => task.ActualDaysTaken);
                    chartDatasetModel.Data[index] = totalCompletedDays;
                    index++;
                }

                chartDataModel.Datasets = new List <ChartDatasetModel> {
                    chartDatasetModel
                };
                chartModel.Data  = chartDataModel;
                chartModel.Title = "User Completed Days - Past Two Weeks";

                return(chartModel);
            }
        }
示例#2
0
        /// <summary>
        /// Creates the estimated days bar chart.
        /// </summary>
        /// <returns></returns>
        public ChartModel CreateEstimatedDaysChart()
        {
            using (var dbContext = GetDatabaseContext())
            {
                ChartModel chartModel = new ChartModel
                {
                    Type = "bar"
                };

                ChartDataModel chartDataModel = new ChartDataModel
                {
                    Labels = new List <string>()
                };

                foreach (User user in dbContext.Users.ToList())
                {
                    chartDataModel.Labels.Add(user.UserName);
                }

                ChartDatasetModel chartDatasetModel = new ChartDatasetModel
                {
                    Data            = new int[dbContext.Users.Count()],
                    BackgroundColor = new string[] { "#FF69B4" },
                    BorderColor     = new string[] { "#FFFFFF" },
                    BorderWidth     = 1
                };

                int index = 0;

                foreach (User user in dbContext.Users.ToList())
                {
                    IEnumerable <Task> tasksWithinTimePeriod = user.AssignedTasks.Where(task => task.OriginalCreationDate >= DateTime.Now.AddDays(-14));

                    int totalEstimatedDays = tasksWithinTimePeriod != null?tasksWithinTimePeriod.Select(task => task.EstimatedDaysTaken).Sum() : 0;

                    chartDatasetModel.Data[index] = totalEstimatedDays;
                    index++;
                }

                chartDataModel.Datasets = new List <ChartDatasetModel> {
                    chartDatasetModel
                };
                chartModel.Data  = chartDataModel;
                chartModel.Title = "Estimated Days for each User - Active Tasks";
                return(chartModel);
            }
        }
示例#3
0
        /// <summary>
        /// Creates the open tasks chart model.
        /// </summary>
        /// <returns></returns>
        public ChartModel CreateOpenTasksChart()
        {
            using (var dbContext = GetDatabaseContext())
            {
                ChartModel chartModel = new ChartModel
                {
                    Type = "polarArea"
                };

                ChartDataModel chartDataModel = new ChartDataModel
                {
                    Labels = new List <string> {
                        "Very Low", "Low", "Medium", "High", "Very High"
                    }
                };

                ChartDatasetModel chartDatasetModel = new ChartDatasetModel
                {
                    Data            = new int[5],
                    BackgroundColor = new string[] { "#4CE641", "#95EC32", "#F2F222", "#F88D11", "#FF1200" },
                    BorderColor     = new string[] { "#ffffff" },
                    BorderWidth     = 1
                };
                List <Task> openTasks = dbContext.Tasks.Where(task => task.TaskStateId == 1).ToList();

                chartDatasetModel.Data[0] = openTasks.Count(task => task.TaskPriority == 1);
                chartDatasetModel.Data[1] = openTasks.Count(task => task.TaskPriority == 2);
                chartDatasetModel.Data[2] = openTasks.Count(task => task.TaskPriority == 3);
                chartDatasetModel.Data[3] = openTasks.Count(task => task.TaskPriority == 4);
                chartDatasetModel.Data[4] = openTasks.Count(task => task.TaskPriority == 5);

                chartDataModel.Datasets = new List <ChartDatasetModel> {
                    chartDatasetModel
                };
                chartModel.Data  = chartDataModel;
                chartModel.Title = "Open Tasks - Priority Weighting";
                return(chartModel);
            }
        }
示例#4
0
        /// <summary>
        /// Creates the logged in user doughnut chart.
        /// </summary>
        /// <returns></returns>
        public ChartModel CreateLoggedInUserChart()
        {
            ChartModel chartModel = new ChartModel
            {
                Type = "doughnut"
            };

            ChartDataModel chartDataModel = new ChartDataModel
            {
                Labels = new List <string> {
                    "Online", "Offline"
                }
            };

            ChartDatasetModel chartDatasetModel = new ChartDatasetModel
            {
                Data            = new int[2],
                BackgroundColor = new string[] { "#66FF66", "#FF6666" },
                BorderColor     = new string[] { "#ffffff", "#ffffff" },
                BorderWidth     = 1
            };

            using (var dbContext = GetDatabaseContext())
            {
                int userCount = dbContext.Users.Count();

                chartDatasetModel.Data[0] = dbContext.Users.Where(user => user.IsLoggedIn == 1).Count();
                chartDatasetModel.Data[1] = dbContext.Users.Where(user => user.IsLoggedIn == 0).Count();
            }

            chartDataModel.Datasets = new List <ChartDatasetModel> {
                chartDatasetModel
            };
            chartModel.Data  = chartDataModel;
            chartModel.Title = "Currently Logged in Users";
            return(chartModel);
        }
示例#5
0
        public async Task <IActionResult> Measurements([FromQuery] SaMiQueryModel saMiQuery)
        {
            IncrementQueryCount();

            var user = await userManager.GetUserAsync(HttpContext.User);

            user.Queries.Add(saMiQuery);

            if (user.Queries.Count > 3)
            {
                user.Queries.RemoveAt(0);
            }

            userManager.UpdateAsync(user);

            if (!ModelState.IsValid)
            {
                return(BadRequest());
            }

            var date = saMiQuery.Date;

            var tomorrow = date.AddDays(1);

            var url = $"{configuration.GetSection("Urls").GetSection("Measurements").Value}{saMiQuery.Key}?data-tags={saMiQuery.Tag}&from={date.ToShortDateString()}&to={tomorrow.ToShortDateString()}&take=288";

            var request = new HttpRequestMessage(HttpMethod.Get, url);

            var client = clientFactory.CreateClient();

            var response = await client.SendAsync(request);

            if (!response.IsSuccessStatusCode)
            {
                return(BadRequest());
            }

            var body = await response.Content.ReadAsStringAsync();

            var measurements = JsonSerializer.Deserialize <List <SaMiMeasurementModel> >(body);

            var chartData = new ChartDataModel();

            var chartDataSet = new ChartDatasetModel();

            foreach (var measurement in measurements)
            {
                chartData.Labels.Add(measurement.TimestampISO8601.ToShortTimeString());
                chartDataSet.Data.Add(measurement.Data[0].Value);
            }

            chartData.Labels.Reverse();

            chartDataSet.Label = saMiQuery.Unit;

            chartDataSet.Data.Reverse();

            chartData.Datasets.Add(chartDataSet);

            body = JsonSerializer.Serialize(chartData);

            IncrementMeasurementCount();

            return(Content(body, "application/json"));
        }
示例#6
0
        /// <summary>
        /// Creates the task bar chart.
        /// </summary>
        /// <param name="tasksDesired">The tasks desired.</param>
        /// <returns></returns>
        public ChartModel CreateTaskBarChart(string tasksDesired)
        {
            using (var dbContext = GetDatabaseContext())
            {
                // Initial blank filter model.
                TaskFilterModel filterModel = new TaskFilterModel
                {
                    OriginalCreationDateFrom = DateTime.Now.AddDays(-14),
                    OriginalCreationDateTo   = DateTime.Now,
                    ActualFinishDateFrom     = DateTime.Now.AddDays(-14),
                    ActualFinishDateTo       = DateTime.Now,
                    StartedDate   = DateTime.Now.AddDays(-14),
                    TasksDesired  = tasksDesired,
                    AllUsers      = dbContext.Users.ToList(),
                    CreatedUserId = "",
                    TaskPriority  = -1
                };

                ChartModel chartModel = new ChartModel
                {
                    Type = "bar"
                };

                ChartDataModel chartDataModel = new ChartDataModel
                {
                    Labels = new List <string> {
                        "Open", "Active", "Closed"
                    }
                };

                ChartDatasetModel chartDatasetModel = new ChartDatasetModel
                {
                    Data            = new int[3],
                    BackgroundColor = new string[] { "#ffb6c1", "#98ff98", "#C0C0C0" },
                    BorderColor     = new string[] { "#FFFFFF" }
                };

                User        currentUser = GetCurrentUser();
                List <Task> tasks;

                switch (tasksDesired)
                {
                case "mytasks":
                    tasks            = dbContext.Tasks.Where(task => task.AssignedUserId == currentUser.Id).ToList();
                    chartModel.Title = "Task State - My Tasks - Past Two Weeks";
                    break;

                case "teamtasks":
                    tasks            = dbContext.Tasks.Where(task => task.AssignedUser.TeamId == currentUser.TeamId).ToList();
                    chartModel.Title = "Task State - Team Tasks - Past Two Weeks";
                    break;

                default:
                    tasks            = dbContext.Tasks.ToList();
                    chartModel.Title = "Task State - All Tasks - Past Two Weeks";
                    break;
                }

                // Apply the dates filter.
                tasks = tasks.Where(task => task.OriginalCreationDate >= filterModel.OriginalCreationDateFrom &&
                                    task.OriginalCreationDate <= filterModel.OriginalCreationDateTo ||
                                    task.TaskStartedDate >= filterModel.StartedDate ||
                                    task.ActualFinishDate >= filterModel.ActualFinishDateFrom &&
                                    task.ActualFinishDate <= filterModel.ActualFinishDateTo).ToList();

                foreach (Task task in tasks)
                {
                    switch (task.TaskState.TaskStateCurrent)
                    {
                    case "Open":
                        chartDatasetModel.Data[0]++;
                        break;

                    case "Active":
                        chartDatasetModel.Data[1]++;
                        break;

                    case "Closed":
                        chartDatasetModel.Data[2]++;
                        break;

                    default:
                        break;
                    }
                }

                chartDataModel.Datasets = new List <ChartDatasetModel> {
                    chartDatasetModel
                };
                chartModel.Data = chartDataModel;

                return(chartModel);
            }
        }
示例#7
0
        /// <summary>
        /// Creates the created tasks in the past week graph.
        /// </summary>
        /// <returns></returns>
        public ChartModel CreateCreatedTasksLineGraph()
        {
            using (var dbContext = GetDatabaseContext())
            {
                ChartModel chartModel = new ChartModel
                {
                    Type = "line"
                };

                ChartDataModel chartDataModel = new ChartDataModel
                {
                    Labels = new List <string> {
                        DateTime.Now.AddDays(-6).DayOfWeek.ToString(),
                        DateTime.Now.AddDays(-5).DayOfWeek.ToString(),
                        DateTime.Now.AddDays(-4).DayOfWeek.ToString(),
                        DateTime.Now.AddDays(-3).DayOfWeek.ToString(),
                        DateTime.Now.AddDays(-2).DayOfWeek.ToString(),
                        DateTime.Now.AddDays(-1).DayOfWeek.ToString(),
                        DateTime.Now.DayOfWeek.ToString()
                    }
                };

                ChartDatasetModel chartDatasetModel = new ChartDatasetModel
                {
                    Label           = "Created Per Day",
                    Data            = new int[7],
                    BackgroundColor = new string[] { "#0078d7" },
                    BorderColor     = new string[] { "#FFFFFF" },
                    BorderWidth     = 1
                };

                ChartDatasetModel chartDatasetModelCumulative = new ChartDatasetModel
                {
                    Label           = "Cumulative Total",
                    Data            = new int[7],
                    BackgroundColor = new string[] { "#d70078" },
                    BorderColor     = new string[] { "#FFFFFF" },
                    BorderWidth     = 1
                };

                DateTime           lastWeek = DateTime.Now.AddDays(-7);
                IEnumerable <Task> tasks    = dbContext.Tasks.Where(task => task.OriginalCreationDate >= lastWeek).ToList();
                foreach (Task task in tasks)
                {
                    switch ((DateTime.Now - task.OriginalCreationDate).Days.ToString())
                    {
                    case "7":
                        chartDatasetModel.Data[0]++;
                        break;

                    case "6":
                        chartDatasetModel.Data[1]++;
                        break;

                    case "5":
                        chartDatasetModel.Data[2]++;
                        break;

                    case "4":
                        chartDatasetModel.Data[3]++;
                        break;

                    case "3":
                        chartDatasetModel.Data[4]++;
                        break;

                    case "2":
                        chartDatasetModel.Data[5]++;
                        break;

                    default:
                        chartDatasetModel.Data[6]++;
                        break;
                    }
                }

                // Make the cumulative dataset.
                int total;
                for (int i = 0; i < 7; i++)
                {
                    total = 0;
                    for (int j = 0; j <= i; j++)
                    {
                        total += chartDatasetModel.Data[j];
                    }
                    chartDatasetModelCumulative.Data[i] = total;
                }

                chartDataModel.Datasets = new List <ChartDatasetModel> {
                    chartDatasetModel, chartDatasetModelCumulative
                };
                chartModel.Data  = chartDataModel;
                chartModel.Title = "Tasks Created - Past Week";
                return(chartModel);
            }
        }