/// <summary>
        /// Updates the channel data for the specified data object URI.
        /// </summary>
        /// <param name="uri">The parent data object URI.</param>
        /// <param name="reader">The update reader.</param>
        public void UpdateChannelData(EtpUri uri, ChannelDataReader reader)
        {
            // TODO: Transaction support needed here
            Logger.Debug($"Updating channel data for URI: {uri}");

            // Capture primary index info when auto-creating data object
            var indexInfos = Exists(uri) ? null : reader.Indices;
            var offset     = reader.Indices.Take(1).Select(x => x.IsTimeIndex).FirstOrDefault()
                ? reader.GetChannelIndexRange(0).Offset
                : null;

            // Ensure data object and parent data objects exist
            var dataProvider = Container.Resolve <IEtpDataProvider>(new ObjectName(uri.ObjectType, uri.Version));

            dataProvider.Ensure(uri);

            // Only use the URI of the channelSet as it is a top level object
            uri        = EtpUris.Witsml200.Append(ObjectTypes.ChannelSet, uri.ObjectId);
            reader.Uri = uri.Uri;

            if (indexInfos != null)
            {
                // Update data object with primary index info after it has been auto-created
                UpdateIndexInfo(uri, indexInfos, offset);
            }

            // Ensure all logCurveInfo elements exist
            UpdateChannels(uri, reader, offset);

            // Update channel data and index range
            UpdateChannelDataAndIndexRange(uri, reader);
        }
Esempio n. 2
0
        /// <summary>
        /// Adds ChannelDataChunks using the specified reader.
        /// </summary>
        /// <param name="reader">The <see cref="ChannelDataReader" /> used to parse the data.</param>
        /// <exception cref="WitsmlException"></exception>
        public void Add(ChannelDataReader reader)
        {
            if (reader == null || reader.RecordsAffected <= 0)
            {
                return;
            }

            Logger.Debug("Adding ChannelDataChunk records with a ChannelDataReader.");

            try
            {
                BulkWriteChunks(
                    ToChunks(
                        reader.AsEnumerable()),
                    reader.Uri,
                    string.Join(",", reader.Mnemonics),
                    string.Join(",", reader.Units),
                    string.Join(",", reader.NullValues)
                    );

                CreateChannelDataChunkIndex();
            }
            catch (MongoException ex)
            {
                Logger.ErrorFormat("Error when adding data chunks: {0}", ex);
                throw new WitsmlException(ErrorCodes.ErrorAddingToDataStore, ex);
            }
            catch (FormatException ex)
            {
                Logger.ErrorFormat("Error when adding data chunks: {0}", ex);
                throw new WitsmlException(ErrorCodes.ErrorMaxDocumentSizeExceeded, ex);
            }
        }
        public void Log141DataAdapter_AddToStore_With_Custom_Data_Delimiter()
        {
            var delimiter = "|";

            AddParents();

            // Set data delimiter to other charactrer than ","
            Log.DataDelimiter = delimiter;

            DevKit.InitHeader(Log, LogIndexType.measureddepth);
            DevKit.InitDataMany(Log, DevKit.Mnemonics(Log), DevKit.Units(Log), 10, hasEmptyChannel: false);

            var response = DevKit.Add <LogList, Log>(Log);

            Assert.AreEqual((short)ErrorCodes.Success, response.Result);

            var result = GetLog(Log);

            // Assert data delimiter
            Assert.AreEqual(delimiter, result.DataDelimiter);

            var data = result.LogData.FirstOrDefault()?.Data;

            Assert.IsNotNull(data);

            var channelCount = Log.LogCurveInfo.Count;

            // Assert data delimiter in log data
            foreach (var row in data)
            {
                var points = ChannelDataReader.Split(row, delimiter);
                Assert.AreEqual(channelCount, points.Length);
            }
        }
        private void GetUpdatedLogHeaderIndexRange(ChannelDataReader reader, string[] mnemonics, Dictionary <string, Range <double?> > ranges, bool increasing = true)
        {
            for (var i = 0; i < mnemonics.Length; i++)
            {
                var             mnemonic = mnemonics[i];
                Range <double?> current;

                if (!ranges.TryGetValue(mnemonic, out current))
                {
                    current = new Range <double?>(null, null);
                }

                var update = reader.GetChannelIndexRange(i);
                var start  = current.Start;
                var end    = current.End;

                if (!current.Start.HasValue || !update.StartsAfter(current.Start.Value, increasing))
                {
                    start = update.Start;
                }
                if (!current.End.HasValue || !update.EndsBefore(current.End.Value, increasing))
                {
                    end = update.End;
                }

                ranges[mnemonic] = new Range <double?>(start, end);
            }
        }
