cancer_predict/app/models/cancerpredictrecord.rb

25 lines
1022 B
Ruby
Raw Permalink Normal View History

class Cancerpredictrecord
include Mongoid::Document
include Mongoid::Timestamps
include OrbitModel::Status
include OrbitModel::Impression
# encoding: utf-8
include OrbitTag::Taggable
include OrbitCategory::Categorizable
field :title ,type:String ,default:""
field :submit_time ,type:String ,default:""
field :result , type:Hash , default:{}
field :names , type:Hash , default:{}
field :values , type:Hash , default:{}
field :submit_numbers , type:Fixnum , default: 1
scope :can_display, ->{where(:is_hidden=>false,:is_preview => false).any_of({:postdate.lt=>Time.now, :deadline.gt=>Time.now},{:postdate.lt=>Time.now, :deadline=>nil}).order_by([:is_top, :desc],[:postdate, :desc])}
scope :is_approved, ->{where(:approved => true)}
before_save :set_submit_times
def set_submit_times
2022-01-22 09:27:15 +00:00
self.submit_time = Cancerpredictrecord.all.count + 1
end
def check_missing_data
missing_keys = self.names.keys - self.result.keys rescue []
missing_keys.each{|k| self.result[k] = "" }
end
end