Santhosh has uploaded a new change for review.

  https://gerrit.wikimedia.org/r/236538

Change subject: WIP: Deletion count graph
......................................................................

WIP: Deletion count graph

Change-Id: I8581d07c00dac6228ba5cc8b465acf431a1163e3
---
M api/ApiQueryContentTranslationLanguageTrend.php
M includes/Translation.php
M modules/stats/ext.cx.stats.js
3 files changed, 81 insertions(+), 12 deletions(-)


  git pull 
ssh://gerrit.wikimedia.org:29418/mediawiki/extensions/ContentTranslation 
refs/changes/38/236538/1

diff --git a/api/ApiQueryContentTranslationLanguageTrend.php 
b/api/ApiQueryContentTranslationLanguageTrend.php
index db17780..3aff780 100644
--- a/api/ApiQueryContentTranslationLanguageTrend.php
+++ b/api/ApiQueryContentTranslationLanguageTrend.php
@@ -35,7 +35,8 @@
                        array(
                                'translations' =>
                                        
ContentTranslation\Translation::getPublishTrend( $source, $target, $interval ),
-                               'drafts' => 
ContentTranslation\Translation::getDraftTrend( $source, $target, $interval )
+                               'drafts' => 
ContentTranslation\Translation::getDraftTrend( $source, $target, $interval ),
+                               'deletions' =>  
ContentTranslation\Translation::getDeletionTrend( $interval )
                        )
                );
        }
diff --git a/includes/Translation.php b/includes/Translation.php
index 59c4a2d..cae0cfc 100644
--- a/includes/Translation.php
+++ b/includes/Translation.php
@@ -291,6 +291,62 @@
        }
 
        /**
+        * Get time-wise cumulative number of drafts for given
+        * language pairs, with given interval.
+        */
+       public static function getDeletionTrend( $interval ) {
+               $dbr = wfGetDB( DB_SLAVE );
+
+               $conditions = array(
+                       'ar_namespace' => 0,
+                       'ct_tag' => 'contenttranslation',
+                       'ar_rev_id = ct_rev_id'
+               );
+               $groupBy = null;
+
+               if ( $interval === 'week' ) {
+                       $groupBy = array(
+                               'GROUP BY' => array(
+                                       'YEARWEEK(ar_timestamp)',
+                               ),
+                       );
+               } elseif ( $interval === 'month' ) {
+                       $groupBy = array(
+                               'GROUP BY' => array(
+                                       'YEAR(ar_timestamp), 
MONTH(ar_timestamp)',
+                               ),
+                       );
+               }
+
+               $rows = $dbr->select(
+                       array( 'change_tag', 'archive' ),
+                       array( 'ar_timestamp', 'count(ar_page_id) as count' ),
+                       $conditions,
+                       __METHOD__,
+                       $groupBy
+               );
+
+               $prev = 0;
+               $count = 0;
+               $result = array();
+               foreach ( $rows as $row ) {
+                       $count += (int)$row->count;
+                       $result[] = array(
+                               'date' => $interval === 'week' ?
+                                       // Week end date
+                                       date( 'Y-m-d', strtotime( 
$row->ar_timestamp . ' + ' .
+                                               ( 6 - date( 'w', strtotime( 
$row->ar_timestamp ) ) ) . ' days' ) ) :
+                                       date( 'Y-m', strtotime( 
$row->ar_timestamp ) ),
+                               'count' => $count,
+                               'delta' => $count - $prev,
+                       );
+                       $prev = $count;
+               }
+
+               return $result;
+       }
+
+       /**
         * Get time-wise cumulative number of translations for given
         * language pairs, with given interval.
         */
diff --git a/modules/stats/ext.cx.stats.js b/modules/stats/ext.cx.stats.js
index 769cba3..6b46e22 100644
--- a/modules/stats/ext.cx.stats.js
+++ b/modules/stats/ext.cx.stats.js
@@ -67,6 +67,7 @@
                        self.totalDraftTrend = mergeAndFill( 
self.totalTranslationTrend, totalTrend.drafts );
                        self.languageDraftTrend = mergeAndFill( 
self.languageTranslationTrend, languageTrend.drafts );
                        self.languageDraftTrend = mergeAndFill( 
self.totalDraftTrend, self.languageDraftTrend );
+                       self.languageDeletionTrend = mergeAndFill( 
self.languageTranslationTrend, totalTrend.deletions );
                        self.renderHighlights();
                        self.drawCumulativeGraph( 'count' );
                        self.drawLanguageCumulativeGraph( 'count' );
@@ -499,6 +500,28 @@
                        } ),
                        datasets: [
                                {
+                                       label:  mw.msg( 
'cx-stats-draft-translations-title' ),
+                                       strokeColor: 'rgba(220, 220, 220, 1)',
+                                       pointColor: 'rgba(220, 220, 220, 1 )',
+                                       pointStrokeColor: '#fff',
+                                       pointHighlightFill: '#fff',
+                                       pointHighlightStroke: 
'rgba(220,220,220,1)',
+                                       data: $.map( this.languageDraftTrend, 
function ( data ) {
+                                               return data[ type ];
+                                       } )
+                               },
+                               {
+                                       label:  mw.msg( 'cx-stats-deletions' ),
+                                       strokeColor: 'rgba(255, 0, 0, 1)',
+                                       pointColor: 'rgba(255, 0, 0, 1 )',
+                                       pointStrokeColor: '#fff',
+                                       pointHighlightFill: '#fff',
+                                       pointHighlightStroke: 'rgba(255, 0, 
0,1)',
+                                       data: $.map( 
this.languageDeletionTrend, function ( data ) {
+                                               return data[ type ];
+                                       } )
+                               },
+                               {
                                        label: mw.message(
                                                'cx-trend-translations-to',
                                                $.uls.data.getAutonym( 
mw.config.get( 'wgContentLanguage' ) )
@@ -509,17 +532,6 @@
                                        pointHighlightFill: '#fff',
                                        pointHighlightStroke: 'rgba(70, 130, 
180, 1)',
                                        data: $.map( 
this.languageTranslationTrend, function ( data ) {
-                                               return data[ type ];
-                                       } )
-                               },
-                               {
-                                       label:  mw.msg( 
'cx-stats-draft-translations-title' ),
-                                       strokeColor: 'rgba(220, 220, 220, 1)',
-                                       pointColor: 'rgba(220, 220, 220, 1 )',
-                                       pointStrokeColor: '#fff',
-                                       pointHighlightFill: '#fff',
-                                       pointHighlightStroke: 
'rgba(220,220,220,1)',
-                                       data: $.map( this.languageDraftTrend, 
function ( data ) {
                                                return data[ type ];
                                        } )
                                }

-- 
To view, visit https://gerrit.wikimedia.org/r/236538
To unsubscribe, visit https://gerrit.wikimedia.org/r/settings

Gerrit-MessageType: newchange
Gerrit-Change-Id: I8581d07c00dac6228ba5cc8b465acf431a1163e3
Gerrit-PatchSet: 1
Gerrit-Project: mediawiki/extensions/ContentTranslation
Gerrit-Branch: master
Gerrit-Owner: Santhosh <santhosh.thottin...@gmail.com>

_______________________________________________
MediaWiki-commits mailing list
MediaWiki-commits@lists.wikimedia.org
https://lists.wikimedia.org/mailman/listinfo/mediawiki-commits

Reply via email to