Esempio n. 5
0
        private bool ToPartialDeleteChunk(ChannelDataReader reader, List <string> deletedChannels, Dictionary <string, Range <double?> > channelRanges, Dictionary <string, Range <double?> > ranges, Dictionary <string, List <double?> > updatedRanges, bool increasing)
        {
            var updatedChannels = ranges.Keys.ToList();

            if (!reader.Mnemonics.Any(m => deletedChannels.Contains(m) || updatedChannels.Contains(m)))
            {
                return(false);
            }

            var toPartialDelete = false;

            foreach (var channelRange in channelRanges)
            {
                if (!ranges.ContainsKey(channelRange.Key))
                {
                    continue;
                }

                var range = ranges[channelRange.Key];
                if (!RangesOverlap(channelRange.Value, range, increasing))
                {
                    continue;
                }

                toPartialDelete = true;
                break;
            }

            return(toPartialDelete);
        }
Esempio n. 6
0
        public void ChannelDataReader_can_Read_ChannelSet_Data()
        {
            var reader = new ChannelDataReader(ChannelSetData);
            var json   = new StringBuilder("[");
            int count  = 0;

            Assert.AreEqual(2, reader.Depth);
            Assert.AreEqual(5, reader.FieldCount);
            Assert.AreEqual(5, reader.RecordsAffected);
            json.AppendLine();

            while (reader.Read())
            {
                Console.WriteLine("Row {0}: {1}, {2}, {3}, {4}, {5}", count++,
                                  reader.GetDouble(0),
                                  reader.GetDateTimeOffset(1),
                                  reader.GetString(2),
                                  reader.GetDouble(3),
                                  reader.GetDouble(4));

                json.AppendLine(reader.GetJson());
            }

            Assert.IsNull(reader.GetJson());

            // original
            Console.WriteLine();
            Console.WriteLine(ChannelSetData);

            // serialized
            Console.WriteLine();
            Console.WriteLine(json.Append("]"));
        }
Esempio n. 7
0
        public void ChannelDataReader_Can_Parse_Null_Data()
        {
            var reader = new ChannelDataReader(string.Empty);

            Assert.AreEqual(0, reader.Depth);
            Assert.AreEqual(0, reader.FieldCount);
            Assert.AreEqual(0, reader.RecordsAffected);
        }
Esempio n. 8
0
        private static void InitNullValues(out string[] nullValues, out SortedDictionary <int, string> nullValueDictionary)
        {
            nullValues = ChannelDataReader.Split("-999.25,,-1000.1");
            var tempDictionary = new SortedDictionary <int, string>();

            nullValues.ForEach((x, i) => tempDictionary.Add(i, x));
            nullValueDictionary = tempDictionary;
        }
Esempio n. 9
0
        private static void InitUnits(out string[] units, out SortedDictionary <int, string> unitDictionary)
        {
            units = ChannelDataReader.Split("unitless,m,m,m");
            var tempDictionary = new SortedDictionary <int, string>();

            units.ForEach((x, i) => tempDictionary.Add(i, x));
            unitDictionary = tempDictionary;
        }
