private void save()
        {
            var lastBordersPulse = context.PulseLimit.FirstOrDefault(e => e.Hranica_TepId == context.PulseLimit.Max(o => o.Hranica_TepId));

            Hranice_Tep ht = new Hranice_Tep
            {
                Hranica_TepId     = lastBordersPulse.Hranica_TepId + 1,
                TimeStamp         = DateTime.Now.ToString(),
                Hranica_Slabe_Min = LowDown,
                Hranica_Slabe_Max = LowUp,
                Hranica_Stredne   = Middle,
                Hranica_Vysoke    = High
            };

            context.PulseLimit.Add(ht);

            var lastBordersTemp = context.TemperatureLimit.FirstOrDefault(a => a.Hranice_TeplotaId == context.TemperatureLimit.Max(p => p.Hranice_TeplotaId));

            Hranice_Teplota htemp = new Hranice_Teplota
            {
                Hranice_TeplotaId = lastBordersTemp.Hranice_TeplotaId + 1,
                TimeStamp         = DateTime.Now.ToString(),
                Hranica_Slabe_Min = LowDownTemp,
                Hranica_Slabe_Max = LowUpTemp,
                Hranica_Stredne   = MiddleTemp,
                Hranica_Vysoke    = HighTemp
            };

            context.TemperatureLimit.Add(htemp);

            Hranice_Pohyb limit = context.MovementLimit.FirstOrDefault(t => t.HranicePohybId == context.MovementLimit.Max(x => x.HranicePohybId));

            int index = limit.HranicePohybId;

            index++;

            Hranice_Pohyb hp = new Hranice_Pohyb()
            {
                HranicePohybId = index,
                LimitCas       = TimeLimit.ToString(),
                OkruhHranica   = Okruh,
                Xhranica       = SettingsController.MaxX,
                Yhranica       = SettingsController.MaxY,
                TimeStamp      = DateTime.Now.ToString()
            };

            context.MovementLimit.Add(hp);



            try
            {
                context.SaveChanges();
            }catch (Exception e)
            {
                System.Diagnostics.Debug.WriteLine("Exception: " + nameof(EditBordersViewModel) + " " + e.ToString());
            }

            Application.Current.MainPage.Navigation.PopAsync();
        }
예제 #2
0
        public int checkIfOutside(DatabaseContext context, Pohyb pohyb)
        {
            Hranice_Pohyb hpoh = context.MovementLimit.FirstOrDefault(t => t.HranicePohybId == context.MovementLimit.Max(x => x.HranicePohybId));

            if ((pohyb.Xhodnota < 0) || (pohyb.Yhodnota < 0) || (pohyb.Xhodnota > hpoh.Xhranica) || (pohyb.Yhodnota > hpoh.Yhranica))
            {
                return(1);
            }
            else
            {
                return(0);
            }
        }
예제 #3
0
        private void storeValuesToDb()
        {
            if (!_context.MovementLimit.Any())
            {
                Hranice_Pohyb hp = new Hranice_Pohyb()
                {
                    HranicePohybId = 1,
                    LimitCas       = TimeLimit.ToString(),
                    OkruhHranica   = Int32.Parse(Okruh),
                    Xhranica       = SettingsController.MaxX,
                    Yhranica       = SettingsController.MaxY,
                    TimeStamp      = DateTime.Now.ToString("h:mm:ss tt")
                };

                _context.MovementLimit.Add(hp);
            }
            else
            {
                //najdi max a uloz zan
                Hranice_Pohyb limit = _context.MovementLimit.FirstOrDefault(t => t.HranicePohybId == _context.MovementLimit.Max(x => x.HranicePohybId));

                int index = limit.HranicePohybId;
                index++;

                Hranice_Pohyb hp = new Hranice_Pohyb()
                {
                    HranicePohybId = index,
                    LimitCas       = TimeLimit.ToString(),
                    OkruhHranica   = Int32.Parse(Okruh),
                    Xhranica       = SettingsController.MaxX,
                    Yhranica       = SettingsController.MaxY,
                    TimeStamp      = DateTime.Now.ToString("h:mm:ss tt")
                };

                _context.MovementLimit.Add(hp);
            }

            try
            {
                _context.SaveChanges();
            }
            catch (Exception e)
            {
                System.Diagnostics.Debug.WriteLine("Exception: " + nameof(AdditionalSettingsViewModel) + " " + e.ToString());
            }

            SettingsController.SleepTime = SleepTime.ToString();
        }
