update cross listing / merge courses

This commit is contained in:
Coding with Peter 2023-05-01 11:07:30 -07:00
parent a63aa0798b
commit 4520a53116
2 changed files with 109 additions and 67 deletions

View File

@ -524,6 +524,9 @@ def combined_name(nic,L):
# string with prettier section numbers combined
if len(L) < 2:
return L[0]
return "/".join(L)
# old method of trying to shorten section numbers
if nic < 2:
return "/".join(L)
L_mod = [ x[nic:6] for x in L]
@ -531,14 +534,26 @@ def combined_name(nic,L):
new_name = "/".join(L_mod)
#print(nic, " ", L_mod)
return new_name
def all_equal2(iterator):
return len(set(iterator)) <= 1
"""
180 2023 Fall
179 2023 Summer
178 2023 Spring
177 2023 Winter
"""
def semester_cross_lister():
sem = "fa23"
term = 180
xlist_filename = f"cache/{sem}_crosslist.csv"
checkfile = codecs.open('cache/xlist_check.html','w','utf-8')
checkfile.write('<html><body><table>\n')
current_term = '178'
xlistfile = codecs.open('cache/sp23_crosslist.csv','r','utf-8').readlines()[1:]
current_term = 179
xlistfile = codecs.open(xlist_filename,'r','utf-8').readlines()[1:]
by_section = {}
by_group = defaultdict( list )
crn_to_canvasid = {}
@ -546,11 +561,7 @@ def semester_cross_lister():
crn_to_canvascode = {}
get_fresh = 0
if get_fresh:
c = getCoursesInTerm(178,0,0) # sp23
codecs.open('cache/courses_in_term_178.json','w','utf-8').write(json.dumps(c,indent=2))
else:
c = json.loads( codecs.open('cache/courses_in_term_178.json','r','utf-8').read() )
c = getCoursesInTerm(term,get_fresh,0)
for C in c:
if 'sis_course_id' in C and C['sis_course_id']:
@ -560,9 +571,9 @@ def semester_cross_lister():
# "Term","PrtTerm","xlstGroup","Subject","CrseNo","EffectCrseTitle","CRN","Session","SecSchdType","AttnMeth","MtgSchdType","MtgType","MaxEnroll","TotalEnroll","SeatsAvail","Bldg","Room","Units","LecHrs","LabHrs","HrsPerDay","HrsPerWk","TotalHrs","Days","D/E","Wks","BegTime","EndTime","StartDate","EndDate","LastName","FirstName","PercentResp"
for xc in xlistfile:
parts = xc.split(r',')
course = parts[3] + " " + parts[4]
group = parts[2]
crn = parts[6]
course = parts[2] + " " + parts[3]
group = parts[1]
crn = parts[5]
if crn in crn_to_canvasid:
cid = crn_to_canvasid[crn]
@ -590,15 +601,26 @@ def semester_cross_lister():
sects.sort()
nic = numbers_in_common(sects)
new_sec = combined_name(nic,sects)
new_name = by_group[y][0][4][0:-5] + new_sec
new_code = by_group[y][0][5][0:-5] + new_sec
# same dept?
depts_list = [ z[1].split(' ')[0] for z in by_group[y] ]
nums_list = list(set([ z[1].split(' ')[1] for z in by_group[y] ]))
if all_equal2(depts_list):
depts = depts_list[0]
nums = '/'.join(nums_list)
else:
depts = list(set(depts_list))
nums = by_group[y][0][1].split(' ')[1]
new_name = depts + nums + " " + ' '.join(by_group[y][0][4].split(' ')[1:-1]) + " " + new_sec
#new_name = by_group[y][0][4][0:-5] + new_sec
new_code = depts + nums + " " + new_sec
#new_code = by_group[y][0][5][0:-5] + new_sec
print(y)
print("\t", sects)
#print("\tThey share %i leading numbers" % nic)
print("\t", by_group[y])
print("\t", new_name)
print()
host_id = by_group[y][0][3]
sections = by_group[y][1:]
@ -609,6 +631,7 @@ def semester_cross_lister():
def xlist_ii(parasite_id,host_id,new_name,new_code):
print("Parasite id: ",parasite_id," Host id: ", host_id)
print("New name: ", new_name)
print("New code: ", new_code)
xyz = input("Perform cross list? Enter for yes, n for no: ")
if xyz != 'n':
uu = url + '/api/v1/courses/%s/sections' % parasite_id
@ -1250,7 +1273,70 @@ def remove_n_analytics(section=0):
print(" " + r3.text)
time.sleep(0.300)
"""
def xlist_cwe():
# cwe190 and wtrm290 get put into 1 shell
# cwe192 get put into another shell
this_sem_190_id = 17549 # they get 190s and 290s
this_sem_192_id = 17154 # they get 192s
this_sem_term = 180 # fa23
get_fresh = 0
sem_courses = getCoursesInTerm(this_sem_term, get_fresh, 0)
for search_string in ['CWE190','WTRM290']:
for R in sem_courses:
try:
if re.search(search_string, R['name']) and str(R['id']) != str(this_sem_190_id):
# use the course to get the section id
print ( R['name'] )
u = url + '/api/v1/courses/%i/sections' % R['id']
for S in fetch(u):
if (S['id']):
myanswer = input( "-> Should I crosslist: %i\t%s\tsection id: %i (y/n) " % (R['id'],R['name'],S['id'] ))
if myanswer=='y':
# cross list
v = url + "/api/v1/sections/%i/crosslist/%i" % (S['id'],this_sem_190_id)
res = requests.post(v, headers = header)
print( json.dumps( json.loads(res.text), indent=2) )
print()
except Exception as e:
print( "Caused a problem: " + str(e) + "\n" + str(R) + "\n" )
## Now the 192s
search_string = "CWE192"
for R in sem_courses:
try:
if re.search(search_string, R['name']) and str(R['id']) != str(this_sem_192_id):
# use the course to get the section id
print ( R['name'] )
u = url + '/api/v1/courses/%i/sections' % R['id']
for S in fetch(u):
if (S['id']):
myanswer = input( "-> Should I crosslist: %i\t%s\tsection id: %i (y/n) " % (R['id'],R['name'],S['id'] ))
if myanswer=='y':
# cross list
v = url + "/api/v1/sections/%i/crosslist/%i" % (S['id'],this_sem_192_id)
res = requests.post(v, headers = header)
print( json.dumps( json.loads(res.text), indent=2) )
print()
except Exception as e:
print( "Caused a problem: " + str(e) + "\n" + str(R) + "\n" )
def create_sandboxes():
@ -1304,6 +1390,11 @@ def set_ext_tools():
s = json.loads(requests.put(r, headers=header, params=data).text)
print(json.dumps(s,indent=2))
def quick_sem_course_list(term=180):
c = getCoursesInTerm(term,1,0)
c = sorted(c, key=lambda k: k['name'])
for C in c:
print(C['name'])
if __name__ == "__main__":
options = { 1: ['Cross check schedule with ztc responses',make_ztc_list] ,
@ -1335,7 +1426,8 @@ if __name__ == "__main__":
27: ['Fine tune term dates and winter session', course_dates_terms],
28: ['Cross list a semester from file', semester_cross_lister],
29: ['Check all courses & their sections in semester', all_semester_course_sanity_check],
#30: ['List latestart classes', list_latestarts ],
30: ['Quick course list', quick_sem_course_list ],
31: ['Cross list CWE courses', xlist_cwe],
# TODO wanted: group shell for each GP (guided pathway) as a basic student services gateway....
#
}

View File

@ -620,55 +620,6 @@ def hours_calc_pulldata(course_id=''):
def xlist_cwe():
this_sem_190_id = 15464 # they get 190s and 290s
this_sem_192_id = 15318 # they get 192s
this_sem_guid558 = 7592
#search_string = "290"
search_string = "192"
#search_string = "190"
the_course_id =this_sem_192_id # this_sem_190_id
this_sem_term = 176 # fa22
sem_cache_fn = 'cache/semester_courses_%s.json' % this_sem_term
docache = input("Use cache courses? (n = fetch fresh list) y/n: ")
# get all courses this semester. Filter to ___ sections
if docache != 'y':
t = url + \
'/api/v1/accounts/1/courses?enrollment_term_id=%i&perpage=100' % this_sem_term
sem_courses = fetch(t,1)
out_file = codecs.open(sem_cache_fn, 'w', 'utf-8')
out_file.write( json.dumps(sem_courses,indent=2) )
out_file.close()
else:
sem_courses = json.loads(codecs.open(sem_cache_fn,'r','utf-8').read())
for R in sem_courses:
try:
if re.search(search_string, R['name']) and str(R['id']) != str(the_course_id):
# use the course to get the section id
print ( R['name'] )
u = url + '/api/v1/courses/%i/sections' % R['id']
for S in fetch(u):
if (S['id']):
myanswer = input( "-> Should I crosslist: %i\t%s\tsection id: %i (y/n) " % (R['id'],R['name'],S['id'] ))
if myanswer=='y':
# cross list
v = url + "/api/v1/sections/%i/crosslist/%i" % (S['id'],the_course_id)
res = requests.post(v, headers = header)
print( json.dumps( json.loads(res.text), indent=2) )
print()
except Exception as e:
print( "Caused a problem: " + str(e) + "\n" + str(R) + "\n" )
@ -1360,7 +1311,6 @@ if __name__ == "__main__":
options = { 1: ['Print answers to a single survey question',survey_answer] ,
2: ['Collate survey answers',survey_organize] ,
3: ['X list CWE classes',xlist_cwe] ,
4: ['parse committees survey',cmtes] ,
5: ['job titles',job_titles] ,
6: ['fetch calendar events to conf_sessions db',cal] ,