Esempio n. 10
0
        /// <summary>
        /// Checks the log data for duplicate indexes.
        /// </summary>
        /// <param name="logData">The log data.</param>
        /// <param name="function">The context function</param>
        /// <param name="delimiter">The data delimiter.</param>
        /// <param name="isTimeLog">Is the log a time log.</param>
        /// <param name="mnemonicCount">The count of mnemonics.</param>
        /// <returns><c>true</c> if Log data has duplicates; otherwise, <c>false</c>.</returns>
        public static bool HasDuplicateIndexes(this List <string> logData, Functions function, string delimiter, bool isTimeLog, int mnemonicCount)
        {
            var warnings    = new List <WitsmlValidationResult>();
            var indexValues = new HashSet <double>();

            foreach (var row in logData)
            {
                var values = ChannelDataReader.Split(row, delimiter, mnemonicCount, warnings);
                var value  = values.FirstOrDefault();

                if (isTimeLog)
                {
                    DateTimeOffset dto;

                    if (!DateTimeOffset.TryParse(value, out dto))
                    {
                        var error = new WitsmlException(function.GetNonConformingErrorCode());
                        ChannelDataExtensions.HandleInvalidDataRow(error, warnings);
                        continue;
                    }

                    // TODO: Add compatibility option for DuplicateIndexSetting
                    if (indexValues.Contains(dto.UtcTicks))
                    {
                        return(true);
                    }

                    indexValues.Add(dto.UtcTicks);
                }
                else
                {
                    double doubleValue;

                    if (!double.TryParse(value, out doubleValue))
                    {
                        var error = new WitsmlException(function.GetNonConformingErrorCode());
                        ChannelDataExtensions.HandleInvalidDataRow(error, warnings);
                        continue;
                    }

                    // TODO: Add compatibility option for DuplicateIndexSetting
                    if (indexValues.Contains(doubleValue))
                    {
                        return(true);
                    }

                    indexValues.Add(doubleValue);
                }
            }

            if (warnings.Any())
            {
                WitsmlOperationContext.Current.Warnings.AddRange(warnings);
            }

            return(false);
        }
Esempio n. 11
0
        /// <summary>
        /// Calculates the index range for a <see cref="ChannelDataReader"/>
        /// </summary>
        /// <param name="reader">The reader.</param>
        /// <param name="channelIndex">Index of the channel.</param>
        /// <param name="index">The index.</param>
        private static void CalculateIndexRange(ChannelDataReader reader, ChannelIndexInfo channelIndex, int index)
        {
            _log.DebugFormat("Calculating channel index range for {0}", channelIndex.Mnemonic);

            var range = reader.GetIndexRange(index);

            channelIndex.Start = range.Start.GetValueOrDefault(double.NaN);
            channelIndex.End   = range.End.GetValueOrDefault(double.NaN);
        }
        public void Log200DataAdapter_Log_Can_Be_Added_With_Decreasing_Log_Data()
        {
            AddParents();

            var numDataValue             = 150;
            var secondaryIndex           = DevKit.LogGenerator.CreateDateTimeIndex();
            var mdChannelIndexDecreasing = DevKit.LogGenerator.CreateMeasuredDepthIndex(IndexDirection.decreasing);

            DevKit.InitHeader(Log, LoggingMethod.surface, mdChannelIndexDecreasing);

            var channelSet = Log.ChannelSet.First();

            channelSet.Index.Add(secondaryIndex);

            // Generate rows of data
            DevKit.LogGenerator.GenerateChannelData(Log.ChannelSet, numDataValue);

            File.WriteAllText("TestData/DecreasingDepthLog-2.0-Well.xml", EnergisticsConverter.ObjectToXml(Well));
            File.WriteAllText("TestData/DecreasingDepthLog-2.0-Wellbore.xml", EnergisticsConverter.ObjectToXml(Wellbore));
            File.WriteAllText("TestData/DecreasingDepthLog-2.0.xml", EnergisticsConverter.ObjectToXml(Log));

            DevKit.AddAndAssert(Log);
            var log = DevKit.GetAndAssert(Log);

            Assert.AreEqual(Log.Citation.Title, log.Citation.Title);
            Assert.AreEqual(Log.Uuid, log.Uuid);

            var mnemonics = channelSet.Index.Select(i => i.Mnemonic).Concat(channelSet.Channel.Select(c => c.Mnemonic)).ToList();
            var logData   = _channelDataProvider.GetChannelData(channelSet.GetUri(), new Range <double?>(null, null), mnemonics, null);

            // Test that the rows of data before and after are the same.
            Assert.AreEqual(numDataValue, logData.Count);

            var start = logData[0][0][0];
            var end   = logData[numDataValue - 1][0][0];

            // Test the log is still decreasing
            Assert.IsTrue(double.Parse(end.ToString()) < double.Parse(start.ToString()));

            // Check PointMetadata values
            foreach (var row in logData)
            {
                var ropValues  = ChannelDataReader.ReadValue(row[1][0]) as object[];
                var hkldValues = ChannelDataReader.ReadValue(row[1][1]) as object[];

                Assert.IsNull(hkldValues);
                if (ropValues == null)
                {
                    continue;
                }

                Assert.AreEqual(2, ropValues.Length);
                Assert.IsTrue(ropValues[0] == null || ropValues[0] is double);
                Assert.IsTrue(ropValues[1] == null || ropValues[1] is bool);
            }
        }
