Пример #1
0
        public SpectrumAnalyzer(XsaCore xsa) : base("SA", xsa)
        {
            trigger = new TriggerMenu(Xsa);

            // Add SAN
            Measurements.Add(typeof(SAN), new SAN(Xsa));
        }
        public void RunSequence(string outFile, List<int> ns, List<double> ps, List<double> alphas, int repeatCount)
        {
            var m = new Measurements();
            var sw = new Stopwatch();

            foreach (var alpha in alphas)
            {
                foreach (var n in ns)
                {
                    for (var x = 0; x < repeatCount; x++)
                    {
                        WriteLine(alpha + "a      " + 0 + "p       " + n);                       
                        // create or reset stuff
                        var sgt = new DataStructures.SGTree<int>(alpha);
                        var SGTNodes = new List<DataStructures.SGTNode<int>>(n);
                        
                        for(var i = 1; i < n; i++)
                        {
                            SGTNodes.Add(new DataStructures.SGTNode<int>(i));
                        }
                        sw.Reset();
                        sw.Start();
                        sgt.insertFirst(0);                        
                        sw.Stop();
                        m.Add(n, 0, alpha, sw.ElapsedTicks);
                    }                    
                }
            }

            m.WriteToFile(outFile);
        }
Пример #3
0
        public void RunSequence(string outFile, List <int> ns, List <double> ps, List <double> alphas, int repeatCount)
        {
            var m  = new Measurements();
            var sw = new Stopwatch();

            foreach (var alpha in alphas)
            {
                foreach (var n in ns)
                {
                    for (var x = 0; x < repeatCount; x++)
                    {
                        WriteLine(alpha + "a      " + 0 + "p       " + n);
                        // create or reset stuff
                        var sgt      = new DataStructures.SGTree <int>(alpha);
                        var SGTNodes = new List <DataStructures.SGTNode <int> >(n);

                        for (var i = 1; i < n; i++)
                        {
                            SGTNodes.Add(new DataStructures.SGTNode <int>(i));
                        }
                        sw.Reset();
                        sw.Start();
                        sgt.insertFirst(0);
                        sw.Stop();
                        m.Add(n, 0, alpha, sw.ElapsedTicks);
                    }
                }
            }

            m.WriteToFile(outFile);
        }
Пример #4
0
 public MeasurementElement(IMeasurementConfig config)
 {
     Enabled   = config.Enabled;
     Name      = config.Name;
     Threshold = config.Threshold;
     Measurements.Add(config.Measurements);
 }
        private void TransformToTopologyElement(ResourceDescription modelEntity)
        {
            DMSType dmsType;

            dmsType = GetDMSTypeOfTopologyElement(modelEntity.Id);

            if (dmsType == DMSType.DISCRETE)
            {
                Measurement newDiscrete = GetPopulatedDiscreteMeasurement(modelEntity);
                Measurements.Add(newDiscrete.Id, newDiscrete);
                Provider.Instance.MeasurementProvider.AddDiscreteMeasurement(newDiscrete as DiscreteMeasurement);
            }
            else if (dmsType == DMSType.ANALOG)
            {
                Measurement newAnalog = GetPopulatedAnalogMeasurement(modelEntity);
                Measurements.Add(newAnalog.Id, newAnalog);
                Provider.Instance.MeasurementProvider.AddAnalogMeasurement(newAnalog as AnalogMeasurement);
            }
            else if (dmsType != DMSType.MASK_TYPE && dmsType != DMSType.BASEVOLTAGE)
            {
                ITopologyElement newElement = GetPopulatedElement(modelEntity);
                TopologyElements.Add(newElement.Id, newElement);
                if (dmsType == DMSType.ENERGYSOURCE)
                {
                    EnergySources.Add(newElement.Id);
                }
                ElementConnections.Add(modelEntity.Id, (GetAllReferencedElements(modelEntity)));
            }
        }
Пример #6
0
        public WCDMA(XsaCore xsa) : base("WCDMA", xsa)
        {
            trigger = new TriggerMenu(xsa);

            // Add LPST
            Measurements.Add(typeof(ListPowerStep), new ListPowerStep(xsa));
            Measurements.Add(typeof(CombinedWcdma), new CombinedWcdma(xsa));
            Measurements.Add(typeof(Acp), new Acp(xsa));
        }
