Skip to content

Commit

Permalink
Merge pull request #176 from wikimedia/rm-damage-scores
Browse files Browse the repository at this point in the history
Remove damage scores
  • Loading branch information
MusikAnimal authored Oct 24, 2023
2 parents 338d6ab + 33705eb commit 63b8d56
Show file tree
Hide file tree
Showing 8 changed files with 6 additions and 63 deletions.
1 change: 1 addition & 0 deletions composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
"ext-iconv": "*",
"ext-json": "*",
"ext-intl": "*",
"ext-apcu": "*",
"doctrine/annotations": "^2.0",
"doctrine/doctrine-bundle": "^2.2",
"phpxmlrpc/phpxmlrpc": "^4.10",
Expand Down
1 change: 0 additions & 1 deletion i18n/en.json
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,6 @@
"record-url-text": "$1 of edit",
"record-noeditor": "No editor found",
"record-noeditor-tooltip": "The revision may have been deleted or the data is not yet available in Labs database.",
"record-damage": "Damage score: $1",
"article": "Article",
"compare-article-loading": "Loading article revision...",
"compare-source-loading": "Loading possible copyvio source...",
Expand Down
1 change: 0 additions & 1 deletion i18n/qqq.json
Original file line number Diff line number Diff line change
Expand Up @@ -77,7 +77,6 @@
"record-url-text": "Label text to show amount of plagiarism. Parameters:\n* $1 - Percentage of edit that was plagiarized.",
"record-noeditor": "Column text shown to user when no editor was found in database for an edit",
"record-noeditor-tooltip": "Tooltip for a text label, shown to editor to explain why no editor could be found",
"record-damage": "The damage score for a record.\nParameters: \n* $1 - Decimal number indicating percentage score.",
"article": "Label shown for a text box, showing an article text. \n{{Identical|Article}}",
"compare-article-loading": "Temporary text shown to user while article text loads",
"compare-source-loading": "Temporary text shown to user while copyvio text source loads",
Expand Down
8 changes: 3 additions & 5 deletions src/Controller/AppController.php
Original file line number Diff line number Diff line change
Expand Up @@ -123,7 +123,7 @@ public function feedAction(
}

