Hello,
I am developing a script to make a query in the database from the SDK module, in designer script I use system.tag.queryTagHistory to get the dataset, but I can't find the function to get the dataset from java, would there be any way to make that query? thank you
From the GatewayContext
delivered to your module's setup, you get the GatewayTagHistoryManager
. From there, issue a tag history query you constructed, and collect the results in a BasicStreamingDataset
, which implements the Dataset
interface.
I understand, while building it I have another problem, for the BasicStreamingDataset I need a StreamingDatasetWriter and I have an error to initialize it in the columType parameter.
public class BasicStreamingDataset extends AbstractDataset implements StreamingDatasetWriter
You don't need an additional class. Construct a BasicStreamingDataset
and pass it directly to queryHistory
.
Ok, to build the BasicStreamingDataset I need two lists, one of names and the other of types, the list of types is the one that is giving me error
No, you don't? It has a no-arg constructor.
I was able to perform the query, thank you very much
tagHistoryManager.queryHistory(params,dataStream);
What option could you recommend me to validate the data I am getting in dataStream?
I am trying to get historical always getting 0.0 as value data using this code:
Blockquote
public void getTagHistoryProvider() {
this.historyManager = context.getTagHistoryManager();
try {
int rangeLength = 600;
TimeUnits rangeUnits = TimeUnits.MIN;
int returnSize = 10; // -1 for all raw data
AggregationMode aggregationMode = AggregationMode.MinMax; // Assuming RAW is a valid enum
ReturnFormat returnFormat = ReturnFormat.Wide; // Adjust as needed
List<String> aliases = null; // or Arrays.asList("Alias1", "Alias2")
List<Aggregate> colAggModes = null; // or specify per tag
// 2) Build a list of the tag paths we want to query
List<Path> tagPaths = Arrays.asList(
TagPathParser.parse("[Sorba/sorba]Cluster1/INPUTS/Flow"),
TagPathParser.parse("[Sorba]Cluster1/INPUTS/Temp"),
TagPathParser.parse("[SORBA]Cluster1/INPUTS/Temp"),
TagPathParser.parse("[Sorba/sorba]Cluster1/INPUTS/Flow"),
TagPathParser.parse("[Sorba/sorba]cluster1/inputs/temp"),
TagPathParser.parse("cluster1/inputs/temp")
);
Date endDate = new Date(); // Current time
Date startDate = new Date(endDate.getTime() - 100000);
BasicTagHistoryQueryParams queryParams = new BasicTagHistoryQueryParams(
tagPaths,
startDate,
endDate,
returnSize,
aggregationMode,
returnFormat,
aliases,
colAggModes
);
StreamingDatasetWriter writer = new StreamingDatasetWriter() {
@Override
public void initialize(String[] columnNames, Class<?>[] columnTypes, boolean supportsQuality, int expectedRows) {
logger.info("Data History Column Names: " + Arrays.toString(columnNames));
logger.info("Data History Expected Rows: " + expectedRows);
}
@Override
public void write(Object[] data, QualityCode[] quality) {
logger.info("Data History: " + Arrays.toString(data));
logger.info("Data History Quality: " + Arrays.toString(quality));
}
@Override
public void finish() {
}
@Override
public void finishWithError(Exception e) {
}
};
this.historyManager.queryHistory(queryParams, writer);
} catch (Exception e) {
logger.error("Error finding historic data:", e);
}
}
Blockquote
I have used python code and I get the values as expected:
endTime = system.date.now()
startTime = system.date.addMinutes(endTime, -600)
dataSet = system.tag.queryTagHistory(
paths=['[Sorba/sorba]Cluster1/INPUTS/Flow'],
startDate=startTime,
endDate=endTime,
returnSize=10,
aggregationMode="MinMax",
returnFormat='Wide'
)
I think is not resolving the correct path in java module, any suggestion?
Please fix your code block to use "Preformatted text", not Block Quote.
Please see Wiki - how to post code on this forum.