示例#1
0
def saveattendance():
    clsn = request.form["classname"].strip()
    term = request.form['term'].strip()
    nameParts = clsn.split("-")
    if request.form['absent'] != '':
        abss = request.form['absent'].strip().split('_')
    else:
        abss = []
    if request.form['late'] != '':
        lats = request.form['late'].strip().split('_')
    else:
        lats = []
    if request.form['excused'] != '':
        excs = request.form['excused'].strip().split('_')
    else:
        excs = []
    if request.form['exlates'] != '':
        exlates = request.form['exlates'].strip().split('_')
    else:
        exlates = []
    date = request.form['date'].strip()
    mydb = db.db()
    if session['teacher'] != mydb.getTeacher( (nameParts[0], nameParts[1], nameParts[2] ), term ):
        return 'false'
    mydb.setMassAttendance( (nameParts[0], nameParts[1], nameParts[2] ),
                    term, abss, lats, excs, exlates, date )
    return "done"
示例#2
0
    def get_from_keyword(word, n):
        conn = db()
        ts = []
        ps = []

        query = '''SELECT * FROM "Thread" WHERE "Heading" like '%''' + word + \
            '''%' AND "Site" = 0 AND "NumPosts" < 200 ORDER BY "NumPosts" DESC'''
        threads = conn.run_query(query)

        for thread in threads:
            ts.append(thread[0])

        for t in ts:
            posts = conn.get_posts_from_thread(t)
            added = 0
            for post in posts:
                if len(ps) < n and len(post[1]) > 200:
                    ps.append(post)
                    added += 1
            if len(ps) >= n:
                break

        conn.close_connection()

        return ps
示例#3
0
def saveattendance():
    clsn = request.form["classname"].strip()
    term = request.form['term'].strip()
    nameParts = clsn.split("-")
    if request.form['absent'] != '':
        abss = request.form['absent'].strip().split('_')
    else:
        abss = []
    if request.form['late'] != '':
        lats = request.form['late'].strip().split('_')
    else:
        lats = []
    if request.form['excused'] != '':
        excs = request.form['excused'].strip().split('_')
    else:
        excs = []
    if request.form['exlates'] != '':
        exlates = request.form['exlates'].strip().split('_')
    else:
        exlates = []
    date = request.form['date'].strip()
    mydb = db.db()
    if session['teacher'] != mydb.getTeacher(
        (nameParts[0], nameParts[1], nameParts[2]), term):
        return 'false'
    mydb.setMassAttendance((nameParts[0], nameParts[1], nameParts[2]), term,
                           abss, lats, excs, exlates, date)
    return "done"
示例#4
0
    def run_query():
        """
        Get threads that each key actor has been involved with across a number of relevant forums
        """
        conn = db()

        forums = [
            107, 326, 44, 176, 186, 277, 46, 203, 48, 205, 374, 299, 92, 106,
            10, 103, 91, 126, 339, 43, 114, 47, 113, 120, 70, 170, 4, 308
        ]
        for forum in forums:
            for user in get_threads.get_actors():
                query = 'SELECT DISTINCT t."IdThread", t."Heading", t."NumPosts", t."Author" FROM "Post" p INNER JOIN "Thread" t ON p."Thread" = t."IdThread" WHERE t."Author" = ' + \
                    str(user) + ' AND t."Forum" = ' + str(forum) + ';'
                records = conn.run_query(query)

                for r in records:
                    print(r)

                with open("threads.data", "a", encoding='utf8') as f:
                    for r in records:
                        f.write(
                            str(r[0]) + ' | ' + str(r[1]) + ' | ' + str(r[2]) +
                            ' | ' + str(r[3]) + '\n')

        conn.close_connection()
示例#5
0
def arrangeRandom():
    clsn = request.form["classname"].strip()
    term = request.form['term'].strip()
    nameParts = clsn.split("-")
    mydb = db.db()
    if session['teacher'] != mydb.getTeacher(
        (nameParts[0], nameParts[1], nameParts[2]), term):
        return 'false'

    cls = mydb.getClass((nameParts[0], nameParts[1], nameParts[2]), term)
    students = cls[0]['students']
    for i in range(100):
        s1 = students[randint(0, len(students) - 1)]
        s2 = students[randint(0, len(students) - 1)]
        r = s1['row']
        c = s1['col']
        s1['row'] = s2['row']
        s1['col'] = s2['col']
        s2['row'] = r
        s2['col'] = c
        mydb.setSeat((nameParts[0], nameParts[1], nameParts[2]), term,
                     s1['id'], s1['row'], s1['col'])
        mydb.setSeat((nameParts[0], nameParts[1], nameParts[2]), term,
                     s2['id'], s2['row'], s2['col'])
    return json.dumps(cls[0])
