Commit 4e40114e89062b3f36abc412c5918c8e9b8f90de
Committed by
João M. M. da Silva
1 parent
f9adf66a
Exists in
master
and in
23 other branches
[Mezuro] added x axis in historical charts
Showing
3 changed files
with
38 additions
and
8 deletions
Show diff stats
plugins/mezuro/controllers/mezuro_plugin_profile_controller.rb
@@ -81,7 +81,9 @@ class MezuroPluginProfileController < ProfileController | @@ -81,7 +81,9 @@ class MezuroPluginProfileController < ProfileController | ||
81 | if project_content_has_errors? | 81 | if project_content_has_errors? |
82 | redirect_to_error_page(@content.errors[:base]) | 82 | redirect_to_error_page(@content.errors[:base]) |
83 | else | 83 | else |
84 | - @score_history = modules_results.collect { |module_result| module_result.grade } | 84 | + @score_history = modules_results.map do |module_result| |
85 | + [module_result.grade, format_date_to_simple_form(module_result.date)] | ||
86 | + end | ||
85 | render :partial => 'content_viewer/score_history' | 87 | render :partial => 'content_viewer/score_history' |
86 | end | 88 | end |
87 | end | 89 | end |
@@ -90,7 +92,7 @@ class MezuroPluginProfileController < ProfileController | @@ -90,7 +92,7 @@ class MezuroPluginProfileController < ProfileController | ||
90 | 92 | ||
91 | def filtering_metric_history(metric_name, module_history) | 93 | def filtering_metric_history(metric_name, module_history) |
92 | metrics_history = module_history.map do |module_result| | 94 | metrics_history = module_history.map do |module_result| |
93 | - [module_result.metric_results, module_result.date.to_s[0..9]] | 95 | + [module_result.metric_results, format_date_to_simple_form(module_result.date)] |
94 | end | 96 | end |
95 | metric_history = metrics_history.map do |metric_results_with_date| | 97 | metric_history = metrics_history.map do |metric_results_with_date| |
96 | [(metric_results_with_date.first.select do |metric_result| | 98 | [(metric_results_with_date.first.select do |metric_result| |
@@ -110,5 +112,10 @@ class MezuroPluginProfileController < ProfileController | @@ -110,5 +112,10 @@ class MezuroPluginProfileController < ProfileController | ||
110 | def project_content_has_errors? | 112 | def project_content_has_errors? |
111 | not @content.errors[:base].nil? | 113 | not @content.errors[:base].nil? |
112 | end | 114 | end |
115 | + | ||
116 | + def format_date_to_simple_form date | ||
117 | + date.to_s[0..9] | ||
118 | + end | ||
119 | + | ||
113 | end | 120 | end |
114 | 121 |
plugins/mezuro/lib/mezuro_plugin/helpers/content_viewer_helper.rb
1 | require 'googlecharts' | 1 | require 'googlecharts' |
2 | 2 | ||
3 | class MezuroPlugin::Helpers::ContentViewerHelper | 3 | class MezuroPlugin::Helpers::ContentViewerHelper |
4 | + | ||
5 | + MAX_NUMBER_OF_LABELS = 5 | ||
6 | + | ||
4 | def self.format_grade(grade) | 7 | def self.format_grade(grade) |
5 | sprintf("%.2f", grade.to_f) | 8 | sprintf("%.2f", grade.to_f) |
6 | end | 9 | end |
@@ -8,7 +11,7 @@ class MezuroPlugin::Helpers::ContentViewerHelper | @@ -8,7 +11,7 @@ class MezuroPlugin::Helpers::ContentViewerHelper | ||
8 | def self.create_periodicity_options | 11 | def self.create_periodicity_options |
9 | [["Not Periodically", 0], ["1 day", 1], ["2 days", 2], ["Weekly", 7], ["Biweeky", 15], ["Monthly", 30]] | 12 | [["Not Periodically", 0], ["1 day", 1], ["2 days", 2], ["Weekly", 7], ["Biweeky", 15], ["Monthly", 30]] |
10 | end | 13 | end |
11 | - | 14 | + |
12 | def self.create_license_options | 15 | def self.create_license_options |
13 | options = YAML.load_file("#{RAILS_ROOT}/plugins/mezuro/licenses.yaml") | 16 | options = YAML.load_file("#{RAILS_ROOT}/plugins/mezuro/licenses.yaml") |
14 | options = options.split(";") | 17 | options = options.split(";") |
@@ -16,7 +19,7 @@ class MezuroPlugin::Helpers::ContentViewerHelper | @@ -16,7 +19,7 @@ class MezuroPlugin::Helpers::ContentViewerHelper | ||
16 | options.each { |option| formated_options << [option, option] } | 19 | options.each { |option| formated_options << [option, option] } |
17 | formated_options | 20 | formated_options |
18 | end | 21 | end |
19 | - | 22 | + |
20 | def self.generate_chart(score_history) | 23 | def self.generate_chart(score_history) |
21 | values = [] | 24 | values = [] |
22 | labels = [] | 25 | labels = [] |
@@ -24,6 +27,7 @@ class MezuroPlugin::Helpers::ContentViewerHelper | @@ -24,6 +27,7 @@ class MezuroPlugin::Helpers::ContentViewerHelper | ||
24 | values << score_data.first | 27 | values << score_data.first |
25 | labels << score_data.last | 28 | labels << score_data.last |
26 | end | 29 | end |
30 | + labels = discretize_array labels | ||
27 | Gchart.line( | 31 | Gchart.line( |
28 | :title_color => 'FF0000', | 32 | :title_color => 'FF0000', |
29 | :size => '600x180', | 33 | :size => '600x180', |
@@ -42,14 +46,33 @@ class MezuroPlugin::Helpers::ContentViewerHelper | @@ -42,14 +46,33 @@ class MezuroPlugin::Helpers::ContentViewerHelper | ||
42 | selected_option = options.find { |option| option.last == index.to_i } | 46 | selected_option = options.find { |option| option.last == index.to_i } |
43 | selected_option.first | 47 | selected_option.first |
44 | end | 48 | end |
45 | - | 49 | + |
46 | def self.format_name(metric_result) | 50 | def self.format_name(metric_result) |
47 | metric_result.metric.name.delete("() ") | 51 | metric_result.metric.name.delete("() ") |
48 | end | 52 | end |
49 | - | 53 | + |
50 | def self.get_license_option(selected) | 54 | def self.get_license_option(selected) |
51 | options = YAML.load_file("#{RAILS_ROOT}/plugins/mezuro/licenses.yaml") | 55 | options = YAML.load_file("#{RAILS_ROOT}/plugins/mezuro/licenses.yaml") |
52 | options.split(";") | 56 | options.split(";") |
53 | selected_option = options.find { |license| license == selected } | 57 | selected_option = options.find { |license| license == selected } |
54 | end | 58 | end |
59 | + | ||
60 | + private | ||
61 | + | ||
62 | + def self.discretize_array(array) | ||
63 | + if array.size > MAX_NUMBER_OF_LABELS | ||
64 | + range_array.map { |i| discrete_element(array, i)} | ||
65 | + else | ||
66 | + array | ||
67 | + end | ||
68 | + end | ||
69 | + | ||
70 | + def self.range_array | ||
71 | + (0..(MAX_NUMBER_OF_LABELS - 1)).to_a | ||
72 | + end | ||
73 | + | ||
74 | + def self.discrete_element(array, i) | ||
75 | + array[(i*(array.size - 1))/(MAX_NUMBER_OF_LABELS - 1)] | ||
76 | + end | ||
77 | + | ||
55 | end | 78 | end |
plugins/mezuro/test/functional/mezuro_plugin_profile_controller_test.rb
@@ -126,7 +126,7 @@ class MezuroPluginProfileControllerTest < ActionController::TestCase | @@ -126,7 +126,7 @@ class MezuroPluginProfileControllerTest < ActionController::TestCase | ||
126 | get :module_metrics_history, :profile => @profile.identifier, :id => @content.id, :module_name => @project.name, | 126 | get :module_metrics_history, :profile => @profile.identifier, :id => @content.id, :module_name => @project.name, |
127 | :metric_name => @module_result.metric_result.first.metric.name.delete("() ") | 127 | :metric_name => @module_result.metric_result.first.metric.name.delete("() ") |
128 | assert_equal @content, assigns(:content) | 128 | assert_equal @content, assigns(:content) |
129 | - assert_equal [@module_result.metric_result[0].value], assigns(:score_history) | 129 | + assert_equal [[@module_result.metric_result[0].value, @module_result.date.to_s[0..9]]], assigns(:score_history) |
130 | assert_response 200 | 130 | assert_response 200 |
131 | end | 131 | end |
132 | 132 | ||
@@ -134,7 +134,7 @@ class MezuroPluginProfileControllerTest < ActionController::TestCase | @@ -134,7 +134,7 @@ class MezuroPluginProfileControllerTest < ActionController::TestCase | ||
134 | Kalibro::ModuleResult.expects(:request).with("ModuleResult", :get_result_history, {:project_name => @project.name, :module_name => @project.name}).returns({:module_result => @module_result}) | 134 | Kalibro::ModuleResult.expects(:request).with("ModuleResult", :get_result_history, {:project_name => @project.name, :module_name => @project.name}).returns({:module_result => @module_result}) |
135 | get :module_grade_history, :profile => @profile.identifier, :id => @content.id, :module_name => @project.name | 135 | get :module_grade_history, :profile => @profile.identifier, :id => @content.id, :module_name => @project.name |
136 | assert_equal @content, assigns(:content) | 136 | assert_equal @content, assigns(:content) |
137 | - assert_equal [@module_result.grade], assigns(:score_history) | 137 | + assert_equal [[@module_result.grade, @module_result.date.to_s[0..9]]], assigns(:score_history) |
138 | assert_response 200 | 138 | assert_response 200 |
139 | end | 139 | end |
140 | 140 |