[ca2115]: app / models / report / base_test_run_by_revision.rb Maximize Restore History

Download this file

base_test_run_by_revision.rb    166 lines (156 with data), 6.2 kB

  1
  2
  3
  4
  5
  6
  7
  8
  9
 10
 11
 12
 13
 14
 15
 16
 17
 18
 19
 20
 21
 22
 23
 24
 25
 26
 27
 28
 29
 30
 31
 32
 33
 34
 35
 36
 37
 38
 39
 40
 41
 42
 43
 44
 45
 46
 47
 48
 49
 50
 51
 52
 53
 54
 55
 56
 57
 58
 59
 60
 61
 62
 63
 64
 65
 66
 67
 68
 69
 70
 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
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
#
# This file is part of the Jikes RVM project (http://jikesrvm.org).
#
# This file is licensed to You under the Eclipse Public License (EPL);
# You may not use this file except in compliance with the License. You
# may obtain a copy of the License at
#
# http://www.opensource.org/licenses/cpl1.0.php
#
# See the COPYRIGHT.txt file distributed with this work for information
# regarding copyright ownership.
#
class Report::BaseTestRunByRevision
# Input parameters
attr_reader :test_run, :window_size
# Output parameters
attr_reader :test_runs
def initialize(test_run, window_size = 7)
@test_run = test_run
@window_size = window_size
perform
end
protected
def perform
options = {}
sql = 'host_id = ? AND start_time <= ? AND variant = ?'
options[:conditions] = [ sql, @test_run.host.id, @test_run.start_time, @test_run.variant]
options[:limit] = @window_size
options[:order] = 'start_time DESC'
@test_runs = Tdm::TestRun.find(:all, options).reverse
end
def rows_to_columns
columns = @test_runs.collect do |tr|
"MAX(case when test_run_id = #{tr.id} then value else NULL end) AS test_run_#{tr.id}"
end.join(', ')
end
def gen_x_by_tr(dimension, label)
sql = <<SQL
SELECT
#{label},
#{rows_to_columns}
FROM
(SELECT
test_runs.id AS test_run_id,
#{dimension} AS #{label},
CAST((CAST(count(case when test_case_executions.result = 'SUCCESS' then 1 else NULL end) AS double precision)/count(*) * 100.0) AS int4) as value
FROM test_case_executions
LEFT JOIN test_cases ON test_case_executions.test_case_id = test_cases.id
LEFT JOIN groups ON test_cases.group_id = groups.id
LEFT JOIN test_configurations ON groups.test_configuration_id = test_configurations.id
LEFT JOIN build_configurations ON test_configurations.build_configuration_id = build_configurations.id
LEFT JOIN test_runs ON build_configurations.test_run_id = test_runs.id
WHERE test_runs.id IN (#{@test_runs.collect{|tr|tr.id}.join(', ')})
GROUP BY test_runs.id, #{dimension}) t
GROUP BY #{label}
HAVING SUM(value) < #{@test_runs.size} * 100
ORDER BY SUM(value), #{label}
SQL
ActiveRecord::Base.connection.select_all(sql)
end
def gen_perf_stats(stats)
stat_names = if stats
"IN (#{stats.collect{|s| "'#{s}'"}.join(', ')})"
else
"IS NOT NULL"
end
filter = <<SQL
statistics_map.label #{stat_names}
SQL
best_score_sql = <<SQL
SELECT
build_configuration_name,
test_configuration_name,
group_name,
test_case_name,
stat_name,
less_is_more,
case when less_is_more = true then min_score else max_score end as best_score
FROM (
SELECT
build_configurations.name as build_configuration_name,
test_configurations.name as test_configuration_name,
groups.name as group_name,
test_cases.name as test_case_name,
statistics_map.label as stat_name,
statistics_map.less_is_more as less_is_more,
MAX(test_case_statistics.value) as max_score,
MIN(test_case_statistics.value) as min_score
FROM test_cases
LEFT JOIN test_case_statistics ON test_case_statistics.owner_id = test_cases.id
LEFT JOIN groups ON test_cases.group_id = groups.id
LEFT JOIN test_configurations ON groups.test_configuration_id = test_configurations.id
LEFT JOIN build_configurations ON test_configurations.build_configuration_id = build_configurations.id
LEFT JOIN test_runs ON build_configurations.test_run_id = test_runs.id
LEFT JOIN hosts ON test_runs.host_id = hosts.id
LEFT JOIN statistics_map ON (
(test_runs.name = statistics_map.test_run_name OR statistics_map.test_run_name IS NULL) AND
(build_configurations.name = statistics_map.build_configuration_name OR statistics_map.build_configuration_name IS NULL) AND
(test_configurations.name = statistics_map.test_configuration_name OR statistics_map.test_configuration_name IS NULL) AND
groups.name = statistics_map.group_name AND
test_cases.name = statistics_map.test_case_name AND
test_case_statistics.key = statistics_map.name
)
WHERE
hosts.name = '#{@test_run.host.name}' AND
test_runs.variant = '#{@test_run.variant}' AND
test_runs.start_time <= '#{@test_run.start_time}' AND
#{filter}
GROUP BY statistics_map.label, statistics_map.less_is_more, build_configurations.name, test_configurations.name, groups.name, test_cases.name
) f
SQL
results_sql = <<SQL
SELECT
test_runs.id AS test_run_id,
statistics_map.label AS stat_name,
test_case_statistics.value AS value
FROM test_cases
LEFT JOIN test_case_statistics ON test_case_statistics.owner_id = test_cases.id
LEFT JOIN groups ON test_cases.group_id = groups.id
LEFT JOIN test_configurations ON groups.test_configuration_id = test_configurations.id
LEFT JOIN build_configurations ON test_configurations.build_configuration_id = build_configurations.id
LEFT JOIN test_runs ON build_configurations.test_run_id = test_runs.id
LEFT JOIN hosts ON test_runs.host_id = hosts.id
LEFT JOIN statistics_map ON (
(test_runs.name = statistics_map.test_run_name OR statistics_map.test_run_name IS NULL) AND
(build_configurations.name = statistics_map.build_configuration_name OR statistics_map.build_configuration_name IS NULL) AND
(test_configurations.name = statistics_map.test_configuration_name OR statistics_map.test_configuration_name IS NULL) AND
groups.name = statistics_map.group_name AND
test_cases.name = statistics_map.test_case_name AND
test_case_statistics.key = statistics_map.name
)
WHERE
test_runs.id IN (#{@test_runs.collect{|tr|tr.id}.join(', ')}) AND
#{filter}
SQL
sql = <<SQL
SELECT
build_configuration_name,
test_configuration_name,
group_name,
test_case_name,
results.stat_name as name,
#{rows_to_columns},
case when less_is_more = true then 1 else 0 end as less_is_more,
stddev(results.value) AS std_deviation,
best_score
FROM
(#{results_sql}) results,
(#{best_score_sql}) best_scores
WHERE best_scores.stat_name = results.stat_name
GROUP BY results.stat_name, less_is_more, best_score, build_configuration_name, test_configuration_name, group_name, test_case_name
ORDER BY results.stat_name
SQL
ActiveRecord::Base.connection.select_all(sql)
end
end