compare values by each metrics based on groups matrices,
and format compare result as echart data_set
background:
For support compare with user-defined template feature,
the work-flow of user-defined template feature:
load_compare_template.yaml --> query_results(ES) ---> auto group jobs_list
---> create groups_matrices ---> compare_values by each metrics ---> format/show results
current patch is the step:
compare_values by each metrics ---> format/show results
Signed-off-by: Lu Weitao <luweitaobe(a)163.com>
---
lib/compare_matrixes.rb | 107 ++++++++++++++++++++++++++++++++++++++++
1 file changed, 107 insertions(+)
diff --git a/lib/compare_matrixes.rb b/lib/compare_matrixes.rb
index 078028a..7e6dfb1 100644
--- a/lib/compare_matrixes.rb
+++ b/lib/compare_matrixes.rb
@@ -399,8 +399,115 @@ def compare_group_matrices(group_matrices, options)
result_str
end
+# compare group_matrices with each dimension(matrix) of each group,
+# and reorganize the result as group-metric-compare-values
+#
+# Input: groups_matrices
+# {
+# group_key_1 => {
+# dimension_1 => matrix_1, (openeuler 20.03)
+# dimension_2 => matrix_2, (openeuler 20.09)
+# dimension_3 => matrix_3, (centos 7.6)
+# },
+# group_key_2 => {...}
+# }
+#
+# output: compare_metrics_values
+# {
+# group_key_1 => {
+# metric_1 => {
+# 'average' => {
+# 'dimension_1' => xxx
+# 'dimension_2' => xxx
+# 'dimension_3' => xxx
+# },
+# 'standard_deviation' => {
+# 'dimension_1' => xxx
+# 'dimension_2' => xxx
+# 'dimension_3' => xxx
+# },
+# 'change' => {
+# 'dimension_2 vs dimension_1' => xxx
+# 'dimension_3 vs dimension_1' => xxx
+# 'dimension_3 vs dimension_2' => xxx
+# }
+# },
+# metric_2 => {...}
+# }
+# }
+def compare_metrics_values(groups_matrices)
+ metrics_compare_values = {}
+ groups_matrices.each do |group_key, dimensions|
+ metrics_compare_values[group_key] = get_metric_values(dimensions)
+ end
+ metrics_compare_values
+end
+
+def get_metric_values(dimensions)
+ metrics_values = {}
+ dimensions.each do |dim, matrix|
+ matrix.each do |metric, values|
+ metrics_values[metric] ||= {}
+ metrics_values[metric]['average'] ||= {}
+ metrics_values[metric]['standard_deviation'] ||= {}
+ metric_value = get_values(values, true)
+ metrics_values[metric]['average'][dim] = metric_value[:average]
+ metrics_values[metric]['standard_deviation'][dim] = metric_value[:stddev]
+ end
+ end
+ get_metric_change(metrics_values)
+ metrics_values
+end
+
+def get_metric_change(metrics_values)
+ metrics_values.each do |metric, values|
+ metrics_values[metric]['change'] = {}
+ next if values['average'].size < 2
+
+ dimension_list = values['average'].keys
+ change_titles = get_change_titles(dimension_list)
+ change_titles.each do |pk|
+ change = get_compare_value(values['average'][pk[0]], values['average'][pk[1]], true)
+ values['change'] = { "#{pk[1]} vs #{pk[0]}" => change }
+ end
+ end
+end
+
+# create all dimension combinations as change_title
+# input: dimension_list
+# eg: ['openeuler 20.03', 'debian sid', 'centos 7.6']
+# return: Array(base_dimension: String, pk_dimension: String)
+# [
+# ['openeuler 20.03', 'debian sid'],
+# ['openeuler 20.03', 'centos 7.6'],
+# ['debian sid', 'centos 7.6']
+# ]
+def get_change_titles(dimension_list)
+ dims = []
+ dimension_list_size = dimension_list.size
+ (1..dimension_list_size - 1).each do |i|
+ (i..dimension_list_size - 1).each do |j|
+ dims << [dimension_list[i - 1], dimension_list[j]]
+ end
+ end
+ dims
+end
+
+def show_chart_compare_result(chart_result)
+ print JSON.pretty_generate(chart_result)
+end
+
# Format Fields
+def format_for_chart(metrics_compare_values, template_params)
+ chart_result = {}
+ chart_result['title'] = template_params['title'] || nil
+ chart_result['unit'] = template_params['unit'] || nil
+ chart_result['x_name'] = template_params['x_params'].join('|') || nil
+ chart_result['tables'] = metrics_compare_values
+ chart_result
+end
+
def format_fails_runs(fails, runs)
fails_width = (SUB_LONG_COLUMN_WIDTH * FAILS_PROPORTION).to_i
runs_width = SUB_LONG_COLUMN_WIDTH - fails_width - 1
--
2.23.0