Fixing and cleaning graphs to reflect awards

selenium-screenshot-testing
CodeKevin 2016-04-30 13:20:30 -04:00
parent 691c971ebd
commit e4e989a0a5
9 changed files with 143 additions and 49 deletions

View File

@ -587,10 +587,29 @@ def admin_solves(teamid="all"):
solves = Solves.query.all()
else:
solves = Solves.query.filter_by(teamid=teamid).all()
awards = Awards.query.filter_by(teamid=teamid).all()
db.session.close()
json_data = {'solves':[]}
for x in solves:
json_data['solves'].append({'id':x.id, 'chal':x.chal.name, 'chalid':x.chalid,'team':x.teamid, 'value': x.chal.value, 'category':x.chal.category, 'time':unix_time(x.date)})
json_data['solves'].append({
'id': x.id,
'chal': x.chal.name,
'chalid': x.chalid,
'team': x.teamid,
'value': x.chal.value,
'category': x.chal.category,
'time': unix_time(x.date)
})
for award in awards:
json_data['solves'].append({
'chal': award.name,
'chalid': None,
'team': award.teamid,
'value': award.value,
'category': award.category,
'time': unix_time(award.date)
})
json_data['solves'].sort(key=lambda k:k['time'])
return jsonify(json_data)

View File

@ -1,7 +1,7 @@
from flask import current_app as app, render_template, request, redirect, abort, jsonify, json as json_mod, url_for, session, Blueprint
from CTFd.utils import ctftime, view_after_ctf, authed, unix_time, get_kpm, can_view_challenges, is_admin, get_config, get_ip, is_verified
from CTFd.models import db, Challenges, Files, Solves, WrongKeys, Keys, Tags, Teams
from CTFd.models import db, Challenges, Files, Solves, WrongKeys, Keys, Tags, Teams, Awards
from sqlalchemy.sql import and_, or_, not_
@ -76,10 +76,28 @@ def solves(teamid=None):
return redirect(url_for('auth.login', next='solves'))
else:
solves = Solves.query.filter_by(teamid=teamid).all()
awards = Awards.query.filter_by(teamid=teamid).all()
db.session.close()
json = {'solves':[]}
for x in solves:
json['solves'].append({ 'chal':x.chal.name, 'chalid':x.chalid,'team':x.teamid, 'value': x.chal.value, 'category':x.chal.category, 'time':unix_time(x.date)})
for solve in solves:
json['solves'].append({
'chal': solve.chal.name,
'chalid': solve.chalid,
'team': solve.teamid,
'value': solve.chal.value,
'category': solve.chal.category,
'time': unix_time(solve.date)
})
for award in awards:
json['solves'].append({
'chal': award.name,
'chalid': None,
'team': award.teamid,
'value': award.value,
'category': award.category,
'time': unix_time(award.date)
})
json['solves'].sort(key=lambda k: k['time'])
return jsonify(json)

View File

@ -76,24 +76,43 @@ def topteams(count):
json = {'scores':{}}
score = db.func.sum(Challenges.value).label('score')
quickest = db.func.max(Solves.date).label('quickest')
teams = db.session.query(Solves.teamid, Teams.name, score)\
.join(Teams)\
.join(Challenges)\
.filter(Teams.banned == None)\
.group_by(Solves.teamid).order_by(score.desc(), quickest)\
.limit(count)
scores = db.session.query(Solves.teamid.label('teamid'), Teams.name.label('name'), score, Solves.date.label('date')) \
.join(Teams) \
.join(Challenges) \
.filter(Teams.banned == None) \
.group_by(Solves.teamid)
for team in teams:
awards = db.session.query(Teams.id.label('teamid'), Teams.name.label('name'),
db.func.sum(Awards.value).label('score'), Awards.date.label('date')) \
.filter(Teams.id == Awards.teamid) \
.group_by(Teams.id)
results = union_all(scores, awards)
standings = db.session.query(results.columns.teamid, results.columns.name,
db.func.sum(results.columns.score).label('score')) \
.group_by(results.columns.teamid) \
.order_by(db.func.sum(results.columns.score).desc(), db.func.max(results.columns.date)) \
.limit(count).all()
for team in standings:
solves = Solves.query.filter_by(teamid=team.teamid).all()
awards = Awards.query.filter_by(teamid=team.teamid).all()
json['scores'][team.name] = []
scores = []
for x in solves:
json['scores'][team.name].append({
'id': x.teamid,
'chal': x.chalid,
'team': x.teamid,
'value': x.chal.value,
'time': unix_time(x.date)
})
for award in awards:
json['scores'][team.name].append({
'chal': None,
'team': award.teamid,
'value': award.value,
'time': unix_time(award.date)
})
json['scores'][team.name] = sorted(json['scores'][team.name], key=lambda k: k['time'])
return jsonify(json)

View File

