예제 #1
0
def new_sheet_request():
    form = request.form
    tid = form.get("tid").lstrip("0")
    mid = form.get("mid").strip().upper()
    alliance = form.get("alliance")

    if not validate_match(mid):
        # Match id does not match the regex
        raise WebException("Invalid match id.")

    _match = match.get_match(mid=mid).first()
    if _match is None:
        # Match does not exist yet, so create one
        match.add_match(mid)

    _team = team.get_team(tid=tid).first()
    if _team is None:
        # Team does not exist yet, so create one
        team.add_team(tid)

    sheet = get_sheet(tid=tid, mid=mid, alliance=alliance).first()
    if sheet is not None:
        # Duplicate sheet exists, so alert the user
        raise WebException("Sheet already exists.")

    # Create a new sheet
    new_sheet(tid, mid, alliance)

    return {"success": 1, "message": "Sheet created."}
예제 #2
0
파일: activity.py 프로젝트: EasyCTF/OpenCTF
def activity_team():
	params = utils.flat_multi(request.args)
	if "team" not in params:
		raise WebException("Please specify a team.")
	_team = get_team(teamname_lower=params.get("team").lower()).first()
	if _team is None:
		raise WebException("Team not found.")
	return _team.get_activity()
예제 #3
0
def problem_data():
    if "admin" in session and session["admin"]:
        pass
    elif "tid" not in session or session["tid"] <= 0:
        raise WebException("You need a team.")
    elif team.get_team(tid=session.get("tid")).first().finalized != True:
        raise WebException("Your team is not finalized.")

    problems = Problems.query.order_by(Problems.value).all()
    problems_return = []
    for problem in problems:
        solves = get_solves(problem.pid)
        solved = Solves.query.filter_by(pid=problem.pid,
                                        tid=session.get("tid", None),
                                        correct=1).first()
        solved = ["Solved", "Unsolved"][solved is None]
        description = process_description(problem.description)

        data = {
            "pid": problem.pid,
            "title": problem.title,
            "category": problem.category,
            "description": description,
            "hint": problem.hint,
            "value": problem.value,
            "solves": solves,
            "solved": solved
        }
        admin_data = {
            "description_source": problem.description,
            "threshold": problem.threshold,
            "weightmap": problem.weightmap,
            "grader_contents": open(problem.grader, "r").read(),
            "bonus": problem.bonus,
            "autogen": problem.autogen == True
        }
        if "admin" in session and session["admin"]:
            data.update(admin_data)
        if problem.autogen:
            grader = imp.load_source("grader", problem.grader)
            tid = session.get("tid", "team")
            try:
                data.update(
                    grader.generate_problem(
                        autogen.get_random(problem.pid, tid), problem.pid))
            except Exception, e:
                logger.log(
                    __name__, "The grader for \"%s\" has thrown an error: %s" %
                    (problem.title, e))
        problems_return.append(data)
예제 #4
0
def problem_data():
	if "admin" in session and session["admin"]:
		pass
	elif "tid" not in session or session["tid"] <= 0:
		raise WebException("You need a team.")
	elif team.get_team(tid=session.get("tid")).first().finalized != True:
		raise WebException("Your team is not finalized.")

	problems = Problems.query.order_by(Problems.value).all()
	problems_return = [ ]
	for problem in problems:
		solves = get_solves(problem.pid)
		solved = Solves.query.filter_by(pid=problem.pid, tid=session.get("tid", None), correct=1).first()
		solved = ["Solved", "Unsolved"][solved is None]
		description = process_description(problem.description)

		data = {
			"pid": problem.pid,
			"title": problem.title,
			"category": problem.category,
			"description": description,
			"hint": problem.hint,
			"value": problem.value,
			"solves": solves,
			"solved": solved
		}
		admin_data = {
			"description_source": problem.description,
			"threshold": problem.threshold,
			"weightmap": problem.weightmap,
			"grader_contents": open(problem.grader, "r").read(),
			"bonus": problem.bonus,
			"autogen": problem.autogen == True
		}
		if "admin" in session and session["admin"]:
			data.update(admin_data)
		if problem.autogen:
			grader = imp.load_source("grader", problem.grader)
			tid = session.get("tid", "team")
			try:
				data.update(grader.generate_problem(autogen.get_random(problem.pid, tid), problem.pid))
			except Exception, e:
				logger.log(__name__, "The grader for \"%s\" has thrown an error: %s" % (problem.title, e))
		problems_return.append(data)