Пример #7
0
        protected override Measurements MeasureOverride(Size availableSize)
        {
            var size = new Size(Width.Point * Scale, Height.Point * Scale);

            var ms = new Measurements();
            var m  = new Measurement(this, size, Margin);

            ms.Add(m);
            return(ms);
        }
Пример #8
0
        public void Add(int cnt = 1)
        {
            foreach (var kvp in SignalGenerator.GetRandom(dt, cnt))
            {
                Measurements.Add(kvp);
                dt = kvp.Key;
            }

            Run();
        }
        public void AddMeasurement()
        {
            SetUp();

            var d1 = new Dictionary <string, string>
            {
                { "ID", m1.Id.ToString() },
                { "experiment", e.Id.ToString() },
                { "result", m1.Result.ToString() },
                { "beginning", m1.Beginning.Id.ToString() },
                { "end", m1.End.Id.ToString() }
            };

            measurementDAO.Add(m1, e);

            var m2 = db.Measurements[0];

            Assert.IsTrue(m2.Count == d1.Count && !m2.Except(d1).Any());
        }
Пример #10
0
 public void SetMeasurements(List <GrowthMeasurement> growthMeasurements, DataType dataType)
 {
     if (Measurements.ContainsKey(dataType))
     {
         Measurements[dataType] = growthMeasurements;
     }
     else
     {
         Measurements.Add(dataType, growthMeasurements);
     }
 }
Пример #11
0
        public override void AddReference(ModelCode referenceId, long globalId)
        {
            switch (referenceId)
            {
            case ModelCode.MEASUREMENT_TERMINAL:
                Measurements.Add(globalId);
                break;

            default:
                base.AddReference(referenceId, globalId);
                break;
            }
        }
Пример #12
0
        public void AddNewMeasurement(MeasurementViewModel newModel)
        {
            NewViewModel = null;
            ShowNew      = false;
            ShowSettings = false;

            Measurements.Add(newModel);
            if (SelectedMeasurement == null)
            {
                SelectedMeasurement           = newModel;
                SelectedMeasurement.IsEnabled = true;
            }
        }
Пример #13
0
        private void AddQCMeasurement()
        {
            if ((Item as ReconstitutedColdKit).QCAnalysis == null)
            {
                return;
            }

            RadiochemicalPurityMeasurement m = new RadiochemicalPurityMeasurement();

            m.Impurity = "???";
            (Item as ReconstitutedColdKit).QCAnalysis.Measurements.Add(m);
            Measurements.Add(m);
            RaisePropertyChanged("Measurements");
        }
Пример #14
0
        public static string MeasureMedian(List <int> ns, int numberMin, int numberMax, int repeatCount)
        {
            var random       = new Random(DateTime.Now.Millisecond);
            var sw           = new Stopwatch();
            var measurements = new Measurements(ns.Count);

            foreach (var n in ns)
            {
                var currentMeasurement = measurements.Add(n);
                for (var i = 0; i < repeatCount; i++)
                {
                    var l1     = new List <int>(n);
                    var middle = n / 2;

                    for (var x = 0; x < n; x++)
                    {
                        l1.Add(random.Next(numberMin, numberMax));
                    }

                    var l2 = new List <int>(l1);
                    var l3 = new List <int>(l1);

                    sw.Start();
                    var mom = l1.Mom(middle, Comparer <int> .Default);
                    sw.Stop();
                    var t1 = sw.Elapsed.Ticks;
                    sw.Reset();

                    sw.Start();
                    var momRandom = l2.MomRandom(middle, Comparer <int> .Default);
                    sw.Stop();
                    var t2 = sw.Elapsed.Ticks;
                    sw.Reset();

                    sw.Start();
                    var quickSelect = l3.QuickSelect(middle, Comparer <int> .Default);
                    sw.Stop();
                    var t3 = sw.Elapsed.Ticks;
                    sw.Reset();

                    currentMeasurement.sum(t1, t2, t3);
                }
            }

            measurements.UpdateStats();

            return(measurements.ToString());
        }