Esempio n. 13
0
 private void WriteRecordsToChunks(ChannelDataReader reader, IEnumerable <IChannelDataRecord> records)
 {
     BulkWriteChunks(
         ToChunks(records),
         reader.Uri,
         string.Join(",", reader.Mnemonics),
         string.Join(",", reader.Units),
         string.Join(",", reader.NullValues)
         );
 }
Esempio n. 14
0
        public void ChannelDataReader_Can_Slice_With_Request_Has_Empty_Channels()
        {
            // Create a Reader
            var reader = new ChannelDataReader(HasEmptyChannels, "CH1,CH2,CH3,CH4,CH5,CH6,CH7,CH8,CH9".Split(','), "ft1,ft2,ft3,ft4,ft5,ft6,ft7,ft8,ft9".Split(','), "double,double,double,double,double,double,double,double, double".Split(','), ",,,,,,,,".Split(','), "eml://witsml14/well(Energistics-well-0001)/wellbore(Energistics-w1-wellbore-0001)/log(Energistics-w1-wb1-log-0002)", "06e4dff8-3de4-4057-a21b-92026e89a6d4")
                         .WithIndex("MD", "ft", true, false);

            Assert.IsTrue(reader.Read());

            Dictionary <int, string> requestedMnemonics = new Dictionary <int, string>()
            {
                { 0, "MD" }, { 1, "CH1" }, { 2, "CH2" }, { 5, "CH5" }, { 6, "CH6" }, { 7, "CH7" }, { 9, "CH9" }
            };
            Dictionary <int, string> requestedUnits = new Dictionary <int, string>()
            {
                { 0, "ft" }, { 1, "ft1" }, { 2, "ft2" }, { 5, "ft5" }, { 6, "ft6" }, { 7, "ft7" }, { 9, "ft9" }
            };
            Dictionary <int, string> requestedDataTypes = new Dictionary <int, string>()
            {
                { 0, "double" }, { 1, "double" }, { 2, "double" }, { 5, "double" }, { 6, "double" }, { 7, "double" }, { 9, "double" }
            };
            Dictionary <int, string> requestedNullValues = new Dictionary <int, string>()
            {
                { 0, string.Empty }, { 1, string.Empty }, { 2, string.Empty }, { 5, string.Empty }, { 6, string.Empty }, { 7, string.Empty }, { 9, string.Empty }
            };

            reader.Slice(requestedMnemonics, requestedUnits, requestedDataTypes, requestedNullValues);

            // Test Mnemonic Slices
            var mnemonics = reader.AllMnemonics;
            var requestedMnemonicValues = requestedMnemonics.Values.ToArray();

            Assert.AreEqual(3, mnemonics.Count());
            Assert.AreEqual(mnemonics.Count(), requestedMnemonicValues.Count());
            for (var i = 0; i < mnemonics.Count; i++)
            {
                Assert.AreEqual(requestedMnemonicValues[i], mnemonics[i]);
            }

            // Test Unit Slices
            var units = reader.AllUnits;

            Assert.AreEqual(3, units.Count());
            Assert.AreEqual(requestedMnemonics.Keys.Count, units.Count);
            Assert.AreEqual("ft", units[0]);
            Assert.AreEqual("ft2", units[1]);
            Assert.AreEqual("ft6", units[2]);

            var values     = new object[9];
            var valueCount = reader.GetValues(values);

            Assert.AreEqual(3, valueCount);
            Assert.AreEqual((long)10, values[0]);
            Assert.AreEqual((long)11, values[1]);
            Assert.AreEqual((long)13, values[2]);
        }
