// Once a DataMessage is verified, this method allows persisting all contents (PerSecondStat objects) into the database. public bool StoreStatsFromDataMessage(DataMessage verifiedMessage) { List <PerSecondStat> temp = new List <PerSecondStat>(); for (int y = 0; y < verifiedMessage.GetLength(); y++) { temp.Add(verifiedMessage.RealTimeStats[y]); } // Remove any possible duplicates. List <PerSecondStat> distinctStats = temp.Distinct().ToList(); return(_dbQueryService.PersistNewPerSecondStats(distinctStats)); }
// Once a DataMessage is verified, this method allows persisting all contents (PerSecondStat objects) into the database. public bool StoreStatsFromDataMessage(DataMessage verifiedMessage) { List <DatabasePerSecondStat> dbSecondsToPersist = new List <DatabasePerSecondStat>(); // Remove any possible duplicates. List <PerSecondStat> distinctPerSecondStats = verifiedMessage.RealTimeStats.Distinct().ToList(); for (int y = 0; y < distinctPerSecondStats.Count; y++) { PerSecondStat stat = distinctPerSecondStats[y]; int cameraId = _dbQueryService.GetCameraIdFromKey(stat.CameraKey); // Only persist PerSecondStats from valid Cameras (with valid CameraKeys). if (cameraId > 0) { DatabasePerSecondStat dbPerSecondStat = new DatabasePerSecondStat(); dbPerSecondStat.CameraId = cameraId; dbPerSecondStat.DateTime = MySqlDateTimeConverter.ToDateTime(stat.DateTime); dbPerSecondStat.HasSavedImage = stat.HasSavedImage; dbPerSecondStat.PerHourStatId = null; dbPerSecondStat.NumDetectedObjects = stat.NumTrackedPeople; dbPerSecondStat.DateTimeReceived = DateTime.Now; // If PerSecondStat has a key frame. if (stat.HasSavedImage && String.IsNullOrWhiteSpace(stat.FrameAsJpg) == false) { // Save it to the server. dbPerSecondStat.FrameJpgPath = SaveKeyImage(stat); } else { dbPerSecondStat.HasSavedImage = false; dbPerSecondStat.FrameJpgPath = null; } dbSecondsToPersist.Add(dbPerSecondStat); } } return(_dbQueryService.PersistNewPerSecondStats(dbSecondsToPersist)); }