History

TimeSeriesPlatformLibrary: Added initial temporal playback sample to AdvancedPublish sample.

J. Ritchie Carroll committed 7 years ago

Commit accf95a1 parent 27ec28614 files · +4474 −86Browse files

Showing the changes to Source/Libraries/TimeSeriesPlatformLibrary/Samples/GenHistory.cpp (1 of 14 files). Show all

Unified · Split

Source/Libraries/TimeSeriesPlatformLibrary/Samples/GenHistory.cpp+101−0
@@ -0,0 +1,101 @@
1//******************************************************************************************************
2// GenHistory.cpp - Gbtc
3//
4// Copyright � 2019, Grid Protection Alliance. All Rights Reserved.
5//
6// Licensed to the Grid Protection Alliance (GPA) under one or more contributor license agreements. See
7// the NOTICE file distributed with this work for additional information regarding copyright ownership.
8// The GPA licenses this file to you under the MIT License (MIT), the "License"; you may not use this
9// file except in compliance with the License. You may obtain a copy of the License at:
10//
11// http://opensource.org/licenses/MIT
12//
13// Unless agreed to in writing, the subject software distributed under the License is distributed on an
14// "AS-IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. Refer to the
15// License for the specific language governing permissions and limitations.
16//
17// Code Modification History:
18// ----------------------------------------------------------------------------------------------------
19// 03/01/2019 - Ritchie Carroll
20// Generated original version of source code.
21//
22//******************************************************************************************************
23
24#include "GenHistory.h"
25#include "../Transport/SubscriberInstance.h"
26#include <iostream>
27
28using namespace std;
29using namespace GSF;
30using namespace GSF::Data;
31using namespace GSF::TimeSeries;
32using namespace GSF::TimeSeries::Transport;
33
34GenHistory::GenHistory(uint16_t port) :
35 m_history(nullptr),
36 m_port(port)
37{
38 m_subscriber = NewSharedPtr<DataSubscriber>();
39 m_subscriber->SetUserData(this);
40}
41
42void GenHistory::StartArchive()
43{
44 m_history = NewSharedPtr<DataSet>();
45 DataTablePtr history = m_history->CreateTable("History");
46
47 history->AddColumn(history->CreateColumn("SignalID", DataType::Guid));
48 history->AddColumn(history->CreateColumn("Timestamp", DataType::Int64));
49 history->AddColumn(history->CreateColumn("Value", DataType::Double));
50
51 m_history->AddOrUpdateTable(history);
52
53 m_subscriber->RegisterNewMeasurementsCallback(&GenHistory::ProcessMeasurements);
54 m_subscriber->Connect("localhost", m_port);
55
56 SubscriptionInfo info;
57 info.FilterExpression = SubscriberInstance::SubscribeAllNoStatsExpression;
58
59 m_subscriber->Subscribe(info);
60}
61
62void GenHistory::StopArchive() const
63{
64 if (m_subscriber->IsConnected())
65 {
66 if (m_subscriber->IsSubscribed())
67 m_subscriber->Unsubscribe();
68
69 m_subscriber->Disconnect();
70
71 if (m_history)
72 {
73 cout << endl << "Client disconnected, writing history dataset..." << endl;
74 m_history->WriteXml("History.xml");
75 cout << endl << "Dataset export complete, see \"History.xml\"." << endl;
76 }
77 }
78}
79
80void GenHistory::ProcessMeasurements(DataSubscriber* source, const vector<MeasurementPtr>& measurements)
81{
82 static const GenHistory& instance = *static_cast<const GenHistory*>(source->GetUserData());
83 static DataTable& history = *instance.m_history->Table("History");
84 static const int32_t signalIDColumn = history["SignalID"]->Index();
85 static const int32_t timestampColumn = history["Timestamp"]->Index();
86 static const int32_t valueColumn = history["Value"]->Index();
87
88 for (const auto& measurement : measurements)
89 {
90 DataRowPtr row = history.CreateRow();
91
92 row->SetGuidValue(signalIDColumn, measurement->SignalID);
93 row->SetInt64Value(timestampColumn, measurement->Timestamp);
94 row->SetDoubleValue(valueColumn, measurement->Value);
95
96 history.AddRow(row);
97 }
98
99 if (history.RowCount() >= 400)
100 Thread([]{ instance.StopArchive(); });
101}

Keyboard shortcuts

General

Show keyboard shortcuts
?
Focus the current search
/

Issues and pull requests

Open filters
f

Issues, pull requests and Inbox

Select next item
j↓
Select previous item
k↑
Open selected item
Enter
Dismiss filters or clear selection
Esc

Repository code

Go to file
t