forked from tne-ai/apps-maria-2
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathget_table_and_chart.py
37 lines (32 loc) · 980 Bytes
/
get_table_and_chart.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
import pandas as pd
from tne.TNE import TNE
from tabulate import tabulate
import json
'''
if type(PROCESS_INPUT) is pd.DataFrame:
if PROCESS_INPUT.empty:
result = "<EMPTY DATAFRAME>"
else:
result = tabulate(PROCESS_INPUT,
headers="keys",
tablefmt="pipe",
showindex=False)
elif type(PROCESS_INPUT) is str:
result = PROCESS_INPUT
else:
result = "<ERROR>"
'''
try:
# Parse the input string as JSON
data = json.loads(PROCESS_INPUT)
# Extract chartData and tableData if they are present
output = {}
if "chartData" in data:
output["chartData"] = data["chartData"]
if "tableData" in data:
output["tableData"] = data["tableData"]
# Convert the result to a JSON string
result = json.dumps(output, indent=4)
except Exception as e:
# Capture the exception message in the result
result = f"Error: {str(e)}"