Query jobs by conditions such as group id or suite, and count the number of passed cases and failed cases.
Signed-off-by: Li Yuanchao lyc163mail@163.com --- src/lib/web_backend.rb | 66 ++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 66 insertions(+)
diff --git a/src/lib/web_backend.rb b/src/lib/web_backend.rb index 89c0f3c..ea45d59 100644 --- a/src/lib/web_backend.rb +++ b/src/lib/web_backend.rb @@ -548,3 +548,69 @@ def new_refs_statistics(params) end [200, headers.merge('Access-Control-Allow-Origin' => '*'), body] end + +def single_count(stats) + fail_count = 0 + pass_count = 0 + single_nr_fail = 0 + single_nr_pass = 0 + stats.each do |stat, value| + fail_count += 1 if stat.match(/.fail$/i) + pass_count += 1 if stat.match(/.pass$/i) + single_nr_fail = value if stat.match(/.nr_fail$/i) + single_nr_pass = value if stat.match(/.nr_pass$/i) + end + fail_count = single_nr_fail.zero? ? fail_count : single_nr_fail + pass_count = single_nr_pass.zero? ? pass_count : single_nr_pass + [fail_count, pass_count, fail_count + pass_count] +end + +def count_stats(job_list) + nr_fail = 0 + nr_pass = 0 + all = 0 + job_list.each do |job| + next unless job['_source']['stats'] + + fail_count, pass_count, all_count = single_count(job['_source']['stats']) + nr_fail += fail_count + nr_pass += pass_count + all += all_count + end + { 'nr_fail' => nr_fail, 'nr_pass' => nr_pass, 'all' => all } +end + +def get_jobs_stats_count(dimension, must, size, from) + dimension_list = get_dimension_list(dimension) + stats_count = {} + dimension_list.each do |dim| + job_list = query_dimension(dimension[0], dim, must, size, from) + stats_count[dim] = count_stats(job_list) + end + stats_count.to_json +end + +def get_stats_by_dimension(conditions, dimension, must, size, from) + must += build_multi_field_subquery_body(conditions) + count_query = { query: { bool: { must: must } } } + total = es_count(count_query) + return {} if total < 1 + + get_jobs_stats_count(dimension, must, size, from) +end + +def get_jobs_stats(params) + dimension, conditions = get_dimension_conditions(params) + must = get_es_must(params) + get_stats_by_dimension(conditions, dimension, must, 1000, 0) +end + +def group_jobs_table(params) + begin + body = get_jobs_stats(params) + rescue StandardError => e + warn e.message + return [500, headers.merge('Access-Control-Allow-Origin' => '*'), 'group jobs table error'] + end + [200, headers.merge('Access-Control-Allow-Origin' => '*'), body] +end
On Wed, Mar 17, 2021 at 11:13:40AM +0800, Li Yuanchao wrote:
Query jobs by conditions such as group id or suite, and count the number of passed cases and failed cases.
Signed-off-by: Li Yuanchao lyc163mail@163.com
src/lib/web_backend.rb | 66 ++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 66 insertions(+)
diff --git a/src/lib/web_backend.rb b/src/lib/web_backend.rb index 89c0f3c..ea45d59 100644 --- a/src/lib/web_backend.rb +++ b/src/lib/web_backend.rb @@ -548,3 +548,69 @@ def new_refs_statistics(params) end [200, headers.merge('Access-Control-Allow-Origin' => '*'), body] end
compass-ci/src/lib/web_backend.rb has too many code, how about add some conments to segmented just like compass-ci/lib/compare.rb
and it's hardly to konw what's the return
+def single_count(stats)
- fail_count = 0
- pass_count = 0
- single_nr_fail = 0
- single_nr_pass = 0
- stats.each do |stat, value|
- fail_count += 1 if stat.match(/.fail$/i)
- pass_count += 1 if stat.match(/.pass$/i)
- single_nr_fail = value if stat.match(/.nr_fail$/i)
- single_nr_pass = value if stat.match(/.nr_pass$/i)
- end
- fail_count = single_nr_fail.zero? ? fail_count : single_nr_fail
- pass_count = single_nr_pass.zero? ? pass_count : single_nr_pass
- [fail_count, pass_count, fail_count + pass_count]
+end
+def count_stats(job_list)
- nr_fail = 0
- nr_pass = 0
- all = 0
- job_list.each do |job|
- next unless job['_source']['stats']
- fail_count, pass_count, all_count = single_count(job['_source']['stats'])
- nr_fail += fail_count
- nr_pass += pass_count
- all += all_count
- end
- { 'nr_fail' => nr_fail, 'nr_pass' => nr_pass, 'all' => all }
+end
+def get_jobs_stats_count(dimension, must, size, from)
- dimension_list = get_dimension_list(dimension)
- stats_count = {}
- dimension_list.each do |dim|
- job_list = query_dimension(dimension[0], dim, must, size, from)
- stats_count[dim] = count_stats(job_list)
- end
- stats_count.to_json
+end
+def get_stats_by_dimension(conditions, dimension, must, size, from)
- must += build_multi_field_subquery_body(conditions)
- count_query = { query: { bool: { must: must } } }
- total = es_count(count_query)
- return {} if total < 1
the total is the sum of nr_pass and nr_fail?
Thanks, Weitao
- get_jobs_stats_count(dimension, must, size, from)
+end
+def get_jobs_stats(params)
- dimension, conditions = get_dimension_conditions(params)
- must = get_es_must(params)
- get_stats_by_dimension(conditions, dimension, must, 1000, 0)
+end
+def group_jobs_table(params)
- begin
- body = get_jobs_stats(params)
- rescue StandardError => e
- warn e.message
- return [500, headers.merge('Access-Control-Allow-Origin' => '*'), 'group jobs table error']
- end
- [200, headers.merge('Access-Control-Allow-Origin' => '*'), body]
+end
2.23.0
On Wed, Mar 17, 2021 at 04:46:53PM +0800, Lu Weitao wrote:
On Wed, Mar 17, 2021 at 11:13:40AM +0800, Li Yuanchao wrote:
Query jobs by conditions such as group id or suite, and count the number of passed cases and failed cases.
Signed-off-by: Li Yuanchao lyc163mail@163.com
src/lib/web_backend.rb | 66 ++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 66 insertions(+)
diff --git a/src/lib/web_backend.rb b/src/lib/web_backend.rb index 89c0f3c..ea45d59 100644 --- a/src/lib/web_backend.rb +++ b/src/lib/web_backend.rb @@ -548,3 +548,69 @@ def new_refs_statistics(params) end [200, headers.merge('Access-Control-Allow-Origin' => '*'), body] end
compass-ci/src/lib/web_backend.rb has too many code, how about add some conments to segmented just like compass-ci/lib/compare.rb
600 lines for a file maybe not big ~
and it's hardly to konw what's the return
ok, I'll add return information to change log.
Thanks, Yuanchao