Пример #15
0
        private void RedefineList(List <Measurement> measurements)
        {
            Measurements.Clear();
            int iterator = 0;

            for (int i = 1; i < measurements.Count; i++)
            {
                var       change = measurements[i - 1].Weight - measurements[i].Weight;
                Changings c      = new Changings(change, measurements[i - 1].Weight, measurements[i - 1].MeasurementDate);
                Measurements.Add(c);
                iterator++;
            }
            Changings ch = new Changings(0, measurements[measurements.Count - 1].Weight, measurements[measurements.Count - 1].MeasurementDate);

            Measurements.Add(ch);
        }
    private void Add_Coroutine(Measurement3D measurement)
    {
        IsBusy = true;
        Measurements.Add(measurement);
        Positions.Add(measurement);

        //      badTriangles:= empty set
        List <Tetrahedron> badTetrahedrons = GetBadTetrahedrons(measurement);

        //   polygon := empty set
        List <Triangle> polygon = TriangleTest(badTetrahedrons);

        UpdateTriangulation(measurement, badTetrahedrons, polygon);
        IsBusy    = false;
        IsUpdated = true;
    }
Пример #17
0
        /// <summary>
        /// Метод добавления в коллекцию измерений
        /// </summary>
        /// <param name="Cur">Ток</param>
        public void AddInCollection(double Cur)
        {
            TextBlockMessageFromServer = "  Статус: " + "Идет измерение...";
            //Годность
            bool   valid;
            Device b    = SelectedDeviceInComboBox as Device;
            var    Umin = context.GetUmin(b);
            var    Umax = context.GetUmax(b);
            var    Unom = context.GetUnom(b);
            //Отклонение от номинального значения
            var    Deviat = Math.Abs(Umax - Umin) / 2;
            double Uizm   = 0;

            //Добавление в коллекцию Oscs и определение наибольшего напряжения
            for (int q = 0; q < 1000; q++)
            {
                double temp = 0;
                temp = masVoltageFromServer[q];
                if (temp > Uizm)
                {
                    Uizm = temp;
                }

                Oscs.Add(new Osc()
                {
                    U = masVoltageFromServer[q], T = masVoltageFromServer[q + 1000]
                });
            }
            //Вызов метода построения осциллограмм
            LoadData(CounterAmountMeasurement);
            //Обновить график
            PlotModel.InvalidatePlot(true);
            //Вывод измеренного напряжения
            TextBlockOfVoltage = Uizm.ToString() + " B";
            valid = (Math.Abs(Unom - Uizm) <= Deviat);
            //Создание нового экземпляра измерения
            var measure = new Measurement {
                device = b, NumberSupressor = Convert.ToInt32(TextBoxNumberOfSupressor), Date = DateTime.Now, Fio = TextBlockOfSurnameInMainWindow, Voltage = Uizm, Valid = valid, Current = Cur
            };

            //Добавление в коллекцию
            Measurements.Add(measure);
            //В БД
            context.AddMeasurementsInDb(measure);
            //Сохранение изменений
            context.SaveDb();
        }
Пример #18
0
        public void Run(string outFile, List<int> ns, List<double> ps, List<double> alphas, int repeatCount)
        {
            var m = new Measurements();
            var random = new Random(DateTime.Now.Millisecond);
            var sw = new Stopwatch();

            foreach (var alpha in alphas)
            {
                foreach(var p in ps)
                {
                    foreach (var n in ns) 
                    {
                        for(var x = 0; x < repeatCount; x++)
                        {
                            WriteLine(alpha + "a      " + p + "p       " + n);
                            // create or reset stuff
                            var sgt = new DataStructures.SGTree<int>(alpha);
                            var SGTNodes = new List<DataStructures.SGTNode<int>>(n);
                            sw.Reset();
                            sw.Start();
                            var prev = sgt.insertFirst(0);
                            SGTNodes.Add(prev);
                            for (var i = 0; i < n; i++)
                            {
                                // sequential probability 
                                if (random.Next(0, 100) / 100.0 < p)
                                {
                                    prev = sgt.insertAfter(prev, i); 
                                    SGTNodes.Add(prev);
                                }
                                else
                                {
                                    var at = random.Next(0, i);
                                    prev = sgt.insertAfter(SGTNodes[at], i);
                                    SGTNodes.Add(prev);
                                }
                            }                            
                            sw.Stop();
                            m.Add(n, p, alpha, sw.ElapsedTicks);                            
                        }                        
                    }
                }
            }

            m.WriteToFile(outFile);
        }