@ -37,7 +37,12 @@ function scoregraph () {
type: 'scatter'
}
];
Plotly.newPlot('score-graph', data);
var layout = {
title: 'Score over Time'
};
Plotly.newPlot('score-graph', data, layout);
});
}
@ -62,8 +67,7 @@ function keys_percentage_graph(){
}];
var layout = {
height: 400,
width: 500
title: 'Key Percentages'
};
Plotly.newPlot('keys-pie-graph', data, layout);
@ -106,8 +110,7 @@ function category_breakdown_graph(){
}];
var layout = {
height: 400,
width: 500
title:'Category Breakdown'
};
Plotly.newPlot('categories-pie-graph', data, layout);
@ -116,5 +119,11 @@ function category_breakdown_graph(){
category_breakdown_graph();
keys_percentage_graph();
adjust_times();
scoregraph();
window.onresize = function () {
Plotly.Plots.resize(document.getElementById('keys-pie-graph'));
Plotly.Plots.resize(document.getElementById('categories-pie-graph'));
Plotly.Plots.resize(document.getElementById('score-graph'));
};

View File

@ -101,6 +101,9 @@ table{
}
#score-graph{
height: 450px;
display: block;
clear: both;
}
#keys-pie-graph{

View File

@ -63,9 +63,13 @@ function scoregraph () {
}
function update(){
updatescores()
scoregraph()
updatescores();
scoregraph();
}
setInterval(update, 300000); // Update scores every 5 minutes
scoregraph()
scoregraph();
window.onresize = function () {
Plotly.Plots.resize(document.getElementById('score-graph'));
};

View File

@ -46,7 +46,12 @@ function scoregraph() {
type: 'scatter'
}
];
Plotly.newPlot('score-graph', data);
var layout = {
title: 'Score over Time'
};
Plotly.newPlot('score-graph', data, layout);
});
}
@ -70,12 +75,12 @@ function keys_percentage_graph() {
type: 'pie'
}];
//var layout = {
// height: 400,
// width: 500
//};
var layout = {
title: 'Key Percentages'
};
Plotly.newPlot('keys-pie-graph', data);
Plotly.newPlot('keys-pie-graph', data, layout);
});
}
@ -114,15 +119,21 @@ function category_breakdown_graph() {
type: 'pie'
}];
//var layout = {
// height: 400,
// width: 500
//};
var layout = {
title: 'Category Breakdown'
};
Plotly.newPlot('categories-pie-graph', data);
Plotly.newPlot('categories-pie-graph', data, layout);
});
}
category_breakdown_graph()
keys_percentage_graph()
scoregraph()
category_breakdown_graph();
keys_percentage_graph();
scoregraph();
window.onresize = function () {
Plotly.Plots.resize(document.getElementById('keys-pie-graph'));
Plotly.Plots.resize(document.getElementById('categories-pie-graph'));
Plotly.Plots.resize(document.getElementById('score-graph'));
};

View File

@ -2,15 +2,13 @@
{% block content %}
<div class="row">
<div class="col-md-6 col-md-offset-1">
<div id="solves-graph"></div>
</div>
</div>
<div class="row">
<div class="col-md-6">
<div>
<div id="keys-pie-graph"></div>
</div>
<div class="col-md-6">
<div>
<div id="categories-pie-graph"></div>
</div>
</div>
@ -19,7 +17,16 @@
{% block scripts %}
<style>
#solves-graph{
width:100%;
display: block;
height: 500px;
}
#keys-pie-graph{
height: 400px;
display: block;
}
#categories-pie-graph{
height: 400px;
display: block;
}
</style>
<script src="/static/js/vendor/plotly.min.js"></script>
@ -73,8 +80,7 @@
}];
var layout = {
height: 600,
width: 960
title: 'Score Counts'
};
Plotly.newPlot('solves-graph', data, layout);
@ -102,8 +108,7 @@
}];
var layout = {
height: 400,
width: 500
title: 'Key Percentages'
};
Plotly.newPlot('keys-pie-graph', data, layout);
@ -130,8 +135,7 @@
}];
var layout = {
height: 400,
width: 500
title: 'Category Breakdown'
};
Plotly.newPlot('categories-pie-graph', data, layout);
@ -146,6 +150,12 @@
$(function() {
update();
window.onresize = function () {
console.log('resizing')
Plotly.Plots.resize(document.getElementById('keys-pie-graph'));
Plotly.Plots.resize(document.getElementById('categories-pie-graph'));
Plotly.Plots.resize(document.getElementById('solves-graph'));
};
});
setInterval(update, 300000);

View File

@ -27,6 +27,8 @@
<div id="keys-pie-graph"></div>
<div id="categories-pie-graph"></div>
<br>
<div id="score-graph"></div>
<div class="clearfix"></div>
@ -75,7 +77,6 @@
</tbody>
</table>
</div>
<div id="score-graph"></div>
</div>
{% endblock %}