Code Coverage |
||||||||||
Lines |
Functions and Methods |
Classes and Traits |
||||||||
Total | |
0.00% |
0 / 45 |
|
0.00% |
0 / 3 |
CRAP | |
0.00% |
0 / 1 |
GenerateWorkload | |
0.00% |
0 / 42 |
|
0.00% |
0 / 3 |
30 | |
0.00% |
0 / 1 |
__construct | |
0.00% |
0 / 11 |
|
0.00% |
0 / 1 |
2 | |||
generateIndexString | |
0.00% |
0 / 9 |
|
0.00% |
0 / 1 |
12 | |||
execute | |
0.00% |
0 / 22 |
|
0.00% |
0 / 1 |
2 |
1 | <?php |
2 | /** |
3 | * Generates harvest files for the MathWebSearch Deamon. |
4 | * Example: php CreateMathIndex.php ~/mws_harvest_files |
5 | * |
6 | * This program is free software; you can redistribute it and/or modify |
7 | * it under the terms of the GNU General Public License as published by |
8 | * the Free Software Foundation; either version 2 of the License, or |
9 | * (at your option) any later version. |
10 | * |
11 | * This program is distributed in the hope that it will be useful, |
12 | * but WITHOUT ANY WARRANTY; without even the implied warranty of |
13 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
14 | * GNU General Public License for more details. |
15 | * |
16 | * You should have received a copy of the GNU General Public License along |
17 | * with this program; if not, write to the Free Software Foundation, Inc., |
18 | * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. |
19 | * http://www.gnu.org/copyleft/gpl.html |
20 | * |
21 | * @ingroup Maintenance |
22 | */ |
23 | |
24 | use MediaWiki\MediaWikiServices; |
25 | |
26 | require_once __DIR__ . '/IndexBase.php'; |
27 | |
28 | /** |
29 | * @author Moritz Schubotz |
30 | */ |
31 | class GenerateWorkload extends IndexBase { |
32 | |
33 | /** @var int */ |
34 | private $id = 0; |
35 | /** @var int */ |
36 | private $selectivity = PHP_INT_MAX; |
37 | |
38 | public function __construct() { |
39 | parent::__construct(); |
40 | $this->addDescription( 'Generates a workload of sample queries.' ); |
41 | $this->addOption( 'selectivity', 'Specifies the selectivity for each individual equation', |
42 | false, true, 'S' ); |
43 | $this->addOption( |
44 | 'lastId', |
45 | 'Specifies to start the ID counter after the given id. ' . |
46 | 'For example \'-l 1\' would start with id 2.', |
47 | false, true, 'l' |
48 | ); |
49 | $this->addOption( 'overwrite', 'Overwrite existing draft queries ', false, false, "o" ); |
50 | } |
51 | |
52 | /** |
53 | * @param stdClass $row |
54 | * |
55 | * @return string |
56 | */ |
57 | protected function generateIndexString( $row ) { |
58 | if ( mt_rand() <= $this->selectivity ) { |
59 | $q = MathQueryObject::newQueryFromEquationRow( $row, ++$this->id ); |
60 | $q->saveToDatabase( $this->getOption( 'overwrite', false ) ); |
61 | $out = $q->exportTexDocument(); |
62 | if ( $out == false ) { |
63 | echo 'problem with ' . var_export( $q, true ) . "\n"; |
64 | $out = ''; |
65 | } |
66 | return $out; |
67 | } else { |
68 | return ''; |
69 | } |
70 | } |
71 | |
72 | public function execute() { |
73 | $i = 0; |
74 | $inc = $this->getArg( 1, 100 ); |
75 | $this->id = $this->getOption( 'lastId', 0 ); |
76 | $sel = $this->getOption( 'selectivity', 0.1 ); |
77 | $this->selectivity = (int)( $sel * mt_getrandmax() ); |
78 | $db = MediaWikiServices::getInstance() |
79 | ->getConnectionProvider() |
80 | ->getReplicaDatabase(); |
81 | echo "getting list of all equations from the database\n"; |
82 | $this->res = |
83 | $db->select( [ 'mathindex' ], |
84 | [ 'mathindex_revision_id', 'mathindex_anchor', 'mathindex_inputhash' ], true, |
85 | __METHOD__, [ |
86 | 'LIMIT' => $this->getOption( 'limit', (int)( 100 / $sel ) ), |
87 | 'ORDER BY' => 'mathindex_inputhash' |
88 | ] ); |
89 | do { |
90 | $fn = $this->getArg( 0 ) . '/math' . sprintf( '%012d', $i ) . '.tex'; |
91 | $res = $this->wFile( $fn, $i, $inc ); |
92 | $i += $inc; |
93 | } while ( $res ); |
94 | echo "last id used: {$this->id}\n"; |
95 | echo ( 'done' ); |
96 | } |
97 | } |
98 | |
99 | $maintClass = GenerateWorkload::class; |
100 | /** @noinspection PhpIncludeInspection */ |
101 | require_once RUN_MAINTENANCE_IF_MAIN; |