Contains the options to use for executing an individual read request.
 public IDictionary<Guid, SignalDataBase> GetQueryResult(DateTime startTime, DateTime endTime, int zoomLevel, IEnumerable<ISignalCalculation> signals)
 {
     using (var db = m_historian.GetDatabase<HistorianKey, HistorianValue>("PPA"))
     {
         //var db = m_historian.ConnectToDatabase("Full Resolution Synchrophasor");
         PeriodicScanner scanner = new PeriodicScanner(m_samplesPerSecond);
         var timestamps = scanner.GetParser(startTime, endTime, 1500u);
         SortedTreeEngineReaderOptions options = new SortedTreeEngineReaderOptions(TimeSpan.FromSeconds(1));
         var results = db.GetSignalsWithCalculations(timestamps, signals, options);
         return results;
     }
 }
        public static IDictionary<Guid, SignalDataBase> GetSignalsWithCalculations(this ClientDatabaseBase<HistorianKey, HistorianValue> database, SeekFilterBase<HistorianKey> timestamps, IEnumerable<ISignalCalculation> signals, SortedTreeEngineReaderOptions readerOptions)
        {
            Dictionary<ulong, SignalDataBase> queryResults = database.GetSignals(timestamps, signals, readerOptions);

            Dictionary<Guid, SignalDataBase> calculatedResults = new Dictionary<Guid, SignalDataBase>();
            foreach (ISignalCalculation signal in signals)
            {
                if (signal.HistorianId.HasValue)
                {
                    calculatedResults.Add(signal.SignalId, queryResults[signal.HistorianId.Value]);
                }
                else
                {
                    calculatedResults.Add(signal.SignalId, new SignalData(signal.Functions));
                }
            }

            foreach (ISignalCalculation signal in signals)
            {
                signal.Calculate(calculatedResults);
            }
            return calculatedResults;
        }
Example #3
0
        public SequentialReaderStream(ArchiveList <TKey, TValue> archiveList,
                                      SortedTreeEngineReaderOptions readerOptions             = null,
                                      SeekFilterBase <TKey> keySeekFilter                     = null,
                                      MatchFilterBase <TKey, TValue> keyMatchFilter           = null,
                                      WorkerThreadSynchronization workerThreadSynchronization = null)
        {
            if (readerOptions is null)
            {
                readerOptions = SortedTreeEngineReaderOptions.Default;
            }
            if (keySeekFilter is null)
            {
                keySeekFilter = new SeekFilterUniverse <TKey>();
            }
            if (keyMatchFilter is null)
            {
                keyMatchFilter = new MatchFilterUniverse <TKey, TValue>();
            }
            if (workerThreadSynchronization is null)
            {
                m_ownsWorkerThreadSynchronization = true;
                workerThreadSynchronization       = new WorkerThreadSynchronization();
            }

            m_workerThreadSynchronization = workerThreadSynchronization;
            m_pointCount         = 0;
            m_keySeekFilter      = keySeekFilter;
            m_keyMatchFilter     = keyMatchFilter;
            m_keyMatchIsUniverse = m_keyMatchFilter as MatchFilterUniverse <TKey, TValue> != null;

            if (readerOptions.Timeout.Ticks > 0)
            {
                m_timeout = new TimeoutOperation();
                m_timeout.RegisterTimeout(readerOptions.Timeout, () => m_timedOut = true);
            }

            m_snapshot = archiveList.CreateNewClientResources();
            m_snapshot.UpdateSnapshot();
            m_tablesOrigList = new List <BufferedArchiveStream <TKey, TValue> >();

            for (int x = 0; x < m_snapshot.Tables.Count(); x++)
            {
                ArchiveTableSummary <TKey, TValue> table = m_snapshot.Tables[x];
                if (table != null)
                {
                    if (table.Contains(keySeekFilter.StartOfRange, keySeekFilter.EndOfRange))
                    {
                        try
                        {
                            m_tablesOrigList.Add(new BufferedArchiveStream <TKey, TValue>(x, table));
                        }
                        catch (Exception e)
                        {
                            //ToDo: Make sure firstkey.tostring doesn't ever throw an exception.
                            StringBuilder sb = new StringBuilder();
                            sb.AppendLine($"Archive ID {table.FileId}");
                            sb.AppendLine($"First Key {table.FirstKey.ToString()}");
                            sb.AppendLine($"Last Key {table.LastKey.ToString()}");
                            sb.AppendLine($"File Size {table.SortedTreeTable.BaseFile.ArchiveSize}");
                            sb.AppendLine($"File Name {table.SortedTreeTable.BaseFile.FilePath}");
                            Log.Publish(MessageLevel.Error, "Error while reading file", sb.ToString(), null, e);
                        }
                    }
                    else
                    {
                        m_snapshot.Tables[x] = null;
                    }
                }
            }

            m_sortedArchiveStreams = new CustomSortHelper <BufferedArchiveStream <TKey, TValue> >(m_tablesOrigList, IsLessThan);

            m_keySeekFilter.Reset();
            if (m_keySeekFilter.NextWindow())
            {
                SeekToKey(m_keySeekFilter.StartOfFrame);
            }
            else
            {
                Dispose();
            }
        }
 static SortedTreeEngineReaderOptions()
 {
     Default = new SortedTreeEngineReaderOptions();
 }