示例#6
0
def noncrime_dataset(n, save=False, load=False, string=False):
    """
    Produces a dataset of noncrime posts, or loads it from a file
    """
    def load_dataset():
        with open('nc.data', 'rb') as f:
            X = pickle.load(f)
        np.random.shuffle(X)
        return X

    pt = process_text_s if string else process_text

    conn = db()

    if load:
        return load_dataset()

    posts = []
    for post in conn.get_noncrime_posts(n):
        processed = pt(post[0])
        if len(processed) > 10:
            p = (processed, -1)
            posts.append(p)
    print(len(posts))
    conn.close_connection()
    X = np.stack(posts)

    if save:
        with open('nc.data', 'wb') as f:
            pickle.dump(X, f)

    np.random.shuffle(X)
    return X
示例#7
0
def getassignments():
    clsn = request.form["classname"].strip()
    term = request.form['term'].strip()
    nameParts = clsn.split("-")
    mydb = db.db()
    if session['teacher'] != mydb.getTeacher( (nameParts[0], nameParts[1], nameParts[2] ), term ):
        return 'false'
    assignments = mydb.getAssignments((nameParts[0],nameParts[1],nameParts[2]), term)
    return json.dumps( assignments )
示例#8
0
def collect_unlabelled_data(forum, number, string=False):
    conn = db()
    posts = []
    pt = process_text_s if string else process_text
    for post in conn.get_posts_from_forum(forum, number):
        p = (pt(post[0]), -1)
        posts.append(p)
    conn.close_connection()
    return posts
示例#9
0
def getinfo(): 
    clsn = request.form["classname"].strip()
    term = request.form['term'].strip()
    nameParts = clsn.split("-")
    mydb = db.db()
    if session['teacher'] != mydb.getTeacher( (nameParts[0], nameParts[1], nameParts[2] ), term ):
        return 'false'
    student = mydb.getStudent((nameParts[0], nameParts[1], nameParts[2] ), term, request.form['sid'])
    return json.dumps(student['students'])
示例#10
0
def changegrade():
    clsn = request.form["classname"].strip()
    term = request.form['term'].strip()
    nameParts = clsn.split("-")
    grades = json.loads(request.form['grades'].strip())
    mydb = db.db()
    if session['teacher'] != mydb.getTeacher( (nameParts[0], nameParts[1], nameParts[2] ), term ):
        return 'false'
    student = mydb.changeGrade((nameParts[0], nameParts[1], nameParts[2] ), term, request.form['sid'].strip(), request.form['atype'].strip(), grades)
    return json.dumps(student['students'])
示例#11
0
def removestudent():
    clsn = request.form["classname"].strip()
    term = request.form['term'].strip()
    nameParts = clsn.split("-")
    mydb = db.db()
    if session['teacher'] != mydb.getTeacher( (nameParts[0], nameParts[1], nameParts[2] ), term ):
        return 'false'
    mydb.removeStudent((nameParts[0], nameParts[1], nameParts[2]),term,
                        request.form['sid'].strip())
    return "done"
示例#12
0
def createassignmenttypr():
    clsn = request.form["classname"].strip()
    term = request.form['term'].strip()
    nameParts = clsn.split("-")
    atname = request.form['atname'].strip()
    mydb = db.db()
    if session['teacher'] != mydb.getTeacher( (nameParts[0], nameParts[1], nameParts[2] ), term ):
        return 'false'
    mydb.addAssignmentType((nameParts[0], nameParts[1], nameParts[2]),term,
                           atname)
    return 'done'
示例#13
0
def removestudent():
    clsn = request.form["classname"].strip()
    term = request.form['term'].strip()
    nameParts = clsn.split("-")
    mydb = db.db()
    if session['teacher'] != mydb.getTeacher(
        (nameParts[0], nameParts[1], nameParts[2]), term):
        return 'false'
    mydb.removeStudent((nameParts[0], nameParts[1], nameParts[2]), term,
                       request.form['sid'].strip())
    return "done"
示例#14
0
def getassignments():
    clsn = request.form["classname"].strip()
    term = request.form['term'].strip()
    nameParts = clsn.split("-")
    mydb = db.db()
    if session['teacher'] != mydb.getTeacher(
        (nameParts[0], nameParts[1], nameParts[2]), term):
        return 'false'
    assignments = mydb.getAssignments(
        (nameParts[0], nameParts[1], nameParts[2]), term)
    return json.dumps(assignments)
