3 class TestNameResolver {
5 function __construct($db) {
7 $this->full_name_to_test = array();
8 $this->test_id_to_child_metrics = array();
9 $this->test_to_metrics = array();
10 $this->tests_sorted_by_full_name = array();
11 $this->metric_to_configurations = array();
12 $this->id_to_metric = array();
13 $this->id_to_aggregator = array();
15 $test_table = $db->fetch_table('tests');
19 $test_id_to_name = array();
20 $test_id_to_parent = array();
21 foreach ($test_table as $test_row) {
22 $test_id = $test_row['test_id'];
23 $test_id_to_name[$test_id] = $test_row['test_name'];
24 $test_id_to_parent[$test_id] = $test_row['test_parent'];
27 $this->full_name_to_test = $this->compute_full_name($test_table, $test_id_to_name, $test_id_to_parent);
28 $this->test_to_metrics = $this->map_metrics_to_tests($db->fetch_table('test_metrics'), $test_id_to_parent);
29 $this->tests_sorted_by_full_name = $this->sort_tests_by_full_name($this->full_name_to_test);
31 if ($configurations = $db->fetch_table('test_configurations')) {
32 foreach ($configurations as $config) {
33 $metric_id = $config['config_metric'];
34 $platform_id = $config['config_platform'];
35 array_set_default($this->metric_to_configurations, $metric_id, array());
36 array_set_default($this->metric_to_configurations[$metric_id], $platform_id, array());
37 array_push($this->metric_to_configurations[$metric_id][$platform_id], $config);
41 if ($aggregator_table = $db->fetch_table('aggregators')) {
42 foreach ($aggregator_table as $aggregator)
43 $this->id_to_aggregator[$aggregator['aggregator_id']] = $aggregator;
47 private function compute_full_name($test_table, $test_id_to_name, $test_id_to_parent) {
48 $full_name_to_test = array();
49 foreach ($test_table as $test_row) {
51 $test_id = $test_row['test_id'];
53 array_push($test_path, $test_id_to_name[$test_id]);
54 $test_id = $test_id_to_parent[$test_id];
56 $test_row['full_name'] = join('/', array_reverse($test_path));
57 $full_name_to_test[$test_row['full_name']] = $test_row;
59 return $full_name_to_test;
62 private function map_metrics_to_tests($metrics_table, $test_id_to_parent) {
63 $test_to_metrics = array();
65 return $test_to_metrics;
67 foreach ($metrics_table as $metric_row) {
68 $this->id_to_metric[$metric_row['metric_id']] = $metric_row;
70 $test_id = $metric_row['metric_test'];
71 array_set_default($test_to_metrics, $test_id, array());
72 array_push($test_to_metrics[$test_id], $metric_row);
74 $parent_id = $test_id_to_parent[$test_id];
76 array_set_default($this->test_id_to_child_metrics, $parent_id, array());
77 $parent_metrics = &$this->test_id_to_child_metrics[$parent_id];
78 if (!in_array($metric_row['metric_name'], $parent_metrics))
79 array_push($parent_metrics, $metric_row['metric_name']);
82 return $test_to_metrics;
85 private function sort_tests_by_full_name($full_name_to_test) {
86 $tests_sorted_by_full_name = array();
87 $full_names = array_keys($full_name_to_test);
89 foreach ($full_names as $name)
90 array_push($tests_sorted_by_full_name, $full_name_to_test[$name]);
91 return $tests_sorted_by_full_name;
95 return $this->tests_sorted_by_full_name;
98 function test_id_for_full_name($full_name) {
99 return array_get($this->full_name_to_test, $full_name);
102 function full_name_for_test($test_id) {
103 foreach ($this->full_name_to_test as $full_name => $test) {
104 if ($test['test_id'] == $test_id)
110 function full_name_for_metric($metric_id) {
111 $metric_row = array_get($this->id_to_metric, $metric_id);
114 $full_name = $this->full_name_for_test($metric_row['metric_test']) . ':' . $metric_row['metric_name'];
115 if ($aggregator_id = $metric_row['metric_aggregator'])
116 $full_name .= ':' . $this->id_to_aggregator[$aggregator_id]['aggregator_name'];
120 function metrics_for_test_id($test_id) {
121 return array_get($this->test_to_metrics, $test_id, array());
124 function child_metrics_for_test_id($test_id) {
125 return array_get($this->test_id_to_child_metrics, $test_id, array());
128 function configurations_for_metric_and_platform($metric_id, $platform_id) {
129 $metric_configurations = array_get($this->metric_to_configurations, $metric_id, array());
130 return array_get($metric_configurations, $platform_id);