From 0e672237bbc963337d37aa13aad58d6ceb706286 Mon Sep 17 00:00:00 2001 From: Menci Date: Sun, 16 Jul 2017 14:47:35 +0800 Subject: [PATCH] Add missing file --- config-example.json | 4 +- models/custom_test.js | 101 ++++++++++++++++++++++++++++++++++++++++++ 2 files changed, 104 insertions(+), 1 deletion(-) create mode 100644 models/custom_test.js diff --git a/config-example.json b/config-example.json index b7c4ffc..74501b1 100644 --- a/config-example.json +++ b/config-example.json @@ -31,7 +31,9 @@ "data_size": 209715200, "testdata": 209715200, "submit_code": 102400, - "submit_answer": 10485760 + "submit_answer": 10485760, + "custom_test_input": 20971520, + "testdata_filecount": 5 }, "page": { "problem": 50, diff --git a/models/custom_test.js b/models/custom_test.js new file mode 100644 index 0000000..5b1b5bf --- /dev/null +++ b/models/custom_test.js @@ -0,0 +1,101 @@ +/* + * This file is part of SYZOJ. + * + * Copyright (c) 2016 Menci + * + * SYZOJ is free software: you can redistribute it and/or modify + * it under the terms of the GNU Affero General Public License as + * published by the Free Software Foundation, either version 3 of the + * License, or (at your option) any later version. + * + * SYZOJ is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU Affero General Public License for more details. + * + * You should have received a copy of the GNU Affero General Public + * License along with SYZOJ. If not, see . + */ + +'use strict'; + +let Sequelize = require('sequelize'); +let db = syzoj.db; + +let User = syzoj.model('user'); +let Problem = syzoj.model('problem'); + +let model = db.define('custom_test', { + id: { type: Sequelize.INTEGER, primaryKey: true, autoIncrement: true }, + + input_filepath: { type: Sequelize.TEXT }, + code: { type: Sequelize.TEXT('medium') }, + language: { type: Sequelize.STRING(20) }, + + status: { type: Sequelize.STRING(50) }, + + time: { type: Sequelize.INTEGER }, + pending: { type: Sequelize.BOOLEAN }, + memory: { type: Sequelize.INTEGER }, + + result: { type: Sequelize.TEXT('medium'), json: true }, + + user_id: { type: Sequelize.INTEGER }, + + problem_id: { type: Sequelize.INTEGER }, + + submit_time: { type: Sequelize.INTEGER } +}, { + timestamps: false, + tableName: 'custom_test', + indexes: [ + { + fields: ['status'], + }, + { + fields: ['user_id'], + }, + { + fields: ['problem_id'], + } + ] +}); + +let Model = require('./common'); +class CustomTest extends Model { + static async create(val) { + return CustomTest.fromRecord(CustomTest.model.build(Object.assign({ + input_filepath: '', + code: '', + language: '', + user_id: 0, + problem_id: 0, + submit_time: parseInt((new Date()).getTime() / 1000), + + pending: true, + + time: 0, + memory: 0, + status: 'Waiting', + }, val))); + } + + async loadRelationships() { + this.user = await User.fromID(this.user_id); + this.problem = await Problem.fromID(this.problem_id); + } + + async updateResult(result) { + this.pending = result.pending; + this.status = result.status; + this.time = result.time_used; + this.memory = result.memory_used; + this.result = result; + } + + getModel() { return model; } +} + +CustomTest.model = model; + +module.exports = CustomTest;