示例#1
0
def courses(courseNum = None):
    '''Display courses student is in enrolled in or courses professor teaches'''
    if session.get('logged_in'):
        conn = queries.getConn('c9')
        bnumber = session.get('bnumber')
        instructor = queries.isInstructor(conn, bnumber)
        if courseNum:
            course = queries.findCourse(conn, courseNum)
            roster = queries.roster(conn, courseNum)
            session['courseNum'] = courseNum
            students = queries.allStudents(conn)
            psets = queries.getAssignments(conn, courseNum, bnumber)
            
            return render_template('roster.html', course = course, courseNum = courseNum, 
                                    roster = roster, psets = psets, students = students,
                                    logged_in = session['logged_in'], instructor = instructor)
                
        else:
            if instructor:
                courses = queries.courses(conn, bnumber)
            else:
                courses = queries.coursesStudent(conn, bnumber)
            return render_template('courses.html', courses = courses, 
            logged_in = session['logged_in'], instructor=instructor)
    else:
        flash('Need to login to access page')
        return index()
示例#2
0
def match():
    
    '''CRUX OF APPLICATION
        Not a sophisticated algorithm but matches students in the roster
    '''
    courseNum = request.args.get('courseNum')
    pid = request.args.get('pid')
    try:
        conn = queries.getConn('c9')
        curs = conn.cursor(MySQLdb.cursors.DictCursor)
        roster = queries.roster(conn, courseNum)
        matches = matching.match(roster)
        groupNums = list()
        for match in matches:
            
            allGroups = queries.allGroups(conn)
            groupNum = matching.groupNum(allGroups)
            check = curs.execute('''insert into groups(groupNum, pid, courseNum)
            values(%s, %s, %s)''',[groupNum, pid, courseNum])
            curs.execute('''insert into groupForPset(groupNum, bnumber)
            values(%s, %s)''',[groupNum, match])
        
            if matches[match]:
                curs.execute('''insert into groupForPset(groupNum, bnumber)
                values(%s, %s)''',[groupNum, matches[match]])
            groupNums.append(groupNum)
        return jsonify( {'error': False, 'match': matches, 'groupNum': groupNums})
    except Exception as err:
        return jsonify( {'error': True, 'err': str(err) } )
示例#3
0
def courses(courseNum=None):
    if courseNum:
        conn = queries.getConn('c9')
        course = queries.findCourse(conn, courseNum)
        roster = queries.roster(conn, courseNum)
        bnumber = session.get('bnumber')
        psets = queries.getAssignments(conn, courseNum, bnumber)
        return render_template('roster.html',
                               course=course,
                               roster=roster,
                               psets=psets)
    else:
        conn = queries.getConn('c9')
        courses = queries.courses(conn)
        return render_template('courses.html',
                               courses=courses,
                               logged_in=session['logged_in'])
示例#4
0
    ''' Algorithm that just matches people arbitrarly from roster'''
    matches = {}
    listResHall = []
    matched = set()
    for person in roster:
        listResHall.append(person['bnumber'])
    while len(listResHall) != 0:
        key = listResHall.pop()
        try:
            matches[key] = listResHall.pop()
        except:
            matches[key] = None
    return matches


def groupNum(groups):
    ''' Every group number needs to be unique and it autoincrements in table'''
    result = []
    for group in groups:
        result.append(group['groupNum'])
    return max(result) + 1


if __name__ == '__main__':
    conn = queries.getConn('c9')
    roster = queries.roster(conn, 13587)

    groups = queries.allGroups(conn)
    print(groupNum(groups))
    print(match(roster))