コード例 #1
0
        public int CheckPulseLimits(DatabaseContext context, int hodnota)
        {
            Hranice_Tep hranice = context.PulseLimit.FirstOrDefault(t => t.Hranica_TepId == context.PulseLimit.Max(x => x.Hranica_TepId));

            if ((hodnota >= hranice.Hranica_Slabe_Min) && (hodnota <= hranice.Hranica_Slabe_Max))
            {
                return(0);//ok
            }
            else if (hodnota < hranice.Hranica_Slabe_Min)
            {
                return(-1);//low
            }
            else if ((hodnota > hranice.Hranica_Slabe_Max) && (hodnota <= hranice.Hranica_Stredne))
            {
                return(1);//slabe
            }
            else if ((hodnota > hranice.Hranica_Stredne) && (hodnota <= hranice.Hranica_Vysoke))
            {
                return(2);//stredne
            }
            else if (hodnota > hranice.Hranica_Vysoke)
            {
                return(3);//vysoke
            }
            else
            {
                return(404);//error
            }
        }
コード例 #2
0
        public void LoadPulseLimits(DatabaseContext context)
        {
            HelpMethods helpm = new HelpMethods();

            /* Hranice_Tep tep_limit = new Hranice_Tep
             * {
             *   Hranica_Slabe_Min = 50,
             *   Hranica_Slabe_Max = 90,
             *   Hranica_Stredne = 100,
             *   Hranica_Vysoke = 120,
             *   TimeStamp = DateTime.Now.ToShortTimeString()
             *
             * };*/
            Hranice_Tep tep_limit = new Hranice_Tep
            {
                Hranica_Slabe_Min = 60,
                Hranica_Slabe_Max = 106,
                Hranica_Stredne   = 117,
                Hranica_Vysoke    = 127,
                TimeStamp         = DateTime.Now.ToShortTimeString()
            };

            context.PulseLimit.Add(tep_limit);

            try
            {
                context.SaveChanges();
            }
            catch (Exception e)
            {
                throw e;
            }
        }
コード例 #3
0
        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();
        }
