-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathMain.py
More file actions
247 lines (228 loc) · 13.5 KB
/
Copy pathMain.py
File metadata and controls
247 lines (228 loc) · 13.5 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
import datetime as dt
import DoD_Report_Scan as ReportScan
import sys
import pandas as pd
import os
def main_menu():
while True:
report_data = ReportScan.data
# Fill missing values in the 'Assingned Advisor: Full Name' column with 'Unknown'.
report_data['Assigned Advisor: Full Name'].fillna('Unknown', inplace=True)
# Filter out grad students based on 'course' which will include "DE8W".
# Filter out hybrid students based on 'allies' containing "Hudnor" or "Konya".
report_data = report_data[~report_data['course'].str.contains('DE8W', na=False)]
report_data = report_data[~report_data['allies'].str.contains('Hudnor', na=False)]
report_data = report_data[~report_data['allies'].str.contains('Konya', na=False)]
# Print the menu for the user to select an advisor by name or number in a list, including the "Incoming Team" advisor name.
# Sort the advisor list alphabetically.
advisor_list = list(report_data['Assigned Advisor: Full Name'].unique())
advisor_list.sort()
if 'Incoming Team' not in advisor_list:
advisor_list.append('Incoming Team')
print("Select an advisor:")
for i, advisor in enumerate(advisor_list):
print(f"{i+1}. {advisor}")
# Take user input for the advisor name or number and loop until a valid advisor is selected.
while True:
advisor_input = input("Enter the advisor name or number: ")
if advisor_input.isdigit():
advisor = advisor_list[int(advisor_input)-1]
break
elif advisor_input in advisor_list:
advisor = advisor_input
break
else:
print("Invalid advisor name or number. Please try again.")
# Print the menu for the user to select an option for the selected advisor.
while True:
print(f"\nSelected Advisor: {advisor}")
print("1. Check for students who have not participated in their course(s) in the past 5 days and have course 0s and/or missing assignments.")
print(f"2. See all students for {advisor}.")
print(f"3. List all students whose ally did not match their Assigned Advisor for {advisor}")
print(f"4. Check students with blank LDA's for {advisor}.")
print(f"5. Check students with Course and Section mismatches for {advisor}.")
print("6. Enter '6' to go back and select a different advisor.")
print("7. Enter '7' to exit the program.")
# Take user input for the option and loop until a valid option is selected.
option_input = input("Enter option number: ")
try:
option = int(option_input)
if option in [1, 2, 3, 4, 5, 6, 7]:
process_option(option, advisor, report_data)
else:
print("Invalid option. Please enter a valid option number.")
except ValueError:
print("Invalid option. Please enter a valid option number.")
def process_option(option, advisor, report_data):
if option == 1:
# Check for students who have not participated in the past 5 days and have course 0s and/or missing assignments.
# Print LDA in chronological order for each student, oldest at the top.
students = report_data[(report_data['Assigned Advisor: Full Name'] == advisor) & ((report_data['course zero assignments'] > 0) | (report_data['course missing assignments'] > 0)) & (report_data['course lda'] != '')]
students = students.sort_values(by='course lda')
if students.empty:
print(f"\nNo students with blank LDA's for {advisor}.")
main_menu()
else:
print("Students who have not participated in their course(s) in the past 5 days and have course 0s and/or missing assignments:")
print("---------------------------------------------------------------------------------------------------------------")
for _, student in students.iterrows():
course_lda = student['course lda']
course_lda_date = dt.datetime.strptime(course_lda, '%Y-%m-%d %H:%M:%S+00:00')
current_date = dt.datetime.now()
days_since_lda = (current_date - course_lda_date).days
if days_since_lda >= 5:
print(f"Name: {student['student']}")
print(f"Unity ID: {student['Unity ID']}")
print(f"Course: {student['course']}")
print(f"Unity Email: {student['email']}")
print(f"Personal Email: {student['Personal Email']}")
print(f"Course LDA: {student['course lda']}")
print("-----------------------------------------------------------------------------------------------------------------")
export_data(students)
elif option == 2:
# See all students for the selected advisor.
students = report_data[report_data['Assigned Advisor: Full Name'] == advisor]
students = students.sort_values(by='student')
print(f"\n All students for {advisor}:")
if students.empty:
print(f"\nNo students with blank LDA's for {advisor}.")
main_menu()
else:
print("---------------------------------------------------------------------------------------------------------------")
count = students['student'].count()
for _, student in students.iterrows():
course_lda = student['course lda']
if pd.isna(course_lda) or course_lda == '':
course_lda = 'blank'
print(f"Name: {student['student']}")
print(f"Unity ID: {student['Unity ID']}")
print(f"Course: {student['course']}")
print(f"Unity Email: {student['email']}")
print(f"Personal Email: {student['Personal Email']}")
print(f"Course LDA: {student['course lda']}")
print("-----------------------------------------------------------------------------------------------------------------")
print(f"Total: {count} students.")
export_data(students)
elif option == 3:
# List Ally Mismatch students for the selected advisor.
# Count 'Ally Mismatch' students.
students = report_data[(report_data['ally'] == 'Ally Mismatch') & (report_data['Assigned Advisor: Full Name'] == advisor)]
students = students.sort_values(by='student')
if students.empty:
print(f"\nNo students with blank LDA's for {advisor}.")
main_menu()
else:
print(f"\nStudents whose ally did not match their Assigned Advisor for {advisor}:")
print("---------------------------------------------------------------------------------------------------------------")
count = students['student'].count()
for _, student in students.iterrows():
course_lda = student['course lda']
if pd.isna(course_lda) or course_lda == '':
course_lda = 'blank'
print(f"Name: {student['student']}")
print(f"Unity ID: {student['Unity ID']}")
print(f"Ally: {student['original ally']}")
print(f"Assigned Advisor: {student['Assigned Advisor: Full Name']}")
print("-----------------------------------------------------------------------------------------------------------------")
print(f"Total: {count} students.")
export_report(students)
elif option == 4:
students = report_data[(report_data['course lda'].isna()) & (report_data['Assigned Advisor: Full Name'] == advisor)]
students = students.sort_values(by='student')
if students.empty:
print(f"\nNo students with blank LDA's for {advisor}.")
main_menu()
else:
print(f"\nStudents with blank LDA's for {advisor}:")
print("---------------------------------------------------------------------------------------------------------------")
for _, student in students.iterrows():
print(f"Name: {student['student']}")
print(f"Unity ID: {student['Unity ID']}")
print(f"Course: {student['course']}")
print(f"Unity Email: {student['email']}")
print(f"Personal Email: {student['Personal Email']}")
print("-----------------------------------------------------------------------------------------------------------------")
export_data(students)
# Check for course/section mismatches for students for the selected advisor by checking if all but two of the characters match in the 'course' column of the report_data.
# DE5W01.13.25_MBAQ315-01: DIVERSITY OF MARINE AND AQUATIC VEGETATION versus DE5W01.13.25_MBAQ315-02: DIVERSITY OF MARINE AND AQUATIC VEGETATION.
# These are the same course but different sections.
elif option == 5:
students = report_data[report_data['Assigned Advisor: Full Name'] == advisor]
mismatched_students = []
def is_same_course_different_section(course1, course2):
# Assuming the section is the last part after the last hyphen
base_course1 = course1.rsplit('-', 1)[0]
base_course2 = course2.rsplit('-', 1)[0]
return base_course1 == base_course2 and course1 != course2
grouped_students = students.groupby('Unity ID')
for unity_id, group in grouped_students:
if len(group) > 1:
for i, student1 in group.iterrows():
for j, student2 in group.iterrows():
if i >= j:
continue
if is_same_course_different_section(student1['course'], student2['course']):
mismatched_students.append(student1)
mismatched_students.append(student2)
mismatched_students = pd.DataFrame(mismatched_students).drop_duplicates().sort_values(by='student')
if mismatched_students.empty:
print(f"\nNo students with Course and Section mismatches for {advisor}.")
main_menu()
else:
print(f"\nStudents with Course and Section mismatches for {advisor}:")
print("---------------------------------------------------------------------------------------------------------------")
for _, student in mismatched_students.iterrows():
print(f"Name: {student['student']}")
print(f"Unity ID: {student['Unity ID']}")
print(f"Course: {student['course']}")
print(f"Unity Email: {student['email']}")
print(f"Personal Email: {student['Personal Email']}")
print("-----------------------------------------------------------------------------------------------------------------")
export_data(mismatched_students)
elif option == 6:
main_menu()
elif option == 7:
print("Exiting program...")
sys.exit()
def export_data(data):
while True:
try:
# Define the path to the reports folder in the Downloads directory
downloads_path = os.path.join(os.path.expanduser("~"), "Downloads")
reports_folder = os.path.join(downloads_path, "Reports")
os.makedirs(reports_folder, exist_ok=True)
filename = input("Enter the filename to export the data (e.g., 'filename.csv'): ")
filename = os.path.join(reports_folder, filename)
# Select the specific columns to export
export_columns = ['student', 'Unity ID', 'course', 'email', 'Personal Email', 'course lda']
export_data = data[export_columns]
# Rename columns to match the desired headers
export_data.columns = ['Name', 'Unity ID', 'Course', 'Unity Email', 'Personal Email', 'Course LDA']
export_data.to_csv(filename, index=False)
print(f"Data exported to {filename}.")
main_menu()
except Exception as e:
print(f"Error exporting data: {e}. Please try again.")
def export_report(data):
while True:
try:
# Define the path to the reports folder in the Downloads directory
downloads_path = os.path.join(os.path.expanduser("~"), "Downloads")
reports_folder = os.path.join(downloads_path, "Reports")
os.makedirs(reports_folder, exist_ok=True)
filename = input("Enter the filename to export the report (e.g., 'filename.csv'): ")
filename = os.path.join(reports_folder, filename)
# Select the specific columns to export
export_columns = ['student', 'Unity ID', 'original ally', 'Assigned Advisor: Full Name']
export_data = data[export_columns]
# Rename columns to match the desired headers
export_data.columns = ['Name', 'Unity ID', 'Ally', 'Assigned Advisor']
export_data.to_csv(filename, index=False)
print(f"Report exported to {filename}.")
break
except Exception as e:
print(f"Error exporting report: {e}. Please try again.")
if __name__ == "__main__":
main_menu()
print("Exiting program...")
sys.exit()