Esempio n. 1
0
        private string CreateTestArchive(Guid sessionId)
        {
            var tmpName = Path.GetTempFileName();

            var timeData   = new[] { 1L, 2L, 3L };
            var timeColumn = new DataColumn(
                new DataField <long>("time"),
                timeData);

            var numbersData   = new[] { 42d, 1337d, 6.022e23 };
            var numbersColumn = new DataColumn(
                new DataField <double>("cool_numbers"),
                numbersData);

            var schema = new Schema(timeColumn.Field, numbersColumn.Field);

            var json = new JObject {
                ["meta"] = new JObject(), ["user"] = new JObject()
            };


            using (var ms = new MemoryStream())
            {
                using (var parquetWriter = new ParquetWriter(schema, ms))
                    using (var groupWriter = parquetWriter.CreateRowGroup())
                    {
                        groupWriter.WriteColumn(timeColumn);
                        groupWriter.WriteColumn(numbersColumn);
                    }

                ms.Position = 0;

                using (var parquetReader = new ParquetReader(ms))
                {
                    var tableInformation = new ArchiveTableInformation()
                    {
                        Columns = new List <DataField>(parquetReader.Schema.GetDataFields()),
                        Time    = timeColumn.Field
                    };
                    var table = new ArchiveTable(json, parquetReader, tableInformation, "testData");

                    var archive = Archive.Create(tmpName);

                    var session = ArchiveSession.Create(archive, "testName");
                    var folder  = ArchiveFolder.Create(archive, sessionId, "testFolder");

                    folder.AddChild(table);
                    session.AddChild(folder);
                    archive.AddSession(session);

                    archive.WriteFile().Wait();
                    archive.Close();
                }
            }

            return(tmpName);
        }
Esempio n. 2
0
        public void SaveSingleDataArchive()
        {
            Guid sessionId = Guid.NewGuid(); // Todo fake sessionId

            var tmpName = Path.GetTempFileName();

            var timeData   = new[] { 1L, 2L, 3L };
            var timeColumn = new DataColumn(
                new DataField <long>("time"),
                timeData);

            var numbersData   = new[] { 42d, 1337d, 6.022e23 };
            var numbersColumn = new DataColumn(
                new DataField <double>("cool_numbers"),
                numbersData);

            var schema = new Schema(timeColumn.Field, numbersColumn.Field);

            var json = new JObject {
                ["meta"] = new JObject(), ["user"] = new JObject()
            };


            using (var ms = new MemoryStream())
            {
                using (var parquetWriter = new ParquetWriter(schema, ms))
                    using (var groupWriter = parquetWriter.CreateRowGroup())
                    {
                        groupWriter.WriteColumn(timeColumn);
                        groupWriter.WriteColumn(numbersColumn);
                    }
                ms.Position = 0;

                using (var parquetReader = new ParquetReader(ms)) {
                    var tableInformation = new ArchiveTableInformation()
                    {
                        Columns = new List <DataField>(parquetReader.Schema.GetDataFields()),
                        Time    = timeColumn.Field
                    };
                    var table = new ArchiveTable(json, parquetReader, tableInformation, "testData");

                    var archive = Archive.Create(tmpName);

                    var session = ArchiveSession.Create(archive, "testName");
                    var folder  = ArchiveFolder.Create(archive, sessionId, "testFolder");

                    folder.AddChild(table);
                    session.AddChild(folder);
                    archive.AddSession(session);

                    try
                    {
                        archive.WriteFile().Wait();
                    }
                    catch (Exception)
                    {
                        Assert.True(false);
                    }

                    archive.Close();

                    using (var fr = new FileReader(tmpName))
                    {
                        var openTask = Archive.Open(fr);
                        openTask.Wait();
                        var newArchive = openTask.Result;
                        AssertArchivesEqual(archive, newArchive);

                        Assert.Equal("testName", session.Name);
                        Assert.Single(newArchive.Sessions.First().Children);
                        var readFolder = newArchive.Sessions.First().Children.First();
                        Assert.Equal("testFolder", readFolder.Name);
                        Assert.Single(readFolder.Children);

                        var child = readFolder.Children.First();
                        Assert.Single(child.DataPoints);

                        Assert.IsAssignableFrom <ArchiveTable>(child);
                        var tableChild = (ArchiveTable)child;

                        var dataPoint = tableChild.DataPoints.First();
                        var context   = new TimeSynchronizedContext();
                        context.AvailableTimeRangeChanged +=
                            (sender, from, to) => context.SetSelectedTimeRange(from, to);

                        var viewer = context.GetDataViewerFor(dataPoint);
                        viewer.Wait();
                        var dataViewer = viewer.Result;

                        Assert.IsAssignableFrom <ITimeSeriesViewer>(dataViewer);
                        var timeViewer = (ITimeSeriesViewer)dataViewer;

                        var data = timeViewer.GetCurrentData <double>();
                        Assert.Equal("cool_numbers", dataViewer.DataPoint.Name);

                        Assert.Equal(timeData, data.X.ToArray());
                        Assert.Equal(numbersData, data.Y.ToArray());

                        newArchive.Close();
                    }
                }
            }

            File.Delete(tmpName);
        }