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 @@
质量等级
-<%= @complexity["msr"][9].nil? ? "A" : @complexity["msr"][9]["frmt_val"] %> -
-复杂度
-<%= @complexity["msr"][6].nil? ? 0 : @complexity["msr"][6]["val"] %> -
-代码重复度
-<%= @complexity["msr"][7].nil? ? 0 : @complexity["msr"][7]["frmt_val"] %> -
-注释率
-<%= @complexity["msr"][5].nil? ? 0 : @complexity["msr"][5]["frmt_val"] %> -
-质量等级
+<%= @ha["sqale_rating"] %> +
+复杂度
+<%= @ha["function_complexity"].nil? ? 0 : @ha["function_complexity"] %> +
+ +代码重复度
+<%= @ha["duplicated_lines_density"].nil? ? 0 : @ha["duplicated_lines_density"] %> +
+ +注释率
+<%= @ha["comment_lines_density"].nil? ? 0 : @ha["comment_lines_density"] %> +
+ +代码行数
-<%= @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 : @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"] %>
+