예제 #4
0
        public int checkTimeLimitMovement(DatabaseContext context, Pohyb_Sekvencia pohS)
        {
            Hranice_Pohyb hpoh = context.MovementLimit.FirstOrDefault(t => t.HranicePohybId == context.MovementLimit.Max(x => x.HranicePohybId));

            int zot = 0;

            Int32.TryParse(pohS.Cas_Zotrvania, out zot);

            int hran = 0;

            Int32.TryParse(hpoh.LimitCas, out hran);

            if (zot > hran)
            {
                return(1);
            }
            else
            {
                return(0);
            }
        }
        private void fillValues()
        {
            var lastBordersPulse = context.PulseLimit.FirstOrDefault(e => e.Hranica_TepId == context.PulseLimit.Max(o => o.Hranica_TepId));

            LowDown = lastBordersPulse.Hranica_Slabe_Min;
            LowUp   = lastBordersPulse.Hranica_Slabe_Max;
            Middle  = lastBordersPulse.Hranica_Stredne;
            High    = lastBordersPulse.Hranica_Vysoke;

            var lastBordersTemp = context.TemperatureLimit.FirstOrDefault(a => a.Hranice_TeplotaId == context.TemperatureLimit.Max(p => p.Hranice_TeplotaId));

            LowDownTemp = lastBordersTemp.Hranica_Slabe_Min;
            LowUpTemp   = lastBordersTemp.Hranica_Slabe_Max;
            MiddleTemp  = lastBordersTemp.Hranica_Stredne;
            HighTemp    = lastBordersTemp.Hranica_Vysoke;

            Hranice_Pohyb limit = context.MovementLimit.FirstOrDefault(t => t.HranicePohybId == context.MovementLimit.Max(x => x.HranicePohybId));

            TimeLimit = limit.LimitCas;
            Okruh     = limit.OkruhHranica;
        }
예제 #6
0
        public bool checkMovementValue(DatabaseContext context, Pohyb p, Pohyb_Sekvencia pohS)
        {
            Hranice_Pohyb hpoh    = context.MovementLimit.FirstOrDefault(t => t.HranicePohybId == context.MovementLimit.Max(x => x.HranicePohybId));
            float         hranica = hpoh.OkruhHranica / 10;

            if (((pohS.Xhodnota - hranica) <= p.Xhodnota) && ((pohS.Xhodnota + hranica) >= p.Xhodnota) && ((pohS.Yhodnota - hranica) <= p.Yhodnota) && ((pohS.Yhodnota + hranica) >= p.Yhodnota))
            {//neprekracuje limit vo vzdialenosti
                //skontroluj ci patri do rovnakej izby
                Izby izba = new RoomsDetection().findRoom(p);

                if (izba == null)
                {
                    if (pohS.IzbyFK == null)
                    {
                        return(true);
                    }
                    else
                    {
                        return(false);
                    }
                }
                else
                {
                    if (pohS.IzbyFK == izba.IzbaID)
                    {
                        return(true);
                    }
                    else
                    {
                        return(false);
                    }
                }
            }
            else
            {
                return(false);
            }
        }