Пример #19
0
        public void Run(string outFile, List <int> ns, List <double> ps, List <double> alphas, int repeatCount)
        {
            var m      = new Measurements();
            var random = new Random(DateTime.Now.Millisecond);
            var sw     = new Stopwatch();

            foreach (var alpha in alphas)
            {
                foreach (var p in ps)
                {
                    foreach (var n in ns)
                    {
                        for (var x = 0; x < repeatCount; x++)
                        {
                            WriteLine(alpha + "a      " + p + "p       " + n);
                            // create or reset stuff
                            var sgt      = new DataStructures.SGTree <int>(alpha);
                            var SGTNodes = new List <DataStructures.SGTNode <int> >(n);
                            sw.Reset();
                            sw.Start();
                            var prev = sgt.insertFirst(0);
                            SGTNodes.Add(prev);
                            for (var i = 0; i < n; i++)
                            {
                                // sequential probability
                                if (random.Next(0, 100) / 100.0 < p)
                                {
                                    prev = sgt.insertAfter(prev, i);
                                    SGTNodes.Add(prev);
                                }
                                else
                                {
                                    var at = random.Next(0, i);
                                    prev = sgt.insertAfter(SGTNodes[at], i);
                                    SGTNodes.Add(prev);
                                }
                            }
                            sw.Stop();
                            m.Add(n, p, alpha, sw.ElapsedTicks);
                        }
                    }
                }
            }

            m.WriteToFile(outFile);
        }
Пример #20
0
        private void LoadDataFiles()
        {
            if (!Directory.Exists(SourceFolder))
            {
                throw new DirectoryNotFoundException($"Directory not found: {SourceFolder}");
            }

            var files = Directory.GetFiles(SourceFolder);

            foreach (var file in files)
            {
                var measurement = new Measurement();
                measurement.Init(file);

                Measurements.Add(measurement);
            }
        }
Пример #21
0
        public static string MeasureMedian(List<int> ns,  int numberMin, int numberMax, int repeatCount)
        {
            var random = new Random(DateTime.Now.Millisecond);
            var sw = new Stopwatch();
            var measurements = new Measurements(ns.Count);

            foreach (var n in ns)
            {
                var currentMeasurement = measurements.Add(n);
                for (var i = 0; i < repeatCount; i++)
                {
                    var l1 = new List<int>(n);
                    var middle = n/2;

                    for(var x = 0; x < n; x++)
                        l1.Add(random.Next(numberMin, numberMax));

                    var l2 = new List<int>(l1);
                    var l3 = new List<int>(l1);
                    
                    sw.Start();
                    var mom = l1.Mom(middle, Comparer<int>.Default);
                    sw.Stop();                    
                    var t1 = sw.Elapsed.Ticks;
                    sw.Reset();

                    sw.Start();
                    var momRandom = l2.MomRandom(middle, Comparer<int>.Default);
                    sw.Stop();
                    var t2 = sw.Elapsed.Ticks;
                    sw.Reset();
                    
                    sw.Start();
                    var quickSelect = l3.QuickSelect(middle, Comparer<int>.Default);
                    sw.Stop();
                    var t3 = sw.Elapsed.Ticks;
                    sw.Reset();

                    currentMeasurement.sum(t1, t2, t3);
                }
            }

            measurements.UpdateStats();

            return measurements.ToString();
        }
Пример #22
0
        public ReconstitutedColdKitViewModel(DataStoreItem item) : base(item)
        {
            InsertQCAnalysisCommand = new RelayCommand(CreatQCAnalysis);
            AddQCMeasurementCommand = new RelayCommand(AddQCMeasurement);
            if ((Item as ReconstitutedColdKit).QCAnalysis != null)
            {
                QCExists = true;
            }

            if ((Item as ReconstitutedColdKit).QCAnalysis != null)
            {
                foreach (RadiochemicalPurityMeasurement m in ((Item as ReconstitutedColdKit).QCAnalysis.Measurements))
                {
                    Measurements.Add(m);
                }
            }
        }
