19class TSP extends Maintenance {
20 public function __construct() {
21 parent::__construct();
22 $this->addDescription(
'Script to calculate monthly stats about tsv data produced ' .
23 'by translator-stats.php.' );
30 protected function median( $a ) {
35 } elseif ( $len === 1 ) {
37 } elseif ( $len % 2 === 0 ) {
40 return ( $a[floor( $len / 2 )] + $a[ceil( $len / 2 )] ) / 2;
44 public function execute() {
45 $handle = fopen( $this->getArg( 0 ),
'r' );
52 $l = fgets( $handle );
57 $fields = explode(
"\t", trim( $l,
"\n" ) );
59 $month = substr( $reg, 0, 4 ) .
'-' . substr( $reg, 4, 2 ) .
'-01';
60 $data[$month][] = $fields;
67 echo
"period\tnew\tpromoted\tgood\tmedian promotion time\t" .
68 "avg promotion time\tsandbox approval rate\n";
70 foreach ( $data as $key => $period ) {
78 foreach ( $period as $p ) {
79 list( , $reg, $edits, $translator, $promtime, $method ) = $p;
81 if ( $translator ===
'translator' ) {
90 $delay[] = wfTimestamp( TS_UNIX, $promtime ) - wfTimestamp( TS_UNIX, $reg );
93 if ( $method ===
'sandbox' ) {
103 $median = round( $this->median( $delay ) / 3600 );
104 if ( count( $delay ) ) {
105 $avg = round( array_sum( $delay ) / count( $delay ) / 3600 );
108 if ( $sbar === [] ) {
111 $sbar = count( array_filter( $sbar ) ) / count( $sbar );
114 echo
"$key\t$total\t$promoted\t$good\t$median\t$avg\t$sbar\n";