Index: trunk/wikistats/dammit.lt/cellar/!DammitPatchProjectcountsForBanners.pl |
— | — | @@ -1,189 +0,0 @@ |
2 | | -#!/usr/bin/perl
|
3 | | -
|
4 | | -$| = 1; # flush screen output
|
5 | | -
|
6 | | -open IN, '<', 'PageViewsBannerPages.txt' ;
|
7 | | -open OUT1, '>', 'PageViewsBannerPagesUse.txt' ;
|
8 | | -open OUT2, '>', 'PageViewsBannerPagesDiscard.txt' ;
|
9 | | -open LOG, '>', 'PageViewsBannerPagesLog.txt' ;
|
10 | | -
|
11 | | -while ($line = <IN>)
|
12 | | -{
|
13 | | - ($date,$project,$title,$counts) = split (' ', $line) ;
|
14 | | -
|
15 | | - $date =~ s/^.*?(\d{8}).*$/$1/ ;
|
16 | | - $project =~ s/^.*?:// ;
|
17 | | - $project =~ s/\.z// ;
|
18 | | -
|
19 | | - $projects {$project} ++ ;
|
20 | | -
|
21 | | - ($total = $counts) =~ s/\D.*//g ;
|
22 | | -
|
23 | | -# next if $line !~ /20101001/ ;
|
24 | | -# next if $line !~ /fy\.z/ ;
|
25 | | -
|
26 | | - if ($line !~ /(?:BannerCont|BannerList|BannerLoad|Bannerbeheer)/i)
|
27 | | - {
|
28 | | - print OUT2 $line ;
|
29 | | - $total_discard += $total ;
|
30 | | - $titles_discard {"$project $title"} += $total ;
|
31 | | - next ;
|
32 | | - }
|
33 | | -
|
34 | | - print OUT1 $line ;
|
35 | | - $titles_use {"$project $title"} += $total ;
|
36 | | - $total_use += $total ;
|
37 | | -
|
38 | | - # print "$counts: " ;
|
39 | | - $counts =~ s/^\d+// ; # remove (redundant) preceding total
|
40 | | - while ($counts ne "")
|
41 | | - {
|
42 | | - $letter = substr ($counts,0,1) ;
|
43 | | - $counts = substr ($counts,1) ;
|
44 | | - ($count = $counts) =~ s/^(\d+).*$/$1/ ;
|
45 | | - $counts =~ s/^\d+(.*)$/$1/ ;
|
46 | | - $hour = ord ($letter) - ord ('A') ;
|
47 | | - # print "[$hour] $count " ;
|
48 | | -
|
49 | | - $substract {"$project,$date,$hour"} += $count ;
|
50 | | - # if (($project eq 'fy') && ($date eq '20101001'))
|
51 | | - # { print "$project,$date,$hour\n" ; }
|
52 | | - }
|
53 | | - # print "\n" ;
|
54 | | -
|
55 | | -}
|
56 | | -close IN ;
|
57 | | -
|
58 | | -&Log ("\n\nDiscard:\n") ;
|
59 | | -foreach $title (sort {$titles_discard {$b} <=> $titles_discard {$a}} keys %titles_discard)
|
60 | | -{
|
61 | | - print $titles_discard {$title} . " : $title\n" ;
|
62 | | - print LOG $titles_discard {$title} . " : $title\n" ;
|
63 | | - last if $lines_discard++ > 10 ;
|
64 | | -}
|
65 | | -
|
66 | | -&Log ("\n\nUse:\n") ;
|
67 | | -foreach $title (sort {$titles_use {$b} <=> $titles_use {$a}} keys %titles_use)
|
68 | | -{
|
69 | | - print LOG $titles_use {$title} . " : $title\n" ;
|
70 | | - next if $lines_use++ > 10 ;
|
71 | | - print $titles_use {$title} . " : $title\n" ;
|
72 | | - last if $lines_use++ > 1000 ;
|
73 | | -}
|
74 | | -
|
75 | | -&Log ("\n\nProjects:\n") ;
|
76 | | -foreach $project (sort keys %projects)
|
77 | | -{
|
78 | | - &Log ("$project ") ;
|
79 | | - &Log ("\n") if $projects_printed++ %10 == 0 ;
|
80 | | -}
|
81 | | -close OUT1 ;
|
82 | | -close OUT2 ;
|
83 | | -close LOG ;
|
84 | | -
|
85 | | -&Patch ;
|
86 | | -
|
87 | | -&Log ("Use $total_use\n") ;
|
88 | | -&Log ("Discard $total_discard\n") ;
|
89 | | -&Log ("Substracted $counts_substracted\n") ;
|
90 | | -
|
91 | | -print "\n\nReady\n\n" ;
|
92 | | -exit ;
|
93 | | -
|
94 | | -sub Patch
|
95 | | -{
|
96 | | - &Log ("\n\nPatch\n\n") ;
|
97 | | - if (-d "/a/dammit.lt/projectcounts")
|
98 | | - { $dir = "/a/dammit.lt/projectcounts" ; }
|
99 | | - else
|
100 | | - { $dir = "w:/# In Dammit.lt/projectcounts/t" ; }
|
101 | | -
|
102 | | - chdir ($dir) || die "Cannot chdir to $dir\n" ;
|
103 | | -
|
104 | | - local (*DIR);
|
105 | | - opendir (DIR, ".");
|
106 | | - @files = () ;
|
107 | | -
|
108 | | - while ($file_in = readdir (DIR))
|
109 | | - {
|
110 | | - next if $file_in !~ /^projectcounts-2010(?:09|10)/ ;
|
111 | | - # next if $file_in !~ /^projectcounts-20101001/ ;
|
112 | | -
|
113 | | - push @files, $file_in ;
|
114 | | - }
|
115 | | -
|
116 | | - closedir (DIR);
|
117 | | -
|
118 | | - @files = sort @files ;
|
119 | | -
|
120 | | - foreach $file (@files)
|
121 | | - { &PatchFile ($file) ; }
|
122 | | -
|
123 | | - &Log ("\n\nUnpatched\n\n") ;
|
124 | | - foreach $key (sort keys %substract)
|
125 | | - {
|
126 | | - if (! $substract_found {$key})
|
127 | | - { &Log ("$key\n") ; }
|
128 | | - }
|
129 | | -}
|
130 | | -
|
131 | | -sub PatchFile
|
132 | | -{
|
133 | | - my $file = shift ;
|
134 | | - my $line ;
|
135 | | - print "\nFile $file\n" ;
|
136 | | -
|
137 | | - ($dummy,$date,$time) = split '-', $file ;
|
138 | | - $hour = substr ($time,0,2) + 0 ;
|
139 | | -
|
140 | | - open PROJECTFILE, '<', "$dir/$file" || die "Could not open '$dir/$file'\n" ;
|
141 | | -
|
142 | | - undef @projectfile ;
|
143 | | - $file_changed = 0 ;
|
144 | | - while ($line = <PROJECTFILE>)
|
145 | | - {
|
146 | | - chomp $line ;
|
147 | | - ($project,$dash,$count,$bytes) = split (' ', $line) ;
|
148 | | -
|
149 | | - # next if $project ne 'fy' ;
|
150 | | - # print "$line\n" ;
|
151 | | - next if $bytes eq '' ;
|
152 | | - $count_substract = $substract {"$project,$date,$hour"} ;
|
153 | | - $substract_found {"$project,$date,$hour"} ++ ;
|
154 | | -
|
155 | | - if ($count_substract == 0)
|
156 | | - { push @projectfile, $line ; }
|
157 | | - else
|
158 | | - {
|
159 | | - $file_changed = 1 ;
|
160 | | - $count -= $count_substract ;
|
161 | | - &Log ("\n$line ->\n") ;
|
162 | | - $line = "$project $dash $count 1" ;
|
163 | | - push @projectfile, $line ;
|
164 | | - &Log ("$line\n") ;
|
165 | | - }
|
166 | | - # next if $count_substract eq '' ;
|
167 | | - $counts_substracted += $count_substract ;
|
168 | | - # print "$project $count minus $count_substract\n" ; # '$project,$date,$hour'\n" ;
|
169 | | - }
|
170 | | -
|
171 | | - close PROJECTFILE ;
|
172 | | -
|
173 | | - if ($file_changed)
|
174 | | - {
|
175 | | - open PROJECTFILE, '>', "$dir/$file" || die "Could not open '$dir/$file'\n" ;
|
176 | | - foreach $line (@projectfile)
|
177 | | - { print PROJECTFILE "$line\n" ; }
|
178 | | - close PROJECTFILE ;
|
179 | | - }
|
180 | | -}
|
181 | | -
|
182 | | -sub Log
|
183 | | -{
|
184 | | - my $msg = shift ;
|
185 | | - print $msg ;
|
186 | | - print LOG $msg ;
|
187 | | -}
|
188 | | -
|
189 | | -
|
190 | | -
|
Index: trunk/wikistats/dammit.lt/cellar/!DammitPatchProjectcountsForFundraiser.pl |
— | — | @@ -1,86 +0,0 @@ |
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 | | -
|