Exemplo n.º 1
0
def from_name_get_sid():
    sids = []
    orgs = {}
    name = request.args.get("name") or "朱承浩"
    _sids = eval(rds.hget('info', name) or "[2014210761]")
    """
    {'sids': [{'deptName': '', 'orgName': '', 'sid':''}, ....]} 
    """
    for sid in _sids:
        r = requests.get(MUMEIURL.format(sid=sid))
        _json = r.json()  # dict
        for json in _json:
            value = json.get('orgName')
            if value not in orgs:
                orgs[value] = 1
            else:
                count = orgs.get(value)
                orgs[value] = count + 1
        bestorg = sorted(orgs.iteritems(), key=lambda d: d[1], reverse=True)
        sid_dict = {
            'sid': sid,
            'deptName': _json[0].get('deptName'),
            'orgName': bestorg[0]
        }
        sids.append(sid_dict)
    return jsonify({'sids': sids})
Exemplo n.º 2
0
def submit_info(sid, page):
	if sid is not None:
		sub = Submit.query.filter_by(id=sid).first()
		if sub:
			user = User.query.filter_by(id=sub.user).first()
			if ( user.id == g.user.id ) or ( g.user.role == 'admin' ) or ( g.user.role == 'ta' ):
				sub.language = languages[sub.language]
				sub.user = user.username
				problem = Problem.query.filter_by(id=sub.problem).first()
				fp = open(sub.code_file, 'r')
				code = fp.read()
                                try:
                                        code = code.decode("utf8")
                                except:
                                        code = ""
				fp.close()
				error_message = None
				status = rds.hget('lambda:%d:head' % (sub.id), 'state')
				if status is None:
					status = 'Pending'
				if status == 'Pending':
					sub_results = status
				elif status == 'Compilation Error':
					sub_results = status
					error_message = rds.hget('lambda:%d:head' % (sub.id), 'err_message')
                                        try:
                                                error_message = path_pattern.sub(' *your_code* ', error_message)
                                                error_message = error_message.decode("utf8")
                                        except:
                                                error_message = "Compilation Error"
				else:
                                        sub.score = status
					sub_results = []
					for i in range(0, problem.sample_num):
						sub_results.append(rds.hgetall('lambda:%d:result:%d' % (sub.id, i)))
				return render_template('submit_info.html', 
					problem = problem, 
					sub = sub,
					sub_results = sub_results, 
					error_message = error_message,
					code = code,
					user = g.user)
	return redirect(url_for('status', page=page))
Exemplo n.º 3
0
def profile(page):
	subs = Submit.query.filter_by(user=g.user.id).order_by(desc(Submit.id)).paginate(page, SUBS_PER_PAGE)
	for s in subs.items:
		s.language = languages[s.language]
		status_tmp = rds.hget('lambda:%d:head' % (s.id), 'state')
		if status_tmp is None:
			s.status = 'Pending'
		else:
			s.status = status_tmp

	return render_template('profile.html', 
		user = g.user, 
		subs = subs)
Exemplo n.º 4
0
def status(page):
	subs = Submit.query.order_by(desc(Submit.id)).paginate(page, SUBS_PER_PAGE)
	for s in subs.items:
		s.language = languages[s.language]
		user_tmp = User.query.filter_by(id=s.user).first()
		s.user = user_tmp.username
		status_tmp = rds.hget('lambda:%d:head' % (s.id), 'state')
		if status_tmp is None:
			s.status = 'Pending'
		else:
			s.status = status_tmp
	return render_template('status.html', 
		subs = subs, 
		user = g.user)