Esempio n. 1
0
        public JsonResult GetModules(ChartLoadRequestObject reqObj)
        {
            DateTime startDate        = string.IsNullOrEmpty(reqObj.StartDate) ? System.DateTime.Now.AddDays(-365) : DateTime.ParseExact(reqObj.StartDate, "dd/MM/yyyy", CultureInfo.InvariantCulture);
            DateTime endDate          = string.IsNullOrEmpty(reqObj.EndDate) ? System.DateTime.Now : DateTime.ParseExact(reqObj.EndDate, "dd/MM/yyyy", CultureInfo.InvariantCulture);
            string   connectionString = ConfigurationManager.ConnectionStrings["NHSConStr"].ConnectionString;
            DBEngine dBEngine         = new DBEngine(connectionString);
            List <UserModuleDetails> userModuleDetails = dBEngine.GetUserModuleDetails(startDate, endDate, Convert.ToInt32(Session["LoginUserID"]));

            var moduleList = userModuleDetails.GroupBy(x => x.ModuleName).Select(x => new ModuleInformation()
            {
                ModuleId   = x.Key,
                ModuleName = x.Key
            }).ToList();

            return(Json(moduleList, JsonRequestBehavior.AllowGet));
        }
Esempio n. 2
0
        public JsonResult SessionTimeChartResult(ChartLoadRequestObject reqObj)
        {
            DateTime                 startDate         = string.IsNullOrEmpty(reqObj.StartDate) ? System.DateTime.Now.AddDays(-365) : DateTime.ParseExact(reqObj.StartDate, "dd/MM/yyyy", CultureInfo.InvariantCulture);
            DateTime                 endDate           = string.IsNullOrEmpty(reqObj.EndDate) ? System.DateTime.Now : DateTime.ParseExact(reqObj.EndDate, "dd/MM/yyyy", CultureInfo.InvariantCulture);
            string                   connectionString  = ConfigurationManager.ConnectionStrings["NHSConStr"].ConnectionString;
            DBEngine                 dBEngine          = new DBEngine(connectionString);
            List <UserCount>         users             = dBEngine.GetActiveUsers(startDate, endDate, Convert.ToInt32(Session["LoginUserID"]));
            List <UserModuleDetails> userModuleDetails = dBEngine.GetUserModuleDetails(startDate, endDate, Convert.ToInt32(Session["LoginUserID"]));

            var chartInfo = new List <ChartResponseInformation>();

            var filteredResult = new List <UserCount>();

            var chartOptions = new ChartOptionInformation();

            if (reqObj.RequestType == DataTypeEnum.yearly.ToString())
            {
                filteredResult = users.GroupBy(x => x.DistinctYear).Select(y => new UserCount
                {
                    DistinctYear  = y.Key,
                    ActivityCount = y.Sum(z => z.ActivityCount)
                }).ToList();
            }
            if (reqObj.RequestType == DataTypeEnum.monthly.ToString())
            {
                filteredResult = users.GroupBy(x => x.Month).Select(y => new UserCount
                {
                    Month         = y.Key,
                    ActivityCount = y.Sum(z => z.ActivityCount)
                }).ToList();
            }
            if (reqObj.RequestType == DataTypeEnum.weekly.ToString())
            {
                filteredResult = users.GroupBy(x => x.Week).Select(y => new UserCount
                {
                    Week          = y.Key,
                    ActivityCount = y.Sum(z => z.ActivityCount)
                }).ToList();
            }
            if (reqObj.RequestType == DataTypeEnum.daily.ToString())
            {
                filteredResult = users.GroupBy(x => x.Day).Select(y => new UserCount
                {
                    Day           = y.Key,
                    ActivityCount = y.Sum(z => z.ActivityCount)
                }).ToList();
            }

            var seriesData = new List <string>();
            var xAxisData  = new List <string>();

            foreach (var userCountInfo in filteredResult)
            {
                seriesData.Add(userCountInfo.ActivityCount.ToString());
                xAxisData.Add(reqObj.RequestType == DataTypeEnum.yearly.ToString() ? userCountInfo.DistinctYear :
                              reqObj.RequestType == DataTypeEnum.monthly.ToString() ? userCountInfo.Month :
                              reqObj.RequestType == DataTypeEnum.weekly.ToString() ? userCountInfo.Week :
                              userCountInfo.Day);
            }

            #region Static Data Area


            chartInfo = new List <ChartResponseInformation>
            {
                new ChartResponseInformation()
                {
                    name = "Session",
                    data = seriesData.ToArray()
                }
            };
            chartOptions = new ChartOptionInformation()
            {
                X_axisCategoryType = "category",
                X_axisCategories   = xAxisData.ToArray()
            };


            #endregion

            var result = new ChartResultResponse()
            {
                ChartInfo    = chartInfo,
                ChartOptions = chartOptions,
                UserModuleTimeSpanInformation = userModuleDetails
            };

            return(Json(result, JsonRequestBehavior.AllowGet));
        }
