当前位置: 首页>>代码示例>>Python>>正文


Python Semester.range方法代码示例

本文整理汇总了Python中coredata.models.Semester.range方法的典型用法代码示例。如果您正苦于以下问题:Python Semester.range方法的具体用法?Python Semester.range怎么用?Python Semester.range使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在coredata.models.Semester的用法示例。


在下文中一共展示了Semester.range方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。

示例1: get_timeline

# 需要导入模块: from coredata.models import Semester [as 别名]
# 或者: from coredata.models.Semester import range [as 别名]
def get_timeline(emplid, verbose=False):
    """
        For the student with emplid, 
        Get a list of programs, start and end semester
        [{'program_code':'CPPHD', 'start':1111, 'end':1137, 'on leave':['1121', '1124']) ]
        
        * will include an 'adm_appl_nbr' if an admission record can be found with that program
    """
    programs = get_student_programs(emplid) 
    
    if verbose:
        print "----------"
        for program in programs:
            print program

    # calculate start and end date for programs
    prog_dict = {}
    for program_code, strm, unt_taken in programs: 
        if program_code not in prog_dict:
            prog_dict[program_code] = {'start':'9999', 'end':'1111', 'not_on_leave':[]}
        if int(strm) < int(prog_dict[program_code]['start']):
            prog_dict[program_code]['start'] = strm
        elif int(strm) > int(prog_dict[program_code]['end']):
            prog_dict[program_code]['end'] = strm
        if float(unt_taken) >= 0.1: 
            prog_dict[program_code]['not_on_leave'].append(strm)

    if verbose:
        print "----------"
        for key, val in prog_dict.iteritems():
            print key, val

    # calculate on-leave semesters
    on_leave_semesters = [strm for strm, reason in get_on_leave_semesters(emplid)]

    try:
        for program_code, program_object in prog_dict.iteritems():
            prog_dict[program_code]['on_leave'] = []
            semesters = Semester.range( program_object['start'], program_object['end'] )
            for semester in semesters:
                if (int(semester) <= int(Semester.current().name) and
                    (semester in on_leave_semesters or 
                    semester not in program_object['not_on_leave'])):
                    prog_dict[program_code]['on_leave'].append(semester)
            prog_dict[program_code]['on_leave'].sort()
    except Semester.DoesNotExist:
        print "Semester out of range", program_object['start'], program_object['end']
        return {}

    # put the programs in a list, sorted by start date
    programs = []
    for program_code, program_object in prog_dict.iteritems():
        del program_object['not_on_leave']
        program_object['program_code'] = program_code
        programs.append(program_object) 
    programs = sorted( programs, key= lambda x : int(x['start']) )

    if verbose: 
        print "----------"
        for program in programs:
            print program

    # how did it end?
    for program in programs:
        hdie = get_end_of_degree(emplid, program['program_code'], program['start'])
        if hdie: 
            program['how_did_it_end'] = { 'code':hdie[0], 
                                          'reason':hdie[1],
                                          'date':hdie[2],
                                          'semester': str(Semester.get_semester(hdie[2]).name) } 
            if int(program['how_did_it_end']['semester']) < int(program['end']):
                program['end'] = program['how_did_it_end']['semester']
        
    # for every previous program, create an end-date and cut off all on-leave semesters
    # at the beginning of the next program in the list. 

    for program, next_program in pairs(programs):
        if int(program['end']) > int(next_program['start']):
            program['end'] = next_program['start'] 
        for on_leave in program['on_leave']:
            if int(on_leave) > int(program['end']):
                program['on_leave'].remove(on_leave)
    
    # group the on-leave semesters
    for program in programs:
        on_leave = []
        if len(program['on_leave']) > 0:
            last_group = (program['on_leave'][0], program['on_leave'][0]) 
            last_group_pushed = False
            for semester in program['on_leave']:
                if semester in last_group or int(semester) > int(program['end']):
                    continue
                if semester == lazy_next_semester(last_group[1]):
                    last_group = ( last_group[0], semester )
                    last_group_pushed = False
                else: 
                    on_leave.append(last_group)
                    last_group = (semester, semester) 
                    last_group_pushed = True
            if not last_group_pushed: 
#.........这里部分代码省略.........
开发者ID:avacariu,项目名称:coursys,代码行数:103,代码来源:queries.py


注:本文中的coredata.models.Semester.range方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。