public void GenerateFallOneSample() { DatabaseContext context = new DatabaseContext(); int index = 1; if (!context.Akcelerometers.Any()) { index = 1; } else { Akcelerometer pada = context.Akcelerometers.FirstOrDefault(p => p.AkcelerometerID == context.Akcelerometers.Max(t => t.AkcelerometerID)); index = pada.AkcelerometerID; index++; } Random rnd = new Random(); Akcelerometer pad = new Akcelerometer { AkcelerometerID = index++, Xhodnota = rnd.Next(1, 150), Yhodnota = rnd.Next(1, 150), Zhodnota = rnd.Next(1, 150), TimeStamp = DateTime.Now.ToShortTimeString() }; context.Akcelerometers.Add(pad); System.Diagnostics.Debug.WriteLine("pad " + pad.Xhodnota + " " + pad.TimeStamp + " " + pad.Yhodnota); Izby izba = new RoomsDetection().findRoomByCoord(pad.Xhodnota, pad.Yhodnota); string izbameno = "NA"; try { izbameno = izba.Nazov; } catch (Exception e) { System.Diagnostics.Debug.WriteLine("EXCEPTION " + e.ToString()); } new NotificationGenerator().GenerateNotificationFall(izbameno, pad.TimeStamp, pad.AkcelerometerID); try { context.SaveChanges(); } catch (Exception e) { throw e; } }
private void fillList() { RoomsDetection roomsDetection = new RoomsDetection(); if (_context.MovementSekv.Any()) { var movSekvList = _context.MovementSekv.ToList(); foreach (var movSekv in movSekvList) { DateTime convertedDate = DateTime.Parse(movSekv.TimeStamp); Izby izba = null; String izbaName = ""; try { izba = _context.Rooms.Where(t => t.IzbaID == movSekv.IzbyFK).First(); izbaName = izba.Nazov; } catch (Exception e) { izbaName = "Vonku"; } string alert = "NA"; if (movSekv.Upozornenie_Cas != 0) { alert = "Čas"; } else if (movSekv.Upozornenie_Hranica != 0) { alert = "Hranica"; } MovementObj movObj = new MovementObj { PohId = movSekv.PohSekvId, RoomName = izbaName, Alert = alert, LongDate = convertedDate.ToLongDateString(), Date = convertedDate.ToShortDateString(), Time = convertedDate.ToLongTimeString(), Duration = movSekv.Cas_Zotrvania, xValue = movSekv.Xhodnota, yValue = movSekv.Yhodnota }; SequenceList.Add(movObj); } fillPageWithSequence(SequenceList.Last()); } else { MovAlert = "Neexistuje žiadna sekvencia"; } SequenceList = new ObservableCollection <MovementObj>(SequenceList.Reverse()); }
private void fillList() { RoomsDetection roomsDetection = new RoomsDetection(); if (_context.Akcelerometers.Any()) { var FallValueList = _context.Akcelerometers.ToList(); foreach (var fallValue in FallValueList) { DateTime convertedDate = DateTime.Parse(fallValue.TimeStamp); Izby izba = null; String izbaName = ""; try { izba = roomsDetection.findRoomByCoord(fallValue.Xhodnota, fallValue.Yhodnota); izbaName = izba.Nazov; } catch (Exception e) { izbaName = "Vonku"; } FallObj fallObj = new FallObj { FallId = fallValue.AkcelerometerID, RoomName = izbaName, xValue = fallValue.Xhodnota, yValue = fallValue.Yhodnota, Date = convertedDate.ToShortDateString(), Time = convertedDate.ToLongTimeString() }; FallList.Add(fallObj); } fillPageWithFall(FallList.First()); } else { FallTime = "Neexistuje žiadna sekvencia"; } FallList = new ObservableCollection <FallObj>(FallList.Reverse()); }
public void setMovementValue() { if (_context.MovementSekv.Any()) { Pohyb pohyb = _context.Movement.FirstOrDefault(t => t.PohybId == _context.Movement.Max(x => x.PohybId)); RoomsDetection roomsDetection = new RoomsDetection(); Izby izba = roomsDetection.findRoom(pohyb); if (izba == null) { MotionValue = "Vonku"; } else { MotionValue = roomsDetection.findRoom(pohyb).Nazov; } } else { MotionValue = "NA"; } }
private void FindRoomsStatisticsList() { RoomsDetection roomsDetection = new RoomsDetection(); if (_context.MovementSekv.Any()) { var movSekvList = _context.MovementSekv.ToList(); int counter = 0; foreach (var movSekv in movSekvList) { // if (++counter > 20) break; DateTime convertedDate = DateTime.Parse(movSekv.TimeStamp); Izby izba = null; String izbaName = ""; try { izba = _context.Rooms.Where(t => t.IzbaID == movSekv.IzbyFK).First(); izbaName = izba.Nazov; } catch (Exception e) { izbaName = "Vonku"; } List <Pohyb_Sekvencia> valueList = new List <Pohyb_Sekvencia>(); if (!RoomsList.Any()) { valueList.Add(movSekv); RoomStatisticsObj roomStatisticsObj = new RoomStatisticsObj { RoomName = izbaName, StartDate = convertedDate.ToShortDateString(), StartTime = convertedDate.ToLongTimeString(), Sekvencie = valueList }; RoomsList.Add(roomStatisticsObj); System.Diagnostics.Debug.WriteLine("ROOMS STATS FIRST " + movSekv.PohSekvId); } else { RoomStatisticsObj rObj = RoomsList.Last(); if (rObj.RoomName == izbaName) { valueList = rObj.Sekvencie; valueList.Add(movSekv); rObj.Sekvencie = valueList; //System.Diagnostics.Debug.WriteLine("ROOMS STATS Adding " + movSekv.PohSekvId + " " + izbaName + " " + valueList.Count); } else { if (rObj.StartDate == convertedDate.ToShortDateString()) { rObj.EndDate = ""; } else { rObj.EndDate = convertedDate.ToShortDateString(); } // rObj.EndDate = convertedDate.ToShortDateString(); //rObj.EndTime = convertedDate.ToLongTimeString(); try { rObj.EndTime = DateTime.Parse(movSekv.TimeStamp).ToLongTimeString(); } catch (Exception e) { System.Diagnostics.Debug.WriteLine("Exception: " + nameof(StatisticsMainViewModel) + " " + e.ToString()); rObj.EndTime = convertedDate.ToLongTimeString(); } valueList.Add(movSekv); RoomStatisticsObj roomStatisticsObj = new RoomStatisticsObj { RoomName = izbaName, StartDate = convertedDate.ToShortDateString(), StartTime = convertedDate.ToLongTimeString(), Sekvencie = valueList }; RoomsList.Add(roomStatisticsObj); //System.Diagnostics.Debug.WriteLine("ROOMS STATS New " + movSekv.PohSekvId + " " + izbaName + " " + valueList.Count); } } } RoomsList = new ObservableCollection <RoomStatisticsObj>(RoomsList.Reverse()); } }
public void setAlertListValue() { if (_context.PulseSekv.Any()) { var all = _context.PulseSekv.OrderBy(x => x.TimeStart).ToList(); all.Reverse(); Tep_Sekvencia ts = null; foreach (var a in all) { ts = a; if (a.Upozornenie != 0) { break; } } // Tep_Sekvencia ts = _context.PulseSekv.FirstOrDefault(t => t.TepSekvId == _context.PulseSekv.Max(x => x.TepSekvId)); Helpers.SekvenceHelper.LimitCheck loader = new Helpers.SekvenceHelper.LimitCheck(); if (ts.Upozornenie != 0) { DateTime convertedDate = DateTime.Parse(ts.TimeStart); AlertSequenceObj myObj = new AlertSequenceObj { Name = "Tep", Value = ts.Sekvencia + " BPM", Date = convertedDate.ToShortDateString(), Time = convertedDate.ToLongTimeString(), Alert = loader.getStringValuePulseAndTempLimit(ts.Upozornenie) }; Alerts.Add(myObj); } else { AlertSequenceObj myObj = new AlertSequenceObj { Name = "Tep", Alert = "Neexistuje upozornenie" }; Alerts.Add(myObj); } //String tepSekvString = "Tep " + ts.Sekvencia + " " + ts.TimeStart + " " + loader.getStringValuePulseAndTempLimit(ts.Upozornenie); } else { AlertSequenceObj myObj = new AlertSequenceObj { Name = "Tep", Alert = "Neexistuje sekvencia" }; Alerts.Add(myObj); } if (_context.TemperatureSekv.Any()) { var all = _context.TemperatureSekv.OrderBy(x => x.TimeStart).ToList(); all.Reverse(); Teplota_Sekvencia ts = null; foreach (var a in all) { ts = a; if (a.Upozornenie != 0) { break; } } Helpers.SekvenceHelper.LimitCheck loader = new Helpers.SekvenceHelper.LimitCheck(); if (ts.Upozornenie != 0) { DateTime convertedDate = DateTime.Parse(ts.TimeStart); AlertSequenceObj myObj = new AlertSequenceObj { Name = "Teplota", Value = ts.Sekvencia.ToString("n2") + " °C", Date = convertedDate.ToShortDateString(), Time = convertedDate.ToLongTimeString(), Alert = loader.getStringValuePulseAndTempLimit(ts.Upozornenie) }; Alerts.Add(myObj); } else { AlertSequenceObj myObj = new AlertSequenceObj { Name = "Teplota", Alert = "Neexistuje upozornenie" }; Alerts.Add(myObj); } } else { AlertSequenceObj myObj = new AlertSequenceObj { Name = "Teplota", Alert = "Neexistuje sekvencia" }; Alerts.Add(myObj); } if (_context.MovementSekv.Any()) { var all = _context.MovementSekv.OrderBy(x => x.TimeStamp).ToList(); all.Reverse(); Pohyb_Sekvencia ps = null; foreach (var a in all) { if (a.Upozornenie_Cas != 0) { ps = a; break; } if (a.Upozornenie_Hranica != 0) { ps = a; break; } } if (ps != null) { DateTime convertedDate = DateTime.Parse(ps.TimeStamp); if (ps.Upozornenie_Cas != 0) { AlertSequenceObj myObj = new AlertSequenceObj { Name = "Pohyb", Date = convertedDate.ToShortDateString(), Time = convertedDate.ToLongTimeString(), Alert = "Čas" }; Alerts.Add(myObj); } else if (ps.Upozornenie_Hranica != 0) { AlertSequenceObj myObj = new AlertSequenceObj { Name = "Pohyb", Date = convertedDate.ToShortDateString(), Time = convertedDate.ToLongTimeString(), Alert = "Hranica" }; Alerts.Add(myObj); } else { AlertSequenceObj myObj = new AlertSequenceObj { Name = "Pohyb", Alert = "Neexistuje upozornenie" }; Alerts.Add(myObj); } } else { AlertSequenceObj myObj = new AlertSequenceObj { Name = "Pohyb", Alert = "Neexistuje upozornenie" }; Alerts.Add(myObj); } } else { AlertSequenceObj myObj = new AlertSequenceObj { Name = "Pohyb", Alert = "Neexistuje sekvencia" }; Alerts.Add(myObj); } if (_context.Akcelerometers.Any()) { var pad = _context.Akcelerometers.FirstOrDefault(t => t.AkcelerometerID == _context.Akcelerometers.Max(x => x.AkcelerometerID)); DateTime convertedDate = DateTime.Parse(pad.TimeStamp); RoomsDetection roomsDetection = new RoomsDetection(); Izby izba = roomsDetection.findRoomByCoord(pad.Xhodnota, pad.Yhodnota); string izbameno = "Vonku"; try { izbameno = izba.Nazov; }catch (Exception e) { System.Diagnostics.Debug.WriteLine("EXCEPTION " + e.ToString()); } AlertSequenceObj myObj = new AlertSequenceObj { Name = "Pád", Date = convertedDate.ToShortDateString(), Time = convertedDate.ToLongTimeString(), Value = izbameno, Alert = "Nastal pád" }; Alerts.Add(myObj); } else { AlertSequenceObj myObj = new AlertSequenceObj { Name = "Pád", Alert = "Pád nenastal" }; Alerts.Add(myObj); } //TODO: ZOBRAZENIE POHYBU }