Class: CompareCompressors::CommandLineInterface

Inherits:
Thor
  • Object
show all
Defined in:
lib/compare_compressors/command_line_interface.rb

Overview

Handle generic command line options and run the relevant command.

Class Method Summary collapse

Instance Method Summary collapse

Class Method Details

.cost_optionsObject



48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
# File 'lib/compare_compressors/command_line_interface.rb', line 48

def cost_options
  option \
    :gibyte_cost,
    type: :numeric,
    desc: 'storage cost per gigabyte of compressed output',
    default: CostModel::DEFAULT_GIBYTE_COST
  option \
    :compression_hour_cost,
    type: :numeric,
    desc: 'compute cost per hour of CPU time for compression',
    default: CostModel::DEFAULT_HOUR_COST
  option \
    :decompression_hour_cost,
    type: :numeric,
    desc: 'compute cost per hour of CPU time for decompression',
    default: CostModel::DEFAULT_HOUR_COST
  option \
    :currency,
    type: :string,
    desc: 'currency symbol for display',
    default: CostModel::DEFAULT_CURRENCY
end

.plot_optionsObject



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
# File 'lib/compare_compressors/command_line_interface.rb', line 71

def plot_options
  option \
    :terminal,
    desc: 'the terminal line for gnuplot',
    default: Plotter::DEFAULT_TERMINAL
  option \
    :output,
    desc: 'the output name for gnuplot',
    default: Plotter::DEFAULT_OUTPUT
  option \
    :pareto_only,
    desc: 'plot only non-dominated compressor-level pairs',
    type: :boolean,
    default: true
  option \
    :logscale_size,
    desc: 'use a log10 scale for the size (lucky you if you need this)',
    type: :boolean,
    default: Plotter::DEFAULT_LOGSCALE_SIZE
  option \
    :autoscale_fix,
    desc: 'zoom axes to fit the points tightly',
    type: :boolean,
    default: Plotter::DEFAULT_AUTOSCALE_FIX
  option \
    :show_labels,
    desc: 'show compression level labels on the plot',
    type: :boolean,
    default: Plotter::DEFAULT_SHOW_LABELS
  option \
    :lmargin,
    desc: 'adjust lmargin (workaround if y label is cut off on png)',
    type: :numeric,
    default: Plotter::DEFAULT_LMARGIN
  option \
    :title,
    desc: 'main title (must not contain double quotes)',
    type: :string,
    default: Plotter::DEFAULT_TITLE
end

.scale_optionObject



32
33
34
35
36
37
38
# File 'lib/compare_compressors/command_line_interface.rb', line 32

def scale_option
  option \
    :scale,
    type: :numeric,
    desc: 'scale factor from sample targets to full dataset',
    default: 1.0
end

.use_cpu_time_optionObject



40
41
42
43
44
45
46
# File 'lib/compare_compressors/command_line_interface.rb', line 40

def use_cpu_time_option
  option \
    :use_cpu_time,
    type: :boolean,
    desc: 'use CPU time rather than elapsed time',
    default: CostModel::DEFAULT_USE_CPU_TIME
end

Instance Method Details

#compare(*targets) ⇒ Object



25
26
27
28
29
# File 'lib/compare_compressors/command_line_interface.rb', line 25

def compare(*targets)
  CSV do |csv|
    Comparer.new.run(csv, COMPRESSORS, targets)
  end
end

#plot(csv_file = nil) ⇒ Object



124
125
126
127
128
129
130
131
132
# File 'lib/compare_compressors/command_line_interface.rb', line 124

def plot(csv_file = nil)
  results = read_results(csv_file)
  group_results = GroupResult.group(results, scale: options[:scale])
  plotter = make_plotter(
    SizePlotter, options,
    decompression: options[:decompression]
  )
  plotter.plot(group_results, pareto_only: options[:pareto_only])
end

#plot_3d(csv_file = nil) ⇒ Object



140
141
142
143
144
145
# File 'lib/compare_compressors/command_line_interface.rb', line 140

def plot_3d(csv_file = nil)
  results = read_results(csv_file)
  group_results = GroupResult.group(results, scale: options[:scale])
  plotter = make_plotter(RawPlotter, options)
  plotter.plot(group_results, pareto_only: options[:pareto_only])
end

#plot_costs(csv_file = nil) ⇒ Object



159
160
161
162
163
164
165
166
167
168
169
170
# File 'lib/compare_compressors/command_line_interface.rb', line 159

def plot_costs(csv_file = nil)
  results = read_results(csv_file)
  group_results = GroupResult.group(results, scale: options[:scale])
  cost_model = make_cost_model(options)
  costed_group_results =
    CostedGroupResult.from_group_results(cost_model, group_results)
  plotter = make_plotter(
    CostPlotter, options, cost_model,
    show_cost_contours: options[:show_cost_contours]
  )
  plotter.plot(costed_group_results, pareto_only: options[:pareto_only])
end

#summarize(csv_file = nil) ⇒ Object



183
184
185
186
187
188
189
190
# File 'lib/compare_compressors/command_line_interface.rb', line 183

def summarize(csv_file = nil)
  results = read_results(csv_file)
  group_results = GroupResult.group(results, scale: options[:scale])
  cost_model = make_cost_model(options)
  costed_group_results =
    CostedGroupResult.from_group_results(cost_model, group_results)
  puts cost_model.summarize(costed_group_results, options[:top])
end

#versionObject



14
15
16
17
18
19
# File 'lib/compare_compressors/command_line_interface.rb', line 14

def version
  puts "compare_compressors-#{CompareCompressors::VERSION}"
  COMPRESSORS.each do |compressor|
    puts format('%10s: %s', compressor.name, compressor.version || '?')
  end
end