import sys
from LOGS import LOGS
from LOGS.Entities import TrackXY
# Get datasetId from command line argument
if len(sys.argv) < 2:
raise Exception("Dataset ID not specified")
datasetId = int(sys.argv[1])
# Connect to LOGS
logs = LOGS()
# Retrive a dataset by its LOGS-id
dataset = logs.dataset(datasetId)
# To simplify API responses, the LOGS REST API uses resource expansion. This means that the API will
# only return parts of the resource if not explicitly requested for the full entity. This helps to
# avoid large entity responses when requesting many entities and makes your requests more efficient.
#
# This normally concernes parts of an entity that are not ofter used or specifically large. E.g. in
# this this example the dataset tracks and parameters that can be potentially very large.
dataset.fetchFull()
if not dataset.tracks:
raise Exception("This dataset has no tracks")
print("Dataset %a tracks:" % dataset.name)
# Iterate trough all tracks of this dataset
for i, track in enumerate(dataset.tracks):
print("Track %d %a of type %a:" % (i, track.name, track.type))
# Each track of a dataset can be assembled form of datastreams, called datatracks, dependent on the format.
if not track.datatracks:
continue
# E.g. a track of type 'TrackXY' (x-values plotted against y-values) contains two numeric array datatracks
if isinstance(track, TrackXY):
# In order to fetch the actual data point of this track we use the above mentioned resource expansion again
track.datatracks.fetchFull()
if (
track.datatracks.x
and track.datatracks.x.data is not None
and track.datatracks.y
and track.datatracks.y.data is not None
):
# We plot the first 10 values of each x and y datatrack
print(
" x: %s ..."
% ", ".join(["%.3f" % x for x in track.datatracks.x.data[:10]])
)
print(
" y: %s ..."
% ", ".join(["%.3f" % y for y in track.datatracks.y.data[:10]])
)