Ask question to dashboard
POST
/
api
/
questions
Authorizations
x-api-key
string
headerrequiredResponse
200 - application/json
The response is of type object
.
{
"id": "e380c78a-89b0-4f89-84a4-54018e59993e",
"created_at": "2024-03-13T08:35:11.1161+00:00",
"dashboard": "fc5624ac-abd8-453c-b56d-898b990a94f0",
"query": "How many orders do I have in total?\nCan you split it by year?",
"embed_user": null,
"account": null,
"team": "ee5b08c6-5167-4425-bbc3-a746fe4a7ead",
"messages": [
{
"role": "user",
"content": "How many orders do I have in total?"
},
{
"role": "assistant",
"content": "```python def main():\n import pandas as pd\n # Load necessary columns\n orders_df = pd.read_csv('/tmp/1fcf8b4f-4ac6-4fc9-8be2-e7356baa115f.csv', usecols=['Order ID'])\n # Calculate total orders\n total_orders = orders_df['Order ID'].nunique()\n # Chart.js object\n chart = {\n \"type\": \"metric\",\n \"data\": {\n \"datasets\": [{\n \"label\": \"Total Orders\",\n \"data\": [total_orders]\n }]\n },\n \"options\": {\n \"responsive\": True,\n \"maintainAspectRatio\": False,\n \"plugins\": {\n \"title\": {\n \"text\": \"Total Number of Orders\",\n \"display\": True\n },\n \"datalabels\": {\n \"display\": False\n }\n }\n }\n }\n return chart\n``` ```json {\"type\":\"metric\",\"data\":{\"datasets\":[{\"label\":\"Total Orders\",\"data\":[5009]}]},\"options\":{\"responsive\":true,\"maintainAspectRatio\":false,\"plugins\":{\"title\":{\"text\":\"Total Number of Orders\",\"display\":true},\"datalabels\":{\"display\":false}}}} ``` The total number of orders is **5009** based on the provided chart."
},
{
"role": "user",
"content": "Can you split it by year?"
},
{
"role": "assistant",
"content": "```python import pandas as pd def main():\n # Load necessary columns\n orders_df = pd.read_csv('/tmp/1fcf8b4f-4ac6-4fc9-8be2-e7356baa115f.csv', usecols=['Order ID', 'Order Date'])\n \n # Convert Order Date to datetime\n orders_df['Order Date'] = pd.to_datetime(orders_df['Order Date'], format='%Y-%m-%d')\n \n # Extract year from Order Date\n orders_df['Year'] = orders_df['Order Date'].dt.year\n \n # Count unique orders per year\n orders_per_year = orders_df.groupby('Year')['Order ID'].nunique().reset_index()\n \n # Prepare data for chart.js\n chart_data = {\n 'type': 'bar',\n 'data': {\n 'labels': orders_per_year['Year'].tolist(),\n 'datasets': [{\n 'label': 'Number of Orders',\n 'data': orders_per_year['Order ID'].tolist(),\n 'backgroundColor': [\n 'rgba(255, 99, 132, 0.2)',\n 'rgba(54, 162, 235, 0.2)',\n 'rgba(255, 206, 86, 0.2)',\n 'rgba(75, 192, 192, 0.2)',\n 'rgba(153, 102, 255, 0.2)',\n 'rgba(255, 159, 64, 0.2)'\n ],\n 'borderColor': [\n 'rgba(255, 99, 132, 1)',\n 'rgba(54, 162, 235, 1)',\n 'rgba(255, 206, 86, 1)',\n 'rgba(75, 192, 192, 1)',\n 'rgba(153, 102, 255, 1)',\n 'rgba(255, 159, 64, 1)'\n ],\n 'borderWidth': 1\n }]\n },\n 'options': {\n 'responsive': True,\n 'maintainAspectRatio': False,\n 'plugins': {\n 'title': {\n 'display': True,\n 'text': 'Number of Orders by Year'\n },\n 'datalabels': {\n 'display': False\n }\n },\n 'scales': {\n 'y': {\n 'beginAtZero': True\n }\n }\n }\n }\n \n return chart_data\n``` ```json {\"type\":\"bar\",\"data\":{\"labels\":[2015,2016,2017,2018],\"datasets\":[{\"label\":\"Number of Orders\",\"data\":[969,1038,1315,1687],\"backgroundColor\":[\"rgba(255, 99, 132, 0.2)\",\"rgba(54, 162, 235, 0.2)\",\"rgba(255, 206, 86, 0.2)\",\"rgba(75, 192, 192, 0.2)\",\"rgba(153, 102, 255, 0.2)\",\"rgba(255, 159, 64, 0.2)\"],\"borderColor\":[\"rgba(255, 99, 132, 1)\",\"rgba(54, 162, 235, 1)\",\"rgba(255, 206, 86, 1)\",\"rgba(75, 192, 192, 1)\",\"rgba(153, 102, 255, 1)\",\"rgba(255, 159, 64, 1)\"],\"borderWidth\":1}]},\"options\":{\"responsive\":true,\"maintainAspectRatio\":false,\"plugins\":{\"title\":{\"display\":true,\"text\":\"Number of Orders by Year\"},\"datalabels\":{\"display\":false}},\"scales\":{\"y\":{\"beginAtZero\":true}}}} ``` **Total number of orders:** The total number of orders across all years is **5,009**. **Number of orders by year:** - 2015: **969** orders - 2016: **1,038** orders - 2017: **1,315** orders - 2018: **1,687** orders This breakdown provides a clear view of how the number of orders has increased over the years, showing a consistent growth trend."
}
]
}
You can find all properties for Questions in the concepts at this link