/// <summary> /// Add a new Alert Event to this Driver's History. /// </summary> /// <param name="ae"></param> /// <returns>New Average Score of the driver</returns> public double AddEvent(AlertEvent ae) { _driversEvents.Add(ae); recalculateAverage(); return _avgScore; }
public double AnalyzeFrontPicture(WriteableBitmap bitmap) { // Foreach Alerter, try to analize the value. List<AlertEvent> alertEvents = new List<AlertEvent>(); foreach (IAlerter alerter in frontAlerters) { alerter.GetData(); AlertEvent alertEvent = new AlertEvent() { AlertLevel = alerter.ProcessData(bitmap), AlertTime = DateTime.Now, AlertType = alerter.GetAlerterType(), Driver = _currentDriver }; //uploadEventToDatabase(alertEvent); if (alertEvent.AlertLevel >= ALERT_THRESHOLD) { if (isGPSEnabled()) { //Get GPS Location var task = Task.Run(async () => { myLocation = await getLocationTask(); }); task.Wait() ; alertEvent.AlertLocation = myLocation.Coordinate; myLocation = null; } _currentDrive.Events.Add(alertEvent); alertEvents.Add(alertEvent); } } // Calculate the safety score (for all valid values). return calculateSafetyScore(alertEvents.Where(_event => _event.AlertLevel >= 0)); }
private async void uploadEventToDatabase(AlertEvent alertEvent) { await alertEventsTable.InsertAsync(alertEvent); }
private void frontCam_ThumbnailAvailable(object sender, ContentReadyEventArgs e) { this.Dispatcher.BeginInvoke(delegate() { if (frontCam == null) { //MessageBox.Show("ERROR: Camera is not available", "ERROR", MessageBoxButton.OK); ShowToastMessage("Error Starting Front Camera", "Front Camera could not be initialized"); return; } // Initialize a new Bitmap image WriteableBitmap bitmap = new WriteableBitmap((int)frontCam.PreviewResolution.Width, (int)frontCam.PreviewResolution.Height); // Get the bitmap from the camera frontCam.GetPreviewBufferArgb32(bitmap.Pixels); // Foreach Alerter, try to analize the value. List<AlertEvent> alertEvents = new List<AlertEvent>(); foreach (IAlerter alerter in frontAlerters) { alerter.GetData(); AlertEvent alertEvent = new AlertEvent() { AlertLevel = alerter.ProcessData(bitmap), AlertTime = DateTime.Now, AlertType = alerter.GetAlerterType(), Driver = _currentDriver }; if (alertEvent.AlertLevel >= ALERT_THRESHOLD) _currentDrive.Events.Add(alertEvent); alertEvents.Add(alertEvent); } // Calculate the safety score (for all valid values). double res = calculateSafetyScore(alertEvents.Where(_event => _event.AlertLevel != -1)); // Update the UI updateScreen(res); }); }