Implement different solve bonuses
This commit is contained in:
parent
c38ad5611d
commit
720fcd40d4
5 changed files with 45 additions and 5 deletions
|
@ -25,7 +25,8 @@ def problem_data():
|
|||
"value": problem.value,
|
||||
"threshold": problem.threshold,
|
||||
"weightmap": problem.weightmap,
|
||||
"grader_contents": open(problem.grader, "r").read()
|
||||
"grader_contents": open(problem.grader, "r").read(),
|
||||
"bonus": problem.bonus
|
||||
})
|
||||
problems_return.sort(key=lambda prob: prob["value"])
|
||||
return { "success": 1, "problems": problems_return }
|
||||
|
|
|
@ -71,7 +71,14 @@ class Teams(db.Model):
|
|||
return members
|
||||
|
||||
def points(self):
|
||||
bonuses = [5, 3, 1] # TODO: Make this a setting in the web interface
|
||||
bonuses = [
|
||||
[0, 0, 0],
|
||||
[3, 2, 1],
|
||||
[5, 3, 1],
|
||||
[8, 5, 3],
|
||||
[10, 8, 6],
|
||||
[20, 12, 8]
|
||||
]
|
||||
points = 0
|
||||
|
||||
# TODO: use joins
|
||||
|
@ -80,7 +87,7 @@ class Teams(db.Model):
|
|||
problem = Problems.query.filter_by(pid=solve.pid).first()
|
||||
multiplier = 1
|
||||
if solve.bonus != -1:
|
||||
multiplier += bonuses[solve.bonus-1]/100.0
|
||||
multiplier += bonuses[problem.bonus][solve.bonus-1]/100.0
|
||||
points += round(problem.value*multiplier)
|
||||
return points
|
||||
|
||||
|
@ -152,6 +159,7 @@ class Problems(db.Model):
|
|||
threshold = db.Column(db.Integer)
|
||||
weightmap = db.Column(db.PickleType)
|
||||
grader = db.Column(db.Text)
|
||||
bonus = db.Column(db.Integer)
|
||||
|
||||
def __init__(self, pid, title, category, description, value, hint="", autogen=False, bonus=0, threshold=0, weightmap={}):
|
||||
self.pid = pid
|
||||
|
@ -163,6 +171,7 @@ class Problems(db.Model):
|
|||
self.autogen = autogen
|
||||
self.threshold = threshold
|
||||
self.weightmap = weightmap
|
||||
self.bonus = bonus
|
||||
|
||||
class Files(db.Model):
|
||||
fid = db.Column(db.Integer, primary_key=True)
|
||||
|
|
|
@ -24,6 +24,7 @@ def problem_add():
|
|||
hint = request.form["hint"]
|
||||
value = request.form["value"]
|
||||
grader_contents = request.form["grader_contents"]
|
||||
bonus = request.form["bonus"]
|
||||
pid = utils.generate_string()
|
||||
while Problems.query.filter_by(pid=pid).first():
|
||||
pid = utils.generate_string()
|
||||
|
@ -37,7 +38,7 @@ def problem_add():
|
|||
except Exception, e:
|
||||
raise WebException("There is a syntax error in the grader: %s" % e)
|
||||
|
||||
problem = Problems(pid, title, category, description, value, hint=hint)
|
||||
problem = Problems(pid, title, category, description, value, hint=hint, bonus=bonus)
|
||||
db.session.add(problem)
|
||||
db.session.commit()
|
||||
|
||||
|
@ -92,6 +93,7 @@ def problem_update():
|
|||
hint = request.form["hint"]
|
||||
value = request.form["value"]
|
||||
grader_contents = request.form["grader_contents"]
|
||||
bonus = request.form["bonus"]
|
||||
try:
|
||||
exec(grader_contents)
|
||||
except Exception, e:
|
||||
|
@ -104,6 +106,7 @@ def problem_update():
|
|||
problem.description = description
|
||||
problem.hint = hint
|
||||
problem.value = value
|
||||
problem.bonus = bonus
|
||||
|
||||
grader = open(problem.grader, "w")
|
||||
grader.write(grader_contents)
|
||||
|
|
|
@ -9,6 +9,8 @@ var create_problem = function() {
|
|||
var data = $("#new_problem_form").serializeObject();
|
||||
var grader_contents = ace.edit("new_grader").getValue();
|
||||
data["grader_contents"] = grader_contents;
|
||||
var bonus = $("#bonus").val();
|
||||
data["bonus"] = bonus;
|
||||
$(input).attr("disabled", "disabled");
|
||||
api_call("POST", "/api/problem/add", data, function(result) {
|
||||
if (result["success"] == 1) {
|
||||
|
@ -31,10 +33,13 @@ var create_problem = function() {
|
|||
var update_problem = function(form_id) {
|
||||
var input = "#" + form_id + " input";
|
||||
var data = $("#" + form_id).serializeObject();
|
||||
pid = data["pid"];
|
||||
var pid = data["pid"];
|
||||
|
||||
var grader_contents = ace.edit(pid + "_grader").getValue();
|
||||
data["grader_contents"] = grader_contents;
|
||||
var bonus = $("#" + pid + "_bonus").val();
|
||||
console.log(bonus);
|
||||
data["bonus"] = bonus;
|
||||
|
||||
$(input).attr("disabled", "disabled");
|
||||
api_call("POST", "/api/problem/update", data, function(result) {
|
||||
|
@ -47,6 +52,7 @@ var update_problem = function(form_id) {
|
|||
$(input).removeAttr("disabled");
|
||||
});
|
||||
}
|
||||
console.log(result);
|
||||
}, function(jqXHR, status, error) {
|
||||
var result = jqXHR["responseText"];
|
||||
display_message(pid + "_status", "danger", "Error " + jqXHR["status"] + ": " + result["message"], function() {
|
||||
|
|
|
@ -34,6 +34,17 @@
|
|||
<input class="form-control" name="hint" placeholder="Hint" required/>
|
||||
<br>
|
||||
<input class="form-control" name="value" type="number" placeholder="Problem Value" required autocomplete="off"/>
|
||||
<br>
|
||||
<label for="bonus">Speed bonuses (%)</label>
|
||||
<select class="form-control" id="bonus">
|
||||
<option value="0">0/0/0</option>
|
||||
<option value="1">3/2/1</option>
|
||||
<option value="2">5/3/1</option>
|
||||
<option value="3">8/5/3</option>
|
||||
<option value="4">10/8/6</option>
|
||||
<option value="5">20/12/8</option>
|
||||
</select>
|
||||
|
||||
<br>
|
||||
<div id="new_grader"></div>
|
||||
<br>
|
||||
|
@ -61,6 +72,16 @@
|
|||
<br>
|
||||
<input class="form-control" type="number" name="value" value="{{ problem['value'] }}" required/>
|
||||
<br>
|
||||
<label for="bonus">Speed bonuses (%)</label>
|
||||
<select class="form-control" id="{{ problem.pid }}_bonus">
|
||||
<option ng-selected="problem.bonus == 0" value="0">0/0/0</option>
|
||||
<option ng-selected="problem.bonus == 1" value="1">3/2/1</option>
|
||||
<option ng-selected="problem.bonus == 2" value="2">5/3/1</option>
|
||||
<option ng-selected="problem.bonus == 3" value="3">8/5/3</option>
|
||||
<option ng-selected="problem.bonus == 4" value="4">10/8/6</option>
|
||||
<option ng-selected="problem.bonus == 5" value="5">20/12/8</option>
|
||||
</select>
|
||||
<br>
|
||||
<div id="{{ problem['pid'] }}_grader"></div>
|
||||
<br>
|
||||
<input type="submit" class="btn btn-success" value="Update"/>
|
||||
|
|
Loading…
Reference in a new issue