diff --git a/app/controllers/quality_analysis_controller.rb b/app/controllers/quality_analysis_controller.rb index 79bb733e8..1d23c28c2 100644 --- a/app/controllers/quality_analysis_controller.rb +++ b/app/controllers/quality_analysis_controller.rb @@ -209,8 +209,22 @@ class QualityAnalysisController < ApplicationController arr = JSON.parse(projects_date).map {|m| m["nm"]} # eg: ["Hjqreturn:cc_rep", "Hjqreturn:putong", "Hjqreturn:sonar_rep2", "shitou:sonar_rep"] @quality_analyses = QualityAnalysis.where(:project_id => @project.id).select{|qa| arr.include?(qa.sonar_name)} else - complexity_date = open(@sonar_address + "/api/resources/index?resource=#{@resource_id}&depth=0&metrics=sqale_rating,function_complexity,duplicated_lines_density,comment_lines_density,sqale_index,lines,file_line,files,functions,classes,directories").read + filter = "sqale_rating,function_complexity,duplicated_lines_density,comment_lines_density,sqale_index,lines,files,functions,classes,directories,blocker_violations,critical_violations,major_violations,minor_violations,info_violations,violations" + complexity_date = open(@sonar_address + "/api/resources/index?resource=#{@resource_id}&depth=0&metrics=#{filter}").read @complexity =JSON.parse(complexity_date).first + + # 按名称转换成hash键值对 + @ha = {} + @complexity["msr"].each do |com| + key = com["key"] + if key == "sqale_index" + value = com["frmt_val"] + else + value = com["val"].to_i + end + @ha.store(key,value) + end + issue_date = open(@sonar_address + "/api/resources/index?resource=#{@resource_id}&depth=0&metrics=blocker_violations,critical_violations,major_violations,minor_violations,info_violations,violations").read @sonar_issues = JSON.parse(issue_date).first end diff --git a/app/views/quality_analysis/_hightchars.html.erb b/app/views/quality_analysis/_hightchars.html.erb index 9e6cdf5aa..306f000b0 100644 --- a/app/views/quality_analysis/_hightchars.html.erb +++ b/app/views/quality_analysis/_hightchars.html.erb @@ -94,7 +94,7 @@ }, series: [{ name: '代码质量', - data: [<%= @complexity["msr"][9].nil? ? 0 : @complexity["msr"][9]["val"] %>] + data: [<%= @ha["sqale_rating"].nil? ? 0 : @ha["sqale_rating"] %>] // tooltip: { // valueSuffix: ' km/h' // } @@ -209,7 +209,7 @@ }, series: [{ name: '复杂度', - data: [<%= @complexity["msr"][6].nil? ? 0 : @complexity["msr"][6]["val"] %>] + data: [<%= @ha["function_complexity"].nil? ? 0 : @ha["function_complexity"] %>] // tooltip: { // valueSuffix: ' km/h' // } @@ -329,7 +329,7 @@ }, series: [{ name: '重复率', - data: [<%= @complexity["msr"][7].nil? ? 0 : @complexity["msr"][7]["val"] %>] + data: [<%= @ha["duplicated_lines_density"].nil? ? 0 : @ha["duplicated_lines_density"] %>] // tooltip: { // valueSuffix: ' km/h' // } @@ -454,7 +454,7 @@ }, series: [{ name: '质量等级', - data: [<%= @complexity["msr"][5].nil? ? 0 : @complexity["msr"][5]["val"] %>] + data: [<%= @ha["comment_lines_density"].nil? ? 0 : @ha["comment_lines_density"] %>] // tooltip: { // valueSuffix: ' km/h' // } diff --git a/app/views/quality_analysis/_show.html.erb b/app/views/quality_analysis/_show.html.erb index 2442299bd..3a2b17720 100644 --- a/app/views/quality_analysis/_show.html.erb +++ b/app/views/quality_analysis/_show.html.erb @@ -3,139 +3,169 @@

质量分析

当前分支:<%= params[:branch] %>
-
-
项目代码质量分析报告
-
概要信息
-<% if @complexity["msr"].count > 3 %> - <%= render :partial => "hightchars" %> -
-
-
-

-

质量等级

-

<%= @complexity["msr"][9].nil? ? "A" : @complexity["msr"][9]["frmt_val"] %> - borderRadius"><%= @complexity["msr"][9].blank? ? "很好" : sqale_rating_status(@complexity["msr"][9]["val"].to_i)[0] %>

-
-
-

-

复杂度

-

<%= @complexity["msr"][6].nil? ? 0 : @complexity["msr"][6]["val"] %> - borderRadius"><%= @complexity["msr"][6].nil? ? 0 : complexity_status(@complexity["msr"][6]["val"].to_i)[0] %>

-
-
-
-
-

-

代码重复度

-

<%= @complexity["msr"][7].nil? ? 0 : @complexity["msr"][7]["frmt_val"] %> - borderRadius"><%= @complexity["msr"][7].nil? ? 0 : duplicated_lines_density_status(@complexity["msr"][7]["val"].to_i)[0] %>

