Skip to content

Commit bea8897

Browse files
committed
Created methods for separating list items by sections and single questions
1 parent 3ea4495 commit bea8897

File tree

2 files changed

+107
-54
lines changed

2 files changed

+107
-54
lines changed

core/process.py

Lines changed: 106 additions & 53 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,20 @@
11
from typing import Union
2+
from pprint import pprint
23

34
class Process:
45

56
def __init__(self, file_path: str=None):
67
self.file_path = file_path
7-
self.list = []
8+
9+
self.cert_list = []
10+
self.submit_list = []
11+
self.conduct_list = []
12+
self.residency_list = []
13+
14+
self.consultant_list = []
15+
self.new_consultant_list = []
16+
self.concentration_list = []
17+
self.faculty_list = []
818

919
def read_spe_file(self) -> list:
1020

@@ -122,12 +132,21 @@ def remove_markdown_items(self, _list: list) -> list:
122132
'ISA','GS','SBT','SRE']
123133

124134
# Adding because it wasn't specified if needed
125-
_translate.append('CRS')
126-
_translate.append('RQS!AQ!ZZ!PARENT')
127-
_translate.append('DTP!196!')
128-
_translate.append('DTP!197!')
135+
_translate.append('CRS') # CRS work info
136+
_translate.append('RQS!AQ!ZZ!PARENT') # Parent education info, can't translate properly
137+
_translate.append('DTP!196!') # Start date for extra curriculars
138+
_translate.append('DTP!197!') # End date ^
129139
_translate.append('REF!PSM!')
130140
_translate.append('IN2!18!')
141+
_translate.append('RQS!AQ!ZZ!CTRY SPOUSE!!') # Spouse info
142+
_translate.append('RQS!AQ!ZZ!CTRY CHILD') # Child info
143+
_translate.append('RQS!AQ!ZZ!TEST1 SENT!') # GRE Test scores that aren't used
144+
_translate.append('RQS!AQ!ZZ!TEST2 SENT!') # ^
145+
_translate.append('RQS!AQ!ZZ!SPOKEN LANGUAGES!!') # Languages spoken, not translated anymore
146+
_translate.append('RQS!AQ!ZZ!OPTIONAL MODULES!!') # Extra course moudles info, not needed
147+
_translate.append('RQS!AQ!ZZ!CUR COLLEGE') # Current college course work, not needed
148+
_translate.append('RQS!AQ!ZZ!ALIEN APP/INT\\') # Always empty, remove
149+
_translate.append('RQS!AQ!ZZ!FAMILY!!') # Can't properly translate, remove
131150

132151
for sublist in _list:
133152
sublist[:] = [item for item in sublist if not any(str(item).startswith(remove) for remove in _translate)]
@@ -225,67 +244,101 @@ def rearrange_list(self, _list: list) -> list:
225244
print(len(_list))
226245
return _list
227246

247+
def separate_list_section(self, apps: list, start: tuple, end: str, end_lines: int, separate_list: list) -> None:
248+
249+
start_idx = 0
250+
change_check_flag = 0
251+
252+
for idx, items in enumerate(apps):
253+
if str(items).startswith(start) and change_check_flag == 0:
254+
start_idx = idx
255+
change_check_flag = 1
256+
elif str(items).startswith(end):
257+
if change_check_flag != 0:
258+
# raise IndexError('Could not find a start point to separate.')
259+
separate_list.append(apps[start_idx:idx+end_lines])
260+
for remove in range((idx+end_lines)-start_idx):
261+
apps.pop(start_idx)
262+
else:
263+
separate_list.append([])
264+
265+
def separate_list_question(self, apps: list, app_idx: int, start: list, end_lines: int, separate_list: list) -> None:
266+
267+
change_check_flag = 0
268+
269+
for idx, items in enumerate(apps):
270+
if str(items).startswith(start) or str(items).endswith(start):
271+
change_check_flag = 1
272+
273+
while not str(apps[idx+end_lines]).startswith('MSG!'):
274+
end_lines = end_lines - 1
275+
276+
separate_list.append((apps[idx:idx+end_lines+1], app_idx))
277+
278+
for remove in range((idx+end_lines+1)-idx):
279+
apps.pop(idx)
280+
281+
if change_check_flag == 0:
282+
separate_list.append([])
283+
284+
def merge_list_question(self, separate_list: list) -> list:
285+
286+
# Dictionary to group sublists by their ending number
287+
grouped_data = {}
288+
289+
for sublist, group_num in separate_list:
290+
if group_num not in grouped_data:
291+
grouped_data[group_num] = []
292+
grouped_data[group_num].append(sublist)
293+
294+
# Convert dictionary values to a list of lists
295+
return list(grouped_data.values())
296+
228297
def new_rearrange_list(self, _list: list, app_type: str) -> list:
229298

230299
new_list = []
231300

232-
cert_list_holder = []
233-
conduct_list_holder = []
234-
submit_transmit_app = []
235-
residency_list_holder = []
236-
237301
_types = self.find_app_types(_list)
238302

239303
# Focuses on only one app_type at a time
240304
for idx, app in enumerate(_types):
241305
if app == app_type:
242306
new_list.append(_list[idx])
243307

244-
# Remove the sections of each list to move easily relocate later
245308
for idx, apps in enumerate(new_list):
246-
cert_idx = 0
247-
conduct_idx = 0
248-
semester_idx = 0
249-
for idx, items in enumerate(apps):
250-
# Capturing Cert Questions
251-
if str(items).startswith('RQS!AQ!ZZ!FERPA CERT SWITCH!'):
252-
cert_idx = idx
253-
elif str(items).startswith('RQS!AQ!ZZ!TRUTH CERT SWITCH!'):
254-
cert_list_holder.append(apps[cert_idx: idx+1])
255-
for idx in range((idx+1)-cert_idx):
256-
apps.pop(cert_idx)
257-
# Capturing Conduct Questions
258-
elif str(items).startswith('RQS!AQ!ZZ!$ 4!!'):
259-
conduct_idx = idx
260-
elif str(items).startswith('RQS!AQ!ZZ!$ 11!!'):
261-
conduct_list_holder.append(apps[conduct_idx:idx+5])
262-
for idx in range((idx+5)-conduct_idx):
263-
apps.pop(conduct_idx)
264-
# Capturing SUBMIT/TRANSMIT times and Major|Term Information
265-
elif str(items).startswith('SSE!'):
266-
semester_idx = idx
267-
elif str(items).startswith('RQS!AQ!ZZ!APP SUBMIT/TRANSMIT!!'):
268-
submit_transmit_app.append(apps[semester_idx:idx+1])
269-
for idx in range((idx+1)-semester_idx):
270-
apps.pop(semester_idx)
271-
# Capturing Residency Questions
272-
elif str(items).startswith('RQS!AQ!ZZ!RES:'):
273-
print(items)
274-
residency_list_holder.append(items)
309+
self.separate_list_section(apps, 'RQS!AQ!ZZ!FERPA CERT SWITCH!', 'RQS!AQ!ZZ!TRUTH CERT SWITCH!', 1, self.cert_list)
310+
self.separate_list_section(apps, 'SSE!', 'RQS!AQ!ZZ!APP SUBMIT/TRANSMIT!!', 1, self.submit_list)
311+
self.separate_list_section(apps, ('RQS!AQ!ZZ!$ 4!!', 'RQS!AQ!ZZ!$ 9!!'), 'RQS!AQ!ZZ!$ 11!!', 5, self.conduct_list)
312+
self.separate_list_section(apps, ('RQS!AQ!ZZ!RES: PREVIOUS ENROLLMENT!!'), 'RQS!AQ!ZZ!RES: DETERM!', 1, self.residency_list)
313+
self.separate_list_question(apps, idx, ('Consultant Agency\\', 'Consultant/Agency\\'), 3, self.consultant_list)
314+
self.new_consultant_list = self.merge_list_question(self.consultant_list)
315+
self.separate_list_question(apps, idx, 'RQS!AQ!ZZ!$ 1!!', 4, self.concentration_list)
316+
self.separate_list_question(apps, idx, 'Faculty Mentor\\', 4, self.faculty_list)
317+
318+
pprint(self.new_consultant_list)
319+
print(len(self.new_consultant_list))
320+
# print(len(self.faculty_list))
321+
# print(len(self.concentration_list))
322+
# pprint(new_list[4])
323+
# print(len(new_list))
324+
325+
# for apps in new_list:
326+
# print(len(apps))
275327

276328
# Relocate each item in the separated list into the proper index
277-
for idx, apps in enumerate(new_list):
278-
for items in submit_transmit_app[idx]:
279-
apps.insert(0, items)
280-
# for items in residency_list_holder[idx]:
281-
# apps.append(items)
282-
for items in conduct_list_holder[idx]:
283-
apps.append(items)
284-
for items in cert_list_holder[idx]:
285-
apps.append(items)
286-
287-
from pprint import pprint
288-
#pprint(residency_list_holder)
289-
pprint(new_list)
329+
# for idx, apps in enumerate(new_list):
330+
# for items in submit_transmit_app[idx]:
331+
# apps.insert(0, items)
332+
# # for items in residency_list_holder[idx]:
333+
# # apps.append(items)
334+
# for items in conduct_list_holder[idx]:
335+
# apps.append(items)
336+
# for items in cert_list_holder[idx]:
337+
# apps.append(items)
338+
339+
# from pprint import pprint
340+
# pprint(residency_list_holder)
341+
# pprint(new_list[15])
342+
# print(len(new_list))
290343

291344
return new_list

main.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -65,7 +65,7 @@ def run(file_path: str, filename: str) -> None:
6565
spe_list = p.read_spe_file()
6666

6767
clean_list = p.remove_markdown_items(spe_list)
68-
new_list = p.new_rearrange_list(clean_list, 'U.S. Freshman Admission')
68+
new_list = p.new_rearrange_list(clean_list, 'International Graduate Admission')
6969
# new_list = p.rearrange_list(clean_list)
7070

7171
# translated_spe = []

0 commit comments

Comments
 (0)