21class TSP extends Maintenance {
22 public function __construct() {
23 parent::__construct();
24 $this->addDescription(
'Script to calculate monthly stats about tsv data produced ' .
25 'by translator-stats.php.' );
32 protected function median( $a ) {
37 } elseif ( $len === 1 ) {
39 } elseif ( $len % 2 === 0 ) {
42 return ( $a[(
int)floor( $len / 2 )] + $a[(
int)ceil( $len / 2 )] ) / 2;
46 public function execute() {
47 $handle = fopen( $this->getArg( 0 ),
'r' );
54 $l = fgets( $handle );
59 $fields = explode(
"\t", trim( $l,
"\n" ) );
61 $month = substr( $reg, 0, 4 ) .
'-' . substr( $reg, 4, 2 ) .
'-01';
62 $data[$month][] = $fields;
69 echo
"period\tnew\tpromoted\tgood\tmedian promotion time\t" .
70 "avg promotion time\tsandbox approval rate\n";
72 foreach ( $data as $key => $period ) {
80 foreach ( $period as $p ) {
81 [ , $reg, $edits, $translator, $promtime, $method ] = $p;
83 if ( $translator ===
'translator' ) {
92 $delay[] = (int)wfTimestamp( TS_UNIX, $promtime ) - (int)wfTimestamp( TS_UNIX, $reg );
95 if ( $method ===
'sandbox' ) {
105 $median = round( $this->median( $delay ) / 3600 );
106 if ( count( $delay ) ) {
107 $avg = round( array_sum( $delay ) / count( $delay ) / 3600 );
110 if ( $sbar === [] ) {
113 $sbar = count( array_filter( $sbar ) ) / count( $sbar );
116 echo
"$key\t$total\t$promoted\t$good\t$median\t$avg\t$sbar\n";