[Why]
We just skip useless job when make job_list --> matrix,
had not did: job_list.size - 1,
the average: sum($job['stats']['metric'])/job_list.size will be incorrect.
standard deviation is the same reason
[How]
Remove useless job before job_list --> matrix,
and do minor refactoring
Signed-off-by: Lu Weitao <luweitaobe(a)163.com>
---
lib/matrix2.rb | 11 ++---------
lib/params_group.rb | 16 ++++++++++++++--
2 files changed, 16 insertions(+), 11 deletions(-)
diff --git a/lib/matrix2.rb b/lib/matrix2.rb
index 14e9558..ce64da1 100644
--- a/lib/matrix2.rb
+++ b/lib/matrix2.rb
@@ -83,7 +83,7 @@ def create_matrix(job_list)
suites = []
job_list.each do |job|
stats = job['stats']
- next unless stats && assign_suites(suites, job, stats)
+ suites << job['suite']
stats.each do |key, value|
next if key.include?('timestamp')
@@ -97,17 +97,10 @@ def create_matrix(job_list)
return matrix, suites
end
-def assign_suites(suites, job, stats)
- return unless job['suite'] && stats.keys.any? { |stat| stat.start_with?(job['suite']) }
-
- suites << job['suite']
-end
-
# input: query results from es_query
# return: matrix
def combine_query_data(query_data)
- job_list = query_data['hits']['hits']
- job_list.map! { |job| job['_source'] }
+ job_list = extract_jobs_list(query_data['hits']['hits'])
create_matrix(job_list)
end
diff --git a/lib/params_group.rb b/lib/params_group.rb
index 57cd5c1..7bb7f5b 100644
--- a/lib/params_group.rb
+++ b/lib/params_group.rb
@@ -38,9 +38,21 @@ def auto_group(jobs_list, dimensions)
end
def extract_jobs_list(jobs_list)
- jobs_list.map do |job|
- job['_source']
+ jobs_list.map! do |job|
+ job['_source'] if job_is_useful?(job)
end
+
+ jobs_list.compact
+end
+
+def job_is_useful?(job)
+ stats = job['_source']['stats']
+ return unless stats
+
+ suite = job['_source']['suite']
+ return unless suite && stats.keys.any? { |stat| stat.start_with?(suite) }
+
+ true
end
def group(jobs_list, dimensions)
--
2.23.0