示例#15
0
def seated():
    clsn = request.form["classname"].strip()
    term = request.form['term'].strip()
    nameParts = clsn.split("-")
    mydb = db.db()
    if session['teacher'] != mydb.getTeacher( (nameParts[0], nameParts[1], nameParts[2] ), term ):
        return 'false'
    mydb.setSeated( (nameParts[0], nameParts[1], nameParts[2]), term,
                  request.form["seated"].strip(),
                  request.form['rows'].strip(), request.form['cols'].strip())
    return "seated set"
示例#16
0
def getbackupcsv():
    clsn = request.args.get('classname')
    term = request.args.get('term')
    nameParts = clsn.split("-")    
    mydb = db.db()
    if session['teacher'] != mydb.getTeacher( (nameParts[0], nameParts[1], nameParts[2] ), term ):
        return 'false'
    backup = mydb.getBackupCSV((nameParts[0], nameParts[1], nameParts[2]), term)
    response = make_response( backup )
    response.headers['Content-Disposition'] = 'attachment; filename=' + clsn + '-' + term + '-' + str(datetime.date.today()) + '.csv'
    return response
示例#17
0
def getinfo():
    clsn = request.form["classname"].strip()
    term = request.form['term'].strip()
    nameParts = clsn.split("-")
    mydb = db.db()
    if session['teacher'] != mydb.getTeacher(
        (nameParts[0], nameParts[1], nameParts[2]), term):
        return 'false'
    student = mydb.getStudent((nameParts[0], nameParts[1], nameParts[2]), term,
                              request.form['sid'])
    return json.dumps(student['students'])
示例#18
0
def seated():
    clsn = request.form["classname"].strip()
    term = request.form['term'].strip()
    nameParts = clsn.split("-")
    mydb = db.db()
    if session['teacher'] != mydb.getTeacher(
        (nameParts[0], nameParts[1], nameParts[2]), term):
        return 'false'
    mydb.setSeated((nameParts[0], nameParts[1], nameParts[2]), term,
                   request.form["seated"].strip(),
                   request.form['rows'].strip(), request.form['cols'].strip())
    return "seated set"
示例#19
0
def savegradeoptions():
    clsn = request.form["classname"].strip()
    term = request.form['term'].strip()
    nameParts = clsn.split("-")
    option = request.form['option'].strip()
    mydb = db.db()

    if session['teacher'] != mydb.getTeacher( (nameParts[0], nameParts[1], nameParts[2] ), term ):
        return 'false'
    
    mydb.saveGradeOptions((nameParts[0], nameParts[1], nameParts[2]),term, option)
    return "done";
示例#20
0
def backupreset():
    backup = request.files['backupfile']
    backup = backup.read()
    backup = json.loads(backup)
    clsn = backup['code'] + "-" + backup['section'] + '-' + backup['period']
    nameParts = clsn.split("-")    
    term = backup['term']
    mydb = db.db()
    if session['teacher'] != mydb.getTeacher( (nameParts[0], nameParts[1], nameParts[2] ), term ):
        return 'false'
    mydb.resetFromBackup(backup)
    return render_template("classview.html", clsname = clsn,trm = term )
示例#21
0
def getallbackupcsv():
    teacher = session['teacher']
    term = request.args.get('term')
    mydb = db.db();
    classes = mydb.getClasses(teacher, term)
    backup = ''
    for c in classes:
        backup+= mydb.getBackupCSV(c, term) + '\n\n'

    response = make_response( backup )
    response.headers['Content-Disposition'] = 'attachment; filename=' + teacher + '-' + term + '-' + str(datetime.date.today()) + '.csv'
    return response
示例#22
0
def changeweights():
    clsn = request.form["classname"].strip()
    term = request.form['term'].strip()
    nameParts = clsn.split("-")
    weights =  json.loads(request.form['weights'].strip())
    mydb = db.db()

    if session['teacher'] != mydb.getTeacher( (nameParts[0], nameParts[1], nameParts[2] ), term ):
        return 'false'
    mydb.changeWeights((nameParts[0], nameParts[1], nameParts[2]),term,
                        weights)
    return "done"
示例#23
0
def createassignmenttypr():
    clsn = request.form["classname"].strip()
    term = request.form['term'].strip()
    nameParts = clsn.split("-")
    atname = request.form['atname'].strip()
    mydb = db.db()
    if session['teacher'] != mydb.getTeacher(
        (nameParts[0], nameParts[1], nameParts[2]), term):
        return 'false'
    mydb.addAssignmentType((nameParts[0], nameParts[1], nameParts[2]), term,
                           atname)
    return 'done'
