/// <summary> /// Generate the all page report summary to create a line chart /// </summary> /// <param name="pageReportType"></param> /// <param name="dateFrom"></param> /// <param name="dateTo"></param> /// <returns></returns> public static PageReportSummary GeneratePageReport(PageReportType pageReportType, DateTime dateFrom, DateTime dateTo, string selectedPage = "") { dateFrom = new DateTime(dateFrom.Year, dateFrom.Month, dateFrom.Day, 0, 0, 1); dateTo = new DateTime(dateTo.Year, dateTo.Month, dateTo.Day, 23, 59, 59); PageReportSummary PageReportSummary = new PageReportSummary(); //add 3 lists to represent the all categories if (string.IsNullOrWhiteSpace(selectedPage) || "all".Equals(selectedPage)) { PageReportSummary.PageReportSeriesList.Add(new PageReportSeries { name = "Page Views", data = new List <int>() }); PageReportSummary.PageReportSeriesList.Add(new PageReportSeries { name = "Website Visits", data = new List <int>() }); PageReportSummary.PageReportSeriesList.Add(new PageReportSeries { name = "Unique Website Visits", data = new List <int>() }); } else { PageReportSummary.PageReportSeriesList.Add(new PageReportSeries { name = "Page Views", data = new List <int>() }); } List <PageView> PageViewList = ReportDAO.LoadPageViews(dateFrom, dateTo, selectedPage); if (PageViewList != null && PageViewList.Count > 0) { while (dateFrom <= dateTo) { string DateTimeFormat = GetDateTimeCategoryToString(pageReportType); string Category = dateFrom.ToString(DateTimeFormat); PageReportSummary.MasterCategoryList.Add(Category); if (string.IsNullOrWhiteSpace(selectedPage) || "all".Equals(selectedPage)) { ProcessAllPageReportRow(PageReportSummary, PageViewList, DateTimeFormat, Category); } else { ProcessSpecificPageReportRow(PageReportSummary, PageViewList, DateTimeFormat, Category); } dateFrom = IncreaseDateTime(pageReportType, dateFrom); } ProcessBasicStatistics(PageReportSummary, PageViewList); ProcessBrowserSummary(PageReportSummary, PageViewList); ProcessOperatingSystemSummary(PageReportSummary, PageViewList); } return(PageReportSummary); }
public PageReportCache(string cacheKey, DateTime lastAccessedUtc, PageReportSummary pageReport, string selectedPageType, PageReportType pageReportType, DateTime dateFrom, DateTime dateTo) { CacheKey = cacheKey; LastAccessedUtc = lastAccessedUtc; ReportSummary = pageReport; SelectedPageType = selectedPageType; PageReportType = pageReportType; DateFrom = dateFrom; DateTo = dateTo; }
/// <summary> /// Get the to string used for date time to string /// </summary> /// <param name="pageReportType"></param> /// <returns></returns> private static string GetDateTimeCategoryToString(PageReportType pageReportType) { switch (pageReportType) { case PageReportType.HOURLY: return "h tt"; case PageReportType.DAY: return "MMM dd"; case PageReportType.MONTH: return "MMM yyyy"; } return ""; }
/// <summary> /// Generate the all page report summary to create a line chart /// </summary> /// <param name="pageReportType"></param> /// <param name="dateFrom"></param> /// <param name="dateTo"></param> /// <returns></returns> public static PageReportSummary GeneratePageReport(PageReportType pageReportType, DateTime dateFrom, DateTime dateTo, string selectedPage = "") { dateFrom = new DateTime(dateFrom.Year, dateFrom.Month, dateFrom.Day, 0, 0, 1); dateTo = new DateTime(dateTo.Year, dateTo.Month, dateTo.Day, 23, 59, 59); PageReportSummary PageReportSummary = new PageReportSummary(); //add 3 lists to represent the all categories if (string.IsNullOrWhiteSpace(selectedPage) || "all".Equals(selectedPage)) { PageReportSummary.PageReportSeriesList.Add(new PageReportSeries { name = "Page Views", data = new List<int>() }); PageReportSummary.PageReportSeriesList.Add(new PageReportSeries { name = "Website Visits", data = new List<int>() }); PageReportSummary.PageReportSeriesList.Add(new PageReportSeries { name = "Unique Website Visits", data = new List<int>() }); } else { PageReportSummary.PageReportSeriesList.Add(new PageReportSeries { name = "Page Views", data = new List<int>() }); } List<PageView> PageViewList = ReportDAO.LoadPageViews(dateFrom, dateTo, selectedPage); if (PageViewList != null && PageViewList.Count > 0) { while (dateFrom <= dateTo) { string DateTimeFormat = GetDateTimeCategoryToString(pageReportType); string Category = dateFrom.ToString(DateTimeFormat); PageReportSummary.MasterCategoryList.Add(Category); if (string.IsNullOrWhiteSpace(selectedPage) || "all".Equals(selectedPage)) { ProcessAllPageReportRow(PageReportSummary, PageViewList, DateTimeFormat, Category); } else { ProcessSpecificPageReportRow(PageReportSummary, PageViewList, DateTimeFormat, Category); } dateFrom = IncreaseDateTime(pageReportType, dateFrom); } ProcessBasicStatistics(PageReportSummary, PageViewList); ProcessBrowserSummary(PageReportSummary, PageViewList); ProcessOperatingSystemSummary(PageReportSummary, PageViewList); } return PageReportSummary; }
/// <summary> /// Get the to string used for date time to string /// </summary> /// <param name="pageReportType"></param> /// <returns></returns> private static string GetDateTimeCategoryToString(PageReportType pageReportType) { switch (pageReportType) { case PageReportType.HOURLY: return("h tt"); case PageReportType.DAY: return("MMM dd"); case PageReportType.MONTH: return("MMM yyyy"); } return(""); }
/// <summary> /// Increase the date from according to the page report type /// </summary> /// <param name="pageReportType"></param> /// <param name="dateFrom"></param> /// <returns></returns> private static DateTime IncreaseDateTime(PageReportType pageReportType, DateTime dateFrom) { switch (pageReportType) { case PageReportType.HOURLY: return(dateFrom.AddHours(1)); case PageReportType.DAY: return(dateFrom.AddDays(1)); case PageReportType.MONTH: return(dateFrom.AddMonths(1)); } return(dateFrom); }
public ActionResult Index(string selectedPageType, PageReportType? pageReportType, DateTime? dateFrom, DateTime? dateTo) { try { if (selectedPageType == null) { selectedPageType = string.Empty; } if (pageReportType == null) { pageReportType = PageReportType.DAY; } if (dateFrom == null) { dateFrom = DateTime.UtcNow.AddDays(-7); } if (dateTo == null) { dateTo = DateTime.UtcNow; } if (ChimeraWebsite.Helpers.AppSettings.AllowPageReportRecording) { ViewBag.PageReportSummary = ChimeraWebsite.Helpers.AppCache.GetPageReportSummary(selectedPageType, pageReportType.Value, dateFrom.Value, dateTo.Value); ViewBag.UniquePageTypes = Chimera.DataAccess.ReportDAO.LoadUniquePageTypes(); } ViewBag.NotificationList = DashboardNotificationDAO.LoadDashboardList(SiteContext.User.RoleList); } catch (Exception e) { CompanyCommons.Logging.WriteLog("ChimeraWebsite.Areas.Admin.Controllers.Dashboard() ", e); } ViewBag.selectedPageType = selectedPageType; ViewBag.pageReportType = pageReportType.Value; ViewBag.dateFrom = dateFrom.Value; ViewBag.dateTo = dateTo.Value; return View(); }
/// <summary> /// Check the app cache and see if this report cache has expired. /// </summary> /// <param name="selectedPageType"></param> /// <param name="pageReportType"></param> /// <param name="dateFrom"></param> /// <param name="dateTo"></param> /// <returns></returns> public static PageReportCache GetPageReportSummary(string selectedPageType, PageReportType pageReportType, DateTime dateFrom, DateTime dateTo) { string CacheKey = String.Format("{0}|{1}|{2}|{3}", selectedPageType.ToUpper(), pageReportType, dateFrom.ToString("MM/dd/yyyy"), dateTo.ToString("MM/dd/yyyy")); PageReportSummary ReportSummary = new PageReportSummary(); Dictionary <string, PageReportCache> PageReportDictionary = (Dictionary <string, PageReportCache>)HttpContext.Current.Application[PAGE_REPORT_APP_CACHE] ?? new Dictionary <string, PageReportCache>(); bool RunNewReport = false; if (PageReportDictionary.ContainsKey(CacheKey)) { if (PageReportDictionary[CacheKey].LastAccessedUtc <= DateTime.UtcNow) { RunNewReport = true; } else { ReportSummary = PageReportDictionary[CacheKey].ReportSummary; } } else { RunNewReport = true; } if (RunNewReport) { ReportSummary = PageReport.GeneratePageReport(pageReportType, dateFrom, dateTo, selectedPageType); PageReportDictionary[CacheKey] = new PageReportCache(CacheKey, DateTime.UtcNow.AddHours(1), ReportSummary, selectedPageType, pageReportType, dateFrom, dateTo); HttpContext.Current.Application[PAGE_REPORT_APP_CACHE] = PageReportDictionary; } return(PageReportDictionary[CacheKey]); }
/// <summary> /// Check the app cache and see if this report cache has expired. /// </summary> /// <param name="selectedPageType"></param> /// <param name="pageReportType"></param> /// <param name="dateFrom"></param> /// <param name="dateTo"></param> /// <returns></returns> public static PageReportCache GetPageReportSummary(string selectedPageType, PageReportType pageReportType, DateTime dateFrom, DateTime dateTo) { string CacheKey = String.Format("{0}|{1}|{2}|{3}", selectedPageType.ToUpper(), pageReportType, dateFrom.ToString("MM/dd/yyyy"), dateTo.ToString("MM/dd/yyyy")); PageReportSummary ReportSummary = new PageReportSummary(); Dictionary<string, PageReportCache> PageReportDictionary = (Dictionary<string, PageReportCache>)HttpContext.Current.Application[PAGE_REPORT_APP_CACHE] ?? new Dictionary<string, PageReportCache>(); bool RunNewReport = false; if (PageReportDictionary.ContainsKey(CacheKey)) { if (PageReportDictionary[CacheKey].LastAccessedUtc <= DateTime.UtcNow) { RunNewReport = true; } else { ReportSummary = PageReportDictionary[CacheKey].ReportSummary; } } else { RunNewReport = true; } if (RunNewReport) { ReportSummary = PageReport.GeneratePageReport(pageReportType, dateFrom, dateTo, selectedPageType); PageReportDictionary[CacheKey] = new PageReportCache(CacheKey, DateTime.UtcNow.AddHours(1), ReportSummary, selectedPageType, pageReportType, dateFrom, dateTo); HttpContext.Current.Application[PAGE_REPORT_APP_CACHE] = PageReportDictionary; } return PageReportDictionary[CacheKey]; }
/// <summary> /// Increase the date from according to the page report type /// </summary> /// <param name="pageReportType"></param> /// <param name="dateFrom"></param> /// <returns></returns> private static DateTime IncreaseDateTime(PageReportType pageReportType, DateTime dateFrom) { switch (pageReportType) { case PageReportType.HOURLY: return dateFrom.AddHours(1); case PageReportType.DAY: return dateFrom.AddDays(1); case PageReportType.MONTH: return dateFrom.AddMonths(1); } return dateFrom; }