Пример #23
0
        protected override Measurements MeasureOverride(Size availableSize)
        {
            elementMap.Clear();
            var ms = new Measurements();

            foreach (var element in Elements)
            {
                var elementMs = element.Measure(availableSize);

                foreach (var measurement in elementMs)
                {
                    measurement.Flexible    = Flexible;
                    elementMap[measurement] = element;
                    ms.Add(measurement);
                }

                if (elementMs.Count > 0)
                {
                    elementMs[^ 1].PagebreakPenalty = double.PositiveInfinity;
Пример #24
0
        public void Run()
        {
            var filter = new UKF(1, 1);

            n = 1;
            q = 0.05;
            r = 0.3;
            N = 100;

            Q = Matrix.Build.Diagonal(n, n, q * q); //covariance of process
            NotifyChanged("Q");
            R = Matrix.Build.Dense(1, 1, r * r);    //covariance of measurement
            f = new FEquation();                    //nonlinear state equations
            h = new HEquation();                    //measurement equation
            x = q * Matrix.Build.Random(1, 1);      //s + q * Matrix.Build.Random(1, 1); //initial state with noise
            P = Matrix.Build.Diagonal(n, n, 1);     //initial state covariance


            var xV = Matrix.Build.Dense(n, N, 0); //Estimate
            var zV = Matrix.Build.Dense(1, N, 0); //measurement


            for (int k = 1; k < N; k++)
            {
                Matrix <double> z = ProcessBuilder.SineWave(k, r);
                //measurments

                Matrix <double>[] x_and_P = filter.Update(f, x, P, h, z, Q, R);                //ukf
                x = x_and_P[0];
                P = x_and_P[1];

                Measurements.Add(new Measurement()
                {
                    Value = z[0, 0], Time = TimeSpan.FromSeconds(k)
                });
                Estimates.Add(new Measurement()
                {
                    Value = x_and_P[0][0, 0], Time = TimeSpan.FromSeconds(k), Variance = x_and_P[1][0, 0]
                });
            }
        }
        async Task ExecuteLoadMeasurementsCommand()
        {
            IsBusy = true;

            try
            {
                Measurements.Clear();
                var measurements = await DataStoreUserMeasurement.GetItemsAsync(true);

                foreach (var measurement in measurements)
                {
                    Measurements.Add(measurement);
                }
            }
            catch (Exception ex)
            {
                Debug.WriteLine(ex);
            }
            finally
            {
                IsBusy = false;
            }
        }
Пример #26
0
        /// <summary>
        /// Add measurement to the collection
        /// </summary>
        /// <returns></returns>
        private Measurement AddMeasurement()
        {
            //Store measurement
            Measurement _newMeasurement = new Measurement();

            _newMeasurement.Time     = DateTime.Now;
            _newMeasurement.Position = _lastPosition.Coordinate.Point.Position;
            _newMeasurement.Duration = new TimeSpan();

            if (Measurements.Count > 0)
            {
                double _deltaDistance = 0;

                if (Measurements.Count > 1)
                {
                    _deltaDistance = CalculateDistance(Measurements.Last().Position.Latitude,
                                                       Measurements.Last().Position.Longitude,
                                                       _newMeasurement.Position.Latitude,
                                                       _newMeasurement.Position.Longitude);
                }

                TimeSpan _deltaDuration = _newMeasurement.Time - Measurements.Last().Time;

                if (Measurements.Last().Pause)
                {
                    _deltaDistance = 0;
                    _deltaDuration = new TimeSpan(0);
                }

                _newMeasurement.Distance = Measurements.Last().Distance + _deltaDistance;
                _newMeasurement.Duration = Measurements.Last().Duration + _deltaDuration;
            }

            Measurements.Add(_newMeasurement);

            return(_newMeasurement);
        }
Пример #27
0
        private void OnMeasurementReceived(MeasurementData data)
        {
            const int maxValues = 15;

            var measurementModel = new MeasurementModel(data);

            Measurements.Add(measurementModel);

            //if ((Measurements.Count % 10) == 0)
            //{
            //    var timeSpan = data.Timestamp - (MeasurementManager.CurrentExperiment?.StartTime ?? data.Timestamp);
            //}

            //WeightGraphLabels.Add(timeSpan.TotalSeconds.ToString());

            if (WeightGraphData[0].Values.Count > maxValues)
            {
                WeightGraphData[0].Values.RemoveAt(0);
            }

            WeightGraphData[0].Values.Add(new ObservablePoint(data.Second, data.Weight));

            if (SpeedGraphData[0].Values.Count > maxValues)
            {
                SpeedGraphData[0].Values.RemoveAt(0);
            }

            SpeedGraphData[0].Values.Add(new ObservablePoint(data.Second, data.Speed));

            if (AccelerationGraphData[0].Values.Count > maxValues)
            {
                AccelerationGraphData[0].Values.RemoveAt(0);
            }

            AccelerationGraphData[0].Values.Add(new ObservablePoint(data.Second, data.Acceleration));
        }
Пример #28
0
 public virtual void AddMeasurement(Measurement measurement)
 {
     Measurements.Add(measurement);
     measurement.Tree = this;
 }
Пример #29
0
 private void NewTemperature(IMeasurement newMeasurement)
 {
     Application.Current.Dispatcher.Invoke(delegate { Measurements.Add((TemperatureMeasurement)newMeasurement); });
 }
 public void addToList(double measurement)
 {
     Measurements.Add(measurement);
 }
Пример #31
0
    public void Parse(IEnumerable <dynamic> records)
    {
        if (records is null)
        {
            throw new System.ArgumentNullException(nameof(records));
        }

        //On text applications, the line numbering will start from 1 but we start from 2 due to header.
        int i = 1;

        foreach (var item in records)
        {
            i++;

            Measurement m = new Measurement();
            m.Id = i;

            var       dateParseResult = datePattern.Parse((string)((IDictionary <string, object>)item)["Date"]);
            LocalDate dateOfMeasurement;
            if (!dateParseResult.TryGetValue(dateFailureValue, out dateOfMeasurement))
            {
                parsingErrors.Add("Date parsing error on line: " + i);
                continue;
            }

            var       timeParseResult = timePattern.Parse((string)((IDictionary <string, object>)item)["Time"]);
            LocalTime timeOfMeasurement;
            if (!timeParseResult.TryGetValue(timeFailureValue, out timeOfMeasurement))
            {
                parsingErrors.Add("Time parsing error on line: " + i);
                continue;
            }

            m.dateOfMeasurment  = dateOfMeasurement;
            m.timeOfMeasurement = timeOfMeasurement;

            float latitudeOfMeasurement;
            if (!float.TryParse((string)((IDictionary <string, object>)item)["GPS Latitude"], NumberStyles.Any, cultureInfo, out latitudeOfMeasurement))
            {
                parsingErrors.Add("Latitude parsing error on line: " + i);
                continue;
            }

            m.latitudeOfMeasurement = latitudeOfMeasurement;

            float longitudeOfMeasurement;
            if (!float.TryParse((string)((IDictionary <string, object>)item)["GPS Longitude"], NumberStyles.Any, cultureInfo, out longitudeOfMeasurement))
            {
                parsingErrors.Add("Longitude parsing error on line: " + i);
                continue;
            }

            m.longitudeOfMeasurement = longitudeOfMeasurement;

            float depthOfMeasurement;
            if (!float.TryParse((string)((IDictionary <string, object>)item)["depth"], NumberStyles.Any, cultureInfo, out depthOfMeasurement))
            {
                parsingErrors.Add("Depth parsing error on line: " + i);
                continue;
            }

            m.depthOfMeasurement = depthOfMeasurement;
            Measurements.Add(m);
        }
    }
Пример #32
0
        public void AddData(IEntity data, EntityType entityType)
        {
            switch (entityType)
            {
            case EntityType.Person:
            {
                Persons.Add((Person)data);
                break;
            }

            case EntityType.Death:
            {
                Deaths.Add((Death)data);
                break;
            }

            case EntityType.PayerPlanPeriod:
            {
                PayerPlanPeriods.Add((PayerPlanPeriod)data);
                break;
            }

            case EntityType.ConditionOccurrence:
            {
                ConditionOccurrences.Add((ConditionOccurrence)data);
                break;
            }

            case EntityType.DrugExposure:
            {
                DrugExposures.Add((DrugExposure)data);
                break;
            }

            case EntityType.ProcedureOccurrence:
            {
                ProcedureOccurrences.Add((ProcedureOccurrence)data);
                break;
            }

            case EntityType.Observation:
            {
                Observations.Add((Observation)data);
                break;
            }

            case EntityType.VisitOccurrence:
            {
                VisitOccurrences.Add((VisitOccurrence)data);
                break;
            }

            case EntityType.VisitDetail:
            {
                VisitDetails.Add((VisitDetail)data);
                break;
            }

            case EntityType.Cohort:
            {
                Cohort.Add((Cohort)data);
                break;
            }

            case EntityType.Measurement:
            {
                Measurements.Add((Measurement)data);
                break;
            }

            case EntityType.DeviceExposure:
            {
                DeviceExposure.Add((DeviceExposure)data);
                break;
            }

            case EntityType.ObservationPeriod:
            {
                ObservationPeriods.Add((ObservationPeriod)data);
                break;
            }

            case EntityType.DrugEra:
            {
                DrugEra.Add((EraEntity)data);
                break;
            }

            case EntityType.ConditionEra:
            {
                ConditionEra.Add((EraEntity)data);
                break;
            }

            case EntityType.Note:
            {
                Note.Add((Note)data);
                break;
            }
            }
        }
Пример #33
0
        /**
         * @brief Asynchronous chart update procedure with
         *        data obtained from IoT server responses.
         * @param ip IoT server IP address.
         */
        private async void UpdatePlotWithServerResponse()
        {
#if CLIENT
#if GET
            string responseText = await Server.GETwithClient();
#else
            string responseText_IMU = await Server.POSTwithClient("rpy");

            string responseText_ENV = await Server.POSTwithClient("env");
#endif
#else
#if GET
            string responseText = await Server.GETwithRequest();
#else
            string responseText = await Server.POSTwithRequest();
#endif
#endif
            try
            {
#if DYNAMIC
                App.Current.Dispatcher.Invoke((System.Action) delegate
                {
                    JArray measurementsJsonArray = JArray.Parse(responseText_ENV.Replace(']', ',') + responseText_IMU.TrimStart('['));

                    var measurementsList = measurementsJsonArray.ToObject <List <MeasurementModel> >();

                    measurementsList.RemoveAt(3);
                    measurementsList.RemoveAt(6);

                    if (Measurements.Count < measurementsList.Count)
                    {
                        foreach (var m in measurementsList)
                        {
                            Measurements.Add(new MeasurementViewModel(m));
                        }
                    }
                    // Update existing elements in collection
                    else
                    {
                        for (int i = 0; i < Measurements.Count; i++)
                        {
                            Measurements[i].UpdateWithModel(measurementsList[i]);
                        }
                    }
                });



                JArray array_IMU = JArray.Parse(responseText_IMU);
                JArray array_ENV = JArray.Parse(responseText_ENV);

                foreach (JObject obj in array_IMU.Children <JObject>())
                {
                    foreach (JProperty singleProp in obj.Properties())
                    {
                        if (singleProp.Path == "[0].value")
                        {
                            string x      = singleProp.Value.ToString();
                            double result = Convert.ToDouble(x);
                            if (result > 180)
                            {
                                result -= 360;
                            }
                            Roll_read = result.ToString("N1");
                            UpdatePlot_IMU(timeStamp / 1000.0, result, 0);
                        }

                        if (singleProp.Path == "[1].value")
                        {
                            string x      = singleProp.Value.ToString();
                            double result = Convert.ToDouble(x);
                            if (result > 180)
                            {
                                result -= 360;
                            }
                            Pitch_read = result.ToString("N1");
                            UpdatePlot_IMU(timeStamp / 1000.0, result, 1);
                        }

                        if (singleProp.Path == "[2].value")
                        {
                            string x      = singleProp.Value.ToString();
                            double result = Convert.ToDouble(x);
                            if (result > 180)
                            {
                                result -= 360;
                            }
                            Yaw_read = result.ToString("N1");
                            UpdatePlot_IMU(timeStamp / 1000.0, result, 2);
                        }
                    }
                }
                foreach (JObject obj in array_ENV.Children <JObject>())
                {
                    foreach (JProperty singleProp in obj.Properties())
                    {
                        if (singleProp.Path == "[0].value")
                        {
                            string x      = singleProp.Value.ToString();
                            double result = Convert.ToDouble(x);
                            Temp_read = result.ToString("N2");
                            UpdatePlot_temp(timeStamp / 1000.0, result);
                        }
                        if (singleProp.Path == "[1].value")
                        {
                            string x      = singleProp.Value.ToString();
                            double result = Convert.ToDouble(x);
                            Press_read = result.ToString("N2");
                            UpdatePlot_press(timeStamp / 1000.0, result);
                        }
                        if (singleProp.Path == "[2].value")
                        {
                            string x      = singleProp.Value.ToString();
                            double result = Convert.ToDouble(x);
                            Humid_read = result.ToString("N2");
                            UpdatePlot_humid(timeStamp / 1000.0, result);
                        }
                    }
                }
#else
                ServerData resposneJson = JsonConvert.DeserializeObject <ServerData>(responseText);
                UpdatePlot(timeStamp / 1000.0, resposneJson.data);
#endif
            }
            catch (Exception e)
            {
                Debug.WriteLine("JSON DATA ERROR");
                Debug.WriteLine(responseText_IMU);
                Debug.WriteLine(e);
            }

            timeStamp += config.SampleTime;
        }