public static Tuple <DateTime, DateTime> GetDates(this PastPeriod period) { var now = DateTime.UtcNow; var endDate = new DateTime(now.Year, now.Month, now.Day, now.Hour, now.Minute, 0, DateTimeKind.Utc); var startDate = endDate.AddDays(-1); switch (App.Settings.PastPeriod) { case PastPeriod.Hour: startDate = endDate.AddHours(-1); break; case PastPeriod.Day: startDate = endDate.AddDays(-1); break; case PastPeriod.Month: startDate = endDate.AddMonths(-1); break; case PastPeriod.Year: startDate = endDate.AddYears(-1); break; default: throw new NotSupportedException($"Value of type {period} isn't supported."); } return(new Tuple <DateTime, DateTime>(startDate, endDate)); }
private DateTime GetLatestDateForPastPeriod(PastPeriod pastPeriod, DateTime?startDate = null) { if (pastPeriod == PastPeriod.LastHalfHour) { return(DateTime.Now.AddMinutes(-30)); } else if (pastPeriod == PastPeriod.LastDay) { return(DateTime.Now.AddDays(-1)); } else if (pastPeriod == PastPeriod.LastWeek) { return(DateTime.Now.AddDays(-7)); } else if (pastPeriod == PastPeriod.LastMonth) { return(DateTime.Now.AddMonths(-1)); } else if (pastPeriod == PastPeriod.LastYear) { return(DateTime.Now.AddYears(-1)); } else if (pastPeriod == PastPeriod.Custom && startDate != null) { return(startDate.Value); } throw new ArgumentException("Can't find Latest Valid Date for specified arguments"); }
public GraphStatistics GetStatisticsForPastPeriod(int cameraId, PastPeriod pastPeriod, DateTime?startDate = null, DateTime?endDate = null) { GraphStatistics graphStatistics = new GraphStatistics(); if (startDate != null && endDate != null) { graphStatistics.StartDate = startDate; graphStatistics.EndDate = endDate; } List <DatabasePerSecondStat> perSecondStats = GetDatabasePerSecondStatsForPastPeriod(cameraId, pastPeriod, startDate, endDate); AddDelimiterStatsForPastPeriod(perSecondStats, pastPeriod, startDate, endDate); AddDummyStatsForDeadPeriods(perSecondStats); List <string[]> perSecondStatsFormattedStrings = new List <string[]>(); perSecondStatsFormattedStrings.Add(new [] { "DateTime", "People Detected" }); foreach (DatabasePerSecondStat perSecondStat in perSecondStats) { perSecondStatsFormattedStrings.Add(new [] { DateTime.SpecifyKind(perSecondStat.DateTime, DateTimeKind.Local).ToString("o"), perSecondStat.NumDetectedObjects.ToString() }); } graphStatistics.Stats = perSecondStatsFormattedStrings.ToArray(); graphStatistics.SelectedPeriod = pastPeriod; return(graphStatistics); }
public GraphStatistics GetSharedRoomStatisticsForPastPeriod(int roomId, PastPeriod pastPeriod, DateTime?startDate = null, DateTime?endDate = null) { List <DatabaseCamera> dbCameras = _databaseQueryService.GetAllCamerasInRoom(roomId); List <int> cameraIds = dbCameras.Select(camera => camera.CameraId).ToList(); return(GetSharedRoomStatisticsForPastPeriod(cameraIds, pastPeriod, startDate, endDate)); }
public JsonResult GetSharedRoomGraphStats(int roomId, PastPeriod pastPeriod) { if (HttpContext.Session.GetString("currentUsername") == null) { return(Json(false)); } GraphStatistics statistics = GraphStatisticService.GetSharedRoomStatisticsForPastPeriod(roomId, pastPeriod); return(Json(statistics)); }
public IActionResult SharedRoomGraphDashboard(int roomId, PastPeriod pastPeriod = PastPeriod.LastDay, DateTime?startDate = null, DateTime?endDate = null) { if (HttpContext.Session.GetString("currentUsername") == null) { return(RedirectToAction("SignIn", "Home")); } SharedGraphStatistics sharedGraphStatistics = CameraService.GetSharedRoomGraphStatistics(roomId); sharedGraphStatistics.SelectedPeriod = pastPeriod; sharedGraphStatistics.StartDate = startDate; sharedGraphStatistics.EndDate = endDate; return(View("RoomStatistics", sharedGraphStatistics)); }
// GET: /<controller>/ public IActionResult GraphDashboard(int cameraId, PastPeriod pastPeriod = PastPeriod.LastDay, DateTime?startDate = null, DateTime?endDate = null) { if (HttpContext.Session.GetString("currentUsername") == null) { return(RedirectToAction("SignIn", "Home")); } CameraInformation cameraInfo = CameraService.getCameraInformationById(cameraId); cameraInfo.GraphStatistics.SelectedPeriod = pastPeriod; cameraInfo.GraphStatistics.StartDate = startDate; cameraInfo.GraphStatistics.EndDate = endDate; return(View(cameraInfo)); }
public static String GetTitle(PastPeriod value) { switch (value) { case PastPeriod.Hour: return(ResourceLoader.GetString("Text_Hour")); case PastPeriod.Day: return(ResourceLoader.GetString("Text_Day")); case PastPeriod.Month: return(ResourceLoader.GetString("Text_Month")); case PastPeriod.Year: return(ResourceLoader.GetString("Text_Year")); default: throw new NotSupportedException($"Value of type {value} isn't supported."); } }
public PastPeriodItem(PastPeriod value) { Value = value; }
private List <DatabasePerSecondStat> GetDatabasePerSecondStatsForPastPeriod(int cameraId, PastPeriod pastPeriod, DateTime?startDate, DateTime?endDate) { List <DatabasePerSecondStat> perSecondStats = _databaseQueryService.GetPerSecondStatsForCamera(cameraId); //Remove all stats set into the future perSecondStats.RemoveAll(stat => DateTime.Now < stat.DateTime); if (pastPeriod == PastPeriod.LastHalfHour) { perSecondStats.RemoveAll(stat => DateTime.Now.AddMinutes(-30) >= stat.DateTime); } else if (pastPeriod == PastPeriod.LastDay) { perSecondStats.RemoveAll(stat => DateTime.Now.AddDays(-1) >= stat.DateTime); } else if (pastPeriod == PastPeriod.LastWeek) { perSecondStats.RemoveAll(stat => DateTime.Now.AddDays(-7) >= stat.DateTime); } else if (pastPeriod == PastPeriod.LastMonth) { perSecondStats.RemoveAll(stat => DateTime.Now.AddMonths(-1) >= stat.DateTime); } else if (pastPeriod == PastPeriod.LastYear) { perSecondStats.RemoveAll(stat => DateTime.Now.AddYears(-1) >= stat.DateTime); } else if (pastPeriod == PastPeriod.Custom) { if (startDate == null || endDate == null) { throw new InvalidDataException( "Graph on custom date range requested but startDate or endDate is null"); } perSecondStats.RemoveAll(stat => startDate.Value >= stat.DateTime || endDate.Value <= stat.DateTime); } return(perSecondStats); }
private void AddDelimiterStatsForPastPeriod(List <DatabasePerSecondStat> perSecondStats, PastPeriod pastPeriod, DateTime?startDate, DateTime?endDate = null) { perSecondStats.Insert(0, new DatabasePerSecondStat { DateTime = GetLatestDateForPastPeriod(pastPeriod, startDate), NumDetectedObjects = 0 }); perSecondStats.Add(new DatabasePerSecondStat { DateTime = pastPeriod == PastPeriod.Custom && endDate != null ? endDate.Value : DateTime.Now, NumDetectedObjects = 0 }); }
public GraphStatistics GetSharedRoomStatisticsForPastPeriod(List <int> cameraIds, PastPeriod pastPeriod, DateTime?startDate = null, DateTime?endDate = null) { GraphStatistics graphStatistics = new GraphStatistics(); if (startDate != null && endDate != null) { graphStatistics.StartDate = startDate; graphStatistics.EndDate = endDate; } List <List <DatabasePerSecondStat> > perSecondStatsForEachCamera = new List <List <DatabasePerSecondStat> >(); foreach (var cameraId in cameraIds) { perSecondStatsForEachCamera.Add(GetDatabasePerSecondStatsForPastPeriod(cameraId, pastPeriod, startDate, endDate)); } foreach (var perSecondStats in perSecondStatsForEachCamera) { AddDelimiterStatsForPastPeriod(perSecondStats, pastPeriod, startDate, endDate); AddDummyStatsForDeadPeriods(perSecondStats); } List <string[]> perSecondStatsFormattedStrings = new List <string[]>(); string[] titleString = new string[perSecondStatsForEachCamera.Count + 1]; titleString[0] = "DateTime"; for (int i = 0; i < cameraIds.Count; i++) { int cameraId = cameraIds.ElementAt(i); DatabaseCamera camera = _databaseQueryService.GetCameraById(cameraId); titleString[i + 1] = $"People Detected for {camera.CameraName}"; } perSecondStatsFormattedStrings.Add(titleString); for (int i = 1; i <= perSecondStatsForEachCamera.Count; i++) { List <DatabasePerSecondStat> perSecondStats = perSecondStatsForEachCamera.ElementAt(i - 1); foreach (DatabasePerSecondStat perSecondStat in perSecondStats) { string[] row = new string[perSecondStatsForEachCamera.Count + 1]; row[0] = perSecondStat.DateTime.ToString("o"); row[i] = perSecondStat.NumDetectedObjects.ToString(); perSecondStatsFormattedStrings.Add(row); } } graphStatistics.Stats = perSecondStatsFormattedStrings.ToArray(); graphStatistics.SelectedPeriod = pastPeriod; return(graphStatistics); }