个人成长记录中心的数据处理
This commit is contained in:
parent
2f8b5a8a0f
commit
aecf1ff13c
|
|
@ -1,5 +1,5 @@
|
|||
class Experience < ActiveRecord::Base
|
||||
attr_accessible :container_id, :container_type, :score, :user_id
|
||||
attr_accessible :container_id, :container_type, :score, :user_id, :created_at, :updated_at
|
||||
|
||||
belongs_to :user
|
||||
end
|
||||
|
|
|
|||
|
|
@ -315,9 +315,7 @@ class User < Principal
|
|||
end
|
||||
}
|
||||
def challenge_tags
|
||||
shixuns = Shixun.where(:id => Myshixun.where(:user_id => self.id).map(&:shixun_id), :status => [2,3])
|
||||
myshixuns = Myshixun.where(:user_id => self.id, :shixun_id => shixuns.map(&:id))
|
||||
games = self.games.where(:myshixun_id => myshixuns.map(&:id), :status => 2)
|
||||
games = self.games.where(:id => self.experiences.map(&:container_id), :status => 2)
|
||||
challenge_tags = ChallengeTag.where(:challenge_id => games.map(&:challenge_id))
|
||||
end
|
||||
|
||||
|
|
|
|||
|
|
@ -19,7 +19,7 @@
|
|||
<td>闯关</td>
|
||||
<td>+ <%= exp.score %></td>
|
||||
<% game = Game.where(:id => exp.container_id).first %>
|
||||
<td><%= game ? "通过实训“#{game.challenge.shixun.name}”的第#{game.challenge.position}关获得的奖励" : "" %></td>
|
||||
<td><%= game ? "通过实训“#{game.challenge.shixun.name}”的第#{game.challenge.position}关获得的奖励" : "--" %></td>
|
||||
<td><%= format_time exp.created_at %></td>
|
||||
</tr>
|
||||
<% end %>
|
||||
|
|
|
|||
|
|
@ -33,12 +33,12 @@
|
|||
<td>查看参考答案</td>
|
||||
<td>- <%= grade.score.abs %></td>
|
||||
<% game = Game.where(:id => grade.container_id).first %>
|
||||
<td><%= game ? "查看实训“#{game.challenge.shixun.name}”第#{game.challenge.position}关的参考答案消耗的金币" : "" %></td>
|
||||
<td><%= game ? "查看实训“#{game.challenge.shixun.name}”第#{game.challenge.position}关的参考答案消耗的金币" : "--" %></td>
|
||||
<% when 'Game' %>
|
||||
<td>闯关</td>
|
||||
<td>+ <%= grade.score %></td>
|
||||
<% game = Game.where(:id => grade.container_id).first %>
|
||||
<td><%= game ? "通过实训“#{game.challenge.shixun.name}”的第#{game.challenge.position}关获得的奖励" : "" %></td>
|
||||
<td><%= game ? "通过实训“#{game.challenge.shixun.name}”的第#{game.challenge.position}关获得的奖励" : "--" %></td>
|
||||
<% end %>
|
||||
<td><%= format_time grade.created_at %></td>
|
||||
</tr>
|
||||
|
|
|
|||
|
|
@ -15,13 +15,16 @@
|
|||
</thead>
|
||||
<tbody>
|
||||
<% @user_tags.each do |tag| %>
|
||||
<tr>
|
||||
<td>闯关</td>
|
||||
<% game = Game.where(:id => tag.container_id).first %>
|
||||
<td>+ 标签:<%= game ? game.challenge.challenge_tags.map(&:name).join("、") : "" %></td>
|
||||
<td><%= game ? "通过实训“#{game.challenge.shixun.name}”的第#{game.challenge.position}关获得的标签" : "" %></td>
|
||||
<td><%= format_time tag.created_at %></td>
|
||||
</tr>
|
||||
<% game = Game.where(:id => tag.container_id).first %>
|
||||
<% if game && game.challenge.challenge_tags.count > 0 %>
|
||||
<tr>
|
||||
<td>闯关</td>
|
||||
<% game = Game.where(:id => tag.container_id).first %>
|
||||
<td>+ 标签:<%= game ? game.challenge.challenge_tags.map(&:name).join("、") : "" %></td>
|
||||
<td><%= "通过实训“#{game.challenge.shixun.name}”的第#{game.challenge.position}关获得的标签" %></td>
|
||||
<td><%= format_time tag.created_at %></td>
|
||||
</tr>
|
||||
<% end %>
|
||||
<% end %>
|
||||
</tbody>
|
||||
</table>
|
||||
|
|
|
|||
|
|
@ -1,14 +1,12 @@
|
|||
class MigrateGradeExp < ActiveRecord::Migration
|
||||
def up
|
||||
Grade.where(:container_type => "--- !ruby/class 'Game'").update_all(:container_type => 'Game')
|
||||
Experience.where(:container_type => "--- !ruby/class 'Game'").update_all(:container_type => 'Game')
|
||||
|
||||
count = Grade.where(:container_type => "Game") / 30 + 2
|
||||
count = Grade.where(:container_type => "Game").count / 30 + 2
|
||||
transaction do
|
||||
for i in 1 .. count do
|
||||
Grade.where(:container_type => "Game").page(i).per(30).each do |score|
|
||||
if Experience.where(:container_type => "Game", :container_id => score.container_id).blank?
|
||||
Experience.create!(:user_id => score.user_id, :container_id => score.container_id, :container_type => "Game", :score => score.score, :created_at => score.created_at, :updated_at => score.updated_at)
|
||||
exp = Experience.create!(:user_id => score.user_id, :container_id => score.container_id, :container_type => "Game", :score => score.score, :created_at => score.created_at, :updated_at => score.updated_at)
|
||||
exp.user.update_column(:experience, (exp.score.to_i + exp.user.experience.to_i))
|
||||
end
|
||||
end
|
||||
end
|
||||
|
|
|
|||
Loading…
Reference in New Issue