Problem whith dataset using queryStatus function

I'am working with alarms satus. I don't whant use Alarm status Component.
I
I'am using a system.alarm.queryStatus to get dataset of alarm and I put it on a power table.

This the function that I created:

def queryStatus():
	 
	from collections import defaultdict
	from com.inductiveautomation.ignition.common.alarming.config import CommonAlarmProperties
	
	results = system.alarm.queryStatus(source = "*Sensor*",provider = "fonctionnalites")
	ds = results.getDataset() # gets the same columns that the function binding returns
	data = defaultdict(list)
	data_ackTime = defaultdict(list)
	for alarmEvent in range ( len(results)):

		data["Name"].append(results[alarmEvent].get(CommonAlarmProperties.Name))
		data["Notes"].append(results[alarmEvent].get(CommonAlarmProperties.Notes))
		data["Ack Notes"].append(results[alarmEvent].get(CommonAlarmProperties.AckNotes))
		data["Label"].append(results[alarmEvent].get(CommonAlarmProperties.Label))
		data["Ack User"].append(str(results[alarmEvent].get(CommonAlarmProperties.AckUser)))
	
		#MM/DD/YYYY HH:mm:ss
		AckTime = results[alarmEvent].get(CommonAlarmProperties.AckTime)
		if AckTime == None:
			data_ackTime["ACK TIME"].append(system.date.parse("Mon Apr 00 00:00:00 UTC 0000","E MMM dd HH:mm:ss Z yyyy"))
		else:
			data_ackTime["ACK TIME"].append(AckTime)
	#return data
	for column, values in data.items():
		ds1 = system.dataset.addColumn(ds, ds.columnCount, values, column, basestring)
	#return ds1	      
	
	for column, values in data_ackTime.items():
		ds2 = system.dataset.addColumn(ds1, ds1.columnCount, values, column, Date)
	return ds2

The problem is, when a return ds1 it work.

but if I return ds2 I'am getting error

Someone can explain me why I can't return ds2 ?

def queryStatus():
    from collections import defaultdict
    from com.inductiveautomation.ignition.common.alarming.config import CommonAlarmProperties
    from java.util import Date
    from java.lang import String

    results = system.alarm.queryStatus(source="*Sensor*", provider="fonctionnalites")
    ds = results.getDataset()  # gets the same columns that the function binding returns

    data = defaultdict(list)
    data_ackTime = defaultdict(list)

    for alarmEvent in range(len(results)):
        data["Name"].append(results[alarmEvent].get(CommonAlarmProperties.Name))
        data["Notes"].append(results[alarmEvent].get(CommonAlarmProperties.Notes))
        data["Ack Notes"].append(results[alarmEvent].get(CommonAlarmProperties.AckNotes))
        data["Label"].append(results[alarmEvent].get(CommonAlarmProperties.Label))
        data["Ack User"].append(str(results[alarmEvent].get(CommonAlarmProperties.AckUser)))

     
        AckTime = results[alarmEvent].get(CommonAlarmProperties.AckTime)
        if AckTime is None:
            defaultDate = Date(0)  # Epoch time
            data_ackTime["ACK TIME"].append(defaultDate)
        else:
            data_ackTime["ACK TIME"].append(AckTime)

  
    for column, values in data.items():
        ds = system.dataset.addColumn(ds, ds.columnCount, values, column, String)

 
    for column, values in data_ackTime.items():
        ds = system.dataset.addColumn(ds, ds.columnCount, values, column, Date)

    return ds

using just one ds

You are my saviour @Alejandro_Alaco :sweat_smile:

1 Like

defaut date is 1970-1-1 1:00:00
it is possible to set it 0000-0-0 0:00:00 ?

Thats the age of Christ.

The default date 1970-01-01 00:00:00 is known as the Unix epoch time, which is the starting point for many computer-based time systems. However, it's not possible to set a date as 0000-00-00 because it's not valid according to standard date conventions.

A solution may be:

from collections import defaultdict
from com.inductiveautomation.ignition.common.alarming.config import CommonAlarmProperties
from java.util import Date
from java.lang import String

custom_sentinel_date = Date(0)  # Epoch time is 1970-01-01 00:00:00

def queryStatus():
    results = system.alarm.queryStatus(source="*Sensor*", provider="fonctionnalites")
    ds = results.getDataset()

    data = defaultdict(list)
    data_ackTime = defaultdict(list)

    for alarmEvent in range(len(results)):
        data["Name"].append(results[alarmEvent].get(CommonAlarmProperties.Name))
        data["Notes"].append(results[alarmEvent].get(CommonAlarmProperties.Notes))
        data["Ack Notes"].append(results[alarmEvent].get(CommonAlarmProperties.AckNotes))
        data["Label"].append(results[alarmEvent].get(CommonAlarmProperties.Label))
        data["Ack User"].append(str(results[alarmEvent].get(CommonAlarmProperties.AckUser)))

   
        AckTime = results[alarmEvent].get(CommonAlarmProperties.AckTime)
        if AckTime is None:
            data_ackTime["ACK TIME"].append(custom_sentinel_date)
        else:
            data_ackTime["ACK TIME"].append(AckTime)

 
    for column, values in data.items():
        ds = system.dataset.addColumn(ds, ds.columnCount, values, column, String)

    # Add the ACK TIME column
    for column, values in data_ackTime.items():
        ds = system.dataset.addColumn(ds, ds.columnCount, values, column, Date)

    return ds

By using a sentinel value like Date(0), you can consistently detect it and handle the scenario differently where necessary.

thank you @Alejandro_Alaco

1 Like