Esempio n. 15
0
        /// <summary>
        /// Gets a <see cref="ChannelDataReader"/> that can be used to process the <see cref="ChannelDataChunk"/> data.
        /// </summary>
        /// <param name="channelDataChunk">The channel data chunk.</param>
        /// <param name="reverse">if set to <c>true</c> the primary index should be reversed.</param>
        /// <returns></returns>
        public static ChannelDataReader GetReader(this ChannelDataChunk channelDataChunk, bool reverse = false)
        {
            _log.DebugFormat("Creating a ChannelDataReader for a ChannelDataChunk. Reverse: {0}", reverse);

            var mnemonics  = ChannelDataReader.Split(channelDataChunk.MnemonicList);
            var units      = ChannelDataReader.Split(channelDataChunk.UnitList);
            var dataTypes  = new string[0];
            var nullValues = ChannelDataReader.Split(channelDataChunk.NullValueList);

            return(new ChannelDataReader(channelDataChunk.Data, mnemonics, units, dataTypes, nullValues, channelDataChunk.Uri, channelDataChunk.Uid)
                   .WithIndices(channelDataChunk.Indices, calculate: reverse, reverse: reverse));
        }
Esempio n. 16
0
        public void ChannelDataReader_Can_Calculate_Channel_Min_Max_Indices_With_Multiple_Values()
        {
            var reader = new ChannelDataReader(UpdateLogData3, new[] { "ROP", "GR", "HKLD" })
                         .WithIndex("MD", "m", true, false);

            Assert.AreEqual(1, reader.Depth);
            Assert.AreEqual(4, reader.FieldCount);
            Assert.AreEqual(6, reader.RecordsAffected);

            var range = reader.GetChannelIndexRange(reader.GetOrdinal("GR"));

            Assert.AreEqual(3.5, range.Start);
            Assert.AreEqual(7.0, range.End);
        }
Esempio n. 17
0
        public void ChannelDataExtensions_GetReader_Returns_ChannelDataReader()
        {
            string[] mnemonics, mnemonicFilter;
            SortedDictionary <int, string> mnemonicFilterDictionary;

            InitMnemonics(out mnemonics, out mnemonicFilter, out mnemonicFilterDictionary);

            string[] units;
            SortedDictionary <int, string> unitDictionary;

            InitUnits(out units, out unitDictionary);

            string[] dataTypes;
            SortedDictionary <int, string> dataTypeDictionary;

            InitDataTypes(out dataTypes, out dataTypeDictionary);

            string[] nullValues;
            SortedDictionary <int, string> nullValueDictionary;

            InitNullValues(out nullValues, out nullValueDictionary);

            var ranges = new Dictionary <string, Range <double?> >();

            var listofCii = new List <ChannelIndexInfo>
            {
                new ChannelIndexInfo()
                {
                    DataType    = "double",
                    Mnemonic    = "MD",
                    Unit        = "m",
                    Increasing  = true,
                    IsTimeIndex = false
                }
            };
            var records = new ChannelDataReader("[[[0],[0,0,0]],[[1],[1,1,1]]]", mnemonics, units, dataTypes, nullValues, "eml://witsml14/well(1)/wellbore(1)/log(1)", "1")
                          .WithIndices(listofCii).AsEnumerable();

            Assert.IsNotNull(records);
            using (var reader = records.GetReader())
            {
                var logData = reader.GetData(new ResponseContext()
                {
                    HasAllRequestedValues = false, RequestLatestValues = null
                }, mnemonicFilterDictionary, unitDictionary, dataTypeDictionary, nullValueDictionary, out ranges);
                Assert.AreEqual(1, logData.Count);
                Assert.AreEqual(2, logData[0].Count);
                Assert.AreEqual(1, logData[0][0].Count);
            }
        }
