User:AnomieBOT/source/tasks/ArticleCreationGrapher.pm: Difference between revisions

Content deleted Content added
AnomieBOT (talk | contribs)
Updating published sources: ArticleCreationGrapher: * Add separate thumbnail size setting. * Fix "nextrun" logic. * Add the ability to label events at the top of the graph.
AnomieBOT (talk | contribs)
Updating published sources: ArticleCreationGrapher: * Discontinue task. Graph doesn't seem to really be used anymore, and mw:Extension:Graph exists which would be a better way to do it than a monthly file upload.
 
(13 intermediate revisions by the same user not shown)
Line 1:
{{ombox|type=notice|text= ApprovalApproved requested2010-08-29<br />[[Wikipedia:Bots/Requests for approval/AnomieBOT 41]]}}
{{ombox|type=notice|text= Task discontinued 2022-01-25. The graph has trailed off, the page it's on hasn't been updated in years and gets minimal views, and we now have [[mw:Extension:Graph]] that can generate graphs from data instead of having to have an image uploaded monthly. If someone still wants such a graph, it would be better to have a bot create a data table somewhere to be graphed via that extension.}}
<sourcesyntaxhighlight lang="perl">
package tasks::ArticleCreationGrapher;
 
Line 10 ⟶ 11:
Task: ArticleCreationGrapher
BRFA: Wikipedia:Bots/Requests for approval/AnomieBOT 41
Status: BRFAInactive 2022-01-25
Created: 2010-08-25
 
Line 24 ⟶ 25:
use Data::Dumper;
use IPC::Open2;
use POSIXAnomieBOT::Task qw/strftime mktime:time/;
use AnomieBOT::Task;
use vars qw/@ISA/;
@ISA=qw/AnomieBOT::Task/;
 
my $epoch=2; # Increment this to force a new graph, e.g. if an improved version of gnuplot is installed
 
my @gnuplot=("/usr/bin/gnuplot");
Line 58 ⟶ 60:
 
=for info
ApprovalApproved requested2010-08-29<br />[[Wikipedia:Bots/Requests for approval/AnomieBOT 41]]
 
=for info
Task discontinued 2022-01-25. The graph has trailed off, the page it's on hasn't been updated in years and gets minimal views, and we now have [[mw:Extension:Graph]] that can generate graphs from data instead of having to have an image uploaded monthly. If someone still wants such a graph, it would be better to have a bot create a data table somewhere to be graphed via that extension.
 
=cut
 
sub approved {
return 0-6;
}
 
Line 71 ⟶ 76:
 
$api->task('ArticleCreationGrapher', 0, 10, qw/d::Timestamp/);
 
# Spend a max of 10 minutes on this task before restarting
my $endtime=time()+600;
 
foreach my $page (@pages){
myreturn 0 if $pgdata=$api->store->{$page->{'page'}} // {halting;
 
nextrun => 0,
# pages => {},Update
if ( exists( $api->store->{$page->{'page'}} ) ) {
};
my $pgdata=$api->store->{$page->{'page'}};
$api->store->{'epoch:'.$page->{'page'}} = $pgdata->{'epoch'} // 0;
$api->store->{'nextrun:'.$page->{'page'}} = $pgdata->{'nextrun'};
$api->store->{'pg:'.$page->{'page'}} = $pgdata->{'pages'};
delete( $api->store->{$page->{'page'}} );
};
 