示例#24
0
def changegrade():
    clsn = request.form["classname"].strip()
    term = request.form['term'].strip()
    nameParts = clsn.split("-")
    grades = json.loads(request.form['grades'].strip())
    mydb = db.db()
    if session['teacher'] != mydb.getTeacher(
        (nameParts[0], nameParts[1], nameParts[2]), term):
        return 'false'
    student = mydb.changeGrade((nameParts[0], nameParts[1], nameParts[2]),
                               term, request.form['sid'].strip(),
                               request.form['atype'].strip(), grades)
    return json.dumps(student['students'])
示例#25
0
def backupallreset():
    backups = request.files['backupfile']
    backups = backups.read().strip().split('\n')    
    mydb = db.db()
    for b in backups:
        backup = json.loads(b)
        clsn = backup['code'] + "-" + backup['section'] + '-' + backup['period']
        nameParts = clsn.split("-")    
        term = backup['term']
        if session['teacher'] != mydb.getTeacher( (nameParts[0], nameParts[1], nameParts[2] ), term ):
            return 'false'
        mydb.resetFromBackup(backup)
    return render_template("selectclass.html", term = CURRENT_TERM)
示例#26
0
def changeweights():
    clsn = request.form["classname"].strip()
    term = request.form['term'].strip()
    nameParts = clsn.split("-")
    weights = json.loads(request.form['weights'].strip())
    mydb = db.db()

    if session['teacher'] != mydb.getTeacher(
        (nameParts[0], nameParts[1], nameParts[2]), term):
        return 'false'
    mydb.changeWeights((nameParts[0], nameParts[1], nameParts[2]), term,
                       weights)
    return "done"
示例#27
0
def getassignment():
    clsn = request.form["classname"].strip()
    term = request.form['term'].strip()
    nameParts = clsn.split("-")
    mydb = db.db()
    if session['teacher'] != mydb.getTeacher( (nameParts[0], nameParts[1], nameParts[2] ), term ):
        return 'false'
    try:
        assignment = mydb.getAssignment((nameParts[0],nameParts[1],nameParts[2]), term,
                                     request.form['aname'].strip())
        return json.dumps( assignment )
    except:
        return '{"grades":[]}'
示例#28
0
def gettoday():
    clsn = request.form["classname"].strip()
    term = request.form['term'].strip()
    nameParts = clsn.split("-")
    mydb = db.db()
    if session['teacher'] != mydb.getTeacher( (nameParts[0], nameParts[1], nameParts[2] ), term ):
        return 'false'
    a = mydb.getTodaysAttendance((nameParts[0], nameParts[1], nameParts[2]), term, request.form['date'].strip(), 'absent')
    l = mydb.getTodaysAttendance((nameParts[0], nameParts[1], nameParts[2]), term, request.form['date'].strip(), 'late')
    e = mydb.getTodaysAttendance((nameParts[0], nameParts[1], nameParts[2]), term, request.form['date'].strip(), 'excused')
    el = mydb.getTodaysAttendance((nameParts[0], nameParts[1], nameParts[2]), term, request.form['date'].strip(), 'exlate')
    d = {'absent':a, 'late':l, 'excused':e, 'exlate':el}
    return json.dumps(d)
示例#29
0
def backupreset():
    backup = request.files['backupfile']
    backup = backup.read()
    backup = json.loads(backup)
    clsn = backup['code'] + "-" + backup['section'] + '-' + backup['period']
    nameParts = clsn.split("-")
    term = backup['term']
    mydb = db.db()
    if session['teacher'] != mydb.getTeacher(
        (nameParts[0], nameParts[1], nameParts[2]), term):
        return 'false'
    mydb.resetFromBackup(backup)
    return render_template("classview.html", clsname=clsn, trm=term)
示例#30
0
def deletegrades():
    clsn = request.form["classname"].strip()
    term = request.form['term'].strip()
    nameParts = clsn.split("-")
    ids = json.loads(request.form['ids'])
    mydb = db.db()
    if session['teacher'] != mydb.getTeacher( (nameParts[0], nameParts[1], nameParts[2] ), term ):
        return 'false'
    print ids
    mydb.deleteAssignment( (nameParts[0], nameParts[1], nameParts[2] ),
                           term, ids,
                           request.form['aname'].strip(), request.form['atype'].strip()); 
    return "done"
