public GraphStatistics GetLast30MinutesStatistics(int cameraId) { GraphStatistics graphStatistics = new GraphStatistics(); List <DatabasePerSecondStat> perSecondStats = _databaseQueryService.GetPerSecondStatsForCamera(cameraId); perSecondStats.RemoveAll(stat => DateTime.Now.AddMinutes(-30.0) >= stat.DateTime); if (perSecondStats.Count == 0) { return(null); } List <string[]> perSecondStatsFormattedStrings = new List <string[]>(); perSecondStatsFormattedStrings.Add(new string[2] { "Time", "People" }); foreach (DatabasePerSecondStat perSecondStat in perSecondStats) { perSecondStatsFormattedStrings.Add(new string[2] { perSecondStat.DateTime.ToString("HH:mm:ss"), perSecondStat.NumDetectedObjects.ToString() }); } graphStatistics.Stats = perSecondStatsFormattedStrings.ToArray(); return(graphStatistics); }
public CameraStatistics getCameraStatisticsForNowById(int cameraId) { DatabaseCamera camera = _dbQueryService.GetCameraById(cameraId); DatabasePerSecondStat mostRecentStat = _dbQueryService.GetLatestPerSecondStatForCamera(cameraId); GraphStatistics graphStatistics = _graphStatisticsService.GetLast30MinutesStatistics(cameraId); if (camera != null) { CameraStatistics cameraStatistics = new CameraStatistics() { CameraInformation = new CameraInformation(camera), DayTimeOfTheWeekAverageCount = 0, DayTimeOfTheWeekAverageCountAvailable = false, DayTimeOfTheWeekAverageCountDisplayString = null, LastUpdatedTime = null, MostRecentPeopleCount = 0, PeriodOfTheDayAverageCount = 0, PeriodOfTheDayAverageCountAvailable = false, PeriodOfTheDayAverageCountDisplayString = null, GraphStatistics = graphStatistics }; if (mostRecentStat != null) { cameraStatistics.LastUpdatedTime = mostRecentStat.DateTime; cameraStatistics.MostRecentPeopleCount = mostRecentStat.NumDetectedObjects; } return(cameraStatistics); } else { return(null); } }
public GraphStatistics GetYearlyGraphStatistics(int cameraId) { GraphStatistics graphStatistics = new GraphStatistics(); List <string[]> maxStats = new List <string[]>(); Random rnd = new Random(); int hour = DateTime.Now.Hour; int counter = hour; for (int i = 0; i <= counter; i++) { string hourString = (hour - i).ToString() + ":00"; maxStats.Add(new string[2] { hourString, rnd.Next(0, 20).ToString() }); } maxStats.Add(new string[2] { "Time", "People" }); maxStats.Reverse(); graphStatistics.Stats = maxStats.ToArray(); return(graphStatistics); }
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); }
//Grab Graph Stats between an interval of time using unix time and specify the interval between each data point in seconds for a specific camera. //For example, between 1514808000 (01/01/2018 @ 12:00pm (UTC)) and 1517486400 (02/01/2018 @ 12:00pm (UTC)) with each point 3600 seconds apart (1 hour) public GraphStatistics GetGraphStatisticsByInterval(int cameraId, int startDate, int endDate, int interval) { GraphStatistics graphStatistics = new GraphStatistics(); List <string[]> maxStats = new List <string[]>(); DateTime epoch = new DateTime(1970, 1, 1, 0, 0, 0, DateTimeKind.Utc); DateTime end = epoch.AddSeconds(endDate); DateTime start = end.AddSeconds(interval * -1); for (int i = endDate; i > startDate; i = i - interval) { DatabaseGraphStat value = _databaseQueryService.getGraphStatByTimeInterval(cameraId, start, end); int epochUnixTime = (int)(value.End - new DateTime(1970, 1, 1)).TotalSeconds; maxStats.Add(new string[2] { epochUnixTime.ToString(), value.MaximumDetectedObjects.ToString() }); start = start.AddSeconds(interval); end = end.AddSeconds(interval); } // maxStats.Add(new string[2] { "dateTime", "People" }); maxStats.Reverse(); graphStatistics.Stats = maxStats.ToArray(); return(graphStatistics); }
private void create_new_graph_bar(int i) { int current_year = RawData.startYear + i; int people_alive = GraphStatistics.GetAmountOfPeopleAliveDuringYear(current_year); GameObject new_bar = build_graph_bar_game_object(current_year, people_alive); m_graph_bars.Add(new_bar); set_graph_bar_data(new_bar, current_year, people_alive); }
public CameraInformation GetCameraInformationWithYearlyData(int cameraId) { CameraInformation cameraInformation = getCameraInformationById(cameraId); // Line below is what it should be... but we're using the placeholder graphStatisticService for now GraphStatistics graphStatistics = _graphStatisticsService.GetYearlyGraphStatistics(cameraId); // GraphStatistics graphStatistics = new PlaceholderGraphStatisticsService().GetYearlyGraphStatistics(cameraId); cameraInformation.GraphStatistics = graphStatistics; return(cameraInformation); }
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 CameraStatistics getCameraStatisticsForNowById(int cameraId) { DatabaseCamera camera = _dbQueryService.GetCameraById(cameraId); DatabaseRoom room = null; if (camera != null && camera.RoomId != null) { room = _dbQueryService.GetRoomById(camera.RoomId.Value); } DatabasePerSecondStat mostRecentStat = _dbQueryService.GetLatestPerSecondStatForCamera(cameraId); GraphStatistics graphStatistics = _graphStatisticsService.GetLast30MinutesStatistics(cameraId); if (camera != null) { CameraStatistics cameraStatistics = new CameraStatistics { CameraInformation = new CameraInformation(camera), CameraDetails = new CameraDetails(camera), DayTimeOfTheWeekAverageCount = 0, DayTimeOfTheWeekAverageCountAvailable = false, DayTimeOfTheWeekAverageCountDisplayString = null, LastUpdatedTime = null, MostRecentPeopleCount = null, PeriodOfTheDayAverageCount = 0, PeriodOfTheDayAverageCountAvailable = false, PeriodOfTheDayAverageCountDisplayString = null, GraphStatistics = graphStatistics, TempImagePath = null }; if (room != null) { cameraStatistics.CameraDetails.MonitoredArea = room.RoomName; cameraStatistics.CameraInformation.CameraRoomName = room.RoomName; cameraStatistics.CameraInformation.RoomId = room.RoomId; } if (mostRecentStat != null) { cameraStatistics.LastUpdatedTime = mostRecentStat.DateTime; cameraStatistics.MostRecentPeopleCount = mostRecentStat.NumDetectedObjects; } if (camera.LocationId != null) { cameraStatistics.CameraDetails.Location = new LocationDetails(_dbQueryService.GetLocationById(camera.LocationId.Value)); } cameraStatistics.CameraInformation.TempImagePath = GetTempPathFromFullPath(camera.ImagePath); return(cameraStatistics); } return(null); }
public JsonResult GetSharedRoomCustomGraphStats(int roomId, DateTime startDate, DateTime endDate) { if (HttpContext.Session.GetString("currentUsername") == null) { return(Json(false)); } GraphStatistics statistics = GraphStatisticService.GetSharedRoomStatisticsForPastPeriod(roomId, PastPeriod.Custom, startDate, endDate); return(Json(statistics)); }
private void set_results_text() { List <int> years = GraphStatistics.yearsWithMostPeopleAlive; int amount_of_people_alive = GraphStatistics.mostPeopleAliveAtOnce; string year_string = years.Count == 1 ? years[0].ToString() : get_comma_seperated_year_string(years); string results_string = "In " + year_string + " there was the most people alive with " + amount_of_people_alive + " living"; m_results_text.text = results_string; m_left_side_results_output.text = GraphStatistics.GetStringForAllYears(GraphStatistics.leftColumn, years[0]); m_right_side_results_output.text = GraphStatistics.GetStringForAllYears(GraphStatistics.rightColumn, years[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); }
public void getCorrectGraphStatFor1DayTest() { Mock <IDatabaseQueryService> mockDBService = new Mock <IDatabaseQueryService>(MockBehavior.Loose); mockDBService.Setup(x => x.getGraphStatByTimeInterval(1, graphStats[0].Start, It.IsAny <DateTime>())).Returns(graphStats[0]); mockDBService.Setup(x => x.getGraphStatByTimeInterval(1, graphStats[1].Start, It.IsAny <DateTime>())).Returns(graphStats[1]); mockDBService.Setup(x => x.getGraphStatByTimeInterval(1, graphStats[2].Start, It.IsAny <DateTime>())).Returns(graphStats[2]); GraphStatisticService graphStatisticsService = new GraphStatisticService(mockDBService.Object); GraphStatistics graphStatistics = graphStatisticsService.GetGraphStatisticsByInterval(1, 1514808000, 1514980800, 86400); string[][] stats = new string[2][]; stats[0] = new string[2] { "1515067200", "18" }; stats[1] = new string[2] { "1514980800", "17" }; Assert.That(graphStatistics.Stats, Is.EqualTo(stats)); }
public GraphStatistics GetYearlyGraphStatistics(int cameraId) { GraphStatistics graphStatistics = new GraphStatistics(); List <string[]> maxStats = new List <string[]>(); //using a placeholder time right now since we dont have data coming in at the same time. //Ideally the end datetime should be the current datetime and the add seconds should be bigger for yearly DateTime end = new DateTime(2018, 4, 11, 14, 53, 18); DateTime start = end.AddSeconds(-5); for (int i = 0; i < 200; i++) { DatabaseGraphStat value = _databaseQueryService.getGraphStatByTimeInterval(cameraId, start, end); int epoch = (int)(value.End - new DateTime(1970, 1, 1)).TotalSeconds; maxStats.Add(new string[2] { epoch.ToString(), value.MaximumDetectedObjects.ToString() }); start = start.AddSeconds(5); end = end.AddSeconds(5); } graphStatistics.Stats = maxStats.ToArray(); return(graphStatistics); }
private void set_graph_data() { m_graph_data = m_dataset.GetListOfBirthToEndDates(); GraphStatistics.SetGraphData(m_graph_data); }
public void SetTextForNewSelectedYear(int year) { m_left_side_results_output.text = GraphStatistics.GetStringForAllYears(GraphStatistics.leftColumn, year); m_right_side_results_output.text = GraphStatistics.GetStringForAllYears(GraphStatistics.rightColumn, year); }