my $nextrun = $api->store->{'nextrun:'.$page->{'page'}} // 0;
my $pages = $api->store->{'pg:'.$page->{'page'}} // {};
my @pp=();
if($nonet){
foreach my $v (values %{$pgdata->{'pages'}}){
next unless ref($v) eq 'HASH';
push @pp, { redir=>$v->{'r'}, ts=>$v->{'t'}, title=>$v->{'tt'} };
}
} else {
next if($nextrun > time() && ($pgdataapi->store->{'nextrunepoch:'.$page->{'page'}}//0) >= time($epoch);
$api->log( "Loading data to graph " . $page->{'page'} );
my $i=$api->iterator(
generator => 'categorymembers',
Line 93 ⟶ 105:
gcmlimit => 'max',
gcmnamespace => '0|1',
nextrun gcmtype => 0'page',
prop => 'info',
inprop => 'subjectid',
Line 107 ⟶ 120:
my $ct=0;
foreach my $p (@pageids) {
return 0 if(exists( $pgdataapi->{'pages'}{$p})){halting;
if(exists($pages->{$p})){
push @px, $p;
next;
Line 113 ⟶ 127:
if($ct++>=100){
# periodic save
$api->store->{'pg:'.$page->{'page'}}=$pgdatapages;
$ct=0;
}
Line 124 ⟶ 138:
);
if($res->{'code'} eq 'shutoff'){
$api->store->{'pg:'.$page->{'page'}}=$pgdatapages;
$api->warn("Task disabled: ".$res->{'content'}."\n");
return 300;
}
if($res->{'code'} ne 'success'){
$api->store->{'pg:'.$page->{'page'}}=$pgdatapages;
$api->warn("Failed to get info for $p: ".$res->{'error'}."\n");
return 60;
Line 139 ⟶ 153:
next if $ts eq '';
$ts=$api->ISO2timestamp($ts);
$pgdatapages->{'pages'}{$p}={
t=>$ts,
r=>$is_redir,
Line 150 ⟶ 164:
};
}
$api->store->{'pg:'.$page->{'page'}}=$pgdatapages;
if(@px){
my %q=(
Line 166 ⟶ 180:
}
my $p=$_->{'pageid'};
$pgdatapages->{'pages'}{$p}{'r'}=exists($_->{'redirect'});
$pgdatapages->{'pages'}{$p}{'tt'}=$_->{'title'};
push @pp, {
title=>$_->{'title'},
redir=>$pgdatapages->{'pages'}{$p}{'r'},
ts=>$pgdatapages->{'pages'}{$p}{'t'},
};
}
$api->store->{'pg:'.$page->{'page'}}=$pgdatapages;
}
}
$api->log( "Graphing data for " . $page->{'page'} );
@pp=sort {
my $x=($a->{'ts'} <=> $b->{'ts'});
Line 207 ⟶ 222:
EOH
 
my @t=localtimegmtime $pp[0]{'ts'};
my $end=strftime('%Y-%m', localtimegmtime);
my $x;
print W "set xtics (";
Line 214 ⟶ 229:
do {
$x=strftime('%Y-%m', 0,0,0,1,$t[4]++,$t[5]);
($t[4], $t[5]) = (1, $t[5]+1) if $t[4] == 13;
print W "," unless $f;
if($x=~/^(\d+)-01$/){
Line 249 ⟶ 265:
 
if($page->{'writepage'}){
$api->log( "Updating " . $page->{'page'} );
my $tok=$api->edittoken($page->{'page'});
if($tok->{'code'} eq 'shutoff'){
Line 277 ⟶ 294:
}
 
$api->log( "Uploading image file " . $page->{'graph'} . ' for ' . $page->{'page'} );
my $tok=$api->edittoken($page->{'graph'});
if($tok->{'code'} eq 'shutoff'){
Line 287 ⟶ 305:
}
my $comment="Updated graph";
my $txt="{{imbox|type=style|image=[[File:Ambox warning yellow.svg|50px]]|imageright=[[File:Crystal Clear action run.svg|50px]]|text=This image is automatically updated by a bot, {{User|".$api->user."}}. Any changes will be overwritten automatically.<center>'''Do not move this file to Wikimedia Commons.'''<br /><small>If for some reason you need to stop the bot, place {{tl|nobots}} on this page or post a message [[User:".$api->user."/shutoff/ArticleCreationGrapher|here]].</small></center>}}\n{{Information\n|description=Bot-generated graph of [[$page->{page}|$page->{for}]] article creation\n|source=Own work, created using [[Gnuplot]]\n|date=~~~~~\n|author={{User|".$api->operator."}} as the author of {{User|".$api->user."}}\n|permission={{PD-self|date=August 2010}}\n}}\n{{esoteric file}}\n\n[[Category:Wikipedia charts]]\n";
foreach my $c (@{$page->{'graph_cats'}}){
$txt.="[[Category:$c]]\n";
Line 301 ⟶ 319:
next;
}
@t=localtimegmtime;
$pgdataapi->store->{'nextrunpg:'.$page->{'page'}}=mktime(0,0,0,1,$t[4]+1,$t[5])pages;
$api->store->{'epoch:'.$page->{'page'}}=$pgdataepoch;
$api->store->{'nextrun:'.$page->{'page'}}=timegm(0,0,0,1,$t[4]+1,$t[5]);
 
if(!exists($tok->{'missing'})){
$api->log( "Updating image description for " . $page->{'graph'} );
$res=$api->edit($tok, $txt, "Update page text", 0, 0);
if($res->{'code'} eq 'shutoff'){
Line 317 ⟶ 337:
}
 
# No more pages to check, try again in 10 minutes or so in case of errors.later
returnmy 600$t=undef;
foreach my $page (@pages){
my $nextrun=$api->store->{'nextrun:'.$page->{'page'}};
$t=$nextrun if(!defined($t) || $t>$nextrun);
}
myreturn $endtime=t-time()+600;
}
 
sub g_tt {
my @t=localtimegmtime shift;
return strftime('%Y-%m', 0,0,0,1,$t[4],$t[5]);
}
Line 358 ⟶ 383:
1;
 
</syntaxhighlight>
</source>