Hello everyone,
I'm trying to create a new dataset line by line based off of data in an existing dataset so I can add some calculations based on existing data for a report I'm generating. I've gotten to the point where it is doing the calculations and appending the row to my py Data Set, but for some reason it is making every row the data / calcs from the first row of the existing dataset instead of looping through. It does end up with the right amount of rows... but they're all the same. Here's the code I've cobbled together so far:
def updateData(data, sample):
#Import SQL query results
dataset = data['TestQuery'].getCoreResults()
#Convert to PyDataset
pyData = system.dataset.toPyDataSet(dataset)
#Import L/360 Value
L360 = data['L360']
#Create dataset for new data with calcs
pyDataCalcs = []
header = ['CheckID', 'Product', 'RatedLoad', 'TestResults', 'Slope', 'SlopeL360']
#Loop for performing cacls and adding each row to pyDataCals
for row in pyData:
#Set Values for Original Columns
CheckID = row[0]
Product = row[1]
TestResults = row[2]
#Set Value of Rated Load (16 for heavy duty products or 12 for medium duty)
if Product == "Product1":
RatedLoad = 16
elif Product == "Product2":
RatedLoad = 16
else:
RatedLoad = 12
#Perform slope calcs based on rated load
Slope = RatedLoad / TestResults
SlopeL360 = Slope * L360
newRow = [CheckID, Product, RatedLoad, TestResults, Slope, SlopeL360]
pyDataCalcs.append(newRow)
dataSetCalcs = system.dataset.toDataSet(header, pyDataCalcs)
data['FullData'] = dataSetCalcs
Any help would be greatly appreciated, I'm assuming I'm not fully comprehending how either append works or the looping function.