示例#31
0
def backupallreset():
    backups = request.files['backupfile']
    backups = backups.read().strip().split('\n')
    mydb = db.db()
    for b in backups:
        backup = json.loads(b)
        clsn = backup['code'] + "-" + backup['section'] + '-' + backup['period']
        nameParts = clsn.split("-")
        term = backup['term']
        if session['teacher'] != mydb.getTeacher(
            (nameParts[0], nameParts[1], nameParts[2]), term):
            return 'false'
        mydb.resetFromBackup(backup)
    return render_template("selectclass.html", term=CURRENT_TERM)
示例#32
0
def deletegrades():
    clsn = request.form["classname"].strip()
    term = request.form['term'].strip()
    nameParts = clsn.split("-")
    ids = json.loads(request.form['ids'])
    mydb = db.db()
    if session['teacher'] != mydb.getTeacher(
        (nameParts[0], nameParts[1], nameParts[2]), term):
        return 'false'
    print ids
    mydb.deleteAssignment((nameParts[0], nameParts[1], nameParts[2]), term,
                          ids, request.form['aname'].strip(),
                          request.form['atype'].strip())
    return "done"
示例#33
0
def saveinfo():
    print request.form
    clsn = request.form["classname"].strip()
    term = request.form['term'].strip()
    nameParts = clsn.split("-")
    mydb = db.db()
    if session['teacher'] != mydb.getTeacher( (nameParts[0], nameParts[1], nameParts[2] ), term ):
        return 'false'
    student = mydb.saveInfo((nameParts[0], nameParts[1], nameParts[2]),
                            term,
                            request.form['sid'].strip(), request.form['nick'].strip(),
                            request.form['id'].strip(), request.form['email'].strip(),
                            request.form['stuyid'].strip(), request.form['hr'].strip())
    return json.dumps(student['students'])
示例#34
0
def savegradeoptions():
    clsn = request.form["classname"].strip()
    term = request.form['term'].strip()
    nameParts = clsn.split("-")
    option = request.form['option'].strip()
    mydb = db.db()

    if session['teacher'] != mydb.getTeacher(
        (nameParts[0], nameParts[1], nameParts[2]), term):
        return 'false'

    mydb.saveGradeOptions((nameParts[0], nameParts[1], nameParts[2]), term,
                          option)
    return "done"
示例#35
0
def getallbackupcsv():
    teacher = session['teacher']
    term = request.args.get('term')
    mydb = db.db()
    classes = mydb.getClasses(teacher, term)
    backup = ''
    for c in classes:
        backup += mydb.getBackupCSV(c, term) + '\n\n'

    response = make_response(backup)
    response.headers[
        'Content-Disposition'] = 'attachment; filename=' + teacher + '-' + term + '-' + str(
            datetime.date.today()) + '.csv'
    return response
示例#36
0
def addstudent():
    clsn = request.form["classname"].strip()
    term = request.form['term'].strip()
    nameParts = clsn.split("-")
    mydb = db.db()
    if session['teacher'] != mydb.getTeacher( (nameParts[0], nameParts[1], nameParts[2] ), term ):
        return 'false'
    mydb.addStudent( (nameParts[0], nameParts[1], nameParts[2] ),term,
                     request.form['first'].strip(), request.form['last'].strip(),
                     request.form['nick'].strip(), request.form['sid'].strip(), 
                     request.form['email'].strip(), int(request.form['row'].strip()),
                     int(request.form['col'].strip() ), request.form['stuyid'].strip(),
                     request.form['hr'].strip());
    return "done"
示例#37
0
def getassignment():
    clsn = request.form["classname"].strip()
    term = request.form['term'].strip()
    nameParts = clsn.split("-")
    mydb = db.db()
    if session['teacher'] != mydb.getTeacher(
        (nameParts[0], nameParts[1], nameParts[2]), term):
        return 'false'
    try:
        assignment = mydb.getAssignment(
            (nameParts[0], nameParts[1], nameParts[2]), term,
            request.form['aname'].strip())
        return json.dumps(assignment)
    except:
        return '{"grades":[]}'
示例#38
0
def getbackupcsv():
    clsn = request.args.get('classname')
    term = request.args.get('term')
    nameParts = clsn.split("-")
    mydb = db.db()
    if session['teacher'] != mydb.getTeacher(
        (nameParts[0], nameParts[1], nameParts[2]), term):
        return 'false'
    backup = mydb.getBackupCSV((nameParts[0], nameParts[1], nameParts[2]),
                               term)
    response = make_response(backup)
    response.headers[
        'Content-Disposition'] = 'attachment; filename=' + clsn + '-' + term + '-' + str(
            datetime.date.today()) + '.csv'
    return response
