PraneshJs commited on
Commit
2eebd4f
·
verified ·
1 Parent(s): 835b233

removed analytics feature

Browse files
Files changed (1) hide show
  1. app.py +13 -135
app.py CHANGED
@@ -21,12 +21,6 @@ ist = timezone("Asia/Kolkata")
21
  # Scopes (read-only)
22
  SCOPES = ["https://www.googleapis.com/auth/spreadsheets.readonly"]
23
 
24
- # GLOBAL ANALYTICS VARIABLES - Add at the top after imports
25
- visit_count = 0
26
- searched_roll_numbers = []
27
- unique_searches = set()
28
- search_history = [] # Store with timestamps
29
-
30
  def authorize():
31
  creds = None
32
 
@@ -64,45 +58,6 @@ def authorize():
64
 
65
  return gspread.authorize(creds)
66
 
67
- # Function to increment visit count
68
- def increment_visit_count():
69
- global visit_count
70
- visit_count += 1
71
-
72
- # Function to log searched roll numbers
73
- def log_search(roll_no):
74
- global searched_roll_numbers, unique_searches, search_history
75
-
76
- if roll_no and roll_no.strip():
77
- roll_no = roll_no.strip().upper()
78
- searched_roll_numbers.append(roll_no)
79
- unique_searches.add(roll_no)
80
-
81
- # Add to search history with timestamp
82
- search_entry = {
83
- 'roll_no': roll_no,
84
- 'timestamp': datetime.now(ist).strftime('%Y-%m-%d %H:%M:%S'),
85
- 'search_count': len(searched_roll_numbers)
86
- }
87
- search_history.append(search_entry)
88
-
89
- # Function to get analytics data
90
- def get_analytics_summary():
91
- """Get current analytics summary"""
92
- total_searches = len(searched_roll_numbers)
93
- unique_users = len(unique_searches)
94
-
95
- # Get recent searches (last 5)
96
- recent_searches = searched_roll_numbers[-5:] if searched_roll_numbers else []
97
-
98
- return {
99
- 'visits': visit_count,
100
- 'total_searches': total_searches,
101
- 'unique_searches': unique_users,
102
- 'recent_searches': recent_searches,
103
- 'all_searches': searched_roll_numbers
104
- }
105
-
106
  # Function to get data from a specific sheet
107
  def get_sheet_data(spreadsheet, gid, sheet_name):
108
  try:
@@ -871,9 +826,6 @@ def search_student(roll_no):
871
  # Convert roll number to uppercase for consistent searching
872
  roll_no = roll_no.strip().upper()
873
 
874
- # Log the search
875
- log_search(roll_no)
876
-
877
  # Get cached data (fast response, auto-refreshes every 12 hours)
878
  combined_df, studentwise_data, details_info, reward_points_df = get_cached_data()
879
 
@@ -999,13 +951,11 @@ def get_system_info():
999
  if not details_info:
1000
  return "❌ No system information available"
1001
 
1002
- # Get analytics data
1003
- analytics = get_analytics_summary()
1004
-
1005
  output = []
1006
  output.append("=" * 80)
1007
  output.append("SYSTEM INFORMATION")
1008
  output.append("=" * 80)
 
1009
  # Average Points
1010
  if 'average_points' in details_info:
1011
  output.append("\n🎯 AVERAGE REWARD POINTS BY YEAR:")
@@ -1054,42 +1004,18 @@ def get_system_info():
1054
 
1055
  return "\n".join(output)
1056
 
1057
- # Function to get live analytics for header display
1058
- def get_live_analytics():
1059
- """Get current analytics for header display"""
1060
- analytics = get_analytics_summary()
1061
- return f"📊 Visits: {analytics['visits']} | 🔍 Searches: {analytics['total_searches']} | 👥 Unique Users: {analytics['unique_searches']}"
1062
-
1063
- # Create Gradio interface with analytics
1064
  with gr.Blocks(
1065
  title="Student Reward Points Check",
1066
  theme=gr.themes.Soft(),
1067
  ) as app:
