I am running ignition edge and once a day I am creating a csv file with floating point values coming from the tag historian. I have everything working perfect except my date is being shown as a [u'] type instead of just a string which I want it to be.
Here is a screenshot of the csv file and also the script I have to create the file:
Here is my script which creates the csv file:
def create_analogin_csv():
"""Create analog input csv file with values from past 24 hours
Params:
none
Returns:
none
"""
#establish logger
logger = system.util.getLogger("AI CSV file")
#dynamically create list of analog input tag paths including filter to only look at UDT instance tags
path = '[PLC]AnalogInputs'
fltr = {'tagType': "UdtInstance"}
tags = system.tag.browse(path,fltr)
dataTagPaths = [str(tag['fullPath']) + "/InputValue" for tag in tags]
#create custom header row
headers = []
headerTagPaths = [str(tag['fullPath']) + "/DeviceName" for tag in tags]
#reads in device names and creates array for header. Inserts DATE/TIME header in first index position
headers = 'DATE/TIME' + ","
for header in system.tag.readBlocking(headerTagPaths):
headers = headers + str(header.value) + ","
#execute tag history query returning hourly values for last 24 hours
AIdataset = system.tag.queryTagHistory(paths=dataTagPaths, returnSize=24,
aggregationMode="LastValue", returnFormat='Wide', columnNames=headers, rangeHours = -24)
#write data to dataset tag
AIdatasetTag = '[PLC]AnalogInputCSV'
system.tag.writeBlocking(AIdatasetTag, AIdataset)
logger.info("Data written to dataset tag")
#take resulting dataset and format time and date
AIdatasetF = system.dataset.formatDates(AIdataset, "MM-dd-yyyy HH:mm")
#format dataset to one decimal place and convert dataset to csv
outputRows = [headers]
for row in xrange(AIdatasetF.rowCount):
# add the date value
outputRow = [AIdatasetF.getValueAt(row, 0)]
outputRow = str(outputRow) + ","
# skip the date column
for col in xrange(1, AIdatasetF.columnCount):
outputRow = outputRow + str(round(AIdatasetF.getValueAt(row, col), 1)) + ","
outputRows.append(outputRow)
csv = "\n".join((row for row in outputRows))
#convert dataset to csv file
#csv = system.dataset.toCSV(dataset = AIdatasetF, showHeaders = True)
#define file path and populate file
filePath = "C:\\DailyCSVFiles\\analogin.csv"
system.file.writeFile(filePath, csv)
if system.file.fileExists("C:\\DailyCSVFiles\\analogin.csv"):
logger.info("File written to csv")
else:
logger.info("File does not exist!")