Example #5
0
 static SortedTreeEngineReaderOptions()
 {
     Default = new SortedTreeEngineReaderOptions();
 }
 /// <summary>
 /// Gets frames from the historian as individual frames.
 /// </summary>
 /// <param name="database">the database to use</param>
 /// <param name="timestamps">the timestamps to query for</param>
 /// <param name="points">the points to query</param>
 /// <param name="options">A list of query options</param>
 /// <returns></returns>
 public static SortedList<DateTime, FrameData> GetFrames(this IDatabaseReader<HistorianKey, HistorianValue> database,
     SortedTreeEngineReaderOptions options, SeekFilterBase<HistorianKey> timestamps, MatchFilterBase<HistorianKey,HistorianValue> points)
 {
     return database.Read(options, timestamps, points).GetFrames();
 }
Example #7
0
        public SequentialReaderStream(ArchiveList <TKey, TValue> archiveList,
                                      SortedTreeEngineReaderOptions readerOptions             = null,
                                      SeekFilterBase <TKey> keySeekFilter                     = null,
                                      MatchFilterBase <TKey, TValue> keyMatchFilter           = null,
                                      WorkerThreadSynchronization workerThreadSynchronization = null)
        {
            if (readerOptions == null)
            {
                readerOptions = SortedTreeEngineReaderOptions.Default;
            }
            if (keySeekFilter == null)
            {
                keySeekFilter = new SeekFilterUniverse <TKey>();
            }
            if (keyMatchFilter == null)
            {
                keyMatchFilter = new MatchFilterUniverse <TKey, TValue>();
            }
            if (workerThreadSynchronization == null)
            {
                m_ownsWorkerThreadSynchronization = true;
                workerThreadSynchronization       = new WorkerThreadSynchronization();
            }

            m_workerThreadSynchronization = workerThreadSynchronization;
            m_pointCount         = 0;
            m_keySeekFilter      = keySeekFilter;
            m_keyMatchFilter     = keyMatchFilter;
            m_keyMatchIsUniverse = (m_keyMatchFilter as MatchFilterUniverse <TKey, TValue>) != null;

            if (readerOptions.Timeout.Ticks > 0)
            {
                m_timeout = new TimeoutOperation();
                m_timeout.RegisterTimeout(readerOptions.Timeout, () => m_timedOut = true);
            }

            m_snapshot = archiveList.CreateNewClientResources();
            m_snapshot.UpdateSnapshot();
            m_tablesOrigList = new List <BufferedArchiveStream <TKey, TValue> >();

            for (int x = 0; x < m_snapshot.Tables.Count(); x++)
            {
                ArchiveTableSummary <TKey, TValue> table = m_snapshot.Tables[x];
                if (table != null)
                {
                    if (table.Contains(keySeekFilter.StartOfRange, keySeekFilter.EndOfRange))
                    {
                        m_tablesOrigList.Add(new BufferedArchiveStream <TKey, TValue>(x, table));
                    }
                    else
                    {
                        m_snapshot.Tables[x] = null;
                    }
                }
            }

            m_sortedArchiveStreams = new CustomSortHelper <BufferedArchiveStream <TKey, TValue> >(m_tablesOrigList, IsLessThan);

            m_keySeekFilter.Reset();
            if (m_keySeekFilter.NextWindow())
            {
                SeekToKey(m_keySeekFilter.StartOfFrame);
            }
            else
            {
                Dispose();
            }
        }