Esempio n. 18
0
        public void ChannelDataReader_Can_Set_Data_Value()
        {
            var reader = new ChannelDataReader(UpdateLogData1, new[] { "MD", "ROP", "GR", "HKLD" })
                         .WithIndex("MD", "m", true, false);

            Assert.AreEqual(1, reader.Depth);
            Assert.AreEqual(4, reader.FieldCount);
            Assert.AreEqual(9, reader.RecordsAffected);

            if (reader.Read())
            {
                reader.SetValue(1, 1000.0);
                Assert.AreEqual(1000.0, reader.GetDouble(1));
            }
        }
Esempio n. 19
0
        /// <summary>
        /// Formats the value.
        /// </summary>
        /// <param name="value">The value.</param>
        /// <param name="attributes">The attributes.</param>
        /// <returns></returns>
        protected object FormatValue(object value, List <object> attributes)
        {
            value = ChannelDataReader.ReadValue(value);
            var data = value as object[];

            if (data == null)
            {
                return(FormatValue(value));
            }

            // Separate PointMetadata values
            attributes.AddRange(data.Skip(1).Select(FormatValue));

            return(FormatValue(data.FirstOrDefault()));
        }
Esempio n. 20
0
        /// <summary>
        /// Updates a <see cref="ChannelDataReader"/> with multiple the indices.
        /// </summary>
        /// <param name="reader">The reader.</param>
        /// <param name="indices">The indices.</param>
        /// <param name="calculate">if set to <c>true</c> the index range is calculated.</param>
        /// <param name="reverse">if set to <c>true</c> the sort order is reversed.</param>
        /// <returns>The <see cref="ChannelDataReader"/> instance being updated.</returns>
        public static ChannelDataReader WithIndices(this ChannelDataReader reader, IEnumerable <ChannelIndexInfo> indices, bool calculate = false, bool reverse = false)
        {
            _log.Debug("Adding channel indexes to ChannelDataReader");

            foreach (var index in indices)
            {
                reader.Indices.Add(index);

                if (calculate)
                {
                    CalculateIndexRange(reader, index, reader.Indices.Count - 1);
                }
            }

            return(calculate ? reader.Sort(reverse) : reader);
        }
Esempio n. 21
0
        private static void InitMnemonics(out string[] mnemonics, out string[] mnemonicFilter, out SortedDictionary <int, string> mnemonicFilterDictionary)
        {
            mnemonics = ChannelDataReader.Split("DEPTH,A,B,C");
            var tempFilter     = new[] { "MD", "A", "B" };
            var tempDictionary = new SortedDictionary <int, string>();

            mnemonics.ForEach((x, i) =>
            {
                if (tempFilter.ContainsIgnoreCase(x))
                {
                    tempDictionary.Add(i, x);
                }
            });
            mnemonicFilter           = tempFilter;
            mnemonicFilterDictionary = tempDictionary;
        }
Esempio n. 22
0
        /// <summary>
        /// Adds index data to a <see cref="ChannelDataReader"/> instance
        /// </summary>
        /// <param name="reader">The reader.</param>
        /// <param name="mnemonic">The mnemonic.</param>
        /// <param name="unit">The unit.</param>
        /// <param name="increasing">if set to <c>true</c> the data is increasing, otherwise false.</param>
        /// <param name="isTimeIndex">if set to <c>true</c> the index is time, otherwise false.</param>
        /// <returns>The <see cref="ChannelDataReader"/> instance being updated.</returns>
        public static ChannelDataReader WithIndex(this ChannelDataReader reader, string mnemonic, string unit, bool increasing, bool isTimeIndex)
        {
            _log.DebugFormat("Adding channel index to ChannelDataReader for {0}", mnemonic);

            var index = new ChannelIndexInfo()
            {
                Mnemonic    = mnemonic,
                Increasing  = increasing,
                IsTimeIndex = isTimeIndex,
                Unit        = unit
            };

            reader.Indices.Add(index);
            CalculateIndexRange(reader, index, reader.Indices.Count - 1);

            return(reader.Sort());
        }
