Add 2 dataset values and put in single dataset

You should use is None instead of == None, it prevents unexpected behavior when comparing things for which the equality operator has been overridden.

It’s also faster !

The dataset is constructed with the types you want, but the actual data is still Dates. You now have to iterate through your data to cast it to the types you want to use. The DatasetBuilder class mentioned earlier in this thread would help there.
EDIT: fixed error in the constructor lines.

from com.inductiveautomation.ignition.common import DatasetBuilder
from java.lang import String, Integer, Long, Boolean, Float 

ds11 = system.tag.queryTagHistory(paths=[

"[MQTT Engine]Edge Nodes/VaujoursV5/Line/Takeoff/Takeoff_/DET/DET 1/Production Data/Deck Number"
], 
			startDate='2022-08-31 22:00:00', endDate='2022-08-31 22:00:10',returnSize=-1,  aggregationMode="MinMax", returnFormat='Wide',noInterpolation = False)

builder = DatasetBuilder.newBuilder()
builder.colNames(['date','H01'])
builder.colTypes([String, Float])

for row in system.dataset.toPyDataSet(ds11)
	builder.addRow([system.date.format(row[0], "yyyy-MM-dd HH:mm:ss"), row[1]])

data1 = builder.build()
1 Like

if i want to convert Double column type to string means what i have to do in this line?

builder.addRow([system.date.format(row[0], “yyyy-MM-dd HH:mm:ss”), row[1]])

What column is a Double?

[class java.lang.Double]

i am getting this type for one column in my dataset

For that i want to convert it to string column type

Is it the date column, or is it a value?

value column that’s why i am asking

str(row[1])

builder.addRow([str(row[1])])

like this?

You need an item for each column in the row. Assuming there is a date and a value for each row, and you want a string for each of them:

builder.addRow([system.date.format(row[0], "yyyy-MM-dd HH:mm:ss"), str(row[1])])
1 Like

one error i am getting


Traceback (most recent call last):
  File "<input>", line 22, in <module>
NameError: name 'builder' is not defined

Show your code. I can’t quite read it from here.

As a guess, I’m betting you’re missing something like:
builder = DatasetBuilder.newBuilder()

from com.inductiveautomation.ignition.common.util import DatasetBuilder
from java.lang import String, Integer, Long, Boolean, Float

ds11 = system.tag.queryTagHistory(paths=[

"[MQTT Engine]Edge Nodes/VaujoursV5/Line/Takeoff/Takeoff_/DET/DET 1/Production Data/Deck Number"
],
startDate='2022-08-31 22:00:00', endDate='2022-08-31 22:00:10',returnSize=-1, aggregationMode="MinMax", returnFormat='Wide',noInterpolation = False)

print ds11
builder = DatasetBuilder.newBuilder()
builder.colNames = ['date','H01']
builder.colTypes = [String, Float]

for row in system.dataset.toPyDataSet(ds11):
builder.addRow([system.date.format(row[0], "yyyy-MM-dd HH:mm:ss"), row[1]])

data1 = builder.build()

error
Traceback (most recent call last):
  File "<input>", line 36, in <module>
TypeError: readonly attribute

for this line i am getting **builder.colNames = [‘date’,‘H01’]**

.colNames and .colTypes are methods, not properties. You are trying to assign to them. That is incorrect. Look at Jordan’s examples again. { Edit: grumble. Didn’t expect Jordan to screw that up. }

1 Like

Whoops! Been a while since I’ve used it. Try:

builder.colNames(['date','H01'])
builder.colTypes([String, Float])
1 Like

That one really was on me. :roll_eyes:

EDIT: fixed code above.

2 Likes

getting error for this line when i try to convert double to string
builder.addRow([system.date.format(row[0], "yyyy-MM-dd HH:mm:ss"), str(row[1])])

 File "<event:mouseClicked>", line 38, in <module>