/**
* Returns a Record object, with additional data such as user edit counts, which pages are dead, and damage scores.
* Returns a Record object, with additional data such as user edit counts, and which pages are dead.
*
* @param array $rows
* @param WikiRepository $wikiRepo
Expand Down Expand Up @@ -160,11 +160,10 @@ public function decorateRecords( array $rows, WikiRepository $wikiRepo ): array

$editCounts = $wikiRepo->getEditCounts( array_unique( $usernames ) );
$livePages = $wikiRepo->getLivePagesWithWikiProjects( $titlesByNs );
$damageScores = $wikiRepo->getDamageScores( array_unique( $revIds ) );
$tagsAndComments = $wikiRepo->getRevisionMetadata( $revIds );

// Create a Record object for each row.
return array_map( static function ( $row ) use ( $editCounts, $livePages, $damageScores, $tagsAndComments ) {
return array_map( static function ( $row ) use ( $editCounts, $livePages, $tagsAndComments ) {
// $tagsAndComments aren't indexed by rev_id, so we need to locate the row first.
$extraData = array_filter( $tagsAndComments, static function ( $data ) use ( $row ) {
return $data['rev_id'] === $row['rev_id'];
Expand All @@ -182,8 +181,7 @@ public function decorateRecords( array $rows, WikiRepository $wikiRepo ): array
isset( $livePages[$row['page_namespace']][$row['page_title']] ),
isset( $livePages['2'][$row['rev_user_text']] ),
isset( $livePages['3'][$row['rev_user_text']] ),
$livePages[$row['page_namespace']][$row['page_title']] ?? [],
$damageScores[$row['rev_id']] ?? null
$livePages[$row['page_namespace']][$row['page_title']] ?? []
);
}, $newRows );
}
Expand Down
6 changes: 1 addition & 5 deletions src/Model/Record.php
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,6 @@ class Record {
protected bool $userPageExists;
protected bool $userTalkExists;
protected array $wikiProjects;
protected ?float $damageScore;

/**
* @param array $row From the CopyPatrol database.
Expand All @@ -26,16 +25,14 @@ class Record {
* @param bool $userPageExists
* @param bool $userTalkExists
* @param array $wikiProjects
* @param float|null $damageScore
*/
public function __construct(
array $row,
int $editCount = null,
bool $pageExists = false,
bool $userPageExists = false,
bool $userTalkExists = false,
array $wikiProjects = [],
float $damageScore = null
array $wikiProjects = []
) {
$this->data = $row;
$this->editCount = $editCount;
Expand All @@ -44,7 +41,6 @@ public function __construct(
$this->userTalkExists = $userTalkExists;
// Remove any null values.
$this->wikiProjects = array_filter( $wikiProjects );
$this->damageScore = $damageScore;
}

/** REPORT ATTRIBUTES */
Expand Down
43 changes: 0 additions & 43 deletions src/Repository/WikiRepository.php
Original file line number Diff line number Diff line change
Expand Up @@ -274,49 +274,6 @@ private function getTagsLabels( array $tagNames ): array {
return $messages;
}

/**
* Get the damage scores for the given revision IDs.
*
* @param int[] $revIds
* @return array
*/
public function getDamageScores( array $revIds ): array {
if ( !$revIds ) {
return [];
}

$dbName = "{$this->getLang()}wiki";

$ret = [];
$responses = [];
foreach ( $revIds as $revId ) {
if ( $this->cache->hasItem( "$dbName-damage-score-$revId" ) ) {
$ret[$revId] = $this->cache->getItem( "$dbName-damage-score-$revId" )->get();
} else {
$responses[] = $this->httpClient->request(
'POST',
"https://api.wikimedia.org/service/lw/inference/v1/models/$dbName-damaging:predict",
[ 'json' => [ 'rev_id' => $revId ] ]
);
}
}

foreach ( $responses as $response ) {
$data = $response->toArray( false );
$revId = array_keys( $data[$dbName]['scores'] ?? [] )[0] ?? null;
if ( $revId ) {
$ret[$revId] = $data[$dbName]['scores'][$revId]['damaging']['score']['probability']['true'] ?? null;
$cacheItem = $this->cache->getItem( "$dbName-damage-score-$revId" )
->set( $ret[$revId] )
->expiresAfter( new DateInterval( 'PT10M' ) );
$this->cache->saveDeferred( $cacheItem );
}
}
$this->cache->commit();

return $ret;
}

/**
* Return whether the language associated with this WikiRepository instance support PageAssessments.
*
Expand Down
5 changes: 0 additions & 5 deletions templates/feed.html.twig
Original file line number Diff line number Diff line change
Expand Up @@ -110,11 +110,6 @@
</div>
</div>
<div class="summary-container">
{% if row.damageScore is not empty %}
<div>
{{ msg('record-damage', [row.damageScore]) }}%
</div>
{% endif %}
{% if row.summary is not empty %}
<div>{{ msg('edit-summary') }}: <i class="text-muted">{{ row.summary|raw }}</i></div>
{% endif %}
Expand Down
4 changes: 1 addition & 3 deletions tests/Model/RecordTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -58,8 +58,7 @@ public function setUp(): void {
false,
true,
true,
[ 'New York City', null ],
0.15
[ 'New York City', null ]
);

parent::setUp();
Expand Down Expand Up @@ -102,7 +101,6 @@ public function testGetters(): void {
);
static::assertSame( '2016-06-20 00:33', $this->record->getDiffTimestamp() );
static::assertSame( [ 'New York City' ], $this->record->getWikiProjects() );
static::assertNull( $this->record->getDamageScore() );
static::assertSame( 726095124, $this->record->getRevId() );
static::assertSame( 0, $this->record->getRevParentId() );
static::assertSame( 'Starec2016', $this->record->getEditor() );
Expand Down

0 comments on commit 63b8d56

Please sign in to comment.