Spaces:
Running
Running
fixed issues in activity details sheet
Browse files
app.py
CHANGED
|
@@ -390,171 +390,104 @@ def load_reward_points_data():
|
|
| 390 |
print(f"❌ Error loading Reward Points data: {str(e)}")
|
| 391 |
return None
|
| 392 |
|
|
|
|
|
|
|
| 393 |
# Function to get activity details from cached data in breakdown format
|
| 394 |
def get_activity_details(roll_no, reward_points_df):
|
| 395 |
-
"""Get activity details for a specific roll number from cached reward points data
|
| 396 |
try:
|
| 397 |
if reward_points_df is None or reward_points_df.empty:
|
| 398 |
return ""
|
| 399 |
-
|
| 400 |
-
# Normalize roll number for search
|
| 401 |
roll_no_search = roll_no.strip().upper()
|
| 402 |
-
|
| 403 |
-
#
|
|
|
|
|
|
|
| 404 |
roll_col = None
|
|
|
|
|
|
|
| 405 |
for col in reward_points_df.columns:
|
| 406 |
-
|
|
|
|
| 407 |
roll_col = col
|
| 408 |
break
|
| 409 |
-
|
| 410 |
-
|
| 411 |
-
|
| 412 |
-
|
| 413 |
-
|
| 414 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 415 |
df = reward_points_df.copy()
|
| 416 |
-
|
| 417 |
-
# Normalize the roll number column
|
| 418 |
df[roll_col] = df[roll_col].astype(str).str.strip().str.upper()
|
| 419 |
-
|
| 420 |
-
# Filter rows by roll number
|
| 421 |
student_rows = df[df[roll_col] == roll_no_search]
|
| 422 |
-
|
|
|
|
| 423 |
if student_rows.empty:
|
| 424 |
-
# Try partial matching
|
| 425 |
partial_matches = df[df[roll_col].str.contains(roll_no_search, na=False)]
|
| 426 |
if not partial_matches.empty:
|
| 427 |
student_rows = partial_matches
|
| 428 |
-
|
| 429 |
-
return ""
|
| 430 |
-
|
| 431 |
if student_rows.empty:
|
| 432 |
-
return ""
|
| 433 |
-
|
| 434 |
-
#
|
| 435 |
-
|
| 436 |
-
student_name = first_record.get('NAME OF THE STUDENT', 'N/A')
|
| 437 |
-
student_year = first_record.get('YEAR OF STUDY', 'N/A')
|
| 438 |
-
student_dept = first_record.get('DEPARTMENT', 'N/A')
|
| 439 |
-
|
| 440 |
-
# Calculate activity summary by type
|
| 441 |
activity_summary = {}
|
| 442 |
activity_count = {}
|
| 443 |
total_points = 0
|
| 444 |
-
|
| 445 |
for _, row in student_rows.iterrows():
|
| 446 |
-
activity_type = str(row.get(
|
| 447 |
-
reward_points = str(row.get(
|
| 448 |
-
|
| 449 |
-
# Convert points
|
| 450 |
try:
|
| 451 |
-
points_val = float(reward_points
|
| 452 |
-
total_points += points_val
|
| 453 |
except:
|
| 454 |
points_val = 0
|
| 455 |
-
|
| 456 |
-
|
| 457 |
-
|
| 458 |
-
|
| 459 |
-
|
| 460 |
-
|
| 461 |
-
|
| 462 |
-
|
| 463 |
-
|
| 464 |
-
# Format output in breakdown style
|
| 465 |
-
output = []
|
| 466 |
-
|
| 467 |
-
# Define all possible activity categories in order
|
| 468 |
-
activity_categories = [
|
| 469 |
-
"INITIAL POINTS / CARRY-OVER",
|
| 470 |
-
"TECHNICAL EVENTS",
|
| 471 |
-
"SKILLS",
|
| 472 |
-
"ASSIGNMENTS",
|
| 473 |
-
"INTERVIEW",
|
| 474 |
-
"TECHNICAL SOCIETY ACTIVITIES",
|
| 475 |
-
"P SKILL",
|
| 476 |
-
"TAC",
|
| 477 |
-
"SPECIAL LAB INITIATIVES",
|
| 478 |
-
"EXTRA-CURRICULAR ACTIVITIES",
|
| 479 |
-
"STUDENT INITIATIVES",
|
| 480 |
-
"EXTERNAL EVENTS",
|
| 481 |
-
"EXTERNAL TECHNICAL EVENTS"
|
| 482 |
-
]
|
| 483 |
-
|
| 484 |
-
# Map activity types to standard categories (case-insensitive matching)
|
| 485 |
-
category_mapping = {}
|
| 486 |
-
for activity_type in activity_summary.keys():
|
| 487 |
-
activity_upper = activity_type.upper()
|
| 488 |
-
matched_category = None
|
| 489 |
-
|
| 490 |
-
# Try exact matching first
|
| 491 |
-
for category in activity_categories:
|
| 492 |
-
if category.upper() in activity_upper or activity_upper in category.upper():
|
| 493 |
-
matched_category = category
|
| 494 |
-
break
|
| 495 |
-
|
| 496 |
-
# If no exact match, use the original activity type
|
| 497 |
-
if not matched_category:
|
| 498 |
-
matched_category = activity_type
|
| 499 |
-
|
| 500 |
-
category_mapping[activity_type] = matched_category
|
| 501 |
-
|
| 502 |
-
# Group activities by mapped categories
|
| 503 |
-
final_summary = {}
|
| 504 |
-
final_count = {}
|
| 505 |
-
|
| 506 |
-
for activity_type, points in activity_summary.items():
|
| 507 |
-
category = category_mapping[activity_type]
|
| 508 |
-
if category in final_summary:
|
| 509 |
-
final_summary[category] += points
|
| 510 |
-
final_count[category] += activity_count[activity_type]
|
| 511 |
-
else:
|
| 512 |
-
final_summary[category] = points
|
| 513 |
-
final_count[category] = activity_count[activity_type]
|
| 514 |
-
|
| 515 |
-
# Display all categories (including zeros)
|
| 516 |
-
for category in activity_categories:
|
| 517 |
-
count = final_count.get(category, 0)
|
| 518 |
-
points = final_summary.get(category, 0.0)
|
| 519 |
-
|
| 520 |
-
|
| 521 |
-
# Add any categories not in the standard list
|
| 522 |
-
for category, points in final_summary.items():
|
| 523 |
-
if category not in activity_categories:
|
| 524 |
-
count = final_count.get(category, 0)
|
| 525 |
-
output.append(f"📋 **{category}**")
|
| 526 |
-
output.append(f" Count: {count} | Points: {points:.2f}")
|
| 527 |
-
|
| 528 |
-
# Add summary totals
|
| 529 |
-
output.append("")
|
| 530 |
-
|
| 531 |
-
# Add detailed activity list if needed
|
| 532 |
-
if len(student_rows) <= 20: # Only show detailed list for reasonable number of activities
|
| 533 |
-
output.append("📋 DETAILED ACTIVITY LIST")
|
| 534 |
-
output.append("=" * 80)
|
| 535 |
-
|
| 536 |
-
for idx, (_, row) in enumerate(student_rows.iterrows(), 1):
|
| 537 |
-
activity_type = str(row.get('Activity Type', 'N/A'))
|
| 538 |
-
activity_name = str(row.get('Activity Name', 'N/A'))
|
| 539 |
-
reward_points = str(row.get('Reward Points', '0'))
|
| 540 |
-
|
| 541 |
-
try:
|
| 542 |
-
points_val = float(reward_points.replace(',', '')) if reward_points else 0
|
| 543 |
-
except:
|
| 544 |
-
points_val = 0
|
| 545 |
-
|
| 546 |
-
# Truncate long names for display
|
| 547 |
-
display_name = activity_name[:50] + "..." if len(activity_name) > 63 else activity_name
|
| 548 |
-
output.append(f"{idx:2d}. {activity_type}: {display_name} - {points_val:.2f} pts")
|
| 549 |
-
|
| 550 |
output.append("=" * 80)
|
| 551 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 552 |
return "\n".join(output)
|
| 553 |
-
|
| 554 |
except Exception as e:
|
| 555 |
print(f"❌ Error fetching activity details: {str(e)}")
|
| 556 |
return ""
|
| 557 |
|
|
|
|
| 558 |
# Function to get details sheet information
|
| 559 |
def get_details_info(spreadsheet):
|
| 560 |
try:
|
|
|
|
| 390 |
print(f"❌ Error loading Reward Points data: {str(e)}")
|
| 391 |
return None
|
| 392 |
|
| 393 |
+
# Function to get activity details from cached data in breakdown format
|
| 394 |
+
|
| 395 |
# Function to get activity details from cached data in breakdown format
|
| 396 |
def get_activity_details(roll_no, reward_points_df):
|
| 397 |
+
"""Get activity details for a specific roll number from cached reward points data."""
|
| 398 |
try:
|
| 399 |
if reward_points_df is None or reward_points_df.empty:
|
| 400 |
return ""
|
| 401 |
+
|
|
|
|
| 402 |
roll_no_search = roll_no.strip().upper()
|
| 403 |
+
|
| 404 |
+
# -----------------------------
|
| 405 |
+
# FIXED ROLL NUMBER DETECTION
|
| 406 |
+
# -----------------------------
|
| 407 |
roll_col = None
|
| 408 |
+
|
| 409 |
+
# 1️⃣ Try header match
|
| 410 |
for col in reward_points_df.columns:
|
| 411 |
+
cl = col.lower().replace(" ", "")
|
| 412 |
+
if "roll" in cl or "reg" in cl:
|
| 413 |
roll_col = col
|
| 414 |
break
|
| 415 |
+
|
| 416 |
+
# 2️⃣ Pattern match (fallback)
|
| 417 |
+
if roll_col is None:
|
| 418 |
+
for col in reward_points_df.columns:
|
| 419 |
+
sample = (
|
| 420 |
+
reward_points_df[col]
|
| 421 |
+
.astype(str)
|
| 422 |
+
.str.upper()
|
| 423 |
+
.head(40)
|
| 424 |
+
)
|
| 425 |
+
if sample.str.match(r"(7376|2025)[A-Z0-9]+").sum() >= 2:
|
| 426 |
+
roll_col = col
|
| 427 |
+
break
|
| 428 |
+
|
| 429 |
+
# 3️⃣ Ultimate fallback
|
| 430 |
+
if roll_col is None:
|
| 431 |
+
roll_col = reward_points_df.columns[len(reward_points_df.columns)//2]
|
| 432 |
+
|
| 433 |
+
# Normalize roll number column
|
| 434 |
df = reward_points_df.copy()
|
|
|
|
|
|
|
| 435 |
df[roll_col] = df[roll_col].astype(str).str.strip().str.upper()
|
| 436 |
+
|
|
|
|
| 437 |
student_rows = df[df[roll_col] == roll_no_search]
|
| 438 |
+
|
| 439 |
+
# Try partial match
|
| 440 |
if student_rows.empty:
|
|
|
|
| 441 |
partial_matches = df[df[roll_col].str.contains(roll_no_search, na=False)]
|
| 442 |
if not partial_matches.empty:
|
| 443 |
student_rows = partial_matches
|
| 444 |
+
|
|
|
|
|
|
|
| 445 |
if student_rows.empty:
|
| 446 |
+
return "" # No activity rows
|
| 447 |
+
|
| 448 |
+
# Build output
|
| 449 |
+
output = []
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 450 |
activity_summary = {}
|
| 451 |
activity_count = {}
|
| 452 |
total_points = 0
|
| 453 |
+
|
| 454 |
for _, row in student_rows.iterrows():
|
| 455 |
+
activity_type = str(row.get("Activity Type", "")).strip()
|
| 456 |
+
reward_points = str(row.get("Reward Points", "0")).replace(",", "")
|
| 457 |
+
|
| 458 |
+
# Convert points
|
| 459 |
try:
|
| 460 |
+
points_val = float(reward_points)
|
|
|
|
| 461 |
except:
|
| 462 |
points_val = 0
|
| 463 |
+
|
| 464 |
+
total_points += points_val
|
| 465 |
+
|
| 466 |
+
# Update summary
|
| 467 |
+
activity_summary[activity_type] = activity_summary.get(activity_type, 0) + points_val
|
| 468 |
+
activity_count[activity_type] = activity_count.get(activity_type, 0) + 1
|
| 469 |
+
|
| 470 |
+
output.append("📋 DETAILED ACTIVITY LIST")
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 471 |
output.append("=" * 80)
|
| 472 |
+
|
| 473 |
+
for idx, (_, row) in enumerate(student_rows.iterrows(), 1):
|
| 474 |
+
name = str(row.get("Activity Name", "")).strip()
|
| 475 |
+
points = str(row.get("Reward Points", "0"))
|
| 476 |
+
activity_type = str(row.get("Activity Type", "")).strip()
|
| 477 |
+
display = name[:85] + "..." if len(name) > 85 else name
|
| 478 |
+
output.append(f"{idx:2d}. {activity_type}: {display} - {points} pts")
|
| 479 |
+
|
| 480 |
+
output.append("=" * 80)
|
| 481 |
+
output.append(f"🎯 TOTAL REWARD POINTS FROM ACTIVITIES: {total_points:.2f}")
|
| 482 |
+
output.append("=" * 80)
|
| 483 |
+
|
| 484 |
return "\n".join(output)
|
| 485 |
+
|
| 486 |
except Exception as e:
|
| 487 |
print(f"❌ Error fetching activity details: {str(e)}")
|
| 488 |
return ""
|
| 489 |
|
| 490 |
+
|
| 491 |
# Function to get details sheet information
|
| 492 |
def get_details_info(spreadsheet):
|
| 493 |
try:
|