コード例 #1
0
            course = courses[str(course)]
        else:
            course.creditHours = creditHours
            course.sectionIds = []
            course.titleId = bisectIndex(titles, title)
            course.descriptionId = bisectStartsWith(descriptions, description)
            course.tagIds = set()
            courses[str(course)] = course

        course.creditHours[0] = min(course.creditHours[0], creditHours[0])
        course.creditHours[1] = max(course.creditHours[1], creditHours[1])

        course.sectionIds.append(index)

        attributeText: str = description[len(descriptions[course.descriptionId]
                                             ):]
        if attributeText != '':
            tagText = ''.join(tagPattern.findall(attributeText))
            tagIds = [
                tags.index(tagCode.upper())
                for tagCode in tagCodePattern.findall(tagText)
            ]
            course.tagIds.update(tagIds)

    courses = list(courses.values())

    for course in courses:
        course.tagIds = list(course.tagIds)

    dataclassToJson(Course, courses, 'course')
コード例 #2
0
    if index != len(ls) and ls[index] == value:
        return index

    return -1


if __name__ == '__main__':
    departments = json.load(open('_department.raw.json', 'r'))
    buildings = json.load(open('building.json', 'r'))

    buildings = [b['code'] for b in buildings]

    for department in departments:
        buildingText: str = department['primaryLocation']

        try:
            duplets = re.match(r'(.+) \((\d{3}\w{3})\)', buildingText).groups()
            locationCode = duplets[1]
        except TypeError:
            locationCode = None

        department['buildingId'] = bisectIndex(buildings, locationCode)

    keys = [f.name for f in fields(Department)]
    departments = [
        Department(**{key: d[key]
                      for key in keys}) for d in departments
    ]

    dataclassToJson(Department, departments, 'department')
コード例 #3
0
        subjects[subject] = {'name': subject, 'courseIds': [index]}

    subjects2 = []
    for code, subject in subjects.items():
        subject['code'] = code

        courseIds: List[int] = subject['courseIds']
        courseIds.sort()

        # Coruse IDs are expected to be consecutive, so we can extract the range of it
        expectedCourseIds: List[int] = list(
            range(courseIds[0], courseIds[-1] + 1))

        if courseIds == expectedCourseIds:
            subject['courseIdStart'] = courseIds[0]
            subject['courseIdEnd'] = courseIds[-1] + 1
        else:
            raise ValueError(
                f'Course IDs for subject {code} is not consecutive. Expected {expectedCourseIds}, got {courseIds}.'
            )

        subjects2.append(subject)

    subjects = subjects2
    # print(subjects)

    keys = [f.name for f in fields(Subject)]
    subjects = [Subject(**{key: s[key] for key in keys}) for s in subjects]

    dataclassToJson(Subject, subjects, 'subject')
コード例 #4
0
import json
from dataclasses import dataclass

from util import dataclassToJson


@dataclass
class Tag:
    code: str
    name: str

    def __lt__(self, t):
        return self.code < t.code


# https://catalog.fit.edu/content.php?catoid=9&navoid=367
presetTags = [['CC', 'Cross-cultural'],
              ['CL', 'Computer Literacy Requirement'],
              ['COM', 'Communication Elective'], ['HON', 'Honors Sections'],
              ['HU', 'Humanities Elective'], ['LA', 'Liberal Arts Elective'],
              ['Q', 'Scholarly Inquiry Requirement'],
              ['SS', 'Social Science Elective']]

if __name__ == '__main__':
    tags = [
        Tag(code=presetTag[0], name=presetTag[1]) for presetTag in presetTags
    ]

    dataclassToJson(Tag, tags, 'tag')
コード例 #5
0
            day: str = days[i] if i < len(days) else None
            time: list = times[i] if i < len(times) else [0, 0]
            place: list = places[i] if i < len(places) else [None, None]

            buildingId = bisectIndex(buildings, place[0])
            if place[0] is not None and buildingId != -1:
                place[0] = buildingId

            schedules.append([
                day,  # Day string
                time[0],
                time[1],  # Start time, end time
                place[0],
                place[1]  # Building id | building code, room string
            ])
        section['schedules'] = schedules

        section['levelId'] = bisectIndex(levels, level)

        section['restrictionIds'] = [
            bisectIndex(restrictions, restriction)
            for restriction in section['restrictions']
        ]

        section['prerequisiteId'] = bisectIndex(prerequisites, prerequisite)

    keys = [f.name for f in fields(Section)]
    sections = [Section(**{key: s[key] for key in keys}) for s in sections]

    dataclassToJson(Section, sections, 'section')
コード例 #6
0
        if name != '' and bisectIndex(emails, email) == -1:
            employees.append({
                'name': name,
                'title': None,
                'email': email,
                'phone': None,
                'buildingId': None,
                'room': None,
                'departmentId': None
            })
            bisect.insort(emails, email)

    keys = [f.name for f in fields(Employee)]
    employees = [Employee(**{key: e[key] for key in keys}) for e in employees]

    dataclassToJson(Employee, employees, 'employee')

    # employees.sort()
    # values = [list(astuple(e)) for e in employees]

    # json.dump(
    #     [asdict(e) for e in employees],
    #     open('employee.json', 'w'),
    #     indent=4
    # )
    # json.dump(
    #     {'keys': keys, 'values': values},
    #     open('employee.min.json', 'w'),
    #     separators=(',', ':')
    # )
コード例 #7
0
        return -1

    index = bisect.bisect_left(ls, value)
    if index != len(ls) and ls[index] == value:
        return index

    return -1


if __name__ == '__main__':
    subjects: list = json.load(open('subject.json', 'r'))
    subjects = [
        subject['code']
        for subject in subjects
    ]

    courses: list = json.load(open('course2.json', 'r'))

    for course in courses:
        subjectCode: str = course['subject']
        subjectId = bisectIndex(subjects, subjectCode)
        course['subjectId'] = subjectId

    keys = [f.name for f in fields(Course)]
    courses = [
        Course(**{key: c[key] for key in keys})
        for c in courses
    ]

    dataclassToJson(Course, courses, 'course3', sort=False)