Generate a "TOTAL" row for build-profile table (#7614)
Merge pull request 7614
This commit is contained in:
parent
3cce93d9b8
commit
ec0971ab17
|
@ -3,6 +3,8 @@
|
||||||
module Jekyll
|
module Jekyll
|
||||||
class LiquidRenderer
|
class LiquidRenderer
|
||||||
class Table
|
class Table
|
||||||
|
GAUGES = [:count, :bytes, :time].freeze
|
||||||
|
|
||||||
def initialize(stats)
|
def initialize(stats)
|
||||||
@stats = stats
|
@stats = stats
|
||||||
end
|
end
|
||||||
|
@ -19,6 +21,8 @@ module Jekyll
|
||||||
str = +"\n"
|
str = +"\n"
|
||||||
|
|
||||||
table_head = data.shift
|
table_head = data.shift
|
||||||
|
table_foot = data.pop
|
||||||
|
|
||||||
str << generate_row(table_head, widths)
|
str << generate_row(table_head, widths)
|
||||||
str << generate_table_head_border(table_head, widths)
|
str << generate_table_head_border(table_head, widths)
|
||||||
|
|
||||||
|
@ -26,6 +30,9 @@ module Jekyll
|
||||||
str << generate_row(row_data, widths)
|
str << generate_row(row_data, widths)
|
||||||
end
|
end
|
||||||
|
|
||||||
|
str << generate_table_head_border(table_foot, widths)
|
||||||
|
str << generate_row(table_foot, widths).rstrip
|
||||||
|
|
||||||
str << "\n"
|
str << "\n"
|
||||||
str
|
str
|
||||||
end
|
end
|
||||||
|
@ -71,13 +78,16 @@ module Jekyll
|
||||||
widths
|
widths
|
||||||
end
|
end
|
||||||
|
|
||||||
|
# rubocop:disable Metrics/AbcSize
|
||||||
def data_for_table(num_of_rows)
|
def data_for_table(num_of_rows)
|
||||||
sorted = @stats.sort_by { |_, file_stats| -file_stats[:time] }
|
sorted = @stats.sort_by { |_, file_stats| -file_stats[:time] }
|
||||||
sorted = sorted.slice(0, num_of_rows)
|
sorted = sorted.slice(0, num_of_rows)
|
||||||
|
|
||||||
table = [%w(Filename Count Bytes Time)]
|
table = [header_labels]
|
||||||
|
totals = Hash.new { |hash, key| hash[key] = 0 }
|
||||||
|
|
||||||
sorted.each do |filename, file_stats|
|
sorted.each do |filename, file_stats|
|
||||||
|
GAUGES.each { |gauge| totals[gauge] += file_stats[gauge] }
|
||||||
row = []
|
row = []
|
||||||
row << filename
|
row << filename
|
||||||
row << file_stats[:count].to_s
|
row << file_stats[:count].to_s
|
||||||
|
@ -86,7 +96,17 @@ module Jekyll
|
||||||
table << row
|
table << row
|
||||||
end
|
end
|
||||||
|
|
||||||
table
|
footer = []
|
||||||
|
footer << "TOTAL (for #{sorted.size} files)"
|
||||||
|
footer << totals[:count].to_s
|
||||||
|
footer << format_bytes(totals[:bytes])
|
||||||
|
footer << format("%.3f", totals[:time])
|
||||||
|
table << footer
|
||||||
|
end
|
||||||
|
# rubocop:enable Metrics/AbcSize
|
||||||
|
|
||||||
|
def header_labels
|
||||||
|
GAUGES.map { |gauge| gauge.to_s.capitalize }.unshift("Filename")
|
||||||
end
|
end
|
||||||
|
|
||||||
def format_bytes(bytes)
|
def format_bytes(bytes)
|
||||||
|
|
Loading…
Reference in New Issue