예제 #5
0
def get_problems():
	if session.get("admin"):
		pass
	elif session.get("tid") <= 0:
		raise WebException("You need a team.")
	elif team.get_team(tid=session.get("tid")).first().finalized != True:
		raise WebException("Your team is not finalized.")

	data = []
	problems = Problems.query.filter_by(category="Programming").all()
	if problems is not None:
		for _problem in problems:
			data.append({
				"title": _problem.title,
				"pid": _problem.pid,
				"value": _problem.value
			})

	return { "success": 1, "problems": data }
예제 #6
0
def get_problems():
    if session.get("admin"):
        pass
    elif session.get("tid") <= 0:
        raise WebException("You need a team.")
    elif team.get_team(tid=session.get("tid")).first().finalized != True:
        raise WebException("Your team is not finalized.")

    data = []
    problems = Problems.query.filter_by(category="Programming").all()
    if problems is not None:
        for _problem in problems:
            data.append({
                "title": _problem.title,
                "pid": _problem.pid,
                "value": _problem.value
            })

    return {"success": 1, "problems": data}
예제 #7
0
    def test_check_availability(self):
        t = team.get_team(self.testfile)

        for member in t:
            if member.name == 'alice':
                result = team.check_availability(self.workdate, member)
                self.assertFalse(result)
            elif member.name == 'bob':
                result = team.check_availability(self.workdate, member)
                self.assertFalse(result)
            elif member.name == 'chris':
                result = team.check_availability(self.workdate, member)
                self.assertFalse(result)
            elif member.name == 'debby':
                result = team.check_availability(self.workdate, member)
                self.assertTrue(result)
            elif member.name == 'dude':
                result = team.check_availability(self.workdate, member)
                self.assertTrue(result)
예제 #8
0
def update_sheet_request():
    form = request.form
    sid = form.get("sid")
    mid = form.get("mid").strip().upper()
    tid = form.get("tid").lstrip("0")
    alliance = form.get("alliance")

    if not validate_match(mid):
        # Match id does not match the regex
        raise WebException("Invalid match id.")

    _match = match.get_match(mid=mid).first()
    if _match is None:
        # Match does not exist yet, so create one
        match.add_match(mid)

    _team = team.get_team(tid=tid).first()
    if _team is None:
        # Team does not exist yet, so create one
        team.add_team(tid)

    update_sheet(sid, mid, tid, alliance)
    return {"success": 1, "message": "Sheet updated."}
예제 #9
0
def parse_arguments():
    parser = argparse.ArgumentParser()
    parser.add_argument("year", type=int, help="year e.g. 2016")
    parser.add_argument("month", type=int, help="month e.g. 03")
    parser.add_argument("inputfile", help="location to file with configuration")

    return parser.parse_args()

# PROGRAM FLOW
args = parse_arguments()

logging.basicConfig(level=logging.DEBUG)

workdate = date(args.year, args.month, 1)
holidays = team.get_holidays(args.inputfile)

# team = member.init_team(workdate)
myteam = team.get_team(args.inputfile)

schedule = create_schedule(myteam, holidays, workdate)

print("\nSchedule for %s\n" % str(workdate))
print("Assignment per team member\n")
for m in myteam:
    print("%s %d" % (m.name, m.count))

print("\n\nSchedule\n")
for day in schedule:
    print("%s %s" % (day, schedule[day]))