r109174 MediaWiki - Code Review archive

Repository:MediaWiki
Revision:r109173‎ | r109174 | r109175 >
Date:18:32, 17 January 2012
Author:ezachte
Status:deferred
Tags:
Comment:
for historic reference + as example code: one time patch job
Modified paths:
  • /trunk/wikistats/dammit.lt/!DammitPatchProjectcountsForFundraiser.pl (added) (history)

Diff [purge]

Index: trunk/wikistats/dammit.lt/!DammitPatchProjectcountsForFundraiser.pl
@@ -0,0 +1,86 @@
 2+#!/usr/bin/perl
 3+
 4+$| = 1; # flush screen output
 5+
 6+open IN, '<', 'DammitPatchProjectcountsForFundraiser/AllSquids.csv' ;
 7+open LOG, '>', 'DammitPatchProjectcountsForFundraiser/Log.txt' ;
 8+
 9+chdir ("DammitPatchProjectcountsForFundraiser") || die "Cannot chdir to DammitPatchProjectcountsForFundraiser\n" ;
 10+
 11+while ($line = <IN>)
 12+{
 13+ chomp $line ;
 14+
 15+ next if $line =~ /[*]/ ;
 16+ next if $line !~ /^2010/ ;
 17+
 18+ ($date,$hour,$events,$avg_delta) = split (',', $line) ;
 19+
 20+ next if $avg_delta <= 1005 ; # normally projectcounts also miss a few hits, overcorrecting would skew trends
 21+ &Patch ($date, $hour, $avg_delta) ;
 22+}
 23+
 24+print "\n\nReady\n\n" ;
 25+exit ;
 26+
 27+sub Patch
 28+{
 29+ ($date,$hour,$avg_delta) = @_ ;
 30+
 31+ $date =~ s/-//g ;
 32+ $file = "projectcounts-$date-" . sprintf ("%02d",$hour) . "0000" ;
 33+
 34+ if (! -e $file)
 35+ {
 36+ $file = "projectcounts-$date-" . sprintf ("%02d",$hour) . "0001" ;
 37+ if (! -e $file)
 38+ {
 39+ print "File '$file' missing!\n" ;
 40+ exit ;
 41+ }
 42+ }
 43+ &PatchFile ($file, $avg_delta) ;
 44+}
 45+
 46+sub PatchFile
 47+{
 48+ my ($file,$avg_delta) = @_ ;
 49+ my $line ;
 50+ $correction = $avg_delta / 1000 ;
 51+ print "Patch file $file: avg delta $avg_delta -> correction $correction\n" ;
 52+
 53+ open PROJECTFILE, '<', $file || die "Could not open '$file'\n" ;
 54+
 55+ undef @projectfile ;
 56+ $file_changed = 0 ;
 57+ while ($line = <PROJECTFILE>)
 58+ {
 59+ chomp $line ;
 60+ ($project,$dash,$count,$bytes) = split (' ', $line) ;
 61+
 62+ if ($bytes > 0)
 63+ {
 64+ $count = sprintf ("%.0f", $correction * $count) ;
 65+ # &Log ("\n$line ->\n") ;
 66+ $line = "$project $dash $count 1" ;
 67+ # &Log ("$line\n") ;
 68+ }
 69+ push @projectfile, "$line\n" ;
 70+ }
 71+
 72+ close PROJECTFILE ;
 73+
 74+ open PROJECTFILE, '>', $file || die "Could not open '$file'\n" ;
 75+ print PROJECTFILE @projectfile ;
 76+ close PROJECTFILE ;
 77+}
 78+
 79+sub Log
 80+{
 81+ my $msg = shift ;
 82+ print $msg ;
 83+ print LOG $msg ;
 84+}
 85+
 86+
 87+

Status & tagging log