-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathfog_cup_standard_html_report.rb
158 lines (139 loc) · 4.88 KB
/
fog_cup_standard_html_report.rb
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
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
require_relative "cupcalculation"
class FogCupStandardHtmlReport
attr_accessor :fog_cup
attr_accessor :external_resources
attr_accessor :show_detail
attr_accessor :name1
attr_accessor :name2
def initialize(fog_cup, external_resources, show_points, name1=nil, name2=nil)
@external_resources = external_resources
@fog_cup = fog_cup
@show_points = show_points
@name1 = name1
@name2 = name2
run
end
def run
run_event(@fog_cup.cup.cup_final_result, false, "Gesamtwertung")
@fog_cup.cup.cup_event_results.each do |event|
run_event(event, true)
end
end
def output_cup_event_with_competitors(doc, event_result)
doc.h2("Details:")
clubs_results = event_result.club_event_results.values
clubs_results.sort! do |a, b|
[-a.points, a.club_name] <=> [-b.points, b.club_name]
end
clubs_results.each do |club_result|
doc.table() {
doc.tbody() {
doc.tr() {
doc.th(:class => "cl", :colspan => "2") { doc.text(club_result.club_name) }
doc.th(:class => "pt") { doc.text(club_result.points) }
}
contributors = club_result.contributors.values.sort do |a, b|
[-a.points.to_i, a.full_name.to_s] <=> [-b.points.to_i, b.full_name.to_s]
end
contributors.each do |contributor|
doc.tr() {
doc.td(:class => "pl") { doc.text(contributor.class.to_s) }
doc.td(:class => "cl") { doc.text(contributor.full_name) }
doc.td(:class => "pt") { doc.text(contributor.points.to_i) }
}
end
}
}
end
end
def run_event(event, simple, alternate_name2=nil)
local_name2 = alternate_name2 ? alternate_name2 : @name2
local_name2 = "" if local_name2.nil?
builder = Nokogiri::HTML::Builder.new do |doc|
doc.html {
doc.head() {
doc.title("#{name1} - #{local_name2}")
doc.link(:rel => "stylesheet", :type => "text/css", :href => "cup_printout.css")
}
doc.body() {
doc.div(:id => "page_header") {
doc.table() {
doc.tr() {
doc.th(:id => "cup_name") { doc.nobr { doc.text("#{@name1 ? @name1 : event.event_name}") } }
doc.th(:id => "date_time") {
doc.nobr {
doc.text("#{I18n.localize(Time.now, :format => :orchead)}")
}
}
}
doc.tr() {
doc.th(:id => "event_name") { doc.nobr {doc.text("#{local_name2 ? local_name2 : "Ergebnisse"}") } }
doc.th(:id => "creation_text") { doc.nobr { doc.text("erzeugt mit OR-Converter von Henry Jobst") } }
}
}
}
doc.div(:id => "club_results") {
doc.h2("Ergebnisse:")
doc.table() {
insert_table_header(doc)
insert_table_results(doc,
sort_club_results(event.club_event_results.values),
simple, @external_resources)
}
}
doc.div(:id => "detailed_results") {
if @show_points
output_cup_event_with_competitors(doc, event)
end
}
}
}
end
new_file_name = "#{prepare_filename(@name1 ? @name1 : event.event_name)}_#{prepare_filename(local_name2)}.html"
File.open(new_file_name, 'w') do |f|
f.write builder.to_html
end
end
def insert_table_results(doc, club_results, simple, external_resources)
place = 0
count = 0
points = nil
club_results.each do |club_result|
if (points.nil? || club_result.points < points)
count += 1
place = count
points = club_result.points
else
count += 1
end
if place > 3 || simple
doc.tr() {
doc.td(:class=>"pl") { doc.text("%2s." % place) }
doc.td(:class=>"cl") { doc.text("#{club_result.club_name}") }
doc.td(:class=>"pt") { doc.text("%3s" % club_result.points) }
}
else
doc.tr() {
img_link = "./resources/#{place}.jpg"
img_link = "http://www.kolv.de/bilder/#{place}.jpg" if external_resources
doc.td(:class=>"pl") { doc.img(:src => img_link, :alt=> "Platz %2s." % place) {} }
doc.td(:class=>"cl") { doc.strong() { doc.text("#{club_result.club_name}") } }
doc.td(:class=>"pt") { doc.strong() { doc.text("%3s" % club_result.points) } }
}
end
end
end
def insert_table_header(doc)
doc.tr() {
doc.th(:class=>"pl") {
doc.text("Platz")
}
doc.th(:class=>"cl") {
doc.text("Verein")
}
doc.th(:class=>"pt") {
doc.text("Punkte")
}
}
end
end