示例#39
0
def saveinfo():
    print request.form
    clsn = request.form["classname"].strip()
    term = request.form['term'].strip()
    nameParts = clsn.split("-")
    mydb = db.db()
    if session['teacher'] != mydb.getTeacher(
        (nameParts[0], nameParts[1], nameParts[2]), term):
        return 'false'
    student = mydb.saveInfo(
        (nameParts[0], nameParts[1], nameParts[2]), term,
        request.form['sid'].strip(), request.form['nick'].strip(),
        request.form['id'].strip(), request.form['email'].strip(),
        request.form['stuyid'].strip(), request.form['hr'].strip())
    return json.dumps(student['students'])
示例#40
0
def savegrades():
    clsn = request.form["classname"].strip()
    term = request.form['term'].strip()
    nameParts = clsn.split("-")
    g = json.loads(request.form['grades'].strip())
    mydb = db.db()
    if session['teacher'] != mydb.getTeacher( (nameParts[0], nameParts[1], nameParts[2] ), term ):
        return 'false'

    mydb.setMassGrades( (nameParts[0], nameParts[1], nameParts[2] ),
                        term,
                        request.form['aname'].strip(), request.form['atype'].strip(), 
                        request.form['apublic'].strip(),
                        float(request.form['points'].strip()), g);
    return "done"
示例#41
0
def loadclass():
    clsn = request.form["classname"].strip()
    term = request.form['term'].strip()
    nameParts = clsn.split("-")
    mydb = db.db()
    if session['teacher'] != mydb.getTeacher( (nameParts[0], nameParts[1], nameParts[2] ), term ):
        return 'false'
    
    markUsage( session['teacher'] )
    cls = mydb.getClass( (nameParts[0], nameParts[1], nameParts[2] ), term )
    try:
        mydb.resizeClass( (nameParts[0], nameParts[1], nameParts[2] ),
                          term, request.form["rows"].strip(), request.form["cols"].strip())
    except KeyError:
        pass
    return json.dumps( cls[0] )
示例#42
0
def savegrades():
    clsn = request.form["classname"].strip()
    term = request.form['term'].strip()
    nameParts = clsn.split("-")
    g = json.loads(request.form['grades'].strip())
    mydb = db.db()
    if session['teacher'] != mydb.getTeacher(
        (nameParts[0], nameParts[1], nameParts[2]), term):
        return 'false'

    mydb.setMassGrades((nameParts[0], nameParts[1], nameParts[2]), term,
                       request.form['aname'].strip(),
                       request.form['atype'].strip(),
                       request.form['apublic'].strip(),
                       float(request.form['points'].strip()), g)
    return "done"
示例#43
0
def addstudent():
    clsn = request.form["classname"].strip()
    term = request.form['term'].strip()
    nameParts = clsn.split("-")
    mydb = db.db()
    if session['teacher'] != mydb.getTeacher(
        (nameParts[0], nameParts[1], nameParts[2]), term):
        return 'false'
    mydb.addStudent((nameParts[0], nameParts[1], nameParts[2]), term,
                    request.form['first'].strip(),
                    request.form['last'].strip(), request.form['nick'].strip(),
                    request.form['sid'].strip(), request.form['email'].strip(),
                    int(request.form['row'].strip()),
                    int(request.form['col'].strip()),
                    request.form['stuyid'].strip(), request.form['hr'].strip())
    return "done"
示例#44
0
def get_db_records():
    """
    Gets the posts needed to train the word embedding models from a set of relevant forums
    """
    conn = db()
    records = []
    forums = [4, 10, 46, 48, 92, 107, 114, 170, 186, 222, 293, 248, 167, 262]
    for forum in forums:
        query = 'SELECT p."Content" FROM "Post" p INNER JOIN "Thread" t ON p."Thread" = t."IdThread" WHERE p."Site" = 0 AND LENGTH(p."Content") > 200 AND t."Forum" =' + str(
            forum) + 'LIMIT 10000'
        records.extend([r[0] for r in conn.run_query(query)])
        print("Collected: " + str(forum))
    query = 'SELECT p."Content" FROM "Post" p INNER JOIN "Thread" t ON p."Thread" = t."IdThread" WHERE p."Site" = 0 AND LENGTH(p."Content") > 200 AND t."Forum" = 25 LIMIT 10000'
    records.extend([r[0] for r in conn.run_query(query)])

    conn.close_connection()
    return records
