You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
psfpeqmhf/app/models/hack_user_lastest_code.rb

32 lines
1.2 KiB

This file contains ambiguous Unicode characters!

This file contains ambiguous Unicode characters that may be confused with others in your current locale. If your use case is intentional and legitimate, you can safely ignore this warning. Use the Escape button to highlight these characters.

class HackUserLastestCode < ApplicationRecord
# passed 用户之前评测是否通过
# status: 最新评测状态: -1测试用例结果不匹配; 0: 评测通过; ;2 评测超时;3 创建pod失败; 4 编译失败;5 执行失败
# submit_status: 0: 可以评测, 1评测中
# passed_time:第一次通关的时间
# 编程题最新代码
belongs_to :hack, counter_cache: true
belongs_to :user
has_many :hack_user_codes, dependent: :destroy
has_one :hack_user_debug
scope :mine, ->(author_id){ where(user_id: author_id).first }
scope :mine_hack, ->(author_id){ where(user_id: author_id) }
scope :passed, -> {where(status: 1)}
validates_length_of :notes, maximum: 5000, message: "不能超过5000个字"
# 根据得分比例来算实际得分(试卷、实训作业)
def real_score question_score
((score < 0 ? 0 : score).to_f / hack.score) * question_score
end
# 预计输出先默认是隐藏的
def expected_output
test_check_power ? self[:expected_output] : Base64.urlsafe_encode64("隐藏测试集,暂不支持查看")
end
def input
test_check_power ? self[:input] : "隐藏测试集,暂不支持查看"
end
end