def import_all_meeting_times(strm, extra_where='1=1', offering_map=None): if not offering_map: offering_map = crseid_offering_map(strm) db = SIMSConn() db.execute("""SELECT crse_id, class_section, strm, meeting_time_start, meeting_time_end, facility_id, mon,tues,wed,thurs,fri,sat,sun, start_dt, end_dt, stnd_mtg_pat FROM ps_class_mtg_pat WHERE strm=%s AND """ + extra_where, (strm,)) # keep track of meetings we've found, so we can remove old (non-importing semesters and changed/gone) found_mtg = set() for crse_id, class_section, strm, start, end, room, mon, tues, wed, thurs, fri, sat, sun, start_dt, end_dt, stnd_mtg_pat in db: try: offering = offering_map[(strm, crse_id, class_section)] except KeyError: continue # dates come in as strings from DB2/reporting DB start_dt = datetime.datetime.strptime(start_dt, "%Y-%m-%d").date() end_dt = datetime.datetime.strptime(end_dt, "%Y-%m-%d").date() if not start or not end: # some meeting times exist with no start/end time continue wkdays = [n for n, day in zip(range(7), (mon, tues, wed, thurs, fri, sat, sun)) if day == 'Y'] labtut_section, mtg_type = fix_mtg_info(class_section, stnd_mtg_pat) for wkd in wkdays: m_old = MeetingTime.objects.filter(offering=offering, weekday=wkd, start_time=start, end_time=end, labtut_section=labtut_section, room=room) if len(m_old) > 1: raise KeyError, "Already duplicate meeting: %r" % (m_old) elif len(m_old) == 1: # new data: just replace. m_old = m_old[0] if m_old.start_day == start_dt and m_old.end_day == end_dt and m_old.room == room \ and m_old.meeting_type == mtg_type and m_old.labtut_section == labtut_section: # unchanged: leave it. found_mtg.add(m_old.id) continue else: # it has changed: remove and replace. m_old.delete() m = MeetingTime(offering=offering, weekday=wkd, start_day=start_dt, end_day=end_dt, start_time=start, end_time=end, room=room, labtut_section=labtut_section) m.meeting_type = mtg_type m.save() found_mtg.add(m.id) # delete any meeting times we haven't found in the DB if extra_where == '1=1': MeetingTime.objects.filter(offering__semester__name=strm).exclude(id__in=found_mtg).delete()
def import_all_meeting_times(strm, extra_where='1=1', offering_map=None): if not offering_map: offering_map = crseid_offering_map(strm) db = SIMSConn() db.execute("""SELECT crse_id, class_section, strm, meeting_time_start, meeting_time_end, facility_id, mon,tues,wed,thurs,fri,sat,sun, start_dt, end_dt, stnd_mtg_pat FROM ps_class_mtg_pat WHERE strm=%s AND """ + extra_where, (strm,)) # keep track of meetings we've found, so we can remove old (non-importing semesters and changed/gone) found_mtg = set() for crse_id, class_section, strm, start, end, room, mon, tues, wed, thurs, fri, sat, sun, start_dt, end_dt, stnd_mtg_pat in db: try: offering = offering_map[(strm, crse_id, class_section)] except KeyError: continue if not start or not end: # some meeting times exist with no start/end time continue wkdays = [n for n, day in zip(list(range(7)), (mon, tues, wed, thurs, fri, sat, sun)) if day == 'Y'] labtut_section, mtg_type = fix_mtg_info(class_section, stnd_mtg_pat) for wkd in wkdays: m_old = MeetingTime.objects.filter(offering=offering, weekday=wkd, start_time=start, end_time=end, labtut_section=labtut_section, room=room) if len(m_old) > 1: raise KeyError("Already duplicate meeting: %r" % (m_old)) elif len(m_old) == 1: # new data: just replace. m_old = m_old[0] if m_old.start_day == start_dt and m_old.end_day == end_dt and m_old.room == room \ and m_old.meeting_type == mtg_type and m_old.labtut_section == labtut_section: # unchanged: leave it. found_mtg.add(m_old.id) continue else: # it has changed: remove and replace. m_old.delete() m = MeetingTime(offering=offering, weekday=wkd, start_day=start_dt, end_day=end_dt, start_time=start, end_time=end, room=room, labtut_section=labtut_section) m.meeting_type = mtg_type m.save() found_mtg.add(m.id) # delete any meeting times we haven't found in the DB if extra_where == '1=1': MeetingTime.objects.filter(offering__semester__name=strm).exclude(id__in=found_mtg).delete()
def import_meeting_times(offering): """ Import course meeting times """ db = SIMSConn() db.execute("SELECT meeting_time_start, meeting_time_end, facility_id, mon,tues,wed,thurs,fri,sat,sun, " "start_dt, end_dt, stnd_mtg_pat, class_section FROM ps_class_mtg_pat " "WHERE crse_id=%s and class_section like %s and strm=%s", ("%06i" % (int(offering.crse_id)), offering.section[0:2]+"%", offering.semester.name)) # keep track of meetings we've found, so we can remove old (non-importing semesters and changed/gone) found_mtg = set() for start,end, room, mon,tues,wed,thurs,fri,sat,sun, start_dt,end_dt, stnd_mtg_pat, class_section in db: # dates come in as strings from DB2/reporting DB start_dt = datetime.datetime.strptime(start_dt, "%Y-%m-%d").date() end_dt = datetime.datetime.strptime(end_dt, "%Y-%m-%d").date() if not start or not end: # some meeting times exist with no start/end time continue wkdays = [n for n, day in zip(range(7), (mon,tues,wed,thurs,fri,sat,sun)) if day=='Y'] labtut_section, mtg_type = fix_mtg_info(class_section, stnd_mtg_pat) for wkd in wkdays: m_old = MeetingTime.objects.filter(offering=offering, weekday=wkd, start_time=start, end_time=end, labtut_section=labtut_section, room=room) if len(m_old)>1: raise KeyError, "Already duplicate meeting: %r" % (m_old) elif len(m_old)==1: # new data: just replace. m_old = m_old[0] if m_old.start_day==start_dt and m_old.end_day==end_dt and m_old.room==room \ and m_old.meeting_type==mtg_type and m_old.labtut_section==labtut_section: # unchanged: leave it. found_mtg.add(m_old.id) continue else: # it has changed: remove and replace. m_old.delete() m = MeetingTime(offering=offering, weekday=wkd, start_day=start_dt, end_day=end_dt, start_time=start, end_time=end, room=room, labtut_section=labtut_section) m.meeting_type = mtg_type m.save() found_mtg.add(m.id) # delete any meeting times we haven't found in the DB MeetingTime.objects.filter(offering=offering).exclude(id__in=found_mtg).delete()