Esempio n. 3
0
        public JsonResult TotalTimeSpentByModuleChartResult(ChartLoadRequestObject reqObj)
        {
            DateTime startDate        = string.IsNullOrEmpty(reqObj.StartDate) ? System.DateTime.Now.AddDays(-365) : DateTime.ParseExact(reqObj.StartDate, "dd/MM/yyyy", CultureInfo.InvariantCulture);
            DateTime endDate          = string.IsNullOrEmpty(reqObj.EndDate) ? System.DateTime.Now : DateTime.ParseExact(reqObj.EndDate, "dd/MM/yyyy", CultureInfo.InvariantCulture);
            string   connectionString = ConfigurationManager.ConnectionStrings["NHSConStr"].ConnectionString;
            DBEngine dBEngine         = new DBEngine(connectionString);
            List <UserModuleDetails> userModuleDetails = dBEngine.GetUserModuleDetails(startDate, endDate, Convert.ToInt32(Session["LoginUserID"]));

            List <UserModuleDetails> userModuleTimeSpan = dBEngine.GetUserModuleTimeSpan(startDate, endDate, Convert.ToInt32(Session["LoginUserID"]), false);


            //var filteredResult = userModuleDetails.GroupBy(x => x.UserName).Select(y => new UserModuleDetails
            //{
            //    ModuleName = y.Key,
            //    ActivityCount = Convert.ToInt32(y.Average(z => z.TimeSpan))
            //}).ToList();
            var chartInfo = new List <ChartResponseInformation>();

            var chartOptions = new ChartOptionInformation();

            var filteredUserModuleDetails = new List <UserModuleDetails>();

            if (reqObj.RequestType == DataTypeEnum.yearly.ToString())
            {
                filteredUserModuleDetails = userModuleDetails.GroupBy(x => new { x.Year, x.ModuleName })
                                            .Select(x => new UserModuleDetails
                {
                    ModuleName = x.Key.ModuleName,
                    Year       = x.Key.Year,
                    TimeSpan   = x.Sum(y => y.TimeSpan)
                }).ToList();
            }

            if (reqObj.RequestType == DataTypeEnum.quarter.ToString())
            {
                filteredUserModuleDetails = userModuleDetails.GroupBy(x => new { x.Quarter, x.ModuleName })
                                            .Select(x => new UserModuleDetails
                {
                    ModuleName = x.Key.ModuleName,
                    Quarter    = x.Key.Quarter,
                    TimeSpan   = x.Sum(y => y.TimeSpan)
                }).ToList();
            }

            if (reqObj.RequestType == DataTypeEnum.monthly.ToString())
            {
                filteredUserModuleDetails = userModuleDetails.GroupBy(x => new { x.Month, x.ModuleName })
                                            .Select(x => new UserModuleDetails
                {
                    ModuleName = x.Key.ModuleName,
                    Month      = x.Key.Month,
                    TimeSpan   = x.Sum(y => y.TimeSpan)
                }).ToList();
            }

            if (reqObj.RequestType == DataTypeEnum.weekly.ToString())
            {
                filteredUserModuleDetails = userModuleDetails.GroupBy(x => new { x.Week, x.ModuleName })
                                            .Select(x => new UserModuleDetails
                {
                    ModuleName = x.Key.ModuleName,
                    Week       = x.Key.Week,
                    TimeSpan   = x.Sum(y => y.TimeSpan)
                }).ToList();
            }

            #region Static Data Area
            var xAxisCategories = new List <string>();
            var chartResponse   = new List <ChartResponseInformation>();

            var serisData = new List <string>();

            var dResult = filteredUserModuleDetails.GroupBy(x => x.ModuleName).ToList();
            foreach (var row in dResult)
            {
                chartResponse.Add(new ChartResponseInformation
                {
                    name = row.Key,
                    data = filteredUserModuleDetails.Where(x => x.ModuleName == row.Key).Select(x => x.TimeSpan.ToString()).ToArray()
                });
            }
            if (reqObj.RequestType == DataTypeEnum.yearly.ToString())
            {
                var yearData = filteredUserModuleDetails.GroupBy(x => x.Year).ToList();
                foreach (var year in yearData)
                {
                    if (!xAxisCategories.Any(x => x == year.Key.ToString()))
                    {
                        xAxisCategories.Add((year.Key.ToString()));
                    }
                }
            }
            if (reqObj.RequestType == DataTypeEnum.quarter.ToString())
            {
                var quarterData = filteredUserModuleDetails.GroupBy(x => x.Quarter).ToList();
                foreach (var quarter in quarterData)
                {
                    if (!xAxisCategories.Any(x => x == quarter.Key.ToString()))
                    {
                        xAxisCategories.Add((quarter.Key.ToString()));
                    }
                }
            }

            if (reqObj.RequestType == DataTypeEnum.monthly.ToString())
            {
                var monthData = filteredUserModuleDetails.GroupBy(x => x.Month).ToList();
                foreach (var month in monthData)
                {
                    if (!xAxisCategories.Any(x => x == month.Key.ToString()))
                    {
                        xAxisCategories.Add((month.Key.ToString()));
                    }
                }
            }

            if (reqObj.RequestType == DataTypeEnum.weekly.ToString())
            {
                var weekData = filteredUserModuleDetails.GroupBy(x => x.Week).ToList();
                foreach (var week in weekData)
                {
                    if (!xAxisCategories.Any(x => x == week.Key.ToString()))
                    {
                        xAxisCategories.Add((week.Key.ToString()));
                    }
                }
            }


            chartInfo    = chartResponse;
            chartOptions = new ChartOptionInformation
            {
                X_axisCategoryType = "category",
                X_axisCategories   = xAxisCategories.ToArray()
            };


            #endregion


            var result = new ChartResultResponse()
            {
                ChartInfo    = chartInfo,
                ChartOptions = chartOptions,
                UserModuleTimeSpanInformation = userModuleTimeSpan
            };

            return(Json(result, JsonRequestBehavior.AllowGet));
        }
