I have a dataset that has the history from a few tags in it. Each tag has its own colomn. But the tags save histroy at different times (for example : tag1 : each 15m
tag2 : each 5 m) You get what I mean. This results in a few empty cells in the beginning of the tag history. Can anyone explain how I can script it to search for the first row with all values there? I have been looking and trying for a long time now.
To avoid this scrambling of data at multiple timestamps, always use "tall" format when retrieving "as stored" data..
If for whatever reason you can not change to using a tall format instead of a wide, this function will return the t_stamp column of the first row that has a value other than None (or 0 which may or may not be an issue but can be fixed if needed).
def getFirstFullRow(dataset):
ds = system.dataset.toPyDataSet(dataset)
for row in ds:
col = 1
while row[col]:
col += 1
if col == ds.columnCount:
return row[0]
I'll suggest another version that I believe is easier to understand:
def get_first_full_row(ds):
ds = system.dataset.toPyDataSet(ds)
return next(
(row for row in ds if all(c is not None for c in row)),
None
)
ffr = get_first_full_row(ds)
tstamp = ffr[0] if ffr is not None else 0
edit: wait, this doesn't actually check for nulls, but for "falsy" values.
Gimme a sec to fix it
edit2: updated
Neither does mine
