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 the tag history set to be one floating point value but when my csv file is created it has more than one. I want the values in the csv file to be one decimal point. Best way to do it?
Here is a screenshot of the csv file and also the script I have to create the 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'] + [str(header.value) for header in system.tag.readBlocking(headerTagPaths)]
#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")
#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)


