private void roomStatsCommand() { DatabaseContext context = new DatabaseContext(); var SekvList = context.MovementSekv.ToList(); var results = SekvList.GroupBy( p => p.IzbyFK); String alertText = ""; foreach (var r in results) { try { Izby izba = context.Rooms.Where(p => p.IzbaID == r.Key).First(); var timeList = context.MovementSekv.Where(f => f.IzbyFK == izba.IzbaID).ToList(); double sumTime = 0; int hours = 0; int minutes = 0; int sec = 0; foreach (var a in timeList) { DateTime start = DateTime.Parse(a.TimeStamp); DateTime close = DateTime.Parse(a.TimeStop); TimeSpan fin = close - start; sumTime += Math.Abs(fin.TotalMinutes); hours += Math.Abs(fin.Hours); minutes += Math.Abs(fin.Minutes); sec += Math.Abs(fin.Seconds); } System.Diagnostics.Debug.WriteLine("ROOMS: " + izba.Nazov + " -- " + r.Count() + " " + sumTime + " min"); alertText += izba.Nazov + "(" + r.Count() + "x) - " + hours + " h " + minutes + " min " + sec + " sec" + "\n"; } catch (Exception e) { System.Diagnostics.Debug.WriteLine("ROOMS STATISTIC: " + e.ToString()); System.Diagnostics.Debug.WriteLine("ROOMS: " + " NA " + " -- " + r.Count()); var timeList = context.MovementSekv.Where(f => f.IzbyFK == null).ToList(); double sumTime = 0; int hours = 0; int minutes = 0; int sec = 0; foreach (var a in timeList) { DateTime start = DateTime.Parse(a.TimeStamp); DateTime close = DateTime.Parse(a.TimeStop); TimeSpan fin = close - start; sumTime += Math.Abs(fin.TotalMinutes); hours += Math.Abs(fin.Hours); minutes += Math.Abs(fin.Minutes); sec += Math.Abs(fin.Seconds); } alertText += "NA" + "(" + r.Count() + "x) - " + hours + " h " + minutes + " min " + sec + " sec" + "\n"; } } UserDialogs.Instance.Alert(alertText, "Štatistika pohybu", "OK"); //await Application.Current.MainPage.Navigation.PushAsync(new EditProfilePage()); }
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"; } }
public void add() { int index = 0; if (!_context.Rooms.Any()) { index = 1; } else { Izby izba = _context.Rooms.FirstOrDefault(t => t.IzbaID == _context.Rooms.Max(r => r.IzbaID)); index = izba.IzbaID; index++; } Izby izbaNova = new Izby() { IzbaID = index, Nazov = FindRoomName(), LavaXhodnota = float.Parse(LeftDownX, CultureInfo.InvariantCulture.NumberFormat), LavaYhodnota = float.Parse(LeftDownY, CultureInfo.InvariantCulture.NumberFormat), PravaXhodnota = float.Parse(RightUpX, CultureInfo.InvariantCulture.NumberFormat), PravaYhodnota = float.Parse(RightUpY, CultureInfo.InvariantCulture.NumberFormat) }; _context.Rooms.Add(izbaNova); try { _context.SaveChanges(); } catch (Exception e) { System.Diagnostics.Debug.WriteLine("****************************** " + e.ToString()); } Rooms.Add(izbaNova.Nazov); }
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 }
public void LoadRoomsData(/*DatabaseContext context*/) { DatabaseContext context = new DatabaseContext(); int index = 1; if (!context.Rooms.Any()) { index = 1; } else { Izby poh = context.Rooms.FirstOrDefault(p => p.IzbaID == context.Rooms.Max(t => t.IzbaID)); index = poh.IzbaID; index++; } Izby iz = new Izby { LavaXhodnota = 0, LavaYhodnota = 0, PravaXhodnota = 2, PravaYhodnota = 4, IzbaID = index++, Nazov = "Chodba" }; context.Rooms.Add(iz); iz = null; iz = new Izby { LavaXhodnota = 2, LavaYhodnota = 0, PravaXhodnota = 15, PravaYhodnota = 4, IzbaID = index++, Nazov = "Kuchyna" }; context.Rooms.Add(iz); iz = null; iz = new Izby { LavaXhodnota = 0, LavaYhodnota = 4, PravaXhodnota = 7, PravaYhodnota = 15, IzbaID = index++, Nazov = "Obyvacka" }; context.Rooms.Add(iz); iz = null; iz = new Izby { LavaXhodnota = 4, LavaYhodnota = 4, PravaXhodnota = 15, PravaYhodnota = 15, IzbaID = index++, Nazov = "Spalna" }; context.Rooms.Add(iz); iz = null; try { context.SaveChanges(); } catch (Exception e) { throw e; } /*Vypis tabulky z DB*/ var all = context.Rooms.ToList(); foreach (var a in all) { System.Diagnostics.Debug.WriteLine(a.LavaXhodnota + " " + a.LavaYhodnota + " " + a.PravaXhodnota + " " + a.PravaYhodnota + " " + a.Nazov); } }