no way to caste the integer to string and append it?
is the original dataset1 in type string? you want int types instead of number types tho right?
actually i am getting first row as string type for few query i am running
second row few column i am getting integer type values
soo i want to cast the second or first row… key thing is i want to append that’s it both the rows
else give me idea to append the rows
the easiest way to fix this seems to initialize the dataset with the correct rowtypes and then delete that row immediatly
provide me with your full script so i can tell you where to do it
# Set allowed types --java.lang class names--
allowedTypes = ['Long', 'Integer', 'Double', 'Float']
# Get column names
colNames = list(data.getColumnNames())
dataOut = []
for colNum in range(data.getColumnCount()):
# print colNum, colNames[colNum], data.getColumnType(colNum).__name__
# Check that the column is one that should be summed
if data.getColumnType(colNum).__name__ in allowedTypes:
# Get column values
colValues = data.getColumnAsList(colNum)
#Use None if all values in the list are None
if all(value is None for value in colValues):
dataOut.append(None)
else:
# Sum the values and add to the row. filter() lets us ignore None
dataOut.append(sum(filter(None, colValues)))
else:
dataOut.append(data.getValueAt(0, colNum))
datasetOut = system.dataset.toDataSet(colNames, [dataOut])
data1 = system.dataset.appendDataset(data1, datasetOut)
phew xD a lot of string and prints but 260 lines xd
sorry i didn’t understand what you are saying
every column expect the first one is number right?
yes
line 216(?) +/-
datasetOut = system.dataset.toDataSet(colNames, [dataOut])
i guess you can do this… its really not ideal but i cant get my head around this many lines of code xd
you should kinda work on that xd
datasetOut = system.dataset.toDataSet(colNames, [[system.date.now()]+[1]*(len(colNames)-1)])
datasetOut = system.dataset.deleteRow(datasetOut,0)
datasetOut = system.dataset.addRow(datasetOut, dataOut)
last row might be, but i think not
datasetOut = system.dataset.addRow(datasetOut, [dataOut])
it creates the dateset with the header of colNames, and assignes the values with the right typ to then delete them again xd
i will try now
Traceback (most recent call last):
File "<event:mouseReleased>", line 354, in <module>
java.lang.ClassCastException: java.lang.ClassCastException: class org.python.core.PyObjectDerived cannot be cast to class org.python.core.PySequence (org.python.core.PyObjectDerived and org.python.core.PySequence are in unnamed module of loader java.net.URLClassLoader @1bfc7b0)
caused by ClassCastException: class org.python.core.PyObjectDerived cannot be cast to class org.python.core.PySequence (org.python.core.PyObjectDerived and org.python.core.PySequence are in unnamed module of loader java.net.URLClassLoader @1bfc7b0)
Ignition v8.1.7 (b2021060314)
Java: Azul Systems, Inc. 11.0.11
getting this error for this line datasetOut = system.dataset.toDataSet(colNames, [system.date.now()]+[1]*(len(colNames)-1))
ah right forgot brackets
datasetOut = system.dataset.toDataSet(colNames, [[system.date.now()]+[1]*(len(colNames)-1)])
Try constructing an empty dataset with the column type preconfigured.
from com.inductiveautomation.ignition.common import BasicDataset
from java.lang import String, Integer, Long, Boolean, Float
columnNames = [u'date', u'gasnm3', u'electricitykwh', u'gaskwh', u'productionm2', u'eleckwhm2', u'gaskwhm2', u'epikwhm2']
columnTypes = [String, Integer, Integer, Integer, Integer, Integer, Integer, Integer]
data1 = BasicDataset(columnNames, columnTypes)
There is another way, you can use the DatasetBuilder.
Interesting thanks ^^
i guess i should have checked the javadocs too.
Search this forum for "DatasetBuilder". That gives you full control over column types, without funky work-arounds like deleting a dummy row.
Edit: @lrose beat me to it.
Irose just said that too
Edit seems you saw xd
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.getColumnTypes()
from com.inductiveautomation.ignition.common import BasicDataset
from java.lang import String, Integer, Long, Boolean, Float
data1 = None
columnNames = ['date','H01']
columnTypes = [String, Float]
data1 = BasicDataset(columnNames, columnTypes)
data1 = system.dataset.appendDataset(data1, ds11)
I am trying to change the column datatype from date to string
But i am getting error.
Is there anything i am doing wrong in my script?