Esempio n. 23
0
        public void ChannelDataReader_Can_Read_Depth_Log_Data()
        {
            var reader = new ChannelDataReader(DepthLogData1, new[] { "MD", "ROP", "GR", "HKLD" });
            int count  = 0;

            Assert.AreEqual(1, reader.Depth);
            Assert.AreEqual(4, reader.FieldCount);
            Assert.AreEqual(5, reader.RecordsAffected);

            while (reader.Read())
            {
                Console.WriteLine("Row {0}: {1}, {2}, {3}, {4}", count++,
                                  reader.GetDouble(0),
                                  reader.GetDouble(1),
                                  reader.GetDouble(2),
                                  reader.GetDouble(reader.GetOrdinal("HKLD")));
            }
        }
Esempio n. 24
0
        public void ChannelDataReader_Can_Read_Time_Log_Data()
        {
            var reader = new ChannelDataReader(TimeLogData);
            int count  = 0;

            Assert.AreEqual(1, reader.Depth);
            Assert.AreEqual(4, reader.FieldCount);
            Assert.AreEqual(5, reader.RecordsAffected);

            while (reader.Read())
            {
                Console.WriteLine("Row {0}: {1}, {2}, {3}, {4}", count++,
                                  reader.GetDateTimeOffset(0),
                                  reader.GetDouble(1),
                                  reader.GetDouble(2),
                                  reader.GetDouble(3));
            }
        }
        private void UpdateChannels(EtpUri uri, ChannelDataReader reader, TimeSpan?offset)
        {
            var entity = GetEntity(uri);

            Logger.DebugFormat("Updating channels for uid '{0}' and name '{1}'.", entity.Uuid, entity.Citation.Title);

            var isTimeIndex = reader.Indices.Take(1).Select(x => x.IsTimeIndex).FirstOrDefault();

            var channels = reader.Mnemonics
                           .Select((x, i) => new { Mnemonic = x, Index = i })
                           .Where(x => entity.Channel.GetByMnemonic(x.Mnemonic) == null)
                           .Select(x => CreateChannel(uri, x.Mnemonic, reader.Units[x.Index], reader.DataTypes[x.Index], isTimeIndex, entity.Index));

            var mongoUpdate  = new MongoDbUpdate <ChannelSet>(Container, GetCollection(), null);
            var headerUpdate = MongoDbUtility.BuildPushEach <ChannelSet, Channel>(null, "Channel", channels);
            var filter       = GetEntityFilter(uri);

            mongoUpdate.UpdateFields(filter, headerUpdate);
        }
Esempio n. 26
0
        /// <summary>
        /// Gets multiple readers for each LogData from a <see cref="Witsml141.Log"/> instance.
        /// </summary>
        /// <param name="log">The log.</param>
        /// <returns>An <see cref="IEnumerable{ChannelDataReader}"/>.</returns>
        public static IEnumerable <ChannelDataReader> GetReaders(this Witsml141.Log log)
        {
            if (log?.LogData == null)
            {
                yield break;
            }

            _log.DebugFormat("Creating ChannelDataReaders for {0}", log.GetType().FullName);

            var isTimeIndex = log.IsTimeLog();
            var increasing  = log.IsIncreasing();

            foreach (var logData in log.LogData)
            {
                if (logData?.Data == null || !logData.Data.Any())
                {
                    continue;
                }

                var mnemonics  = ChannelDataReader.Split(logData.MnemonicList);
                var units      = ChannelDataReader.Split(logData.UnitList);
                var dataTypes  = log.LogCurveInfo.Select(x => x.TypeLogData?.ToString()).ToArray();
                var nullValues = log.GetNullValues(mnemonics).ToArray();

                // Split index curve from other value curves
                var indexCurve = log.LogCurveInfo.GetByMnemonic(log.IndexCurve) ?? new Witsml141.ComponentSchemas.LogCurveInfo
                {
                    Mnemonic = new Witsml141.ComponentSchemas.ShortNameStruct(mnemonics.FirstOrDefault()),
                    Unit     = units.FirstOrDefault()
                };

                // Skip index curve when passing mnemonics to reader
                mnemonics  = mnemonics.Skip(1).ToArray();
                units      = units.Skip(1).ToArray();
                dataTypes  = dataTypes.Skip(1).ToArray();
                nullValues = nullValues.Skip(1).ToArray();

                yield return(new ChannelDataReader(logData.Data, mnemonics.Length + 1, mnemonics, units, dataTypes, nullValues, log.GetUri(), dataDelimiter: log.GetDataDelimiterOrDefault())
                             // Add index curve to separate collection
                             .WithIndex(indexCurve.Mnemonic.Value, indexCurve.Unit, increasing, isTimeIndex));
            }
        }
