Beispiel #1
0
        private DataContainer GetDataContainer(string containerId)
        {
            if (DataContainers.ContainsKey(containerId))
            {
                return(DataContainers[containerId]);
            }

            XElement dcEl = ConfigRoot.Descendants("dataContainer")
                            .Where(el => el.Attribute("id").Value.Inject(Parameters) == containerId).Single();

            bool allowDup = false;

            if (dcEl.Attribute("allowDuplicates") != null && dcEl.Attribute("allowDuplicates").Value == "true")
            {
                allowDup = true;
            }

            var container = new DataContainer()
            {
                AllowDuplicates = allowDup
            };

            container.Id = containerId;
            foreach (string readerId in dcEl.Attribute("dataReaders").Value.Inject(Parameters).Split(','))
            {
                container.DataReaders.Add(ParseDataReader(readerId));
            }

            DataContainers.Add(containerId, container);
            return(container);
        }
        /// <summary>
        /// Function which retrieves all processed Data
        /// </summary>
        /// <returns></returns>
        public IDictionary <string, DataProcessedModel> GetAllData()
        {
            // delete old data and predict the new values
            UpdateAndDeleteOldPositions();

            // transform the data from data-processing-Container to data-processed-Container
            DataContainers.GetInstance().DATA_PROCESSED_CONTAINER.Clear();

            //Create CSV Model

            foreach (var model in DataContainers.GetInstance().DATA_PROCESSING_CONTAINER)
            {
                if (model.Value.Altitude < 0 || model.Value.Longitude < 0 || model.Value.Latitude < 0)
                {
                    continue;
                }

                var cw = new CsvWriter <DataProcessedModel>();

                //Write Model into Csv File
                cw.WriteModelToCsvFile(DataProcessingModelToDataProcessedModel(model.Value), Constants.DATA_PROCESSED_FILE_PATH);

                //Add value to Dictionary

                DataContainers.GetInstance().DATA_PROCESSED_CONTAINER.Add(model.Value.Flight, DataProcessingModelToDataProcessedModel(model.Value));
            }

            return(DataContainers.GetInstance().DATA_PROCESSED_CONTAINER);
        }
Beispiel #3
0
        /// <summary>
        /// Add data to Dictionary
        /// </summary>
        /// <param name="receivedData"></param>
        public void RegisterData(DataTransmissionModel receivedData)
        {
            DataProcessingModel dataProcessingModel;

            var updateTimes = 1;

            if (DataContainers.GetInstance().DATA_PROCESSING_CONTAINER.ContainsKey(receivedData.Flight))
            {
                dataProcessingModel = DataContainers.GetInstance().DATA_PROCESSING_CONTAINER[receivedData.Flight];

                dataProcessingModel = DataProcessingOperations.DataTransmissionModelToDataProcessingModel(dataProcessingModel, receivedData);

                DataContainers.GetInstance().DATA_RECEIVED_CONTAINER.Clear();
            }
            else
            {
                DataContainers.GetInstance().DATA_PROCESSING_CONTAINER.Add(receivedData.Flight, DataProcessingOperations.GetInstance().DataTransmissionModelToDataProcessingModelKalman(receivedData));
                dataProcessingModel = DataContainers.GetInstance().DATA_PROCESSING_CONTAINER[receivedData.Flight];
                updateTimes         = 10;
            }

            if (!IsPositionNullOrZero(receivedData.Altitude) && !IsPositionNullOrZero(receivedData.Latitude) && !IsPositionNullOrZero(receivedData.Longitude))
            {
                var cartesianCoordinates = new CartesianCoordinates3D(
                    receivedData.Altitude.Value,
                    receivedData.Longitude.Value,
                    receivedData.Latitude.Value
                    );

                for (var i = 0; i < updateTimes; i++)
                {
                    cartesianCoordinates = dataProcessingModel.KalmanRunner.Update(cartesianCoordinates);
                }

                dataProcessingModel.Altitude  = cartesianCoordinates.Altitude;
                dataProcessingModel.Longitude = cartesianCoordinates.Longitude;
                dataProcessingModel.Latitude  = cartesianCoordinates.Latitude;
                dataProcessingModel.UTC       = DateTime.UtcNow;
            }
        }
        /// <summary>
        /// Delete Old Data in Dictionary after a period of time
        /// </summary>
        private static void UpdateAndDeleteOldPositions()
        {
            var oldFlightsList = new List <string>();

            foreach (var data in DataContainers.GetInstance().DATA_PROCESSING_CONTAINER.Values)
            {
                var currentTime = DateTime.UtcNow;

                double diff = currentTime.Subtract(data.UTC.Value).Seconds;

                if (diff > 60)
                {
                    //DataContainers.GetInstance().DATA_PROCESSING_CONTAINER.Remove(data.Flight);
                    oldFlightsList.Add(data.Flight);
                }
                else
                {
                    double diff2 = currentTime.Subtract(data.UTC_Predicted.Value).Seconds;

                    var cartesianCoordinates = data.KalmanRunner.Predict(diff2);

                    if (cartesianCoordinates == null)
                    {
                        return;
                    }

                    data.Altitude      = cartesianCoordinates.Altitude;
                    data.Longitude     = cartesianCoordinates.Longitude;
                    data.Latitude      = cartesianCoordinates.Latitude;
                    data.UTC_Predicted = DateTime.UtcNow;
                }
            }

            foreach (var str in oldFlightsList)
            {
                DataContainers.GetInstance().DATA_PROCESSING_CONTAINER.Remove(str);
            }
        }