Spaces:
Sleeping
Sleeping
added daily revenue table
Browse files
app.py
CHANGED
|
@@ -69,11 +69,32 @@ def analyze_sales_performance(period, api_token):
|
|
| 69 |
data = get_sales_data(period, api_token)
|
| 70 |
|
| 71 |
if data.empty:
|
| 72 |
-
return "No sales data available for the selected period.", None, None
|
| 73 |
|
| 74 |
# Get enhanced KPIs for Wildberries data
|
| 75 |
kpis = create_wb_kpi_cards(data)
|
| 76 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 77 |
# Create sales summary with Wildberries-specific metrics
|
| 78 |
mode_indicator = "Demo Mode" if not api_token or api_token.strip() == "" else "Live Data"
|
| 79 |
|
|
@@ -107,12 +128,12 @@ def analyze_sales_performance(period, api_token):
|
|
| 107 |
if 'sales_commission' in data.columns:
|
| 108 |
commission_chart = create_commission_analysis_chart(data)
|
| 109 |
|
| 110 |
-
return summary, main_chart, commission_chart
|
| 111 |
|
| 112 |
except Exception as e:
|
| 113 |
error_msg = f"Error analyzing sales: {str(e)}"
|
| 114 |
gr.Error(error_msg)
|
| 115 |
-
return error_msg, None, None
|
| 116 |
|
| 117 |
def calculate_stockout_forecast(method, api_token):
|
| 118 |
"""Calculate days until stockout for products"""
|
|
@@ -301,6 +322,7 @@ def create_interface():
|
|
| 301 |
|
| 302 |
with gr.Tabs():
|
| 303 |
# Sales Analytics Tab
|
|
|
|
| 304 |
with gr.TabItem("📊 Sales Analytics"):
|
| 305 |
with gr.Row():
|
| 306 |
with gr.Column(scale=1):
|
|
@@ -321,11 +343,20 @@ def create_interface():
|
|
| 321 |
with gr.Row():
|
| 322 |
commission_chart = gr.Plot(label="Commission Analysis Dashboard", visible=False)
|
| 323 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 324 |
# Event handlers
|
| 325 |
analyze_btn.click(
|
| 326 |
fn=analyze_sales_performance,
|
| 327 |
inputs=[period_selector, api_token_input],
|
| 328 |
-
outputs=[sales_summary, sales_chart, commission_chart]
|
| 329 |
)
|
| 330 |
|
| 331 |
# Inventory Forecasting Tab
|
|
|
|
| 69 |
data = get_sales_data(period, api_token)
|
| 70 |
|
| 71 |
if data.empty:
|
| 72 |
+
return "No sales data available for the selected period.", None, None, pd.DataFrame()
|
| 73 |
|
| 74 |
# Get enhanced KPIs for Wildberries data
|
| 75 |
kpis = create_wb_kpi_cards(data)
|
| 76 |
|
| 77 |
+
# Create daily revenue breakdown table
|
| 78 |
+
daily_revenue_table = pd.DataFrame()
|
| 79 |
+
if 'sale_date' in data.columns and 'total_price' in data.columns:
|
| 80 |
+
daily_revenue = data.groupby(data['sale_date'].dt.date).agg({
|
| 81 |
+
'total_price': 'sum',
|
| 82 |
+
'quantity': 'sum',
|
| 83 |
+
'sales_commission': 'sum' if 'sales_commission' in data.columns else lambda x: 0,
|
| 84 |
+
'amount_for_pay': 'sum' if 'amount_for_pay' in data.columns else lambda x: 0
|
| 85 |
+
}).reset_index()
|
| 86 |
+
|
| 87 |
+
daily_revenue_table = pd.DataFrame({
|
| 88 |
+
'Date': daily_revenue['sale_date'],
|
| 89 |
+
'Revenue (₽)': daily_revenue['total_price'].round(2),
|
| 90 |
+
'Orders': daily_revenue['quantity'],
|
| 91 |
+
'Commission (₽)': daily_revenue.get('sales_commission', 0).round(2) if 'sales_commission' in daily_revenue.columns else 0,
|
| 92 |
+
'Net Revenue (₽)': daily_revenue.get('amount_for_pay', daily_revenue['total_price']).round(2)
|
| 93 |
+
})
|
| 94 |
+
|
| 95 |
+
# Sort by date descending (most recent first)
|
| 96 |
+
daily_revenue_table = daily_revenue_table.sort_values('Date', ascending=False)
|
| 97 |
+
|
| 98 |
# Create sales summary with Wildberries-specific metrics
|
| 99 |
mode_indicator = "Demo Mode" if not api_token or api_token.strip() == "" else "Live Data"
|
| 100 |
|
|
|
|
| 128 |
if 'sales_commission' in data.columns:
|
| 129 |
commission_chart = create_commission_analysis_chart(data)
|
| 130 |
|
| 131 |
+
return summary, main_chart, commission_chart, daily_revenue_table
|
| 132 |
|
| 133 |
except Exception as e:
|
| 134 |
error_msg = f"Error analyzing sales: {str(e)}"
|
| 135 |
gr.Error(error_msg)
|
| 136 |
+
return error_msg, None, None, pd.DataFrame()
|
| 137 |
|
| 138 |
def calculate_stockout_forecast(method, api_token):
|
| 139 |
"""Calculate days until stockout for products"""
|
|
|
|
| 322 |
|
| 323 |
with gr.Tabs():
|
| 324 |
# Sales Analytics Tab
|
| 325 |
+
# Sales Analytics Tab
|
| 326 |
with gr.TabItem("📊 Sales Analytics"):
|
| 327 |
with gr.Row():
|
| 328 |
with gr.Column(scale=1):
|
|
|
|
| 343 |
with gr.Row():
|
| 344 |
commission_chart = gr.Plot(label="Commission Analysis Dashboard", visible=False)
|
| 345 |
|
| 346 |
+
# Daily Revenue Table
|
| 347 |
+
with gr.Row():
|
| 348 |
+
daily_revenue_table = gr.DataFrame(
|
| 349 |
+
label="📅 Daily Revenue Breakdown",
|
| 350 |
+
headers=["Date", "Revenue (₽)", "Orders", "Commission (₽)", "Net Revenue (₽)"],
|
| 351 |
+
datatype=["str", "number", "number", "number", "number"],
|
| 352 |
+
interactive=False
|
| 353 |
+
)
|
| 354 |
+
|
| 355 |
# Event handlers
|
| 356 |
analyze_btn.click(
|
| 357 |
fn=analyze_sales_performance,
|
| 358 |
inputs=[period_selector, api_token_input],
|
| 359 |
+
outputs=[sales_summary, sales_chart, commission_chart, daily_revenue_table]
|
| 360 |
)
|
| 361 |
|
| 362 |
# Inventory Forecasting Tab
|