Thanks for all the help everyone.
Here is what I came up with so far and I just had two follow up questions because I think I am not doing this the “right” or “clean” way
This is what is my current data transform is and it works in that bu
import system.date
pydset = system.dataset.toPyDataSet(value)
returned_rows = []
for row in pydset:
row_dict = {}
constantColumnsBeforeStyle = ["plantNumber","plantName","LocalDataTableName"]
constantColumnsMiddle = ["LastUpdated","LastRecordDateTime"]
constantColumnsAfterStyle = ["recordsPerHourAvg","LastAttemp_Status","LastUpdated_Status","LastRecordDateTime_Status"]
# Set constants first
for column in constantColumnsBeforeStyle:
row_dict[column] = {'value':row[column]}
# # Style LastAttempt
# now = system.date.now()
# if system.date.hoursBetween(row['LastAttempt'], now) > 1:
# row_dict['LastAttempt'] = {'value': row['LastAttempt'], 'style':{'classes':'TableStyles/BadRecordCount'}}
# else:
# row_dict['LastAttempt'] = {'value': row['LastAttempt']}
#
# Middle constants
for column in constantColumnsMiddle:
row_dict[column] = {'value':row[column]}
# Style Record Columns
if int(row['recordsTotal']) < 5:
row_dict['recordsTotal'] = {'value': row['recordsTotal'], 'style': {'classes':'TableStyles/BadRecordCount'}}
elif int(row['recordsTotal']) < 10:
row_dict['recordsTotal'] = {'value': row['recordsTotal'], 'style': {'classes':'TableStyles/WarningRecordCount'}}
else:
row_dict['recordsTotal'] = {'value': row['recordsTotal'], 'style': {'classes':'TableStyles/GoodRecordCount'}}
# Set constants after
for column in constantColumnsAfterStyle:
row_dict[column] = {'value':row[column]}
returned_rows.append(row_dict)
return returned_rows
Question 1 - am I handling the non styled columns wrong? Is it ok to just do them all in one go or to preserve the order of the columns in the query do I need to do it like how I currently have it?
Question 2 - Normally the recordsTotal is a progress bar -
but after my styling it becomes a normal int - how can I preserve the progress bar?
Last Question - I have a column LastAttempt that is a datetime in the database and selected directly. I wanted to make it so that if the last attempt was over an hour ago it would be styled red. However my attempt
# now = system.date.now()
# if system.date.hoursBetween(row['LastAttempt'], now) > 1:
# row_dict['LastAttempt'] = {'value': row['LastAttempt'], 'style':{'classes':'TableStyles/BadRecordCount'}}
# else:
# row_dict['LastAttempt'] = {'value': row['LastAttempt']}
just gives me a java.lang.NullPointerException
hence why its commented out but I also don’t know why it’s giving me that exception specifically.
I know there is a column called LastAttempt in the dataset which is what I thought would throw me the a NullPointException - trying to get a key from the row that doesn’t exist, but it does exist, so I’m lost as to what’s causing this.