Esempio n. 4
0
        public JsonResult SessionAvgTimeByUserByModuleChartResult(ChartLoadRequestObject reqObj)
        {
            DateTime startDate        = string.IsNullOrEmpty(reqObj.StartDate) ? System.DateTime.Now.AddDays(-365) : DateTime.ParseExact(reqObj.StartDate, "dd/MM/yyyy", CultureInfo.InvariantCulture);
            DateTime endDate          = string.IsNullOrEmpty(reqObj.EndDate) ? System.DateTime.Now : DateTime.ParseExact(reqObj.EndDate, "dd/MM/yyyy", CultureInfo.InvariantCulture);
            string   connectionString = ConfigurationManager.ConnectionStrings["NHSConStr"].ConnectionString;
            DBEngine dBEngine         = new DBEngine(connectionString);
            List <UserModuleDetails> userModuleDetails = dBEngine.GetUserModuleDetails(startDate, endDate, Convert.ToInt32(Session["LoginUserID"]));
            List <UserModuleInfo>    userModuleInfo    = dBEngine.GetUserModuleInfo(startDate, endDate, Convert.ToInt32(Session["LoginUserID"]));
            var chartInfo = new List <ChartResponseInformation>();

            var filteredResult = userModuleDetails.GroupBy(x => new { x.UserName, x.ModuleName }).Select(
                y => new UserModuleDetails
            {
                UserName      = y.Key.UserName,
                ModuleName    = y.Key.ModuleName,
                ActivityCount = y.Count()
            }).ToList();

            var chartOptions  = new ChartOptionInformation();
            var xAxisData     = new List <string>();
            var chartData     = new List <ChartResponseInformation>();
            var chartInfoData = new List <string>();

            var dResult = filteredResult.GroupBy(x => x.ModuleName).ToList();

            foreach (var moduleInfo in dResult)
            {
                chartData.Add(new ChartResponseInformation
                {
                    name = moduleInfo.Key,
                    data = filteredResult.Where(x => x.ModuleName == moduleInfo.Key).Select(x => x.ActivityCount.ToString()).ToArray()
                });
            }

            foreach (var userData in filteredResult.GroupBy(x => x.UserName).ToList())
            {
                if (!xAxisData.Any(x => x == userData.Key))
                {
                    xAxisData.Add(userData.Key);
                }
            }

            chartInfo    = chartData;
            chartOptions = new ChartOptionInformation
            {
                X_axisCategoryType = "category",
                X_axisCategories   = xAxisData.ToArray()
            };


            var result = new ChartResultResponse();

            if (reqObj.FilterByUserId != null && reqObj.FilterByUserId.Length > 0)
            {
                var seriesData           = new List <ChartResponseInformation>();
                var seriesCategoriesData = new List <string>();
                foreach (var userId in reqObj.FilterByUserId)
                {
                    var seriesDataIndex = Array.IndexOf(chartOptions.X_axisCategories, userId);

                    seriesData.Add(chartInfo[seriesDataIndex]);
                    seriesCategoriesData.Add(userId);
                }

                result = new ChartResultResponse()
                {
                    ChartInfo    = seriesData,
                    ChartOptions = new ChartOptionInformation
                    {
                        X_axisCategoryType = "category",
                        X_axisCategories   = seriesCategoriesData.ToArray()
                    }
                };
            }
            else
            {
                result = new ChartResultResponse()
                {
                    ChartInfo             = chartInfo,
                    ChartOptions          = chartOptions,
                    UserModuleInformation = userModuleInfo
                };
            }

            return(Json(result, JsonRequestBehavior.AllowGet));
        }