예제 #7
0
        public void LoadMovementLimits(DatabaseContext context)
        {
            HelpMethods helpm = new HelpMethods();

            Hranice_Pohyb hranpoh = new Hranice_Pohyb
            {
                Xhranica     = 150,
                Yhranica     = 150,
                OkruhHranica = 120,
                LimitCas     = "120",
                TimeStamp    = DateTime.Now.ToShortTimeString()
            };

            context.MovementLimit.Add(hranpoh);
            try
            {
                context.SaveChanges();
            }
            catch (Exception e)
            {
                throw e;
            }
        }
        public void MovementSequencer(DatabaseContext context)
        {
            var        allMovements = context.Movement.Where(t => t.PohSekvFK == null).ToList();
            LimitCheck limitCheck   = new LimitCheck();

            Hranice_Pohyb hpoh = context.MovementLimit.FirstOrDefault(t => t.HranicePohybId == context.MovementLimit.Max(x => x.HranicePohybId));

            foreach (var mov in allMovements)
            {
                Izby izba = new RoomsDetection().findRoom(mov);


                /*Inicializacia ak ziadna sekvencia neexistuje*/
                if (!context.MovementSekv.Any())
                {
                    Pohyb_Sekvencia pohS = null;
                    if (izba == null)
                    {
                        pohS = new Pohyb_Sekvencia
                        {
                            PohSekvId           = 1,
                            Xhodnota            = mov.Xhodnota,
                            Yhodnota            = mov.Yhodnota,
                            TimeStamp           = mov.TimeStamp,
                            Cas_Zotrvania       = "",
                            TimeStop            = mov.TimeStamp,
                            Upozornenie_Cas     = 0,
                            Upozornenie_Hranica = limitCheck.checkIfOutside(context, mov),
                            //Hranice_Pohyb = hpoh,
                            HranicePohybFK = hpoh.HranicePohybId,
                        };
                    }
                    else
                    {
                        pohS = new Pohyb_Sekvencia
                        {
                            PohSekvId           = 1,
                            Xhodnota            = mov.Xhodnota,
                            Yhodnota            = mov.Yhodnota,
                            TimeStamp           = mov.TimeStamp,
                            Cas_Zotrvania       = "",
                            TimeStop            = mov.TimeStamp,
                            Upozornenie_Cas     = 0,
                            Upozornenie_Hranica = limitCheck.checkIfOutside(context, mov),
                            //Hranice_Pohyb = hpoh,
                            HranicePohybFK = hpoh.HranicePohybId,
                            //Izby = izba,
                            IzbyFK = izba.IzbaID
                        };
                    }


                    if (pohS.Upozornenie_Hranica == 1)
                    {
                        new NotificationGenerator().GenerateNotificationMovement(pohS.TimeStamp, pohS.PohSekvId);
                    }

                    Pohyb p = context.Movement.Where(c => c.PohybId == mov.PohybId).First();
                    p.PohSekvFK = 1;
                    System.Diagnostics.Debug.WriteLine("POHYB Inicializacia ak ziadna sekvencia neexistuje");

                    context.MovementSekv.Add(pohS);
                    //context.Movement.Remove(mov);

                    context.Movement.Update(p);

                    try
                    {
                        context.SaveChanges();
                    }
                    catch (Exception e)
                    {
                        System.Diagnostics.Debug.WriteLine("Exception: " + nameof(SequenceCreator) + " " + e.ToString());
                    }
                }
                /*Ak existuju sekvencie*/
                else
                {
                    /*Najdi otvorenu sekvenciu*/
                    Pohyb_Sekvencia pohS = null;
                    try
                    {
                        pohS = context.MovementSekv.FirstOrDefault(p => p.PohSekvId == context.MovementSekv.Max(x => x.PohSekvId));
                    }
                    catch (Exception e)
                    {
                        System.Diagnostics.Debug.WriteLine("POHYB EXC Nemozem najst otvorenu sekvenciu");
                    }
                    double minutes = 0;
                    try
                    {
                        DateTime startTime = DateTime.Parse(pohS.TimeStop);
                        DateTime endTime   = DateTime.Parse(mov.TimeStamp);
                        TimeSpan finalTime = endTime - startTime;
                        minutes = finalTime.TotalMinutes;
                        System.Diagnostics.Debug.WriteLine("/////////////////////// TIME DIFF movement " + finalTime.Hours + ":" + finalTime.Minutes + ":" + finalTime.Seconds + ":" + finalTime.Milliseconds);
                    }
                    catch (Exception e)
                    {
                        System.Diagnostics.Debug.WriteLine("Exception: " + nameof(SequenceCreator) + " " + e.ToString());
                    }


                    /*Spracovavana hodnota patri do aktualne otvorenej sekvencie*/
                    if (limitCheck.checkMovementValue(context, mov, pohS) && minutes <= 1)
                    {
                        System.Diagnostics.Debug.WriteLine("**********POHYB Spracovavana hodnota patri do aktualne otvorenej sekvencie" + mov.Xhodnota + " " + mov.Yhodnota + " " + mov.TimeStamp);
                        //mov.Pohyb_Sekvencia = pohS;//naviaz pohyb
                        mov.PohSekvFK = pohS.PohSekvId;

                        //cas zotrvania
                        DateTime convertedDate = DateTime.Parse(pohS.TimeStamp);
                        String   durationTime  = null;
                        DateTime endtime       = DateTime.Parse(pohS.TimeStamp);
                        try
                        {
                            endtime      = DateTime.Parse(mov.TimeStamp);
                            durationTime = (endtime - convertedDate).TotalMinutes.ToString();
                        }
                        catch (Exception e)
                        {
                            System.Diagnostics.Debug.WriteLine("Exception parse date " + e.ToString());
                            durationTime = "NA";
                        }

                        pohS.Cas_Zotrvania   = durationTime;
                        pohS.Upozornenie_Cas = limitCheck.checkTimeLimitMovement(context, pohS);


                        if (pohS.Upozornenie_Hranica == 1)
                        {
                            new NotificationGenerator().GenerateNotificationMovement(pohS.TimeStamp, pohS.PohSekvId);
                        }


                        if (pohS.Upozornenie_Cas == 1)
                        {
                            RoomsDetection roomsDetection = new RoomsDetection();
                            string         roomName       = roomsDetection.findRoom(mov).Nazov;
                            //call sleep detection
                            SleepDetection sleepDetection = new SleepDetection();
                            Boolean        sleep          = sleepDetection.DetectSleepSeq(context, roomName, convertedDate, endtime, 0);
                            if (sleep = false)
                            {
                                new NotificationGenerator().GenerateNotificationMovementTime(roomName, pohS.TimeStamp, pohS.Cas_Zotrvania, pohS.PohSekvId);
                            }
                        }
                        pohS.TimeStop = mov.TimeStamp;
                        context.MovementSekv.Update(pohS);
                        //context.Movement.Remove(mov);
                        context.Movement.Update(mov);
                        try
                        {
                            context.SaveChanges();
                        }
                        catch (Exception e)
                        {
                            System.Diagnostics.Debug.WriteLine("Exception: " + nameof(SequenceCreator) + " " + e.ToString());
                        }
                    }
                    else /*Spracovavana hodnota nepatri do aktualne otvorenej sekvencie*/
                    {
                        Pohyb_Sekvencia last   = context.MovementSekv.FirstOrDefault(t => t.PohSekvId == context.MovementSekv.Max(x => x.PohSekvId));
                        Pohyb_Sekvencia pohnew = null;
                        if (izba == null)
                        {
                            pohnew = new Pohyb_Sekvencia
                            {
                                PohSekvId           = last.PohSekvId + 1,
                                Xhodnota            = mov.Xhodnota,
                                Yhodnota            = mov.Yhodnota,
                                TimeStamp           = mov.TimeStamp,
                                Cas_Zotrvania       = "",
                                TimeStop            = mov.TimeStamp,
                                Upozornenie_Cas     = 0,
                                Upozornenie_Hranica = limitCheck.checkIfOutside(context, mov),
                                //Hranice_Pohyb = hpoh,
                                HranicePohybFK = hpoh.HranicePohybId,
                            };
                        }
                        else
                        {
                            pohnew = new Pohyb_Sekvencia
                            {
                                PohSekvId           = last.PohSekvId + 1,
                                Xhodnota            = mov.Xhodnota,
                                Yhodnota            = mov.Yhodnota,
                                TimeStamp           = mov.TimeStamp,
                                Cas_Zotrvania       = "",
                                TimeStop            = mov.TimeStamp,
                                Upozornenie_Cas     = 0,
                                Upozornenie_Hranica = limitCheck.checkIfOutside(context, mov),
                                //Hranice_Pohyb = hpoh,
                                HranicePohybFK = hpoh.HranicePohybId,
                                //Izby = izba,
                                IzbyFK = izba.IzbaID
                            };
                        }


                        if (pohS.Upozornenie_Hranica == 1)
                        {
                            new NotificationGenerator().GenerateNotificationMovement(pohS.TimeStamp, pohS.PohSekvId);
                        }
                        if (minutes <= 1)
                        {
                            last.TimeStop = mov.TimeStamp;
                        }

                        //Pohyb p = context.Movement.Where(c => c.PohybId == mov.PohybId).First();
                        //p.PohSekvFK = last.PohSekvId + 1;

                        //var toDelete = context.Movement.Where(c => c.PohSekvFK == last.PohSekvId).ToList();
                        //p.Pohyb_Sekvencia = pohnew;

                        System.Diagnostics.Debug.WriteLine("POHYB Spracovavana hodnota nepatri do aktualne otvorenej sekvencie" + mov.Xhodnota + " " + mov.Yhodnota + " " + mov.TimeStamp);

                        context.MovementSekv.Update(last);

                        context.MovementSekv.Add(pohnew);
                        //context.Movement.Remove(mov);
                        //context.RemoveRange(toDelete);
                        //context.Movement.Update(p);

                        try
                        {
                            context.SaveChanges();
                        }
                        catch (Exception e)
                        {
                            System.Diagnostics.Debug.WriteLine("Exception: " + nameof(SequenceCreator) + " " + e.ToString());
                        }
                    }
                }
                var toDelete = context.Movement.Where(c => c.PohybId == mov.PohybId).First();
                context.Movement.Remove(toDelete);
                try
                {
                    context.SaveChanges();
                }
                catch (Exception e)
                {
                    System.Diagnostics.Debug.WriteLine("Exception on value removing: " + nameof(SequenceCreator) + " " + e.ToString());
                }
            }
        }