Spaces:
Sleeping
Sleeping
Update analytics_tab.py
Browse files- analytics_tab.py +29 -23
analytics_tab.py
CHANGED
|
@@ -188,17 +188,15 @@ class AnalyticsTab:
|
|
| 188 |
"""Clear analytics display"""
|
| 189 |
return None, None, ""
|
| 190 |
|
| 191 |
-
def get_daily_transactions(self, selected_date
|
| 192 |
-
"""Get day-wise transaction details"""
|
| 193 |
try:
|
| 194 |
if not selected_date:
|
| 195 |
return None, "β Please select a date"
|
| 196 |
|
| 197 |
-
df = self.get_all_transactions(
|
| 198 |
|
| 199 |
if df.empty:
|
| 200 |
-
if farmer_name and farmer_name.strip():
|
| 201 |
-
return None, f"β No transactions found for farmer '{farmer_name}'"
|
| 202 |
return None, "β No transactions found"
|
| 203 |
|
| 204 |
# Convert selected date to datetime
|
|
@@ -234,12 +232,10 @@ class AnalyticsTab:
|
|
| 234 |
'Amount': row['Amount']
|
| 235 |
})
|
| 236 |
|
| 237 |
-
farmer_text = f" - {farmer_name}" if farmer_name and farmer_name.strip() else ""
|
| 238 |
-
|
| 239 |
# Create compact HTML summary with black text
|
| 240 |
summary_html = f"""
|
| 241 |
<div style="background: linear-gradient(135deg, #f093fb 0%, #f5576c 100%); padding: 20px; border-radius: 10px; margin: 10px 0;">
|
| 242 |
-
<h3 style="color: white; text-align: center; margin: 0 0 15px 0; font-size: 20px;">π
Daily Summary: {selected_date}
|
| 243 |
|
| 244 |
<div style="display: grid; grid-template-columns: 1fr 1fr; gap: 15px; margin-bottom: 15px;">
|
| 245 |
<div style="background-color: white; border-radius: 8px; padding: 15px; text-align: center;">
|
|
@@ -306,7 +302,7 @@ class AnalyticsTab:
|
|
| 306 |
|
| 307 |
except Exception as e:
|
| 308 |
return None, f"β Error getting daily transactions: {str(e)}"
|
| 309 |
-
|
| 310 |
def clear_daily(self):
|
| 311 |
"""Clear daily transactions display"""
|
| 312 |
return None, ""
|
|
@@ -317,13 +313,14 @@ class AnalyticsTab:
|
|
| 317 |
gr.Markdown("## Transaction Analytics Dashboard")
|
| 318 |
|
| 319 |
# Section 1: All Transactions
|
| 320 |
-
with gr.Accordion("π All Transactions (Without Interest)", open=
|
| 321 |
gr.Markdown("*View complete transaction history for a specific farmer*")
|
| 322 |
|
| 323 |
trans_farmer = gr.Dropdown(
|
| 324 |
label="Select Farmer (Optional - leave empty for all)",
|
| 325 |
choices=self.get_farmers(),
|
| 326 |
-
allow_custom_value=True
|
|
|
|
| 327 |
)
|
| 328 |
|
| 329 |
with gr.Row():
|
|
@@ -340,13 +337,14 @@ class AnalyticsTab:
|
|
| 340 |
gr.Markdown("---")
|
| 341 |
|
| 342 |
# Section 2: Bank-wise Analytics
|
| 343 |
-
with gr.Accordion("π¦ Bank-wise Analytics", open=
|
| 344 |
gr.Markdown("*Analyze incoming and outgoing transactions by bank account*")
|
| 345 |
|
| 346 |
analytics_farmer = gr.Dropdown(
|
| 347 |
label="Select Farmer (Optional - leave empty for all)",
|
| 348 |
choices=self.get_farmers(),
|
| 349 |
-
allow_custom_value=True
|
|
|
|
| 350 |
)
|
| 351 |
|
| 352 |
with gr.Row():
|
|
@@ -372,14 +370,8 @@ class AnalyticsTab:
|
|
| 372 |
gr.Markdown("---")
|
| 373 |
|
| 374 |
# Section 3: Daily Transaction Details
|
| 375 |
-
with gr.Accordion("π
Daily Transaction Details", open=
|
| 376 |
-
gr.Markdown("*View all transactions for a specific date*")
|
| 377 |
-
|
| 378 |
-
daily_farmer = gr.Dropdown(
|
| 379 |
-
label="Select Farmer (Optional - leave empty for all)",
|
| 380 |
-
choices=self.get_farmers(),
|
| 381 |
-
allow_custom_value=True
|
| 382 |
-
)
|
| 383 |
|
| 384 |
daily_date = gr.Textbox(
|
| 385 |
label="Date (YYYY-MM-DD)",
|
|
@@ -406,6 +398,13 @@ class AnalyticsTab:
|
|
| 406 |
outputs=[all_trans_df, trans_status]
|
| 407 |
)
|
| 408 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 409 |
generate_analytics_btn.click(
|
| 410 |
fn=lambda f, m, y: self.get_bank_analytics(
|
| 411 |
f if f else None,
|
|
@@ -422,9 +421,16 @@ class AnalyticsTab:
|
|
| 422 |
outputs=[analytics_chart, analytics_summary, analytics_status]
|
| 423 |
)
|
| 424 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 425 |
get_daily_btn.click(
|
| 426 |
-
fn=
|
| 427 |
-
inputs=[daily_date
|
| 428 |
outputs=[daily_summary, daily_status]
|
| 429 |
)
|
| 430 |
|
|
|
|
| 188 |
"""Clear analytics display"""
|
| 189 |
return None, None, ""
|
| 190 |
|
| 191 |
+
def get_daily_transactions(self, selected_date):
|
| 192 |
+
"""Get day-wise transaction details for all farmers"""
|
| 193 |
try:
|
| 194 |
if not selected_date:
|
| 195 |
return None, "β Please select a date"
|
| 196 |
|
| 197 |
+
df = self.get_all_transactions() # Remove farmer_name parameter
|
| 198 |
|
| 199 |
if df.empty:
|
|
|
|
|
|
|
| 200 |
return None, "β No transactions found"
|
| 201 |
|
| 202 |
# Convert selected date to datetime
|
|
|
|
| 232 |
'Amount': row['Amount']
|
| 233 |
})
|
| 234 |
|
|
|
|
|
|
|
| 235 |
# Create compact HTML summary with black text
|
| 236 |
summary_html = f"""
|
| 237 |
<div style="background: linear-gradient(135deg, #f093fb 0%, #f5576c 100%); padding: 20px; border-radius: 10px; margin: 10px 0;">
|
| 238 |
+
<h3 style="color: white; text-align: center; margin: 0 0 15px 0; font-size: 20px;">π
Daily Summary: {selected_date}</h3>
|
| 239 |
|
| 240 |
<div style="display: grid; grid-template-columns: 1fr 1fr; gap: 15px; margin-bottom: 15px;">
|
| 241 |
<div style="background-color: white; border-radius: 8px; padding: 15px; text-align: center;">
|
|
|
|
| 302 |
|
| 303 |
except Exception as e:
|
| 304 |
return None, f"β Error getting daily transactions: {str(e)}"
|
| 305 |
+
|
| 306 |
def clear_daily(self):
|
| 307 |
"""Clear daily transactions display"""
|
| 308 |
return None, ""
|
|
|
|
| 313 |
gr.Markdown("## Transaction Analytics Dashboard")
|
| 314 |
|
| 315 |
# Section 1: All Transactions
|
| 316 |
+
with gr.Accordion("π All Transactions (Without Interest)", open=False):
|
| 317 |
gr.Markdown("*View complete transaction history for a specific farmer*")
|
| 318 |
|
| 319 |
trans_farmer = gr.Dropdown(
|
| 320 |
label="Select Farmer (Optional - leave empty for all)",
|
| 321 |
choices=self.get_farmers(),
|
| 322 |
+
allow_custom_value=True,
|
| 323 |
+
value=None
|
| 324 |
)
|
| 325 |
|
| 326 |
with gr.Row():
|
|
|
|
| 337 |
gr.Markdown("---")
|
| 338 |
|
| 339 |
# Section 2: Bank-wise Analytics
|
| 340 |
+
with gr.Accordion("π¦ Bank-wise Analytics", open=False):
|
| 341 |
gr.Markdown("*Analyze incoming and outgoing transactions by bank account*")
|
| 342 |
|
| 343 |
analytics_farmer = gr.Dropdown(
|
| 344 |
label="Select Farmer (Optional - leave empty for all)",
|
| 345 |
choices=self.get_farmers(),
|
| 346 |
+
allow_custom_value=True,
|
| 347 |
+
value=None
|
| 348 |
)
|
| 349 |
|
| 350 |
with gr.Row():
|
|
|
|
| 370 |
gr.Markdown("---")
|
| 371 |
|
| 372 |
# Section 3: Daily Transaction Details
|
| 373 |
+
with gr.Accordion("π
Daily Transaction Details", open=False):
|
| 374 |
+
gr.Markdown("*View all transactions for a specific date across all farmers*")
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 375 |
|
| 376 |
daily_date = gr.Textbox(
|
| 377 |
label="Date (YYYY-MM-DD)",
|
|
|
|
| 398 |
outputs=[all_trans_df, trans_status]
|
| 399 |
)
|
| 400 |
|
| 401 |
+
# Refresh farmer list when Load Transactions is clicked
|
| 402 |
+
load_trans_btn.click(
|
| 403 |
+
fn=lambda: gr.Dropdown(choices=self.get_farmers()),
|
| 404 |
+
inputs=[],
|
| 405 |
+
outputs=[trans_farmer]
|
| 406 |
+
)
|
| 407 |
+
|
| 408 |
generate_analytics_btn.click(
|
| 409 |
fn=lambda f, m, y: self.get_bank_analytics(
|
| 410 |
f if f else None,
|
|
|
|
| 421 |
outputs=[analytics_chart, analytics_summary, analytics_status]
|
| 422 |
)
|
| 423 |
|
| 424 |
+
# Refresh farmer list when Generate Analytics is clicked
|
| 425 |
+
generate_analytics_btn.click(
|
| 426 |
+
fn=lambda: gr.Dropdown(choices=self.get_farmers()),
|
| 427 |
+
inputs=[],
|
| 428 |
+
outputs=[analytics_farmer]
|
| 429 |
+
)
|
| 430 |
+
|
| 431 |
get_daily_btn.click(
|
| 432 |
+
fn=self.get_daily_transactions,
|
| 433 |
+
inputs=[daily_date],
|
| 434 |
outputs=[daily_summary, daily_status]
|
| 435 |
)
|
| 436 |
|