TypeError: format(): 1st arg can't be coerced to java.util.Date

	at org.python.core.Py.TypeError(Py.java:236)
	at org.python.core.PyReflectedFunction.throwError(PyReflectedFunction.java:213)
	at org.python.core.PyReflectedFunction.throwBadArgError(PyReflectedFunction.java:316)
	at org.python.core.PyReflectedFunction.throwError(PyReflectedFunction.java:325)
	at org.python.core.PyReflectedFunction.__call__(PyReflectedFunction.java:171)
	at org.python.core.PyReflectedFunction.__call__(PyReflectedFunction.java:208)
	at org.python.core.PyObject.__call__(PyObject.java:477)
	at org.python.core.PyObject.__call__(PyObject.java:481)
	at org.python.pycode._pyx530.f$0(<event:mouseClicked>:48)
	at org.python.pycode._pyx530.call_function(<event:mouseClicked>)
	at org.python.core.PyTableCode.call(PyTableCode.java:173)
	at org.python.core.PyCode.call(PyCode.java:18)
	at org.python.core.Py.runCode(Py.java:1687)
	at com.inductiveautomation.ignition.common.script.ScriptManager.runCode(ScriptManager.java:788)
	at com.inductiveautomation.factorypmi.application.binding.action.ActionAdapter.runActions(ActionAdapter.java:206)
	at com.inductiveautomation.factorypmi.application.binding.action.ActionAdapter.invoke(ActionAdapter.java:299)
	at com.inductiveautomation.factorypmi.application.binding.action.RelayInvocationHandler.invoke(RelayInvocationHandler.java:57)
	at com.sun.proxy.$Proxy55.mouseClicked(Unknown Source)
	at java.desktop/java.awt.AWTEventMulticaster.mouseClicked(Unknown Source)
	at java.desktop/java.awt.Component.processMouseEvent(Unknown Source)
	at java.desktop/javax.swing.JComponent.processMouseEvent(Unknown Source)
	at java.desktop/java.awt.Component.processEvent(Unknown Source)
	at java.desktop/java.awt.Container.processEvent(Unknown Source)
	at java.desktop/java.awt.Component.dispatchEventImpl(Unknown Source)
	at java.desktop/java.awt.Container.dispatchEventImpl(Unknown Source)
	at java.desktop/java.awt.Component.dispatchEvent(Unknown Source)
	at java.desktop/java.awt.LightweightDispatcher.retargetMouseEvent(Unknown Source)
	at java.desktop/java.awt.LightweightDispatcher.processMouseEvent(Unknown Source)
	at java.desktop/java.awt.LightweightDispatcher.dispatchEvent(Unknown Source)
	at java.desktop/java.awt.Container.dispatchEventImpl(Unknown Source)
	at java.desktop/java.awt.Window.dispatchEventImpl(Unknown Source)
	at java.desktop/java.awt.Component.dispatchEvent(Unknown Source)
	at java.desktop/java.awt.EventQueue.dispatchEventImpl(Unknown Source)
	at java.desktop/java.awt.EventQueue$4.run(Unknown Source)
	at java.desktop/java.awt.EventQueue$4.run(Unknown Source)
	at java.base/java.security.AccessController.doPrivileged(Native Method)
	at java.base/java.security.ProtectionDomain$JavaSecurityAccessImpl.doIntersectionPrivilege(Unknown Source)
	at java.base/java.security.ProtectionDomain$JavaSecurityAccessImpl.doIntersectionPrivilege(Unknown Source)
	at java.desktop/java.awt.EventQueue$5.run(Unknown Source)
	at java.desktop/java.awt.EventQueue$5.run(Unknown Source)
	at java.base/java.security.AccessController.doPrivileged(Native Method)
	at java.base/java.security.ProtectionDomain$JavaSecurityAccessImpl.doIntersectionPrivilege(Unknown Source)
	at java.desktop/java.awt.EventQueue.dispatchEvent(Unknown Source)
	at java.desktop/java.awt.EventDispatchThread.pumpOneEventForFilters(Unknown Source)
	at java.desktop/java.awt.EventDispatchThread.pumpEventsForFilter(Unknown Source)
	at java.desktop/java.awt.EventDispatchThread.pumpEventsForHierarchy(Unknown Source)
	at java.desktop/java.awt.EventDispatchThread.pumpEvents(Unknown Source)
	at java.desktop/java.awt.EventDispatchThread.pumpEvents(Unknown Source)
	at java.desktop/java.awt.EventDispatchThread.run(Unknown Source)