コード例 #4
0
        public void PulseSequencer(DatabaseContext context)
        {
            var        all1       = context.Pulse.Where(t => t.TepSekvId == null).ToList();
            LimitCheck limitCheck = new LimitCheck();

            Hranice_Tep ht = context.PulseLimit.FirstOrDefault(h => h.Hranica_TepId == context.PulseLimit.Max(x => x.Hranica_TepId));


            foreach (var a in all1)
            {
                //System.Diagnostics.Debug.WriteLine("SPRACOVAVAM PULZ HODNOTU DO SEKVENCIE: " + a.TepId + " " + a.Hodnota + " " + a.TimeStamp);

                /*Inicializacia ak ziadna sekvencia neexistuje*/
                if (!context.PulseSekv.Any())
                {
                    Tep_Sekvencia tepS = new Tep_Sekvencia
                    {
                        TepSekvId   = 1,
                        Sekvencia   = (int)Math.Round(a.Hodnota),
                        TimeStart   = a.TimeStamp,
                        TimeClose   = "",
                        Upozornenie = limitCheck.CheckPulseLimits(context, (int)Math.Round(a.Hodnota)),
                        //Hranice_Tep = ht,
                        Hranica_TepFK = ht.Hranica_TepId,
                    };

                    if (tepS.Upozornenie != 0)
                    {
                        new NotificationGenerator().GenerateNotification("Tep", a.Hodnota, a.TimeStamp, tepS.Upozornenie, a.TepId);
                    }

                    Tep t = context.Pulse.Where(c => c.TepId == a.TepId).First();
                    t.TepSekvId = 1;


                    //System.Diagnostics.Debug.WriteLine("Novasekvencia " + t.TepId + " " + a.TepId + " " + t.Hodnota + " + " + t.TepSekvId);

                    context.PulseSekv.Add(tepS);
                    context.Pulse.Update(t);

                    try
                    {
                        //System.Diagnostics.Debug.WriteLine("SPRACOVAVAM PULZ HODNOTU DO SEKVENCIE: INICIALIZACNA");

                        context.SaveChanges();
                    }
                    catch (Exception e)
                    {
                        System.Diagnostics.Debug.WriteLine("Nemozem najst otvorenu sekvenciu");
                    }
                }
                /*Ak existuju sekvencie*/
                else
                {
                    /*Najdi otvorenu sekvenciu*/
                    Tep_Sekvencia tepS = null;
                    try
                    {
                        tepS = context.PulseSekv.FirstOrDefault(t => t.TimeClose == "");
                        //System.Diagnostics.Debug.WriteLine("otvorena sekvencia " + tepS.TepSekvId + " " + tepS.Sekvencia);
                    }
                    catch (Exception e)
                    {
                        System.Diagnostics.Debug.WriteLine("Nemozem najst otvorenu sekvenciu");
                    }

                    double minutes = 0;
                    try
                    {
                        Tep      posl      = context.Pulse.Where(p => p.TepSekvId == tepS.TepSekvId).Last();
                        DateTime startTime = DateTime.Parse(posl.TimeStamp);
                        //DateTime startTime = DateTime.Parse(tepS.TimeStart);
                        DateTime endTime   = DateTime.Parse(a.TimeStamp);
                        TimeSpan finalTime = endTime - startTime;
                        minutes = finalTime.TotalMinutes;
                        // System.Diagnostics.Debug.WriteLine("/////////////////////// TIME DIFF pulse" + 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.CheckPulseLimits(context, (int)Math.Round(a.Hodnota)) == tepS.Upozornenie && minutes <= 1)
                    {
                        var allInSekv = context.Pulse.Where(p => p.TepSekvId == tepS.TepSekvId).ToList();
                        int median    = 0;

                        if (tepS.Upozornenie != 0)
                        {
                            new NotificationGenerator().GenerateNotification("Tep", a.Hodnota, a.TimeStamp, tepS.Upozornenie, a.TepId);
                        }

                        /*Aktualizuj hodnotu sekvencie*/

                        foreach (var allIN in allInSekv)
                        {
                            median += (int)Math.Round(allIN.Hodnota);
                        }
                        median += (int)Math.Round(a.Hodnota);
                        median  = median / (allInSekv.Count + 1);

                        a.TepSekvId = tepS.TepSekvId; //naviaz tep
                        //a.Tep_Sekvencia = tepS;
                        context.Pulse.Update(a);

                        tepS.Sekvencia = median;
                        context.PulseSekv.Update(tepS);
                        try
                        {
                            ///System.Diagnostics.Debug.WriteLine("SPRACOVAVAM PULZ HODNOTU DO SEKVENCIE: UKLADAM DO AKTUALNEJ " + a.TepId + " " + a.Hodnota +" " +a.TimeStamp + " " + tepS.TepSekvId + " " + tepS.Sekvencia);

                            context.SaveChanges();
                        }
                        catch (Exception e)
                        {
                            System.Diagnostics.Debug.WriteLine("Nemozem najst otvorenu sekvenciu");
                        }
                    }
                    else /*Spracovavana hodnota nepatri do aktualne otvorenej sekvencie*/
                    {
                        /* Zatvor poslednu sekvenciu*/
                        Tep_Sekvencia ts = context.PulseSekv.FirstOrDefault(t => t.TepSekvId == context.PulseSekv.Max(x => x.TepSekvId)); //najdi poslednu



                        var allInSekv1 = context.Pulse.Where(p => p.TepSekvId == ts.TepSekvId).ToList(); // najdi list pre poslednu
                        var last       = allInSekv1[allInSekv1.Count - 1];                               //zober posledny pulz
                        if (minutes <= 1)
                        {
                            ts.TimeClose = a.TimeStamp; // nastav konecny TS podla TS posledneho v sekvencii / edit-podla novej hodnoty aby som pokril celu casovu os
                        }
                        else
                        {
                            ts.TimeClose = last.TimeStamp;
                        }
                        context.PulseSekv.Update(ts);
                        context.Pulse.RemoveRange(allInSekv1);

                        /*Vytvor novu sekvenciu*/
                        Tep_Sekvencia tepS1 = new Tep_Sekvencia
                        {
                            TepSekvId   = ts.TepSekvId + 1,
                            Sekvencia   = (int)Math.Round(a.Hodnota),
                            TimeStart   = a.TimeStamp,
                            TimeClose   = "",
                            Upozornenie = limitCheck.CheckPulseLimits(context, (int)Math.Round(a.Hodnota)),
                            //Hranice_Tep = ht,
                            Hranica_TepFK = ht.Hranica_TepId
                        };

                        context.PulseSekv.Add(tepS1);

                        if (tepS1.Upozornenie != 0)
                        {
                            new NotificationGenerator().GenerateNotification("Tep", a.Hodnota, a.TimeStamp, tepS1.Upozornenie, a.TepId);
                        }


                        a.TepSekvId = ts.TepSekvId + 1;  //naviaz pulz na sekvenciu
                        //a.Tep_Sekvencia = tepS1;

                        context.Pulse.Update(a);

                        try
                        {
                            //System.Diagnostics.Debug.WriteLine("SPRACOVAVAM PULZ HODNOTU DO SEKVENCIE: VYTVATAM NOVU SEKVENCIU" + a.TepId + " " + a.Hodnota + " " + a.TimeStamp + " " + tepS1.TepSekvId + " " + tepS1.Sekvencia);

                            context.SaveChanges();
                        }
                        catch (Exception e)
                        {
                            System.Diagnostics.Debug.WriteLine("Nemozem najst otvorenu sekvenciu");
                        }
                    }
                }
            }
        }
コード例 #5
0
        public void createLimits()
        {
            List <IGrouping <int, int> > occurrDicta = createOccurTable().ToList();

            int slabe_min = 0, slabe_max, stredne, vysoke;
            int maxOccKey = 0, maxOccValue = 0;

            /*Najdi hodnotu s najcastejsim vyskytom*/
            foreach (var grp in occurrDicta)
            {
                if (grp.Count() > maxOccValue)
                {
                    maxOccValue = grp.Count();
                    maxOccKey   = grp.Key;
                }
            }

            /*Skontroluj ci na zaciatku nie je outlier
             * ak ano = zmaz ho
             * Po odstraneni uloz najnizsiu ako hodnotu pre slabe_min
             */
            string pom;

            for (int i = 0; i < occurrDicta.Count; i++)
            {
                if ((occurrDicta.ElementAt(i).Count() == 1) && ((occurrDicta.ElementAt(i).Key * 1.1) < occurrDicta.ElementAt(i + 1).Key))
                {
                    // pom = "true";
                    // Console.WriteLine("seruuuusssssssssssss {0} {1} {2}", occurrDicta.ElementAt(i).Key, occurrDicta.ElementAt(i).Count(), pom);

                    occurrDicta.RemoveAt(i);
                    i--;
                }
                else
                {
                    //pom = "false";
                    //Console.WriteLine("seruuuusssssssssssss {0} {1} {2}", occurrDicta.ElementAt(i).Key, occurrDicta.ElementAt(i).Count(), pom);
                    slabe_min = Convert.ToInt32(occurrDicta.ElementAt(i).Key *0.9);
                    if (slabe_min < 50)
                    {
                        slabe_min = 50;
                    }
                    break;
                }
            }

            /*
             * K najcastejsej pripocitaj rozdiel so slabe_min
             */
            int low = maxOccKey + (maxOccKey - slabe_min);

            slabe_max = Convert.ToInt32(maxOccKey + ((maxOccKey - slabe_min) * 0.5));

            foreach (var grp in occurrDicta)
            {
                if ((grp.Key > low) && (grp.Count() > 2))
                {
                    int tmpPom = grp.Key - slabe_max;

                    low       = Convert.ToInt32(grp.Key + tmpPom * 0.3);
                    slabe_max = low;
                }
            }

            /*
             * Vytvor ostatne hranice
             */
            stredne = Convert.ToInt32(slabe_max * 1.1);
            vysoke  = Convert.ToInt32(slabe_max * 1.2);
            Console.WriteLine("hranice {0} {1} {2} {3} ", slabe_min, slabe_max, stredne, vysoke);


            /*Vytvor zaznam pre hranice tepu v databaze*/
            DatabaseContext context = context = new DatabaseContext();

            int index = 1;

            if (!context.PulseLimit.Any())
            {
                index = 1;
            }
            else
            {
                Hranice_Tep tmp = context.PulseLimit.FirstOrDefault(t => t.Hranica_TepId == context.PulseLimit.Max(x => x.Hranica_TepId));
                index = tmp.Hranica_TepId;
            }

            Hranice_Tep ht = new Hranice_Tep
            {
                Hranica_TepId     = index,
                Hranica_Slabe_Min = slabe_min,
                Hranica_Slabe_Max = slabe_max,
                Hranica_Stredne   = stredne,
                Hranica_Vysoke    = vysoke,
                TimeStamp         = DateTime.Now.ToString("h:mm:ss tt")
            };

            context.PulseLimit.Add(ht);

            /*Vytvor zaznam pre hranice teploty v databaze*/
            index = 1;
            if (!context.TemperatureLimit.Any())
            {
                index = 1;
            }
            else
            {
                Hranice_Teplota tmp = context.TemperatureLimit.FirstOrDefault(t => t.Hranice_TeplotaId == context.TemperatureLimit.Max(x => x.Hranice_TeplotaId));
                index = tmp.Hranice_TeplotaId;
            }

            Hranice_Teplota htemp = new Hranice_Teplota
            {
                Hranice_TeplotaId = index,
                TimeStamp         = DateTime.Now.ToString("h:mm:ss tt"),
                Hranica_Slabe_Min = 35.5F,
                Hranica_Slabe_Max = 37.0F,
                Hranica_Stredne   = 38.2F,
                Hranica_Vysoke    = 39.0F
            };

            context.TemperatureLimit.Add(htemp);

            var allPulse = context.Pulse.ToList();

            context.Pulse.RemoveRange(allPulse);

            try
            {
                context.SaveChanges();
            }
            catch (Exception e)
            {
                throw e;
            }

            /*Kontrolny vypis*/
            var all = context.TemperatureLimit.ToList();

            foreach (var a in all)
            {
                System.Diagnostics.Debug.WriteLine("teplota hranice " + a.Hranice_TeplotaId + " " + a.TimeStamp + " " + a.Hranica_Slabe_Min + " " + a.Hranica_Slabe_Max + " " + a.Hranica_Stredne + " " + a.Hranica_Vysoke);
            }

            var all1 = context.PulseLimit.ToList();

            foreach (var a in all1)
            {
                System.Diagnostics.Debug.WriteLine("tep hranice " + a.Hranica_TepId + " " + a.TimeStamp + " " + a.Hranica_Slabe_Min + " " + a.Hranica_Slabe_Max + " " + a.Hranica_Stredne + " " + a.Hranica_Vysoke);
            }
        }