示例#45
0
def transferstudent():
    clsn = request.form["classname"].strip()
    term = request.form['term'].strip()
    nameParts = clsn.split("-")
    targetClsn = request.form['targetclass'].strip()
    targetParts = targetClsn.split('-')
    mydb = db.db()
    if session['teacher'] != mydb.getTeacher( (nameParts[0], nameParts[1], nameParts[2] ), term ):
        return 'false'
    spot = mydb.openSpot((targetParts[0],targetParts[1],targetParts[2]), term)
    if spot:
        mydb.transfer((nameParts[0],nameParts[1],nameParts[2]),
                      (targetParts[0],targetParts[1],targetParts[2]),
                      term, request.form['sid'].strip())
        return "done"
    else:
        return "false"
示例#46
0
def loadclass():
    clsn = request.form["classname"].strip()
    term = request.form['term'].strip()
    nameParts = clsn.split("-")
    mydb = db.db()
    if session['teacher'] != mydb.getTeacher(
        (nameParts[0], nameParts[1], nameParts[2]), term):
        return 'false'

    markUsage(session['teacher'])
    cls = mydb.getClass((nameParts[0], nameParts[1], nameParts[2]), term)
    try:
        mydb.resizeClass((nameParts[0], nameParts[1], nameParts[2]), term,
                         request.form["rows"].strip(),
                         request.form["cols"].strip())
    except KeyError:
        pass
    return json.dumps(cls[0])
示例#47
0
def gettoday():
    clsn = request.form["classname"].strip()
    term = request.form['term'].strip()
    nameParts = clsn.split("-")
    mydb = db.db()
    if session['teacher'] != mydb.getTeacher(
        (nameParts[0], nameParts[1], nameParts[2]), term):
        return 'false'
    a = mydb.getTodaysAttendance((nameParts[0], nameParts[1], nameParts[2]),
                                 term, request.form['date'].strip(), 'absent')
    l = mydb.getTodaysAttendance((nameParts[0], nameParts[1], nameParts[2]),
                                 term, request.form['date'].strip(), 'late')
    e = mydb.getTodaysAttendance((nameParts[0], nameParts[1], nameParts[2]),
                                 term, request.form['date'].strip(), 'excused')
    el = mydb.getTodaysAttendance((nameParts[0], nameParts[1], nameParts[2]),
                                  term, request.form['date'].strip(), 'exlate')
    d = {'absent': a, 'late': l, 'excused': e, 'exlate': el}
    return json.dumps(d)
示例#48
0
def reseat():
    clsn = request.form["classname"].strip()
    term = request.form['term'].strip()
    nameParts = clsn.split("-")
    id1 = request.form["id1"].strip()
    row1= request.form["row1"].strip()
    col1 = request.form["col1"].strip()
    id2 = request.form["id2"].strip()
    row2= request.form["row2"].strip()
    col2 = request.form["col2"].strip()
    mydb = db.db()
    if session['teacher'] != mydb.getTeacher( (nameParts[0], nameParts[1], nameParts[2] ), term ):
        return 'false'
    mydb.setSeat( (nameParts[0], nameParts[1], nameParts[2] ), term, 
                  id1, row1, col1)
    mydb.setSeat( (nameParts[0], nameParts[1], nameParts[2] ), term, 
                  id2, row2, col2)
    return "done"
示例#49
0
def transferstudent():
    clsn = request.form["classname"].strip()
    term = request.form['term'].strip()
    nameParts = clsn.split("-")
    targetClsn = request.form['targetclass'].strip()
    targetParts = targetClsn.split('-')
    mydb = db.db()
    if session['teacher'] != mydb.getTeacher(
        (nameParts[0], nameParts[1], nameParts[2]), term):
        return 'false'
    spot = mydb.openSpot((targetParts[0], targetParts[1], targetParts[2]),
                         term)
    if spot:
        mydb.transfer((nameParts[0], nameParts[1], nameParts[2]),
                      (targetParts[0], targetParts[1], targetParts[2]), term,
                      request.form['sid'].strip())
        return "done"
    else:
        return "false"
示例#50
0
def reseat():
    clsn = request.form["classname"].strip()
    term = request.form['term'].strip()
    nameParts = clsn.split("-")
    id1 = request.form["id1"].strip()
    row1 = request.form["row1"].strip()
    col1 = request.form["col1"].strip()
    id2 = request.form["id2"].strip()
    row2 = request.form["row2"].strip()
    col2 = request.form["col2"].strip()
    mydb = db.db()

    if session['teacher'] != mydb.getTeacher(
        (nameParts[0], nameParts[1], nameParts[2]), term):
        return 'false'

    mydb.setSeat((nameParts[0], nameParts[1], nameParts[2]), term, id1, row1,
                 col1)
    mydb.setSeat((nameParts[0], nameParts[1], nameParts[2]), term, id2, row2,
                 col2)
    return "done"