Esempio n. 5
0
        public JsonResult AvgTimeModuleChartResult(ChartLoadRequestObject reqObj)
        {
            DateTime startDate        = string.IsNullOrEmpty(reqObj.StartDate) ? System.DateTime.Now.AddDays(-365) : DateTime.ParseExact(reqObj.StartDate, "dd/MM/yyyy", CultureInfo.InvariantCulture);
            DateTime endDate          = string.IsNullOrEmpty(reqObj.EndDate) ? System.DateTime.Now : DateTime.ParseExact(reqObj.EndDate, "dd/MM/yyyy", CultureInfo.InvariantCulture);
            string   connectionString = ConfigurationManager.ConnectionStrings["NHSConStr"].ConnectionString;
            DBEngine dBEngine         = new DBEngine(connectionString);
            List <UserModuleDetails> userModuleDetails  = dBEngine.GetUserModuleDetails(startDate, endDate, Convert.ToInt32(Session["LoginUserID"]));
            List <UserModuleDetails> userModuleTimeSpan = dBEngine.GetUserModuleTimeSpan(startDate, endDate, Convert.ToInt32(Session["LoginUserID"]), true);


            var filteredResult = userModuleDetails.GroupBy(x => x.ModuleName).Select(y => new UserModuleDetails
            {
                ModuleName = y.Key,
                TimeSpan   = Convert.ToInt32(y.Average(z => z.TimeSpan))
            }).ToList();

            var chartInfo = new List <ChartResponseInformation>();

            var chartOptions = new ChartOptionInformation();

            var modules       = new List <string>();
            var times         = new List <string>();
            var moduleInfoDic = new Dictionary <string, string>();

            foreach (var data in filteredResult)
            {
                modules.Add(data.ModuleName);
                times.Add(data.TimeSpan.ToString());
                moduleInfoDic.Add(data.ModuleName, data.TimeSpan.ToString());
            }

            chartInfo = new List <ChartResponseInformation> {
                new ChartResponseInformation()
                {
                    name = "AVG Time",
                    data = times.ToArray()
                },
            };

            chartOptions = new ChartOptionInformation()
            {
                X_axisCategoryType = "category",
                X_axisCategories   = modules.ToArray()
            };

            var result = new ChartResultResponse();

            if (reqObj.FilterByProjectId != null && reqObj.FilterByProjectId.Length > 0)
            {
                var seriesData         = new List <string>();
                var seriesCategoryData = new List <string>();

                foreach (var project in reqObj.FilterByProjectId)
                {
                    seriesData.Add(moduleInfoDic.FirstOrDefault(x => x.Key == project).Value);
                    seriesCategoryData.Add(moduleInfoDic.FirstOrDefault(x => x.Key == project).Key);
                }

                result = new ChartResultResponse()
                {
                    ChartInfo = chartInfo.Select(x => new ChartResponseInformation()
                    {
                        name   = x.name,
                        titile = x.titile,
                        data   = seriesData.ToArray()
                    })
                    ,
                    ChartOptions = new ChartOptionInformation()
                    {
                        X_axisCategoryType = chartOptions.X_axisCategoryType,
                        X_axisCategories   = seriesCategoryData.ToArray()
                    }
                };
            }
            else
            {
                result = new ChartResultResponse()
                {
                    ChartInfo    = chartInfo,
                    ChartOptions = chartOptions,
                    UserModuleTimeSpanInformation = userModuleTimeSpan
                };
            }
            return(Json(result, JsonRequestBehavior.AllowGet));
        }