Caused by: org.python.core.PyException: TypeError: format(): 1st arg can't be coerced to java.util.Date
	... 49 common frames omitted
17:31:32.375 [EDT-Watchdog-1] INFO edt-watchdog - Non-responsive UI thread detected. Stack saved at 'C:\Users\P5178201\.ignition\cache\gwmetriks-eur001.saint-gobain.com_443\C0\NonResponsiveEdt-2022-09-01_173130.json'
17:32:30.307 [EDT-Watchdog-1] INFO edt-watchdog - Non-responsive UI thread detected. Stack saved at 'C:\Users\P5178201\.ignition\cache\gwmetriks-eur001.saint-gobain.com_443\C0\NonResponsiveEdt-2022-09-01_173230.json'

type i am getting
[class java.lang.Double, class java.lang.Double, class java.lang.Double, class java.lang.Double, class java.lang.Double, class java.lang.Double, class java.lang.Double, class java.lang.Double, class java.lang.Double, class java.lang.Double, class java.lang.Double, class java.lang.Double, class java.lang.Double, class java.lang.Double, class java.lang.Double, class java.lang.Double, class java.lang.Double, class java.lang.Double, class java.lang.Double, class java.lang.Double, class java.lang.Double, class java.lang.Double, class java.lang.Double, class java.lang.Double, class java.lang.Double, class java.lang.Double, class java.lang.Double, class java.lang.Double, class java.lang.Double, class java.lang.Double, class java.lang.Double, class java.lang.Double, class java.lang.Double, class java.lang.Double, class java.lang.Double, class java.lang.Double, class java.lang.Double]

my code

builder = DatasetBuilder.newBuilder()
builder.colNames(["Deck_no", "H01", "H02", "H03", "H04", "H05", "H06", "H07", "H08", "H09", "H10", "H11", "H12", "H13", "H14", "H15", "H16", "H17","H18", "H19", "H20",
"H21", "H22", "H23", "H24", "H25", "H26", "H27", "H28", "H29", "H30", "H31", "H32", "H33", "H34", "H35", "H36"])
builder.colTypes([String, Integer, Integer, Integer, Integer, Integer, Integer, Integer,Integer, Integer, Integer, Integer, Integer, Integer, Integer, Integer, Integer, Integer,Integer, Integer, Integer,
Integer, Integer, Integer, Integer, Integer, Integer, Integer,Integer, Integer, Integer,Integer, Integer, Integer, Integer, Integer, Integer, Integer])

for row in system.dataset.toPyDataSet(filteredData):
	builder.addRow([system.date.format(row[0], "yyyy-MM-dd HH:mm:ss"), str(row[1])])

data1 = builder.build()
event.source.parent.getComponent('Power Table').data = data1

Gotcha. Is Deck_no the timestamp, then? And then everything else is okay?

no its not time stamp

type is
[class java.lang.Double, class java.lang.Double, class java.lang.Double, class java.lang.Double, class java.lang.Double, class java.lang.Double, class java.lang.Double, class java.lang.Double, class java.lang.Double, class java.lang.Double, class java.lang.Double, class java.lang.Double, class java.lang.Double, class java.lang.Double, class java.lang.Double, class java.lang.Double, class java.lang.Double, class java.lang.Double, class java.lang.Double, class java.lang.Double, class java.lang.Double, class java.lang.Double, class java.lang.Double, class java.lang.Double, class java.lang.Double, class java.lang.Double, class java.lang.Double, class java.lang.Double, class java.lang.Double, class java.lang.Double, class java.lang.Double, class java.lang.Double, class java.lang.Double, class java.lang.Double, class java.lang.Double, class java.lang.Double, class java.lang.Double]

double only for all columns

All right. I think we need to back up a moment, as we started out with a date a few posts ago, and now we’re not.

Does filteredData have the same columns as what will be shown in the power table? If not, what are the differences?