content_viewer_helper.rb
2.08 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
class MezuroPlugin::Helpers::ContentViewerHelper
MAX_NUMBER_OF_LABELS = 5
def self.format_grade(grade)
sprintf("%.2f", grade.to_f)
end
def self.create_periodicity_options
[["Not Periodically", 0], ["1 day", 1], ["2 days", 2], ["Weekly", 7], ["Biweeky", 15], ["Monthly", 30]]
end
def self.create_license_options
options = YAML.load_file("#{RAILS_ROOT}/plugins/mezuro/licenses.yaml")
options = options.split(";")
formated_options = []
options.each { |option| formated_options << [option, option] }
formated_options
end
def self.generate_chart(score_history)
values = []
labels = []
score_history.each do |score_data|
values << score_data.first
labels << score_data.last
end
labels = discretize_array labels
Gchart.line(
:title_color => 'FF0000',
:size => '600x180',
:bg => {:color => 'efefef', :type => 'stripes'},
:line_colors => 'c4a000',
:data => values,
:labels => labels,
:axis_with_labels => ['y','x'],
:max_value => values.max,
:min_value => values.min
)
end
def self.get_periodicity_option(index)
options = [["Not Periodically", 0], ["1 day", 1], ["2 days", 2], ["Weekly", 7], ["Biweeky", 15], ["Monthly", 30]]
selected_option = options.find { |option| option.last == index.to_i }
selected_option.first
end
def self.format_name(metric_result)
metric_result.metric.name.delete("() ")
end
def self.get_license_option(selected)
options = YAML.load_file("#{RAILS_ROOT}/plugins/mezuro/licenses.yaml")
options.split(";")
selected_option = options.find { |license| license == selected }
end
private
def self.discretize_array(array)
if array.size > MAX_NUMBER_OF_LABELS
range_array.map { |i| discrete_element(array, i)}
else
array
end
end
def self.range_array
(0..(MAX_NUMBER_OF_LABELS - 1)).to_a
end
def self.discrete_element(array, i)
array[(i*(array.size - 1))/(MAX_NUMBER_OF_LABELS - 1)]
end
end