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"
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
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"
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()
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])
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
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 )
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
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'])
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'])
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"
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'
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"
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)
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"
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
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'])
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"
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";
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 )
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
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"
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'
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'])
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)
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"
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":[]}'
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)
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)
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"
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)
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"
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'])
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"
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
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"
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":[]}'
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
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'])
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"
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] )
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"
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"
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
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"
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])
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)
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"
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"
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"
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"
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")
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"
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] )
def loadselect(): teacher = session['teacher'] mydb = db.db(); return json.dumps( mydb.getAllClasses(teacher) )
def studentload(): sdb = studentdb.studentdb() cdb = db.db() student = sdb.getStudent( session['user'] ) sdb.getGrades( session['user'], CURRENT_TERM ) return json.dumps(student)