Commit 4e40114e89062b3f36abc412c5918c8e9b8f90de
Committed by
João M. M. da Silva
1 parent
f9adf66a
Exists in
staging
and in
42 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 | 81 | if project_content_has_errors? |
| 82 | 82 | redirect_to_error_page(@content.errors[:base]) |
| 83 | 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 | 87 | render :partial => 'content_viewer/score_history' |
| 86 | 88 | end |
| 87 | 89 | end |
| ... | ... | @@ -90,7 +92,7 @@ class MezuroPluginProfileController < ProfileController |
| 90 | 92 | |
| 91 | 93 | def filtering_metric_history(metric_name, module_history) |
| 92 | 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 | 96 | end |
| 95 | 97 | metric_history = metrics_history.map do |metric_results_with_date| |
| 96 | 98 | [(metric_results_with_date.first.select do |metric_result| |
| ... | ... | @@ -110,5 +112,10 @@ class MezuroPluginProfileController < ProfileController |
| 110 | 112 | def project_content_has_errors? |
| 111 | 113 | not @content.errors[:base].nil? |
| 112 | 114 | end |
| 115 | + | |
| 116 | + def format_date_to_simple_form date | |
| 117 | + date.to_s[0..9] | |
| 118 | + end | |
| 119 | + | |
| 113 | 120 | end |
| 114 | 121 | ... | ... |
plugins/mezuro/lib/mezuro_plugin/helpers/content_viewer_helper.rb
| 1 | 1 | require 'googlecharts' |
| 2 | 2 | |
| 3 | 3 | class MezuroPlugin::Helpers::ContentViewerHelper |
| 4 | + | |
| 5 | + MAX_NUMBER_OF_LABELS = 5 | |
| 6 | + | |
| 4 | 7 | def self.format_grade(grade) |
| 5 | 8 | sprintf("%.2f", grade.to_f) |
| 6 | 9 | end |
| ... | ... | @@ -8,7 +11,7 @@ class MezuroPlugin::Helpers::ContentViewerHelper |
| 8 | 11 | def self.create_periodicity_options |
| 9 | 12 | [["Not Periodically", 0], ["1 day", 1], ["2 days", 2], ["Weekly", 7], ["Biweeky", 15], ["Monthly", 30]] |
| 10 | 13 | end |
| 11 | - | |
| 14 | + | |
| 12 | 15 | def self.create_license_options |
| 13 | 16 | options = YAML.load_file("#{RAILS_ROOT}/plugins/mezuro/licenses.yaml") |
| 14 | 17 | options = options.split(";") |
| ... | ... | @@ -16,7 +19,7 @@ class MezuroPlugin::Helpers::ContentViewerHelper |
| 16 | 19 | options.each { |option| formated_options << [option, option] } |
| 17 | 20 | formated_options |
| 18 | 21 | end |
| 19 | - | |
| 22 | + | |
| 20 | 23 | def self.generate_chart(score_history) |
| 21 | 24 | values = [] |
| 22 | 25 | labels = [] |
| ... | ... | @@ -24,6 +27,7 @@ class MezuroPlugin::Helpers::ContentViewerHelper |
| 24 | 27 | values << score_data.first |
| 25 | 28 | labels << score_data.last |
| 26 | 29 | end |
| 30 | + labels = discretize_array labels | |
| 27 | 31 | Gchart.line( |
| 28 | 32 | :title_color => 'FF0000', |
| 29 | 33 | :size => '600x180', |
| ... | ... | @@ -42,14 +46,33 @@ class MezuroPlugin::Helpers::ContentViewerHelper |
| 42 | 46 | selected_option = options.find { |option| option.last == index.to_i } |
| 43 | 47 | selected_option.first |
| 44 | 48 | end |
| 45 | - | |
| 49 | + | |
| 46 | 50 | def self.format_name(metric_result) |
| 47 | 51 | metric_result.metric.name.delete("() ") |
| 48 | 52 | end |
| 49 | - | |
| 53 | + | |
| 50 | 54 | def self.get_license_option(selected) |
| 51 | 55 | options = YAML.load_file("#{RAILS_ROOT}/plugins/mezuro/licenses.yaml") |
| 52 | 56 | options.split(";") |
| 53 | 57 | selected_option = options.find { |license| license == selected } |
| 54 | 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 | 78 | end | ... | ... |
plugins/mezuro/test/functional/mezuro_plugin_profile_controller_test.rb
| ... | ... | @@ -126,7 +126,7 @@ class MezuroPluginProfileControllerTest < ActionController::TestCase |
| 126 | 126 | get :module_metrics_history, :profile => @profile.identifier, :id => @content.id, :module_name => @project.name, |
| 127 | 127 | :metric_name => @module_result.metric_result.first.metric.name.delete("() ") |
| 128 | 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 | 130 | assert_response 200 |
| 131 | 131 | end |
| 132 | 132 | |
| ... | ... | @@ -134,7 +134,7 @@ class MezuroPluginProfileControllerTest < ActionController::TestCase |
| 134 | 134 | Kalibro::ModuleResult.expects(:request).with("ModuleResult", :get_result_history, {:project_name => @project.name, :module_name => @project.name}).returns({:module_result => @module_result}) |
| 135 | 135 | get :module_grade_history, :profile => @profile.identifier, :id => @content.id, :module_name => @project.name |
| 136 | 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 | 138 | assert_response 200 |
| 139 | 139 | end |
| 140 | 140 | ... | ... |