diff --git a/models/user.js b/models/user.js
index 14a9a5d..621493a 100644
--- a/models/user.js
+++ b/models/user.js
@@ -124,14 +124,14 @@ class User extends Model {
async getArticles() {
let Article = syzoj.model('article');
-
+
let all = await Article.model.findAll({
attributes: ['id', 'title', 'public_time'],
where: {
user_id: this.id
}
});
-
+
return all.map(x => ({
id: x.get('id'),
title: x.get('title'),
@@ -139,6 +139,33 @@ class User extends Model {
}));
}
+ async getStatistics() {
+ let JudgeState = syzoj.model('judge_state');
+
+ let statuses = {
+ "Accepted": ["Accepted"],
+ "Wrong Answer": ["Wrong Answer", "File Error", "Output Limit Exceeded"],
+ "Runtime Error": ["Runtime Error"],
+ "Time Limit Exceeded": ["Time Limit Exceeded"],
+ "Memory Limit Exceeded": ["Memory Limit Exceeded"],
+ "Compile Error": ["Compile Error"]
+ };
+
+ let res = {};
+ for (let status in statuses) {
+ res[status] = 0;
+ for (let s of statuses[status]) {
+ res[status] += await JudgeState.count({
+ user_id: this.id,
+ type: 0,
+ status: status
+ });
+ }
+ }
+
+ return res;
+ }
+
async renderInformation() {
this.information = await syzoj.utils.markdown(this.information);
}
diff --git a/modules/user.js b/modules/user.js
index beed682..b990e86 100644
--- a/modules/user.js
+++ b/modules/user.js
@@ -90,8 +90,11 @@ app.get('/user/:id', async (req, res) => {
user.articles = await user.getArticles();
user.allowedEdit = await user.isAllowedEditBy(res.locals.user);
+ let statistics = await user.getStatistics();
+
res.render('user', {
- show_user: user
+ show_user: user,
+ statistics: statistics
});
} catch (e) {
console.log(e);
diff --git a/views/footer.ejs b/views/footer.ejs
index ca5891a..998b88b 100644
--- a/views/footer.ejs
+++ b/views/footer.ejs
@@ -6,6 +6,7 @@
+
<% include footer %>