1068
 
1069
- # Header with analytics
1070
- with gr.Row():
1071
- with gr.Column(scale=2):
1072
- gr.Markdown("# 🎓 Student Reward Points Checker")
1073
- gr.Markdown("### Search for Student details including Reward points with detailed information and Redemption dates")
1074
- gr.Markdown("### எல்லா புகழும் இறைவனுக்கே 🕉 ")
1075
- gr.Markdown("🕒 **Auto-Updates**: Data automatically refreshes when there is a change in Reward Points Sheet")
1076
- gr.Markdown("### Fill this form for any Issue/Feedback: [Issue/Feedback Form](https://docs.google.com/forms/d/e/1FAIpQLScnl0udcN2pUDENHl45HIj5HZbvDuwZ0g2eepBbp8tJYg-NvQ/viewform)")
1077
-
1078
- with gr.Column(scale=1):
1079
- # Live analytics display
1080
- analytics_display = gr.HTML(
1081
- value=f"""
1082
- <div class="analytics-display">
1083
- <h2 style="margin: 0; color: black;">📊 Live Analytics</h2>
1084
- <div style="margin: 10px 0;">
1085
- <div>📊 Visits: {visit_count}</div>
1086
- <div>🔍 Searches: {len(searched_roll_numbers)}</div>
1087
- <div>👥 Unique Users: {len(unique_searches)}</div>
1088
- </div>
1089
- </div>
1090
- """,
1091
- elem_id="analytics_display"
1092
- )
1093
 
1094
  with gr.Tabs():
1095
  with gr.TabItem("🔍 Student Search"):
@@ -1108,8 +1034,7 @@ with gr.Blocks(
1108
  lines=50,
1109
  max_lines=60,
1110
  show_copy_button=True,
1111
- autoscroll=False,
1112
- elem_id="result_output"
1113
  )
1114
 
1115
  with gr.TabItem("ℹ️ System Information"):
@@ -1121,41 +1046,12 @@ with gr.Blocks(
1121
  show_copy_button=True,
1122
  autoscroll=False,
1123
  interactive=False,
1124
- show_label=True,
1125
- elem_id="system_output"
1126
  )
1127
 
1128
- # Function to update analytics display
1129
- def update_analytics_display():
1130
- analytics = get_analytics_summary()
1131
- return f"""
1132
- <div class="analytics-display">
1133
- <h2 style="margin: 0; color: black;">📊 Live Analytics</h3>
1134
- <div style="margin: 10px 0;">
1135
- <div>📊 Visits: {analytics['visits']}</div>
1136
- <div>🔍 Searches: {analytics['total_searches']}</div>
1137
- <div>👥 Unique Users: {analytics['unique_searches']}</div>
1138
- </div>
1139
- </div>
1140
- """
1141
-
1142
- # Enhanced search function that updates analytics
1143
- def search_student_with_analytics(roll_no):
1144
- result = search_student(roll_no)
1145
- updated_analytics = update_analytics_display()
1146
- return result, updated_analytics
1147
-
1148
- # Event handlers
1149
- search_btn.click(
1150
- fn=search_student_with_analytics,
1151
- inputs=roll_input,
1152
- outputs=[result_output, analytics_display]
1153
- )
1154
- roll_input.submit(
1155
- fn=search_student_with_analytics,
1156
- inputs=roll_input,
1157
- outputs=[result_output, analytics_display]
1158
- )
1159
  system_btn.click(fn=get_system_info, outputs=system_output)
1160
 
1161
  # Footer section
@@ -1187,24 +1083,6 @@ with gr.Blocks(
1187
  elem_id="footer"
1188
  )
1189
 
