Hello everyone, I have a PowerTable and I would like to get its dataset so I can format and export it in excel, because the native option only exports in CSV, and I didn't find any more options in the menu.
You would run your own historian query with the corresponding settings and convert that to your target format.
You should be doing this anyways, in my opinion, because a chart should always be on a more efficient sampling rate for performance, and an export can be made to use a higher sample rate or natural return.
I think it's an antipattern the charts make it so tempting to directly export their data, but what do I know...
1 Like
Trying to be feature-comparable to Vision. Vision can handle high-resolution datasets and therefore exporting from the chart itself is perfectly reasonable. Perspective, not so much.
To solve it, I created the following code:
pens = value['pens']
startDate = value['startDate']
endDate = value['endDate']
# Número de resultados que você deseja trazer
num_results = 50
# Lista para armazenar os dados das tags
dados_das_tags = {}
# Loop através dos objetos na lista e buscar os dados
for objeto in pens:
if "data" in objeto and "source" in objeto["data"]:
caminho_da_tag = objeto["data"]["source"]
# Verifica se o caminho da tag está presente
if caminho_da_tag:
tag_path_parts = caminho_da_tag.split(":")
if len(tag_path_parts) > 2:
tag_name = tag_path_parts[-1] # Pega o nome da tag após "tag:"
historico_da_tag = system.tag.queryTagHistory(
paths=[caminho_da_tag],
startDate=startDate,
endDate=endDate,
returnSize=num_results, # Especifica o número de resultados desejado
aggregationMode="LastValue", # Modo de agregação LastValue
returnFormat='Wide' # Formato de retorno amplo
)
# Lista para armazenar os valores desta tag
valores_da_tag = []
# Loop para obter os valores
for i in range(historico_da_tag.getRowCount()):
timestamp = historico_da_tag.getValueAt(i, "t_stamp")
valor = historico_da_tag.getValueAt(i, tag_name) # Obtém o valor da coluna correspondente ao nome da tag
timestamp_str = system.date.format(timestamp, "dd/MM/yyyy HH:mm:ss")
valor_formatado = "{:.2f}".format(round(valor, 2)) # Formata o valor com duas casas decimais
valores_da_tag.append([timestamp_str, valor_formatado])
dados_das_tags[tag_name] = valores_da_tag
else:
dados_das_tags[tag_name] = []
else:
dados_das_tags[tag_name] = []
else:
dados_das_tags[objeto["name"]] = []
# Construir um novo dataset vazio com as colunas desejadas
headers = ["time"]
for tag_name in dados_das_tags.keys():
headers.append(tag_name)
combined_dataset = system.dataset.toDataSet(headers, [])
# Preencher o dataset combinado com os dados dos datasets individuais
for i in range(num_results):
row = []
row.append(dados_das_tags[list(dados_das_tags.keys())[0]][i][0]) # Adicione a coluna de tempo
for tag_name in list(dados_das_tags.keys()):
if len(dados_das_tags[tag_name]) > i:
row.append(dados_das_tags[tag_name][i][1])
else:
row.append(None)
combined_dataset = system.dataset.addRow(combined_dataset, row)
return combined_dataset
Now just export to excel.
Thanks!