report_engine 1.2.4
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- data/.document +5 -0
- data/LICENSE +20 -0
- data/README.rdoc +17 -0
- data/Rakefile +53 -0
- data/VERSION +1 -0
- data/images/empty_heart.jpg +0 -0
- data/images/folder_open.png +0 -0
- data/images/full_heart.jpg +0 -0
- data/images/half_heart.jpg +0 -0
- data/lib/report_engine.rb +50 -0
- data/lib/report_engine/canvas_factory.rb +13 -0
- data/lib/report_engine/container.rb +4 -0
- data/lib/report_engine/footer.rb +13 -0
- data/lib/report_engine/google_chart.rb +59 -0
- data/lib/report_engine/horizontal_chart.rb +43 -0
- data/lib/report_engine/html/container.rb +9 -0
- data/lib/report_engine/html/google_chart.rb +9 -0
- data/lib/report_engine/html/list.rb +18 -0
- data/lib/report_engine/html/question_stats.rb +29 -0
- data/lib/report_engine/html/section.rb +16 -0
- data/lib/report_engine/html/sub_table.rb +14 -0
- data/lib/report_engine/html/table.rb +77 -0
- data/lib/report_engine/html/text.rb +15 -0
- data/lib/report_engine/html_canvas.rb +23 -0
- data/lib/report_engine/list.rb +22 -0
- data/lib/report_engine/page.rb +14 -0
- data/lib/report_engine/pdf/container.rb +9 -0
- data/lib/report_engine/pdf/google_chart.rb +9 -0
- data/lib/report_engine/pdf/list.rb +9 -0
- data/lib/report_engine/pdf/question_stats.rb +27 -0
- data/lib/report_engine/pdf/section.rb +17 -0
- data/lib/report_engine/pdf/sub_table.rb +6 -0
- data/lib/report_engine/pdf/table.rb +72 -0
- data/lib/report_engine/pdf/text.rb +11 -0
- data/lib/report_engine/pdf_canvas.rb +38 -0
- data/lib/report_engine/question_stats.rb +12 -0
- data/lib/report_engine/report.rb +19 -0
- data/lib/report_engine/sub_table.rb +10 -0
- data/lib/report_engine/table.rb +35 -0
- data/lib/report_engine/text.rb +13 -0
- data/report_engine.gemspec +90 -0
- data/test/category_test.rb +65 -0
- data/test/chart_test.rb +8 -0
- data/test/forebyg_test.rb +81 -0
- data/test/helper.rb +11 -0
- data/test/horizontal_chart_test.rb +5 -0
- data/test/pdftest.rb +15 -0
- data/test/repartition_test.rb +32 -0
- data/test/test_chart.rb +22 -0
- data/test/test_correlation_report.rb +65 -0
- data/test/test_feedback.rb +48 -0
- data/test/test_question_stats.rb +35 -0
- data/test/test_report.rb +82 -0
- data/test/test_report_engine.rb +8 -0
- data/test/test_table.rb +54 -0
- metadata +110 -0
data/.document
ADDED
data/LICENSE
ADDED
@@ -0,0 +1,20 @@
|
|
1
|
+
Copyright (c) 2009 Bastien Vaucher
|
2
|
+
|
3
|
+
Permission is hereby granted, free of charge, to any person obtaining
|
4
|
+
a copy of this software and associated documentation files (the
|
5
|
+
"Software"), to deal in the Software without restriction, including
|
6
|
+
without limitation the rights to use, copy, modify, merge, publish,
|
7
|
+
distribute, sublicense, and/or sell copies of the Software, and to
|
8
|
+
permit persons to whom the Software is furnished to do so, subject to
|
9
|
+
the following conditions:
|
10
|
+
|
11
|
+
The above copyright notice and this permission notice shall be
|
12
|
+
included in all copies or substantial portions of the Software.
|
13
|
+
|
14
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
|
15
|
+
EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
|
16
|
+
MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
|
17
|
+
NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
|
18
|
+
LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
|
19
|
+
OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
|
20
|
+
WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
data/README.rdoc
ADDED
@@ -0,0 +1,17 @@
|
|
1
|
+
= report_engine
|
2
|
+
|
3
|
+
Description goes here.
|
4
|
+
|
5
|
+
== Note on Patches/Pull Requests
|
6
|
+
|
7
|
+
* Fork the project.
|
8
|
+
* Make your feature addition or bug fix.
|
9
|
+
* Add tests for it. This is important so I don't break it in a
|
10
|
+
future version unintentionally.
|
11
|
+
* Commit, do not mess with rakefile, version, or history.
|
12
|
+
(if you want to have your own version, that is fine but bump version in a commit by itself I can ignore when I pull)
|
13
|
+
* Send me a pull request. Bonus points for topic branches.
|
14
|
+
|
15
|
+
== Copyright
|
16
|
+
|
17
|
+
Copyright (c) 2010 Bastien Vaucher. See LICENSE for details.
|
data/Rakefile
ADDED
@@ -0,0 +1,53 @@
|
|
1
|
+
require 'rubygems'
|
2
|
+
require 'rake'
|
3
|
+
|
4
|
+
begin
|
5
|
+
require 'jeweler'
|
6
|
+
Jeweler::Tasks.new do |gem|
|
7
|
+
gem.name = "report_engine"
|
8
|
+
gem.summary = "Report engine specific to the teneo app"
|
9
|
+
gem.description = "Layer on top of prawn and the html renderer to generate reports for Novalis::teneo"
|
10
|
+
gem.email = "bastien.vaucher@gmail.com"
|
11
|
+
gem.homepage = "http://github.com/bastien/report_engine"
|
12
|
+
gem.authors = ["Bastien Vaucher", "Jacob Atzen"]
|
13
|
+
# gem.add_development_dependency "thoughtbot-shoulda", ">= 0"
|
14
|
+
# gem is a Gem::Specification... see http://www.rubygems.org/read/chapter/20 for additional settings
|
15
|
+
end
|
16
|
+
Jeweler::GemcutterTasks.new
|
17
|
+
rescue LoadError
|
18
|
+
puts "Jeweler (or a dependency) not available. Install it with: gem install jeweler"
|
19
|
+
end
|
20
|
+
|
21
|
+
require 'rake/testtask'
|
22
|
+
Rake::TestTask.new(:test) do |test|
|
23
|
+
test.libs << 'lib' << 'test'
|
24
|
+
test.pattern = 'test/**/test_*.rb'
|
25
|
+
test.verbose = true
|
26
|
+
end
|
27
|
+
|
28
|
+
begin
|
29
|
+
require 'rcov/rcovtask'
|
30
|
+
Rcov::RcovTask.new do |test|
|
31
|
+
test.libs << 'test'
|
32
|
+
test.pattern = 'test/**/test_*.rb'
|
33
|
+
test.verbose = true
|
34
|
+
end
|
35
|
+
rescue LoadError
|
36
|
+
task :rcov do
|
37
|
+
abort "RCov is not available. In order to run rcov, you must: sudo gem install spicycode-rcov"
|
38
|
+
end
|
39
|
+
end
|
40
|
+
|
41
|
+
task :test => :check_dependencies
|
42
|
+
|
43
|
+
task :default => :test
|
44
|
+
|
45
|
+
require 'rake/rdoctask'
|
46
|
+
Rake::RDocTask.new do |rdoc|
|
47
|
+
version = File.exist?('VERSION') ? File.read('VERSION') : ""
|
48
|
+
|
49
|
+
rdoc.rdoc_dir = 'rdoc'
|
50
|
+
rdoc.title = "report_engine #{version}"
|
51
|
+
rdoc.rdoc_files.include('README*')
|
52
|
+
rdoc.rdoc_files.include('lib/**/*.rb')
|
53
|
+
end
|
data/VERSION
ADDED
@@ -0,0 +1 @@
|
|
1
|
+
1.2.4
|
Binary file
|
Binary file
|
Binary file
|
Binary file
|
@@ -0,0 +1,50 @@
|
|
1
|
+
require 'prawn'
|
2
|
+
require 'prawn/layout'
|
3
|
+
require 'active_support/inflector'
|
4
|
+
|
5
|
+
|
6
|
+
# Dir.glob(File.dirname(__FILE__) + '/report_engine/*.rb').each do |filename|
|
7
|
+
# require filename
|
8
|
+
# end
|
9
|
+
#
|
10
|
+
# Dir.glob(File.dirname(__FILE__) + '/report_engine/pdf/*.rb').each do |filename|
|
11
|
+
# require filename
|
12
|
+
# end
|
13
|
+
#
|
14
|
+
# Dir.glob(File.dirname(__FILE__) + '/report_engine/html/*.rb').each do |filename|
|
15
|
+
# require filename
|
16
|
+
# end
|
17
|
+
|
18
|
+
require File.dirname(__FILE__) + '/report_engine/canvas_factory.rb'
|
19
|
+
require File.dirname(__FILE__) + '/report_engine/pdf_canvas.rb'
|
20
|
+
require File.dirname(__FILE__) + '/report_engine/html_canvas.rb'
|
21
|
+
require File.dirname(__FILE__) + '/report_engine/page.rb'
|
22
|
+
require File.dirname(__FILE__) + '/report_engine/google_chart.rb'
|
23
|
+
require File.dirname(__FILE__) + '/report_engine/horizontal_chart.rb'
|
24
|
+
require File.dirname(__FILE__) + '/report_engine/table.rb'
|
25
|
+
require File.dirname(__FILE__) + '/report_engine/sub_table.rb'
|
26
|
+
require File.dirname(__FILE__) + '/report_engine/text.rb'
|
27
|
+
require File.dirname(__FILE__) + '/report_engine/footer.rb'
|
28
|
+
require File.dirname(__FILE__) + '/report_engine/question_stats.rb'
|
29
|
+
require File.dirname(__FILE__) + '/report_engine/list.rb'
|
30
|
+
require File.dirname(__FILE__) + '/report_engine/container.rb'
|
31
|
+
require File.dirname(__FILE__) + '/report_engine/report.rb'
|
32
|
+
require File.dirname(__FILE__) + '/report_engine/pdf/list.rb'
|
33
|
+
require File.dirname(__FILE__) + '/report_engine/pdf/container.rb'
|
34
|
+
require File.dirname(__FILE__) + '/report_engine/pdf/text.rb'
|
35
|
+
require File.dirname(__FILE__) + '/report_engine/pdf/table.rb'
|
36
|
+
require File.dirname(__FILE__) + '/report_engine/pdf/sub_table.rb'
|
37
|
+
require File.dirname(__FILE__) + '/report_engine/pdf/section.rb'
|
38
|
+
require File.dirname(__FILE__) + '/report_engine/pdf/question_stats.rb'
|
39
|
+
require File.dirname(__FILE__) + '/report_engine/pdf/google_chart.rb'
|
40
|
+
require File.dirname(__FILE__) + '/report_engine/html/list.rb'
|
41
|
+
require File.dirname(__FILE__) + '/report_engine/html/container.rb'
|
42
|
+
require File.dirname(__FILE__) + '/report_engine/html/text.rb'
|
43
|
+
require File.dirname(__FILE__) + '/report_engine/html/table.rb'
|
44
|
+
require File.dirname(__FILE__) + '/report_engine/html/sub_table.rb'
|
45
|
+
require File.dirname(__FILE__) + '/report_engine/html/section.rb'
|
46
|
+
require File.dirname(__FILE__) + '/report_engine/html/question_stats.rb'
|
47
|
+
require File.dirname(__FILE__) + '/report_engine/html/google_chart.rb'
|
48
|
+
|
49
|
+
module ReportEngine
|
50
|
+
end
|
@@ -0,0 +1,13 @@
|
|
1
|
+
module ReportEngine
|
2
|
+
class Footer
|
3
|
+
def initialize(canvas, elements)
|
4
|
+
@canvas = canvas
|
5
|
+
point = [canvas.pdf.bounds.right-30, canvas.pdf.bounds.bottom + 15]
|
6
|
+
@footer = canvas.pdf.repeat(:all, :dynamic => true) do
|
7
|
+
elements.each do |element|
|
8
|
+
canvas.paint(element[:type], element)
|
9
|
+
end
|
10
|
+
end
|
11
|
+
end
|
12
|
+
end
|
13
|
+
end
|
@@ -0,0 +1,59 @@
|
|
1
|
+
require "open-uri"
|
2
|
+
require 'gchart'
|
3
|
+
|
4
|
+
module ReportEngine
|
5
|
+
class GoogleChart
|
6
|
+
def initialize(canvas, options)
|
7
|
+
@canvas = canvas
|
8
|
+
@data = options[:data]
|
9
|
+
@scale_labels = options[:scale_labels]
|
10
|
+
@x_label = options[:x_label]
|
11
|
+
@y_label = options[:y_label]
|
12
|
+
@grouped = options[:grouped].nil? ? true : options[:grouped]
|
13
|
+
@colors = options[:colors] || ['97172E','EE8C9E']
|
14
|
+
@show_marker = options[:show_marker]
|
15
|
+
end
|
16
|
+
|
17
|
+
def generate_url
|
18
|
+
max = @data.max
|
19
|
+
chart = ::GChart.bar do |g|
|
20
|
+
g.grouped = @grouped
|
21
|
+
g.data = @data #values.map{|v| v * 100.0 / max }
|
22
|
+
g.colors = @colors
|
23
|
+
g.width = 520
|
24
|
+
g.height = 140
|
25
|
+
g.orientation = :vertical
|
26
|
+
g.axis(:left) do |a|
|
27
|
+
a.labels = [@y_label] #["%"]
|
28
|
+
a.label_positions = [100]
|
29
|
+
a.text_color = :black
|
30
|
+
end
|
31
|
+
g.axis(:bottom) do |a|
|
32
|
+
a.labels = @scale_labels # ["0-10","10-20","20-30","30-40","40-50","50-60","60-70","70-80","80-90","90-100"]
|
33
|
+
a.text_color = :black
|
34
|
+
end
|
35
|
+
g.axis(:bottom) do |a|
|
36
|
+
a.labels = [@x_label] # ["Procentil"]
|
37
|
+
a.label_positions = [100]
|
38
|
+
a.text_color = :black
|
39
|
+
end
|
40
|
+
extra = {"chbh" => "a,5,10", "chds" => "0,#{max_value}"}
|
41
|
+
extra.update("chbh" => "r,5,10") if @data.flatten.size < 3
|
42
|
+
if @show_marker
|
43
|
+
if @data.first.is_a? Array
|
44
|
+
extra.update("chm" => @data.size.times.map{|i| "N,000000,#{i},-1,11" }.join('|'))
|
45
|
+
else
|
46
|
+
extra.update("chm" => "N,000000,0,-1,11")
|
47
|
+
end
|
48
|
+
end
|
49
|
+
g.extras = extra
|
50
|
+
end
|
51
|
+
chart.to_url
|
52
|
+
end
|
53
|
+
|
54
|
+
def max_value
|
55
|
+
@data.flatten.max
|
56
|
+
end
|
57
|
+
|
58
|
+
end
|
59
|
+
end
|
@@ -0,0 +1,43 @@
|
|
1
|
+
require "open-uri"
|
2
|
+
require 'gchart'
|
3
|
+
|
4
|
+
module ReportEngine
|
5
|
+
class HorizontalChart
|
6
|
+
|
7
|
+
def initialize(options)
|
8
|
+
@reference = options[:reference]
|
9
|
+
@labels = options[:labels]
|
10
|
+
@values = options[:values]
|
11
|
+
end
|
12
|
+
|
13
|
+
def generate_url
|
14
|
+
chart = GChart.bar do |g|
|
15
|
+
g.colors = ['3A94EE']
|
16
|
+
g.width = 600
|
17
|
+
g.height = 160
|
18
|
+
g.max = 100
|
19
|
+
g.data = @values
|
20
|
+
g.orientation = :horizontal
|
21
|
+
g.axis(:left) do |a|
|
22
|
+
a.labels = @labels
|
23
|
+
a.text_color = :black
|
24
|
+
end
|
25
|
+
g.axis(:bottom) do |a|
|
26
|
+
a.labels = [0, 100]
|
27
|
+
a.label_positions = [0,100]
|
28
|
+
a.text_color = :black
|
29
|
+
end
|
30
|
+
if @reference
|
31
|
+
g.axis(:bottom) do |a|
|
32
|
+
a.labels = [@reference]
|
33
|
+
a.label_positions = [@reference]
|
34
|
+
a.text_color = :red
|
35
|
+
end
|
36
|
+
end
|
37
|
+
g.extras = {"chm" => "#{"h,FF0000,0,#{@reference/100.0},1|" if @reference}N,000000,0,-1,11"}
|
38
|
+
end
|
39
|
+
chart.to_url
|
40
|
+
end
|
41
|
+
|
42
|
+
end
|
43
|
+
end
|
@@ -0,0 +1,18 @@
|
|
1
|
+
module ReportEngine
|
2
|
+
module Html
|
3
|
+
class List < ReportEngine::List
|
4
|
+
def add_list_element(element)
|
5
|
+
@canvas.paint(element.delete(:type), element)
|
6
|
+
@canvas.add_content " " unless element == @elements.last
|
7
|
+
end
|
8
|
+
|
9
|
+
def add_list_start
|
10
|
+
@canvas.add_content("<ul>")
|
11
|
+
end
|
12
|
+
|
13
|
+
def add_list_end
|
14
|
+
@canvas.add_content("</ul>")
|
15
|
+
end
|
16
|
+
end
|
17
|
+
end
|
18
|
+
end
|
@@ -0,0 +1,29 @@
|
|
1
|
+
module ReportEngine
|
2
|
+
module Html
|
3
|
+
class QuestionStats < ReportEngine::QuestionStats
|
4
|
+
@@odd = "even"
|
5
|
+
|
6
|
+
def render
|
7
|
+
@canvas.add_content(["<li id='question_#{@id}' class='#{swap_odd}'>",
|
8
|
+
"<div class='sort col index'>#{@index}</div>",
|
9
|
+
"<div class='sort col question'>#{@text}</div>",
|
10
|
+
"<div class='clear'></div>",
|
11
|
+
"<div id='question_details_#{@id}_tab' class='question_details'>",
|
12
|
+
"<img src='#{@canvas.paint(@chart[:type], @chart)}'/>"].join(' '))
|
13
|
+
@canvas.paint(@details[:type], @details)
|
14
|
+
@canvas.add_content("</div></li>")
|
15
|
+
end
|
16
|
+
|
17
|
+
# Alternates between 'odd' and 'even'
|
18
|
+
#
|
19
|
+
def swap_odd
|
20
|
+
if @@odd == "odd"
|
21
|
+
@@odd = "even"
|
22
|
+
else
|
23
|
+
@@odd = "odd"
|
24
|
+
end
|
25
|
+
end
|
26
|
+
|
27
|
+
end
|
28
|
+
end
|
29
|
+
end
|
@@ -0,0 +1,16 @@
|
|
1
|
+
module ReportEngine
|
2
|
+
module Html
|
3
|
+
class Section < ReportEngine::Page
|
4
|
+
def print_title
|
5
|
+
@canvas.add_content("<li><h3>#{@title}</h3></li>")
|
6
|
+
end
|
7
|
+
|
8
|
+
def print_content
|
9
|
+
@elements.each do |element|
|
10
|
+
@canvas.paint(element.delete(:type), element)
|
11
|
+
# @canvas.add_content(element.render_html)
|
12
|
+
end
|
13
|
+
end
|
14
|
+
end
|
15
|
+
end
|
16
|
+
end
|
@@ -0,0 +1,77 @@
|
|
1
|
+
module ReportEngine
|
2
|
+
module Html
|
3
|
+
class Table < ReportEngine::Table
|
4
|
+
|
5
|
+
# renders an html table
|
6
|
+
#
|
7
|
+
def render
|
8
|
+
if !@x_label.nil? && !@y_label.nil?
|
9
|
+
@canvas.add_content( "<h2 class='axes'>#{@axis_title}</h2>
|
10
|
+
<ul class='axes_list'>
|
11
|
+
<li class='x_axis'>#{@x_label}</li>
|
12
|
+
<li class='y_axis'>#{@y_label}</li>
|
13
|
+
</ul>" )
|
14
|
+
end
|
15
|
+
@canvas.add_content("<table>")
|
16
|
+
@canvas.add_content(render_headers)
|
17
|
+
if @data.first.is_a? Hash
|
18
|
+
@data.each.map{|sub_table| @canvas.add_content(ReportEngine::Html::SubTable.new(@canvas, sub_table).render) }
|
19
|
+
else
|
20
|
+
@canvas.add_content("<tbody>#{ render_lines }</tbody>")
|
21
|
+
end
|
22
|
+
@canvas.add_content("</table>")
|
23
|
+
if !@legends.nil?
|
24
|
+
@canvas.add_content("<ul class='legends'>
|
25
|
+
#{@legends.map{|l| "<li>#{l}</li>"}}
|
26
|
+
</ul>")
|
27
|
+
end
|
28
|
+
end
|
29
|
+
|
30
|
+
# renders the header of an html table
|
31
|
+
#
|
32
|
+
def render_headers
|
33
|
+
if @y_headers && !@data.first.is_a?(ReportEngine::SubTable)
|
34
|
+
add_y_headers
|
35
|
+
end
|
36
|
+
if @x_headers
|
37
|
+
"<thead>
|
38
|
+
<tr>
|
39
|
+
#{@x_headers.map{|header| "<th>#{header}</th>" }}
|
40
|
+
</tr>
|
41
|
+
</thead>"
|
42
|
+
else
|
43
|
+
""
|
44
|
+
end
|
45
|
+
end
|
46
|
+
|
47
|
+
# Alternates between 'odd' and 'even'
|
48
|
+
#
|
49
|
+
def swap_odd
|
50
|
+
if @odd == "odd"
|
51
|
+
@odd = "even"
|
52
|
+
else
|
53
|
+
@odd = "odd"
|
54
|
+
end
|
55
|
+
end
|
56
|
+
|
57
|
+
# renders all the lines in the html table
|
58
|
+
#
|
59
|
+
def render_lines
|
60
|
+
@data.map{|line| render_line(line, swap_odd) }.join(' ')
|
61
|
+
end
|
62
|
+
|
63
|
+
# renders a line in an html table
|
64
|
+
#
|
65
|
+
def render_line(line, html_class = nil)
|
66
|
+
"<tr #{ "class='#{html_class}'" if html_class}>#{render_cells(line)}</tr>"
|
67
|
+
end
|
68
|
+
|
69
|
+
# renders cells within a line in a html table
|
70
|
+
#
|
71
|
+
def render_cells(line)
|
72
|
+
line.map{|cell| "<td>#{cell}</td>" }
|
73
|
+
end
|
74
|
+
|
75
|
+
end
|
76
|
+
end
|
77
|
+
end
|