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
|
|
|
|
|
|
|
|
#文档数量
|
2014-08-16 16:28:35 +08:00
|
|
|
def documents_num project
|
2014-08-05 16:39:33 +08:00
|
|
|
project.documents.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
|
|
|
|
|
|
|
|
#文档得分
|
2014-08-16 16:28:35 +08:00
|
|
|
def documents_score project
|
|
|
|
d_num = documents_num(project)
|
2014-08-05 16:39:33 +08:00
|
|
|
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-16 16:28:35 +08:00
|
|
|
result = (issue_score project) + (news_score project) + (documents_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
|
2014-08-26 16:07:17 +08:00
|
|
|
ps.issue_num = issue_num(project)
|
|
|
|
ps.board_message_num = board_message_num(project)
|
|
|
|
ps.changeset_num = changesets_num(project)
|
|
|
|
ps.documents_num = documents_num(project)
|
|
|
|
ps.issue_journal_num = issue_journal_num(project)
|
|
|
|
ps.news_num = news_num(project)
|
|
|
|
|
2014-08-13 11:17:22 +08:00
|
|
|
ps.score = result
|
2014-08-06 11:46:38 +08:00
|
|
|
ps.project = project
|
|
|
|
ps.save
|
|
|
|
else
|
|
|
|
ps = pss.first
|
2014-08-26 16:07:17 +08:00
|
|
|
ps.issue_num = issue_num(project)
|
|
|
|
ps.board_message_num = board_message_num(project)
|
|
|
|
ps.changeset_num = changesets_num(project)
|
|
|
|
ps.documents_num = documents_num(project)
|
|
|
|
ps.issue_journal_num = issue_journal_num(project)
|
|
|
|
ps.news_num = news_num(project)
|
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-26 16:07:17 +08:00
|
|
|
def get_project_score project
|
|
|
|
pss = ProjectScore.where("project_id = '#{project.id}'")
|
|
|
|
ps = nil
|
|
|
|
if pss.nil? || pss.count == 0
|
|
|
|
ps = nil
|
|
|
|
else
|
|
|
|
ps = pss.first
|
|
|
|
end
|
|
|
|
ps
|
|
|
|
end
|
|
|
|
|
2014-08-04 12:23:20 +08:00
|
|
|
end
|