Beispiel #1
0
def import_latest_semester(force=False):
    "Imports RPI data into the database."
    logger.debug('Importing latest semester: %s' % datetime.datetime.now().strftime('%A %x %X %f%Z'))
    notifier = SemesterNotifier()
    #ROCSRPIImporter().sync() # slower.. someone manually updates this I think?
    with commit_all_or_rollback():
        SISRPIImporter(notifier).sync(force=force)
    notifier.notify()
Beispiel #2
0
def import_latest_semester(force=False):
    "Imports RPI data into the database."
    logger.debug('Importing latest semester: %s' %
                 datetime.datetime.now().strftime('%A %x %X %f%Z'))
    notifier = SemesterNotifier()
    #ROCSRPIImporter().sync() # slower.. someone manually updates this I think?
    with commit_all_or_rollback():
        SISRPIImporter(notifier).sync(force=force)
    notifier.notify()
Beispiel #3
0
def import_all_semesters(force=False):
    from rpi_courses import list_sis_files, list_rocs_xml_files
    logger.debug('Importing ALL semesters: %s' % datetime.datetime.now().strftime('%A %x %X %f%Z'))
    notifier = SemesterNotifier()
    urls = []
    urls.extend(list_sis_files())
    urls.extend(list_rocs_xml_files())
    for url in urls:
        print url
        if 'rocs' in url:
            importer = ROCSRPIImporter(notifier)
        else:
            importer = SISRPIImporter(notifier)
        with commit_all_or_rollback():
            importer.sync(get_files=lambda *a, **k: [url])
    notifier.notify()
Beispiel #4
0
def import_all_semesters(force=False):
    from rpi_courses import list_sis_files, list_rocs_xml_files
    logger.debug('Importing ALL semesters: %s' %
                 datetime.datetime.now().strftime('%A %x %X %f%Z'))
    notifier = SemesterNotifier()
    urls = []
    urls.extend(list_sis_files())
    urls.extend(list_rocs_xml_files())
    for url in urls:
        print url
        if 'rocs' in url:
            importer = ROCSRPIImporter(notifier)
        else:
            importer = SISRPIImporter(notifier)
        with commit_all_or_rollback():
            importer.sync(get_files=lambda *a, **k: [url])
    notifier.notify()
Beispiel #5
0
def cache_conflicts(semester_year=None, semester_month=None, semester=None, sql=True, stdout=False):
    assert (semester_year and semester_month) or semester, "Semester year & month must be provided or the semester object."
    import sys
    # trash existing conflict data...
    if not semester:
        semester = courses.Semester.objects.get(year=semester_year, month=semester_month)

    with commit_all_or_rollback():
        # we don't want to increment IDs too quickly (ev 25 minutes)
        #SectionConflict.objects.filter(semester=semester).delete()
        Syncer = Synchronizer(SectionConflict, SectionConflict.objects.values_list('id', flat=True))

        sections = courses.Section.objects.select_related('course', 'semester') \
                .by_semester(semester).prefetch_periods()
        section_courses = dict_by_attr(sections, 'course')

        mapping = {}
        for id, sid1, sid2 in SectionConflict.objects.filter(semester=semester).values_list('id', 'section1', 'section2'):
            mapping[(sid1, sid2)] = id

        conflicts = []

        def log(msg):
            sys.stdout.write(msg)
            sys.stdout.flush()

        def perform_insert(conflicts):
            SectionConflict.objects.bulk_create(conflicts)

        count = 0
        for course1, course2 in itertools.combinations(section_courses.keys(), 2):
            for section1, section2 in itertools.product(section_courses[course1], section_courses[course2]):
                if section1.conflicts_with(section2):
                    if section1.id > section2.id:
                        section1, section2 = section2, section1

                    count += 1
                    if sql:
                        if count % 500 == 0:
                            perform_insert(conflicts)
                            conflicts = []
                            log('.')
                        if (section1.id, section2.id) not in mapping:
                            log('C')
                            conflicts.append(
                                SectionConflict(section1=section1, section2=section2, semester=semester)
                            )
                        else:
                            Syncer.exclude_id(mapping[(section1.id, section2.id)])
                    else:
                        log('C')
                        Syncer.get_or_create(
                            section1=section1,
                            section2=section2,
                            semester=semester,
                        )

        if sql and conflicts:
            log('C')
            perform_insert(conflicts)

        log('\n')
        Syncer.trim(semester=semester)
        log('\n')
Beispiel #6
0
 def handle(self, *args, **options):
     with commit_all_or_rollback():
         models.Selection.objects.all().update(api_cache='')
Beispiel #7
0
def cache_conflicts(semester_year=None,
                    semester_month=None,
                    semester=None,
                    sql=True,
                    stdout=False):
    assert (
        semester_year and semester_month
    ) or semester, "Semester year & month must be provided or the semester object."
    import sys
    # trash existing conflict data...
    if not semester:
        semester = courses.Semester.objects.get(year=semester_year,
                                                month=semester_month)

    with commit_all_or_rollback():
        # we don't want to increment IDs too quickly (ev 25 minutes)
        #SectionConflict.objects.filter(semester=semester).delete()
        Syncer = Synchronizer(
            SectionConflict,
            SectionConflict.objects.values_list('id', flat=True))

        sections = courses.Section.objects.select_related('course', 'semester') \
                .by_semester(semester).prefetch_periods()
        section_courses = dict_by_attr(sections, 'course')

        mapping = {}
        for id, sid1, sid2 in SectionConflict.objects.filter(
                semester=semester).values_list('id', 'section1', 'section2'):
            mapping[(sid1, sid2)] = id

        conflicts = []

        def log(msg):
            sys.stdout.write(msg)
            sys.stdout.flush()

        def perform_insert(conflicts):
            SectionConflict.objects.bulk_create(conflicts)

        count = 0
        for course1, course2 in itertools.combinations(section_courses.keys(),
                                                       2):
            for section1, section2 in itertools.product(
                    section_courses[course1], section_courses[course2]):
                if section1.conflicts_with(section2):
                    if section1.id > section2.id:
                        section1, section2 = section2, section1

                    count += 1
                    if sql:
                        if count % 500 == 0:
                            perform_insert(conflicts)
                            conflicts = []
                            log('.')
                        if (section1.id, section2.id) not in mapping:
                            log('C')
                            conflicts.append(
                                SectionConflict(section1=section1,
                                                section2=section2,
                                                semester=semester))
                        else:
                            Syncer.exclude_id(mapping[(section1.id,
                                                       section2.id)])
                    else:
                        log('C')
                        Syncer.get_or_create(
                            section1=section1,
                            section2=section2,
                            semester=semester,
                        )

        if sql and conflicts:
            log('C')
            perform_insert(conflicts)

        log('\n')
        Syncer.trim(semester=semester)
        log('\n')