private ChannelIndex CreateChannelIndex(ChannelIndexInfo indexInfo) { return(new ChannelIndex { Mnemonic = indexInfo.Mnemonic, Uom = Units.GetUnitOfMeasure(indexInfo.Unit), IndexType = indexInfo.IsTimeIndex ? ChannelIndexType.datetime : ChannelIndexType.measureddepth, Direction = indexInfo.Increasing ? IndexDirection.increasing : IndexDirection.decreasing, DatumReference = "MSL" }); }
/// <summary> /// Creates a logCurveInfo for the specified log curve information. /// </summary> /// <param name="indexInfo">The index information.</param> /// <returns></returns> protected override LogCurveInfo CreateLogCurveInfo(ChannelIndexInfo indexInfo) { var indexDataType = indexInfo.IsTimeIndex ? LogDataType.datetime.ToString() : [email protected](); return(CreateLogCurveInfo(indexInfo.Mnemonic, indexInfo.Unit, indexDataType, indexInfo.IsTimeIndex, 0)); }
/// <summary> /// Gets the direction for the specified index information. /// </summary> /// <param name="indexInfo">The index information.</param> /// <returns></returns> protected override object GetDirection(ChannelIndexInfo indexInfo) { return(indexInfo.Increasing ? LogIndexDirection.increasing : LogIndexDirection.decreasing); }
/// <summary> /// Gets the index curve for the specified index information. /// </summary> /// <param name="indexInfo">The index information.</param> /// <returns></returns> protected override object GetIndexCurve(ChannelIndexInfo indexInfo) { return(indexInfo.Mnemonic); }
/// <summary> /// Gets the index type for the specified index information. /// </summary> /// <param name="indexInfo">The index information.</param> /// <returns></returns> protected override object GetIndexType(ChannelIndexInfo indexInfo) { return(indexInfo.IsTimeIndex ? LogIndexType.datetime : LogIndexType.measureddepth); }
/// <summary> /// Combines <see cref="IEnumerable{IChannelDataRecord}"/> data into RangeSize chunks for storage into the database /// </summary> /// <param name="records">The <see cref="IEnumerable{ChannelDataChunk}"/> records to be chunked.</param> /// <returns>An <see cref="IEnumerable{ChannelDataChunk}"/> of channel data.</returns> private IEnumerable <ChannelDataChunk> ToChunks(IEnumerable <IChannelDataRecord> records) { Logger.Debug("Converting ChannelDataRecords to ChannelDataChunks."); var data = new List <string>(); var id = string.Empty; List <ChannelIndexInfo> indexes = null; ChannelIndexInfo indexChannel = null; Range <long>? plannedRange = null; double startIndex = 0; double endIndex = 0; double?previousIndex = null; string[] chunkMnemonics = null; string[] chunkUnits = null; string[] chunkNullValues = null; var chunkSettingsSet = false; foreach (var record in records) { indexChannel = record.GetIndex(); indexes = record.Indices.Select(x => x.Clone()).ToList(); var increasing = indexChannel.Increasing; var index = record.GetIndexValue(); var rangeSize = WitsmlSettings.GetRangeSize(indexChannel.IsTimeIndex); if (previousIndex.HasValue) { if (previousIndex.Value == index) { Logger.ErrorFormat("Data node index repeated for uri: {0}; channel {1}; index: {2}", record.Uri, indexChannel.Mnemonic, index); throw new WitsmlException(ErrorCodes.NodesWithSameIndex); } if (increasing && previousIndex.Value > index || !increasing && previousIndex.Value < index) { var error = $"Data node index not in sequence for uri: {record.Uri}: channel: {indexChannel.Mnemonic}; index: {index}"; Logger.Error(error); throw new InvalidOperationException(error); } } previousIndex = index; if (!plannedRange.HasValue) { plannedRange = Range.ComputeRange(index, rangeSize, increasing); id = record.Id; startIndex = index; } // TODO: Can we use this instead? plannedRange.Value.Contains(index, increasing) or a new method? if (WithinRange(index, plannedRange.Value.End, increasing, false)) { id = string.IsNullOrEmpty(id) ? record.Id : id; data.Add(record.GetJson()); endIndex = index; if (chunkSettingsSet) { continue; } chunkMnemonics = record.Mnemonics; chunkUnits = record.Units; chunkNullValues = record.NullValues; chunkSettingsSet = true; } else { //var newIndex = indexChannel.Clone(); //newIndex.Start = startIndex; //newIndex.End = endIndex; indexes[0].Start = startIndex; indexes[0].End = endIndex; Logger.DebugFormat("ChannelDataChunk created with id '{0}', startIndex '{1}' and endIndex '{2}'.", id, startIndex, endIndex); yield return(new ChannelDataChunk() { Uid = id, Data = "[" + String.Join(",", data) + "]", //Indices = new List<ChannelIndexInfo> { newIndex }, Indices = indexes, RecordCount = data.Count, MnemonicList = string.Join(",", chunkMnemonics), UnitList = string.Join(",", chunkUnits), NullValueList = string.Join(",", chunkNullValues) }); plannedRange = Range.ComputeRange(index, rangeSize, increasing); data = new List <string>() { record.GetJson() }; startIndex = index; endIndex = index; id = record.Id; chunkMnemonics = record.Mnemonics; chunkUnits = record.Units; chunkNullValues = record.NullValues; } } if (data.Count > 0 && indexes != null) { //var newIndex = indexChannel.Clone(); //newIndex.Start = startIndex; //newIndex.End = endIndex; indexes = indexes.Select(x => x.Clone()).ToList(); indexes[0].Start = startIndex; indexes[0].End = endIndex; Logger.DebugFormat("ChannelDataChunk created with id '{0}', startIndex '{1}' and endIndex '{2}'.", id, startIndex, endIndex); var chunk = new ChannelDataChunk() { Uid = id, Data = "[" + string.Join(",", data) + "]", //Indices = new List<ChannelIndexInfo> { newIndex }, Indices = indexes, RecordCount = data.Count }; if (chunkMnemonics != null) { chunk.MnemonicList = string.Join(",", chunkMnemonics); chunk.UnitList = string.Join(",", chunkUnits); chunk.NullValueList = string.Join(",", chunkNullValues); } yield return(chunk); } }