Esempio n. 27
0
        private bool UnitSpecified(List <LogCurveInfo> logCurves, LogData logData)
        {
            var mnemonics = ChannelDataReader.Split(logData.MnemonicList);
            var units     = ChannelDataReader.Split(logData.UnitList);

            for (var i = 0; i < mnemonics.Length; i++)
            {
                var mnemonic = mnemonics[i];
                var logCurve = logCurves.FirstOrDefault(l => l.Mnemonic.Value.EqualsIgnoreCase(mnemonic));

                // If there are not enough units to cover all of the mnemonics OR
                //... the LogCurve has a unit and the unit is empty the the unit is not specified.
                if (units.Length <= i || (!string.IsNullOrEmpty(logCurve?.Unit) && string.IsNullOrEmpty(units[i].Trim())))
                {
                    return(false);
                }
            }

            return(true);
        }
Esempio n. 28
0
        /// <summary>
        /// Sets the channel data.
        /// </summary>
        /// <param name="reader">The reader.</param>
        private void SetChannelData(ChannelDataReader reader)
        {
            // There's nothing to do if the reader is null.
            if (reader == null)
            {
                return;
            }

            try
            {
                // For performance, only load data grid if below the max number of allowed rows
                //if (reader.RecordsAffected > _maxChannelDataRows) return;

                reader.IncludeUnitWithName = true;

                lock (DataTable)
                {
                    DataTable.BeginLoadData();
                    DataTable.Load(reader, LoadOption.Upsert);
                    DataTable.PrimaryKey = new[] { DataTable.Columns[0] };
                    DataTable.AcceptChanges();
                    DataTable.EndLoadData();
                }

                if (DataTable.Columns.Count > 1 && _control != null)
                {
                    // Use DateTimeOffset formatting for Time logs
                    Runtime.Invoke(() =>
                                   _control.Columns[0].CellContentStringFormat =
                                       DataTable.Columns[0].DataType.IsNumeric() ? null : "{0:o}"
                                   );
                }

                NotifyOfPropertyChange(() => DataTable);
            }
            catch (Exception ex)
            {
                _log.WarnFormat("Error displaying growing object data: {0}", ex);
            }
        }
        private void UpdateChannelDataAndIndexRange(EtpUri uri, ChannelDataReader reader)
        {
            // Get Updated ChannelSet
            var current = GetEntity(uri);

            // Merge ChannelDataChunks
            if (reader != null)
            {
                var increasing   = current.IsIncreasing();
                var allMnemonics = reader.Indices.Select(i => i.Mnemonic).Concat(reader.Mnemonics).ToArray();

                // Get current index information
                var ranges = GetCurrentIndexRange(current);
                GetUpdatedLogHeaderIndexRange(reader, allMnemonics, ranges, increasing);

                // Add ChannelDataChunks
                ChannelDataChunkAdapter.Merge(reader);

                // Update index range
                UpdateIndexRange(uri, current, ranges, allMnemonics);
            }
        }
Esempio n. 30
0
        /// <summary>
        /// Gets the log data mnemonics.
        /// </summary>
        /// <param name="parser">The parser.</param>
        /// <returns></returns>
        public static IEnumerable <string> GetLogDataMnemonics(this WitsmlQueryParser parser)
        {
            _log.Debug("Getting logData mnemonics from parser.");

            var logData = parser.Property("logData");

            if (logData == null)
            {
                return(null);
            }

            var mnemonicList = parser.Properties(logData, "mnemonicList").FirstOrDefault();

            if (mnemonicList == null)
            {
                return(null);
            }

            return(string.IsNullOrWhiteSpace(mnemonicList.Value)
                ? Enumerable.Empty <string>()
                : ChannelDataReader.Split(mnemonicList.Value));
        }