Exemple #1
0
        public List <int> getValuesForList()
        {
            var assembly = typeof(Measurement).GetTypeInfo().Assembly;

            /*Definovanie cesty suboru*/
            //Stream stream = assembly.GetManifestResourceStream("Xamarin.Forms_EFCore.initializationValues.txt");
            Stream stream = assembly.GetManifestResourceStream("Xamarin.Forms_EFCore.initDataset.txt");

            DatabaseContext databaseContext = new DatabaseContext();
            // List<Json> objects = new List<Json>();
            List <DatasetJson> objects = new List <DatasetJson>();

            List <int> occurs = new List <int>();

            using (StreamReader sr = new StreamReader(stream))
            {
                while (sr.Peek() >= 0)
                {
                    /*Json obj = Newtonsoft.Json.JsonConvert.DeserializeObject<Json>(sr.ReadLine());
                     * objects.Add(obj);
                     * occurs.Add(Convert.ToInt32(obj.body.heart_rate.value));*/
                    DatasetJson obj = Newtonsoft.Json.JsonConvert.DeserializeObject <DatasetJson>(sr.ReadLine());
                    objects.Add(obj);
                    occurs.Add(Convert.ToInt32(obj.value));
                }
            }

            return(occurs);
        }
        public async void readLineFromDatasetFile()
        {
            try
            {
                DatabaseContext context = new DatabaseContext();

                IFileSystem fileSystem = FileSystem.Current;
                IFolder     rootFolder = fileSystem.LocalStorage;

                IFile tempFile = await rootFolder.GetFileAsync("pulseDataset.txt");

                string newFileText; string line;
                string fileText = await tempFile.ReadAllTextAsync();

                using (System.IO.StringReader reader = new System.IO.StringReader(fileText))
                {
                    line = reader.ReadLine();
                    //System.Diagnostics.Debug.WriteLine("READ from file pulse " + line);
                    newFileText = reader.ReadToEnd();
                }

                tempFile.WriteAllTextAsync(newFileText);

                DatasetJson obj = Newtonsoft.Json.JsonConvert.DeserializeObject <DatasetJson>(line);

                int index = 1;
                if (!context.Pulse.Any())
                {
                    index = 1;
                }
                else
                {
                    Tep tmp = context.Pulse.FirstOrDefault(t => t.TepId == context.Pulse.Max(x => x.TepId));
                    index = tmp.TepId;
                    index++;
                }


                Tep tep = new Tep
                {
                    TepId = index,
                    //TimeStamp = obj.header.creation_date_time.ToString(),
                    TimeStamp = obj.timestamp.ToString(),
                    Hodnota   = obj.value
                };
                context.Pulse.Add(tep);
                //System.Diagnostics.Debug.WriteLine("****** VLOZENIE TEPU DO DB: " + tep.TepId + " " + tep.Hodnota + " " + tep.TimeStamp);


                context.SaveChanges();
            }
            catch (Exception e)
            {
                System.Diagnostics.Debug.WriteLine("Citanie pulz suboru zo zariadenia: " + nameof(LoadPulse) + e.ToString());
            }
        }
        public void LoadPulseDataset(DatabaseContext context)
        {
            var assembly = typeof(LoadPulse).GetTypeInfo().Assembly;

            /*Definovanie cesty suboru*/
            //Stream stream = assembly.GetManifestResourceStream("Xamarin.Forms_EFCore.pulseWeek.txt");

            Stream stream = assembly.GetManifestResourceStream("Xamarin.Forms_EFCore.pulseDataset.txt");

            List <Json> objects = new List <Json>();

            /*nahranie dat a sparsovanie*/
            int i = 0;

            int index = 1;

            if (!context.Pulse.Any())
            {
                index = 1;
            }
            else
            {
                Tep tmp = context.Pulse.FirstOrDefault(t => t.TepId == context.Pulse.Max(x => x.TepId));
                index = tmp.TepId;
                index++;
            }


            using (StreamReader sr = new StreamReader(stream))
            {
                while (sr.Peek() >= 0)
                {
                    DatasetJson obj = Newtonsoft.Json.JsonConvert.DeserializeObject <DatasetJson>(sr.ReadLine());
                    //objects.Add(obj);
                    //System.Diagnostics.Debug.WriteLine(i++ +" + " + obj.header.creation_date_time.ToString() + " + " + obj.body.heart_rate.value);

                    Tep tep = new Tep
                    {
                        TepId     = index++,
                        TimeStamp = obj.timestamp.ToString(),
                        Hodnota   = obj.value
                    };
                    context.Pulse.Add(tep);
                }
            }

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


            /*Vypis tabulky z DB*/

            /*  var all = context.Pulse.ToList();
             * foreach (var a in all)
             * {
             *    System.Diagnostics.Debug.WriteLine(a.TepId + " " + a.TimeStamp + " " + a.Hodnota);
             *
             *
             * }
             */
        }
Exemple #4
0
        public void loadValues()
        {
            var assembly = typeof(Measurement).GetTypeInfo().Assembly;

            /*Definovanie cesty suboru*/
            // Stream stream = assembly.GetManifestResourceStream("Xamarin.Forms_EFCore.initializationValues.txt");
            Stream stream = assembly.GetManifestResourceStream("Xamarin.Forms_EFCore.initDataset.txt");

            DatabaseContext databaseContext = new DatabaseContext();
            //List<Json> objects = new List<Json>();
            List <DatasetJson> objects = new List <DatasetJson>();

            /*nahranie dat a sparsovanie*/
            int i     = 0;
            int index = 1;

            if (!databaseContext.Pulse.Any())
            {
                index = 1;
            }
            else
            {
                Tep tmp = databaseContext.Pulse.FirstOrDefault(t => t.TepId == databaseContext.Pulse.Max(x => x.TepId));
                index = tmp.TepId;
            }

            index++;

            using (StreamReader sr = new StreamReader(stream))
            {
                while (sr.Peek() >= 0)
                {
                    /* Json obj = Newtonsoft.Json.JsonConvert.DeserializeObject<Json>(sr.ReadLine());
                     * objects.Add(obj);
                     *
                     * String create_date = obj.header.creation_date_time;
                     * float value = obj.body.heart_rate.value;
                     */

                    DatasetJson obj = Newtonsoft.Json.JsonConvert.DeserializeObject <DatasetJson>(sr.ReadLine());
                    objects.Add(obj);

                    String create_date = obj.timestamp.ToString();

                    float value = obj.value;


                    Tep tep = new Tep
                    {
                        TepId     = index++,
                        TimeStamp = create_date,
                        Hodnota   = value
                    };
                    databaseContext.Pulse.Add(tep);
                }
            }
            try
            {
                databaseContext.SaveChanges();
            }
            catch (Exception e)
            {
                System.Diagnostics.Debug.WriteLine("measurement load values* ");
            }

            var all = databaseContext.Pulse.ToList();

            foreach (var a in all)
            {
                System.Diagnostics.Debug.WriteLine("******************************* " + a.TepId + " " + a.TimeStamp + " " + a.Hodnota);
            }
        }