1190
- # System info initialization function
1191
- def initialize_system_info():
1192
- """Initialize system information display and increment visit count"""
1193
- increment_visit_count()
1194
- try:
1195
- result = get_system_info()
1196
- updated_analytics = update_analytics_display()
1197
- return result, updated_analytics
1198
- except Exception as e:
1199
- print(f"⚠️ Error initializing system info: {str(e)}")
1200
- return "⚠️ System information will be available after data loads completely.", update_analytics_display()
1201
-
1202
- # Load system info on startup and update analytics
1203
- app.load(
1204
- fn=initialize_system_info,
1205
- outputs=[system_output, analytics_display]
1206
- )
1207
-
1208
  # Launch the app
1209
  if __name__ == "__main__":
1210
  print("🚀 Launching Gradio interface...")
 
21
  # Scopes (read-only)
22
  SCOPES = ["https://www.googleapis.com/auth/spreadsheets.readonly"]
23
 
 
 
 
 
 
 
24
  def authorize():
25
  creds = None
26
 
 
58
 
59
  return gspread.authorize(creds)
60
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
61
  # Function to get data from a specific sheet
62
  def get_sheet_data(spreadsheet, gid, sheet_name):
63
  try:
 
826
  # Convert roll number to uppercase for consistent searching
827
  roll_no = roll_no.strip().upper()
828
 
 
 
 
829
  # Get cached data (fast response, auto-refreshes every 12 hours)
830
  combined_df, studentwise_data, details_info, reward_points_df = get_cached_data()
831
 
 
951
  if not details_info:
952
  return "❌ No system information available"
953
 
 
 
 
954
  output = []
955
  output.append("=" * 80)
956
  output.append("SYSTEM INFORMATION")
957
  output.append("=" * 80)
958
+
959
  # Average Points
960
  if 'average_points' in details_info:
961
  output.append("\n🎯 AVERAGE REWARD POINTS BY YEAR:")
 
1004
 
1005
  return "\n".join(output)
1006
 
1007
+ # Create Gradio interface - SIMPLE LAYOUT WITHOUT ANALYTICS DISPLAY
 
 
 
 
 
 
1008
  with gr.Blocks(
1009
  title="Student Reward Points Check",
1010
  theme=gr.themes.Soft(),
1011
  ) as app:
1012
 
1013
+ # Simple Header
1014
+ gr.Markdown("# 🎓 Student Reward Points Check")
1015
+ gr.Markdown("### Search for student details including reward points and redemption dates")
1016
+ gr.Markdown("### எல்லா புகழும் இறைவனுக்கே 🕉 ☪")
1017
+ gr.Markdown("🕒 **Auto-Updates**: Data automatically refreshes when there is a change in Reward Points Sheet")
1018
+ gr.Markdown("### Fill this form for any Issue/Feedback: [Issue/Feedback Form](https://docs.google.com/forms/d/e/1FAIpQLScnl0udcN2pUDENHl45HIj5HZbvDuwZ0g2eepBbp8tJYg-NvQ/viewform)")
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1019
 
1020
  with gr.Tabs():
1021
  with gr.TabItem("🔍 Student Search"):
 
1034
  lines=50,
1035
  max_lines=60,
1036
  show_copy_button=True,
1037
+ autoscroll=False
 
1038
  )
1039
 
1040
  with gr.TabItem("ℹ️ System Information"):
 
1046
  show_copy_button=True,
1047
  autoscroll=False,
1048
  interactive=False,
1049
+ show_label=True
 
1050
  )
1051
 
1052
+ # Event handlers - simplified without analytics updates
1053
+ search_btn.click(fn=search_student, inputs=roll_input, outputs=result_output)
1054
+ roll_input.submit(fn=search_student, inputs=roll_input, outputs=result_output)
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1055
  system_btn.click(fn=get_system_info, outputs=system_output)
1056
 
1057
  # Footer section
 
1083
  elem_id="footer"
1084
  )
1085
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1086
  # Launch the app
1087
  if __name__ == "__main__":
1088
  print("🚀 Launching Gradio interface...")