2014-08-04 12:23:20 +08:00
|
|
|
# encoding: utf-8
|
2014-08-05 16:39:33 +08:00
|
|
|
module ProjectScoreHelper
|
2014-08-04 12:23:20 +08:00
|
|
|
#缺陷数量
|
|
|
|
def issue_num project
|
2014-08-05 11:10:41 +08:00
|
|
|
project.issues.count
|
|
|
|
end
|
2014-08-04 12:23:20 +08:00
|
|
|
|
2014-08-05 11:10:41 +08:00
|
|
|
#缺陷留言数量
|
|
|
|
def issue_journal_num project
|
2014-08-05 16:39:33 +08:00
|
|
|
project.issue_changes.count
|
|
|
|
end
|
|
|
|
|
|
|
|
#新闻数量
|
|
|
|
def news_num project
|
|
|
|
project.news.count
|
|
|
|
end
|
|
|
|
|
|
|
|
#文档数量
|
|
|
|
def document_num project
|
|
|
|
project.documents.count
|
|
|
|
end
|
|
|
|
|
|
|
|
#代码提交数量
|
|
|
|
def changesets_num project
|
|
|
|
project.changesets.count
|
|
|
|
end
|
|
|
|
|
|
|
|
#讨论区帖子数量
|
|
|
|
def board_message_num project
|
|
|
|
board_message_count = 0
|
|
|
|
project.boards.each do |board|
|
|
|
|
board_message_count += board.messages_count
|
|
|
|
end
|
|
|
|
board_message_count
|
|
|
|
end
|
|
|
|
|
|
|
|
#缺陷得分
|
|
|
|
def issue_score project
|
|
|
|
i_num = issue_num project
|
|
|
|
i_j_num = issue_journal_num project
|
|
|
|
i_num * 4 + i_j_num
|
|
|
|
end
|
|
|
|
|
|
|
|
# 新闻得分
|
|
|
|
def news_score project
|
|
|
|
n_num = news_num project
|
|
|
|
n_num
|
|
|
|
end
|
|
|
|
|
|
|
|
#文档得分
|
|
|
|
def document_score project
|
|
|
|
d_num = document_num project
|
|
|
|
d_num * 4
|
|
|
|
end
|
|
|
|
|
|
|
|
#代码提交得分
|
|
|
|
def changesets_score project
|
|
|
|
c_num = changesets_num project
|
|
|
|
c_num * 4
|
|
|
|
end
|
|
|
|
|
|
|
|
#讨论区帖子得分
|
|
|
|
def board_message_score project
|
|
|
|
b_m_num = board_message_num project
|
|
|
|
b_m_num * 2
|
|
|
|
end
|
|
|
|
|
2014-08-13 11:17:22 +08:00
|
|
|
#计算项目得分
|
2014-08-05 16:39:33 +08:00
|
|
|
def project_scores project
|
2014-08-06 11:46:38 +08:00
|
|
|
result = (issue_score project) + (news_score project) + (document_score project) + (changesets_score project) + (board_message_score project)
|
2014-08-13 11:17:22 +08:00
|
|
|
pss = ProjectScore.where("project_id = '#{project.id}'")
|
2014-08-06 11:46:38 +08:00
|
|
|
if pss.nil? || pss.count == 0
|
2014-08-13 11:17:22 +08:00
|
|
|
ps = ProjectScore.new
|
|
|
|
ps.score = result
|
2014-08-06 11:46:38 +08:00
|
|
|
ps.project = project
|
|
|
|
ps.save
|
|
|
|
else
|
|
|
|
ps = pss.first
|
2014-08-13 11:17:22 +08:00
|
|
|
ps.score = result
|
2014-08-06 11:46:38 +08:00
|
|
|
ps.save
|
|
|
|
end
|
|
|
|
result
|
2014-08-04 12:23:20 +08:00
|
|
|
end
|
|
|
|
|
2014-08-13 11:17:22 +08:00
|
|
|
#读取项目得分
|
|
|
|
def red_project_scores project
|
|
|
|
grade = 0
|
|
|
|
pss = ProjectScore.where("project_id = '#{project.id}'")
|
|
|
|
if pss.nil? || pss.count == 0
|
|
|
|
grade
|
|
|
|
else
|
|
|
|
ps = pss.first
|
|
|
|
grade = ps.score
|
|
|
|
grade
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2014-08-04 12:23:20 +08:00
|
|
|
end
|