def main() -> int: parser = argparse.ArgumentParser() parser.add_argument("areas", nargs="+") parser.add_argument("--break", dest="break_on_err", action="store_true") parser.add_argument("--list", dest="list", action="store_true") parser.add_argument("-w", dest="workers", type=int, action="store", default=os.cpu_count()) args = parser.parse_args() longest = 0 for f in args.areas: longest = max(longest, len(f)) if args.list: print(f'{f.ljust(longest)}', file=sys.stderr) else: print(f'\r{f.ljust(longest)}', end='', file=sys.stderr) try: with open(f, "r", encoding="utf-8") as infile: area_def = yaml.load(stream=infile, Loader=yaml.SafeLoader) c = Constants(matriculation_year=200) AreaOfStudy.load(specification=area_def, c=c) except Exception: print('', file=sys.stderr) # print(ex, file=sys.stderr) traceback.print_exc(file=sys.stderr) if args.break_on_err: break print() return 0
def one(f: str, break_on_err: bool) -> None: with open(f, "r", encoding="utf-8") as infile: area_def = yaml.load(stream=infile, Loader=yaml.SafeLoader) c = Constants(matriculation_year=200) area = AreaOfStudy.load(specification=area_def, c=c) area.validate()
def test_audit__double_history_and_studio(): student: Dict[str, Any] = { 'areas': [ AreaPointer( code='140', status=AreaStatus.Declared, kind=AreaType.Major, name='Studio Art', degree='B.A.', dept='ART', gpa=None, terms_since_declaration=None, ), AreaPointer( code='135', status=AreaStatus.Declared, kind=AreaType.Major, name='Art History', degree='B.A.', dept='ART', gpa=None, terms_since_declaration=None, ), ], 'courses': [ course_from_str('DEPT 123'), ], } c = Constants(matriculation_year=2000) area = AreaOfStudy.load(c=c, student=Student.load( dict(areas=student['areas'], courses=student['courses'])), specification={ 'name': 'Art History Test', 'type': 'major', 'code': '140', 'degree': 'B.A.', 'result': { 'all': [{ 'course': 'DEPT 123' }], } }) messages = list( audit(area=area, student=Student.load( dict(areas=student['areas'], courses=student['courses'])))) result = messages[-1].result assert result.result.items[-1].result.items[-1].result.assertions[ 0].expected == 18
def main() -> None: parser = argparse.ArgumentParser() parser.add_argument('files', nargs='+') parser.add_argument('--insert', default=False, action='store_true') args = parser.parse_args() files: List[str] = args.files courses: Set[CourseReference] = set() buckets: Set[BucketReference] = set() for filepath in files: if not filepath.endswith('.yaml'): continue file: Path = Path(filepath) code = file.stem catalog = file.parent.stem if '-' in code or '.' in code: continue with open(file, "r", encoding="utf-8") as infile: area_spec = yaml.load(stream=infile, Loader=yaml.SafeLoader) area = AreaOfStudy.load(specification=area_spec, c=Constants(), all_emphases=True) for course in find_courses_in_rule(area.result): courses.add(CourseReference(code=code, course=course)) for limit in area.limit.limits: for bucket in find_buckets_in_clause(limit.where): buckets.add( BucketReference(code=code, catalog=catalog, bucket=bucket)) for bucket in find_buckets_in_rule(area.result): buckets.add( BucketReference(code=code, catalog=catalog, bucket=bucket)) if args.insert: insert_to_db(courses=courses, buckets=buckets) print('inserted') else: for course_ref in sorted(courses): print(f"course: {course_ref.code}:{course_ref.course}") for bucket_ref in sorted(buckets): print( f"{bucket_ref.code}:{bucket_ref.catalog}:{bucket_ref.bucket}")
from dp.data import course_from_str from dp.rule.query import iterate_item_set, QueryRule from dp import Constants from decimal import Decimal c = Constants(matriculation_year=2000) def test_count_courses_optimization(): courses = [ course_from_str('A 101'), course_from_str('B 101'), course_from_str('C 101'), ] rule = QueryRule.load(path=[], c=c, data={ 'from': 'courses', 'assert': { 'count(courses)': { '$gte': 2 } }, }) results = list(iterate_item_set(courses, rule=rule)) assert results == [ tuple([courses[0], courses[1]]), tuple([courses[0], courses[2]]),