示例#1
0
        private void ProcessData(DataWriterExtensionLogicBase dataWriter, DataReaderProgressRecord progressRecord, bool applyStatus)
        {
            var buffers = progressRecord.DatasetToRecordMap.Values.Select(dataRecord =>
            {
                double[] data;

                var elementType = dataRecord.Dataset.GetType().GetElementType();

                if (applyStatus || elementType != typeof(double))
                {
                    data = BufferUtilities.ApplyDatasetStatus2(dataRecord.Dataset, dataRecord.Status);
                }
                else
                {
                    data = (double[])dataRecord.Dataset;
                }

                return((IBuffer)BufferUtilities.CreateSimpleBuffer(data));
            }).ToList();

            var period = progressRecord.End - progressRecord.Begin;

            dataWriter.Write(progressRecord.Begin, period, buffers);

            // clean up
            buffers = null;
            GC.Collect();
        }
示例#2
0
        public void FamosWriterCreatesDatFile()
        {
            // Arrange
            var services = new ServiceCollection();

            ConfigureServices(services);

            var provider   = services.BuildServiceProvider();
            var dataWriter = provider.GetRequiredService <FamosWriter>();

            var projectGuid       = Guid.NewGuid();
            var dataDirectoryPath = Path.Combine(Path.GetTempPath(), projectGuid.ToString());

            Directory.CreateDirectory(dataDirectoryPath);

            var projectDescription     = new NexusProjectDescription(projectGuid, 1, "a", "b", "c");
            var customMetadataEntrySet = new List <CustomMetadataEntry>();
            var dataWriterContext      = new DataWriterContext("Nexus", dataDirectoryPath, projectDescription, customMetadataEntrySet);

            var channelDescriptionSet = new List <ChannelDescription>()
            {
                this.CreateChannelDescription("Var1", "Group1", NexusDataType.FLOAT64, new SampleRateContainer(8640000), "Unit1"),
                this.CreateChannelDescription("Var2", "Group2", NexusDataType.FLOAT64, new SampleRateContainer(8640000), "Unit2"),
                this.CreateChannelDescription("Var3", "Group1", NexusDataType.FLOAT64, new SampleRateContainer(86400), "Unit2"),
            };

            var currentDate = new DateTime(2019, 1, 1, 15, 0, 0);
            var period      = TimeSpan.FromMinutes(1);

            // Act
            dataWriter.Configure(dataWriterContext, channelDescriptionSet);

            for (int i = 0; i < 9; i++)
            {
                var buffers = channelDescriptionSet.Select(current =>
                {
                    var length = (int)current.SampleRate.SamplesPerDay / 1440;
                    var offset = length * i;
                    var data   = Enumerable.Range(offset, length).Select(value => value * 0 + (double)i + 1).ToArray();

                    return(BufferUtilities.CreateSimpleBuffer(data));
                }).ToList();

                dataWriter.Write(currentDate, period, buffers.Cast <IBuffer>().ToList());
                currentDate += period;
            }

            dataWriter.Dispose();

            // Assert
        }