CodingSouls团队项目第二阶段冲刺(5)-个人概况
团队项目第二阶段冲刺第五天:
实现评测功能:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 | import * as TypeORM from "typeorm" ; import Model from "./common" ; declare var stdoj, ErrorMessage: any ; import User from "./user" ; import Problem from "./problem" ; import Contest from "./contest" ; const Judger = stdoj.lib( 'judger' ); enum Status { ACCEPTED = "Accepted" , COMPILE_ERROR = "Compile Error" , FILE_ERROR = "File Error" , INVALID_INTERACTION = "Invalid Interaction" , JUDGEMENT_FAILED = "Judgement Failed" , MEMORY_LIMIT_EXCEEDED = "Memory Limit Exceeded" , NO_TESTDATA = "No Testdata" , OUTPUT_LIMIT_EXCEEDED = "Output Limit Exceeded" , PARTIALLY_CORRECT = "Partially Correct" , RUNTIME_ERROR = "Runtime Error" , SYSTEM_ERROR = "System Error" , TIME_LIMIT_EXCEEDED = "Time Limit Exceeded" , UNKNOWN = "Unknown" , WRONG_ANSWER = "Wrong Answer" , WAITING = "Waiting" } @TypeORM.Entity() @TypeORM. Index ([ 'type' , 'type_info' ]) @TypeORM. Index ([ 'type' , 'is_public' , 'language' , 'status' , 'problem_id' ]) @TypeORM. Index ([ 'type' , 'is_public' , 'status' , 'problem_id' ]) @TypeORM. Index ([ 'type' , 'is_public' , 'problem_id' ]) @TypeORM. Index ([ 'type' , 'is_public' , 'language' , 'problem_id' ]) @TypeORM. Index ([ 'problem_id' , 'type' , 'pending' , 'score' ]) export default class JudgeState extends Model { @TypeORM.PrimaryGeneratedColumn() id: number; // The data zip 's md5 if it' s a submit-answer problem @TypeORM. Column ({ nullable: true , type: "mediumtext" }) code: string; @TypeORM. Column ({ nullable: true , type: "varchar" , length: 20 }) language: string; @TypeORM. Index () @TypeORM. Column ({ nullable: true , type: "enum" , enum: Status }) status: Status; @TypeORM. Index () @TypeORM. Column ({ nullable: true , type: "varchar" , length: 50 }) task_id: string; @TypeORM. Index () @TypeORM. Column ({ nullable: true , type: "integer" , default : 0 }) score: number; @TypeORM. Column ({ nullable: true , type: "integer" , default : 0 }) total_time: number; @TypeORM. Column ({ nullable: true , type: "integer" , default : 0 }) code_length: number; @TypeORM. Column ({ nullable: true , type: "boolean" , default : 0 }) pending: boolean; @TypeORM. Column ({ nullable: true , type: "integer" , default : 0 }) max_memory: number; @TypeORM. Column ({ nullable: true , type: "json" }) compilation: any ; @TypeORM. Column ({ nullable: true , type: "json" }) result: any ; @TypeORM. Index () @TypeORM. Column ({ nullable: true , type: "integer" }) user_id: number; @TypeORM. Index () @TypeORM. Column ({ nullable: true , type: "integer" }) problem_id: number; @TypeORM. Index () @TypeORM. Column ({ nullable: true , type: "integer" }) submit_time: number; /* * "type" indicate it's contest's submission(type = 1) or normal submission(type = 0) * if it's contest's submission (type = 1), the type_info is contest_id * use this way represent because it's easy to expand // Menci:这锅我不背,是 Chenyao 留下来的坑。 */ @TypeORM. Column ({ nullable: true , type: "integer" }) type: number; @TypeORM. Column ({ nullable: true , type: "integer" }) type_info: number; @TypeORM. Index () @TypeORM. Column ({ nullable: true , type: "boolean" }) is_public: boolean; user ?: User ; problem?: Problem; async loadRelationships() { if (!this. user ) { this. user = await User .findById(this.user_id); } if (!this.problem) { if (this.problem_id) this.problem = await Problem.findById(this.problem_id); } } async saveHook() { if (this.score === null ) this.score = 0; } async isAllowedVisitBy( user ) { await this.loadRelationships(); if ( user && user .id === this.problem.user_id) return true ; else if (this.type === 0) return this.problem.is_public || ( user && (await user .hasPrivilege('manage_problem '))); else if (this.type === 1) { let contest = await Contest.findById(this.type_info); if (contest.isRunning()) { return user && await contest.isSupervisior(user); } else { return true; } } } async updateRelatedInfo(newSubmission) { if (this.type === 0) { await this.loadRelationships(); const promises = []; promises.push(this.user.refreshSubmitInfo()); promises.push(this.problem.resetSubmissionCount()); if (!newSubmission) { promises.push(this.problem.updateStatistics(this.user_id)); } await Promise.all(promises); } else if (this.type === 1) { let contest = await Contest.findById(this.type_info); await contest.newSubmission(this); } } async rejudge() { await stdoj.utils.lock([' JudgeState::rejudge ', this.id], async () => { await this.loadRelationships(); let oldStatus = this.status; this.status = Status.UNKNOWN; this.pending = false; this.score = null; if (this.language) { // language is empty if it' s a submit-answer problem this.total_time = null ; this.max_memory = null ; } this.result = {}; this.task_id = require( 'randomstring' ).generate(10); await this.save(); await this.updateRelatedInfo( false ); try { await Judger.judge(this, this.problem, 1); this.pending = true ; this.status = Status.WAITING; await this.save(); } catch (err) { console.log( "Error while connecting to judge frontend: " + err.toString()); throw new ErrorMessage( "无法开始评测。" ); } }); } async getProblemType() { await this.loadRelationships(); return this.problem.type; } } |
【推荐】编程新体验,更懂你的AI,立即体验豆包MarsCode编程助手
【推荐】凌霞软件回馈社区,博客园 & 1Panel & Halo 联合会员上线
【推荐】抖音旗下AI助手豆包,你的智能百科全书,全免费不限次数
【推荐】轻量又高性能的 SSH 工具 IShell:AI 加持,快人一步