[Example]
sbin/compare id=crystal.1686878,crystal.1686879 id=crystal.1686880,crystal.1686881 --min_samples 3
Signed-off-by: Lu Weitao <luweitaobe(a)163.com>
---
lib/compare.rb | 22 +++++++++++++++++++---
lib/matrix2.rb | 4 +++-
sbin/compare | 5 +++++
3 files changed, 27 insertions(+), 4 deletions(-)
diff --git a/lib/compare.rb b/lib/compare.rb
index 7386caea..a6fd9f98 100644
--- a/lib/compare.rb
+++ b/lib/compare.rb
@@ -20,7 +20,13 @@ require 'yaml'
def compare_matrices_list(argv, common_conditions, options)
condition_list = parse_argv(argv, common_conditions)
- matrices_list, suite_list = create_matrices_list(condition_list)
+ matrices_list, suite_list = create_matrices_list(condition_list, options[:min_samples])
+ if matrices_list.size < 2
+ return nil if options[:no_print]
+
+ warn "matrix less than min_samples"
+ end
+
compare_matrixes(matrices_list, suite_list, options: options)
end
@@ -35,13 +41,15 @@ def parse_argv(argv, common_conditions)
conditions
end
-def create_matrices_list(conditions)
+def create_matrices_list(conditions, min_samples)
matrices_list = []
suite_list = []
es = ESQuery.new
conditions.each do |condition|
query_results = es.multi_field_query(condition, desc_keyword: 'start_time')
- matrix, suites = combine_query_data(query_results)
+ matrix, suites = combine_query_data(query_results, min_samples)
+ next unless matrix
+
matrices_list << matrix
suite_list.concat(suites)
end
@@ -49,6 +57,14 @@ def create_matrices_list(conditions)
return matrices_list, suite_list
end
+def matrices_verification(matrices, options)
+ if matrices.size < 2
+ return nil if options[:no_print]
+
+ warn "matrix less than min_samples"
+ end
+end
+
# -------------------------------------------------------------------------------------------
# compare_group
# - one condition only
diff --git a/lib/matrix2.rb b/lib/matrix2.rb
index 12245a80..2fd63243 100644
--- a/lib/matrix2.rb
+++ b/lib/matrix2.rb
@@ -101,8 +101,10 @@ end
# input: query results from es_query
# return: matrix
-def combine_query_data(query_data)
+def combine_query_data(query_data, min_sample)
job_list = extract_jobs_list(query_data['hits']['hits'])
+ return nil if job_list.size < min_sample
+
create_matrix(job_list)
end
diff --git a/sbin/compare b/sbin/compare
index 2ee32688..bcb66ccf 100755
--- a/sbin/compare
+++ b/sbin/compare
@@ -22,6 +22,7 @@ is_group = false
dimensions = nil
colorful = nil
options = {}
+options[:min_samples] = 1
template = nil
opt_parser = OptionParser.new do |opts|
@@ -48,6 +49,10 @@ opt_parser = OptionParser.new do |opts|
colorful = theme
end
+ opts.on('--min_samples min_samples', 'give a number to litmit the min_samples of matrix which used to compare') do |min_samples|
+ options[:min_samples] = min_samples.to_i
+ end
+
opts.on('-t', '--template template', 'compare with user-defined template') do |t|
template = t
end
--
2.23.0