Code Coverage |
||||||||||
Lines |
Functions and Methods |
Classes and Traits |
||||||||
Total | |
100.00% |
12 / 12 |
|
100.00% |
2 / 2 |
CRAP | |
100.00% |
1 / 1 |
SqlScoreLookup | |
100.00% |
12 / 12 |
|
100.00% |
2 / 2 |
2 | |
100.00% |
1 / 1 |
__construct | |
100.00% |
2 / 2 |
|
100.00% |
1 / 1 |
1 | |||
getScores | |
100.00% |
10 / 10 |
|
100.00% |
1 / 1 |
1 |
1 | <?php |
2 | /** |
3 | * This program is free software: you can redistribute it and/or modify |
4 | * it under the terms of the GNU General Public License as published by |
5 | * the Free Software Foundation, either version 3 of the License, or |
6 | * (at your option) any later version. |
7 | * |
8 | * This program is distributed in the hope that it will be useful, |
9 | * but WITHOUT ANY WARRANTY; without even the implied warranty of |
10 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
11 | * GNU General Public License for more details. |
12 | * |
13 | * You should have received a copy of the GNU General Public License |
14 | * along with this program. If not, see <http://www.gnu.org/licenses/>. |
15 | */ |
16 | |
17 | namespace ORES\Storage; |
18 | |
19 | use Wikimedia\Rdbms\IConnectionProvider; |
20 | use Wikimedia\Rdbms\IResultWrapper; |
21 | |
22 | class SqlScoreLookup implements StorageScoreLookup { |
23 | |
24 | private ModelLookup $modelLookup; |
25 | private IConnectionProvider $dbProvider; |
26 | |
27 | public function __construct( |
28 | ModelLookup $modelLookup, |
29 | IConnectionProvider $dbProvider |
30 | ) { |
31 | $this->modelLookup = $modelLookup; |
32 | $this->dbProvider = $dbProvider; |
33 | } |
34 | |
35 | /** |
36 | * Method to retrieve scores of given revision and models |
37 | * |
38 | * @param int|int[] $revisions Single or multiple revision IDs |
39 | * @param string|string[] $models Single or multiple model names. |
40 | * |
41 | * @return IResultWrapper |
42 | */ |
43 | public function getScores( $revisions, $models ) { |
44 | $modelIds = array_map( [ $this->modelLookup, 'getModelId' ], $models ); |
45 | |
46 | return $this->dbProvider->getReplicaDatabase()->newSelectQueryBuilder() |
47 | ->select( [ 'oresc_rev', 'oresc_class', 'oresc_probability', 'oresc_model' ] ) |
48 | ->from( 'ores_classification' ) |
49 | ->where( [ |
50 | 'oresc_rev' => $revisions, |
51 | 'oresc_model' => $modelIds, |
52 | ] ) |
53 | ->caller( __METHOD__ ) |
54 | ->fetchResultSet(); |
55 | } |
56 | |
57 | } |