-
-
-

-

注释率

-

<%= @complexity["msr"][5].nil? ? 0 : @complexity["msr"][5]["frmt_val"] %> - borderRadius"><%= @complexity["msr"][5].nil? ? 0 : comment_lines_density_status(@complexity["msr"][5]["val"].to_i)[0] %>

-
-
+
+
项目代码质量分析报告
+
概要信息
+<%= render :partial => "hightchars" %> +
+
+
+

+

质量等级

+

<%= @ha["sqale_rating"] %> + borderRadius"> + <%= @ha["sqale_rating"].nil? ? "很好" : sqale_rating_status(@ha["sqale_rating"].to_i)[0] %> + +

-<% end %> +
+

+

复杂度

+

<%= @ha["function_complexity"].nil? ? 0 : @ha["function_complexity"] %> + borderRadius"> + <%= @ha["function_complexity"].nil? ? "良好" : complexity_status(@ha["function_complexity"].to_i)[0] %> + +

+
+
+
+
+

+

代码重复度

+

<%= @ha["duplicated_lines_density"].nil? ? 0 : @ha["duplicated_lines_density"] %> + borderRadius"> + <%= @ha["duplicated_lines_density"].nil? ? 0 : duplicated_lines_density_status(@ha["duplicated_lines_density"].to_i)[0] %> + +

+
+
+

+

注释率

+

<%= @ha["comment_lines_density"].nil? ? 0 : @ha["comment_lines_density"] %> + borderRadius"> + <%= @ha["comment_lines_density"].nil? ? 0 : comment_lines_density_status(@ha["comment_lines_density"].to_i)[0] %> + +

+
+
+
-
质量等级<%=@complexity["msr"][9].nil? ? 0 : score_sqale_rating(@complexity["msr"][9]["val"].to_i) %>/5分 - 可定性评价为:质量<%=@complexity["msr"][9].nil? ? "很好" : sqale_rating_status(@complexity["msr"][9]["val"])[0] %>
-
-
技术债务 + +
+ + 质量等级 + <%= @ha["sqale_rating"].nil? ? 0 : score_sqale_rating(@ha["sqale_rating"].to_i) %>/5分 + 可定性评价为:质量<%= @ha["sqale_rating"].nil? ? "很好" : sqale_rating_status(@ha["sqale_rating"].to_i)[0] %>
+
+
技术债务 - <% if @complexity["msr"][8].nil? || @complexity["msr"][8]["frmt_val"] == "0" %> + <% if @ha["sqale_index"].to_i == 0 %> 0 <% else %> - <%= /[0-9]*/.match(@complexity["msr"][8]["frmt_val"])[0] %>天 - <%= / [0-9]*/.match(@complexity["msr"][8]["frmt_val"]).nil? ? 0 : / [0-9]*/.match(@complexity["msr"][8]["frmt_val"]) %>小时 + <%= /[0-9]*/.match(@ha["sqale_index"])[0] %>天 + <%= / [0-9]*/.match(@ha["sqale_index"]).nil? ? 0 : / [0-9]*/.match(@ha["sqale_index"]) %>小时 <% end %> - 查看详情
-
质量问题 - <%=@sonar_issues["msr"][0].nil? ? 0 : @sonar_issues["msr"][0]["frmt_val"] %> 问题分类如下:
- + 查看详情
+
质量问题 + + + <%= @ha["violations"].nil? ? 0 : @ha["violations"] %> + +  问题分类如下:
+ -
代码规模可定性评价为:<%=@complexity["msr"][0].nil? ? 0 : lines_scale(@complexity["msr"][0]["frmt_val"].to_i) %>
-
-
-

代码行数

-

<%= @complexity["msr"][0].nil? ? 0 : @complexity["msr"][0]["frmt_val"] %>

-
-
-

文件

-

<%= @complexity["msr"][2].nil? ? 0 : @complexity["msr"][2]["frmt_val"] %>

-
-
-

目录

-

<%= @complexity["msr"][3].nil? ? 0 : @complexity["msr"][3]["frmt_val"] %>

-
-
-

-

<%= @complexity["msr"][1].nil? ? 0 : @complexity["msr"][1]["frmt_val"] %>

-
-
-

方法

-

<%=@complexity["msr"][4].nil? ? 0 : @complexity["msr"][4]["frmt_val"] %>

-
+
+
+ + 代码规模可定性评价为:<%= @ha["lines"].nil? ? 0 : lines_scale(@ha["lines"].to_i) %>
+
+
+

代码行数

+

<%= @ha["lines"].nil? ? 0 : @ha["lines"] %>

- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - +
+

文件

+

<%= @ha["lines"].nil? ? 0 : @ha["lines"] %>

+
+
+

目录

+

<%= @ha["directories"].nil? ? 0 : @ha["directories"] %>

+
+
+

+

<%= @ha["classes"].nil? ? 0 : @ha["classes"] %>

+
+
+

方法

+

<%=@ha["functions"].nil? ? 0 : @ha["functions"] %>

+
+
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +