The following code
annotations = system.historian.queryAnnotations(
paths=paths,
startDate=system.date.addHours(system.date.now(), -1),
endDate=system.date.now()
)
for anno in annotations.getResults():
# HOW TO READ THE INFORMATION?
logger.info(str(anno['source']))
logger.info(str(anno.source))
logger.info(str(anno.source()))
gives the error
TypeError: 'com.inductiveautomation.historian.common.model.data.AnnotationPoint' object is unsubscriptable
I would like to display the following information for each annotation:
- path
- start time
- end time
- type
- data
How can I do?
Each element in annotations.getResults() will be an instance of AnnotationPoint.
This is a Java record, so you must extract values from it with named accessor functions; so to pull out the Annotation sub-record you use the value() method, which returns an Annotation record which has three components, author, notes, and type.
So reworking your snippet, something like this should work to retrieve the innermost values off the annotation:
for point in annotations.results:
anno = point.value()
notes = anno.notes()
author = anno.author()
type = anno.type()
And the base anno instance will have a start time, end time, source, etc methods you can call, though they will return rich Java types that might require more coercion than you expect.