示例#51
0
def changeAttendance():
    clsn = request.form["classname"].strip()
    term = request.form['term'].strip()
    nameParts = clsn.split("-")
    a = request.form['absent'].strip().split('_')
    l = request.form['late'].strip().split('_')
    e = request.form['excused'].strip().split('_')
    el = request.form['exlate'].strip().split('_')
    if a[0] == '':
        a = []
    if l[0] == '':
        l = []
    if e[0] == '':
        e = []
    if el[0] == '':
        el = []
    mydb = db.db()
    if session['teacher'] != mydb.getTeacher( (nameParts[0], nameParts[1], nameParts[2] ), term ):
        return 'false'
    mydb.changeAllAttendance((nameParts[0], nameParts[1], nameParts[2]),
                             term, request.form['sid'].strip(), a, l, e, el)
    return "done"
示例#52
0
    def build_dataset(keywords):
        """
        Gets threads that include a specific keyword and creates a command line interface to add them to the dataset or not
        """
        conn = db()

        keyword = "'.*(" + '|'.join(keywords) + ").*'"

        query = '''SELECT "IdThread" FROM "Thread" WHERE LOWER("Heading") ~ ''' + \
            keyword + ''' AND "Site" = 0 AND "NumPosts" < 200'''
        threads = conn.run_query(query)

        length = 0

        print(len(threads))
        for thread in threads:
            thread_id = thread[0]

            posts = conn.get_posts_from_thread(thread_id)

            for post in posts:
                pp = process_text(post[1])
                if len(pp) > 5:
                    print(remove_tags(post[1]))
                    add = input()

                    with open(keywords[0] + "_training.data", 'a+') as f:
                        if add == 'y':
                            f.write(str(post[0]) + '\n')

                    with open(keywords[0] + "_training.data", 'r') as f:
                        length = len(f.readlines())

                    if length > 500:
                        print("All done")
                    print(
                        "=================================================================================="
                        + str(length) + "\n")
示例#53
0
def changeAttendance():
    clsn = request.form["classname"].strip()
    term = request.form['term'].strip()
    nameParts = clsn.split("-")
    a = request.form['absent'].strip().split('_')
    l = request.form['late'].strip().split('_')
    e = request.form['excused'].strip().split('_')
    el = request.form['exlate'].strip().split('_')
    if a[0] == '':
        a = []
    if l[0] == '':
        l = []
    if e[0] == '':
        e = []
    if el[0] == '':
        el = []
    mydb = db.db()
    if session['teacher'] != mydb.getTeacher(
        (nameParts[0], nameParts[1], nameParts[2]), term):
        return 'false'
    mydb.changeAllAttendance((nameParts[0], nameParts[1], nameParts[2]), term,
                             request.form['sid'].strip(), a, l, e, el)
    return "done"
示例#54
0
def arrangeRandom():
    clsn = request.form["classname"].strip()
    term = request.form['term'].strip()
    nameParts = clsn.split("-")
    mydb = db.db()
    if session['teacher'] != mydb.getTeacher( (nameParts[0], nameParts[1], nameParts[2] ), term ):
        return 'false'

    cls = mydb.getClass( (nameParts[0], nameParts[1], nameParts[2] ), term )
    students = cls[0]['students']
    for i in range(100):
        s1 = students[randint(0, len(students)-1)]
        s2 = students[randint(0, len(students)-1)]
        r = s1['row']
        c = s1['col']
        s1['row'] = s2['row']
        s1['col'] = s2['col']
        s2['row'] = r
        s2['col'] = c
        mydb.setSeat( (nameParts[0], nameParts[1], nameParts[2]), term,
                      s1['id'], s1['row'], s1['col'])
        mydb.setSeat( (nameParts[0], nameParts[1], nameParts[2]), term,
                      s2['id'], s2['row'], s2['col'])
    return json.dumps( cls[0] )
示例#55
0
def loadselect():
    teacher = session['teacher']
    mydb = db.db();
    return json.dumps( mydb.getAllClasses(teacher) )
示例#56
0
def studentload():
    sdb = studentdb.studentdb()
    cdb = db.db()
    student = sdb.getStudent( session['user'] )
    sdb.getGrades( session['user'], CURRENT_TERM )
    return json.dumps(student)