Rosetta Code/Count examples: Difference between revisions

→‎{{header|Perl 6}}: Update to show sortable top 10 completion. Fix problem with with detecting examples that use non-standard markup
(→‎{{header|Perl 6}}: Modify to show the top 10 language completion rate instead of draft/task status which is denoted by color anyway)
(→‎{{header|Perl 6}}: Update to show sortable top 10 completion. Fix problem with with detecting examples that use non-standard markup)
Line 1,793:
});</lang>
=={{header|Perl 6}}==
{{works with|Rakudo|2018.0312}}
Retrieves counts for both Tasks and Draft Tasks. Save / Display results as a sortable wikitable rather than a static list. Click on a column header to sort on that column. To do a secondary sort, hold down the shift key and click on a second column header. Tasks have a gray (default) background, Draft Tasks have a yellow background.
 
Line 1,800:
use URI::Escape;
use JSON::Fast;
 
unit sub MAIN ( Str $no-fetch = '' );
 
# Friendlier descriptions for task categories
Line 1,818 ⟶ 1,820:
# clear screen
run($*DISTRO.is-win ?? 'cls' !! 'clear');
 
#=begin update
 
note 'Retrieving task information...';
 
mkdir('./pages') unless './pages'.IO.e;
 
my %counts =
Line 1,838 ⟶ 1,834:
my @top10 = %counts.sort( -*.value ).head(10).map: *.key;
 
# dump a copy to STDOUT, mostly for debugging purposes
for %cat.keys.sort -> $cat {
$out.say: '<pre>Top ten programming language by number of task examples completed:';
mediawiki-query(
say "{('①' .. '⑩')[$_]} {@top10[$_]}" for ^@top10;
$url, 'pages',
say "</pre>\n";
:generator<categorymembers>,
 
:gcmtitle("Category:$cat"),
unless $no-fetch {
:gcmlimit<350>,
:rawcontinue(),
:prop<title>
).map({
my $page =
$client.get("{ $url }/index.php?title={ uri-escape .<title> }&action=raw").content;
"./pages/{ uri-escape .<title>.subst(/' '/, '_', :g) } ".IO.spurt($page);
my $count = +$page.lc.comb(/ ^^'==' <-[\n=]>* '{{header|' \w+ \N+ '==' \h* $$ /);
%tasks{.<title>} = {'cat' => %cat{$cat}, :$count};
%tasks{.<title>}<top10> = (^@top10).map( {
$page.contains("\n==\{\{header|{@top10[$_]}}}==") ??
('①' .. '⑩')[$_] !! ' '
} ).join;
print clear, 1 + $++, ' ', %cat{$cat}, ' ', .<title>;
})
 
note 'Retrieving task information...';
print clear;
 
mkdir('./pages') unless './pages'.IO.e;
note "\nTask information saved to local file: {$hashfile.IO.absolute}";
$hashfile.IO.spurt(%tasks.&to-json);
 
for %cat.keys.sort -> $cat {
#=end update
mediawiki-query(
$url, 'pages',
:generator<categorymembers>,
:gcmtitle("Category:$cat"),
:gcmlimit<350>,
:rawcontinue(),
:prop<title>
).map({
my $page =
$client.get("{ $url }/index.php?title={ uri-escape .<title> }&action=raw").content;
"./pages/{ uri-escape .<title>.subst(/' '/, '_', :g) } ".IO.spurt($page);
my $lc = $page.lc;
my $count = +$page.lc.comb(/ ^^'==' <-[\n=]>* '{{header|' \w+ \N+ '==' \h* $$ /);
%tasks{.<title>} = {'cat' => %cat{$cat}, :$count};
%tasks{.<title>}<top10> = (^@top10).map( {
$pagelc.contains("\n==\{\{header|{@top10[$_].lc}}}==") ??
('①' .. '⑩')[$_] !! '  '
} ).join;
print clear, 1 + $++, ' ', %cat{$cat}, ' ', .<title>;
})
})
 
print clear;
 
note "\nTask information saved to local file: {$hashfile.IO.absolute}";
$hashfile.IO.spurt(%tasks.&to-json);
 
 
# Load information from local file
Line 1,880 ⟶ 1,888:
my $out = open($tablefile, :w) or die "$!\n";
 
$out.say: '<pre>Top ten programming language by number of task examples completed:';
# Show top 10
$out.say: '<pre>Top ten programming language by number of task examples:';
$out.say: "{('①' .. '⑩')[$_]} {@top10[$_]}" for ^@top10;
$out.say: "</pre>\n\n<div style=\"height:40em;overflow:scroll;\">";
 
# Add table boilerplate and caption
Line 1,890 ⟶ 1,897:
"|+ As of { DateTime.new(time) } :: Tasks: { $taskcnt } ::<span style=\"background-color:#ffd\"> Draft Tasks:",
"{ $draftcnt } </span>:: Total Tasks: { $count } :: Total Examples: { $total }\n",
"! Count !! Task !!{('①' Top.. 10'⑩').join('!!')}"
;
 
Line 1,905 ⟶ 1,912:
!! "| [[{uri-escape $task.key}|{$task.key}]]\n"
),
"| { $task.value<top10>.comb.join('||') }"
}
 
$out.say( "|}\n</div>" );
$out.close;
 
Line 1,933 ⟶ 1,940:
 
{{out|Abridged output}}
<pre>Top ten programming language by number of task examples completed:
① Go
② Perl 6
Line 1,946 ⟶ 1,953:
</pre>
 
<div style="height:40em;overflow:scroll;">
{|class="wikitable sortable"
|+ As of 2019-01-20T1621T22:4641:21Z28Z :: Tasks: 924 ::<span style="background-color:#ffd"> Draft Tasks:215 </span>:: Total Tasks: 1139 :: Total Examples: 5997159984
! Count !! Task !! Top 10①!!②!!③!!④!!⑤!!⑥!!⑦!!⑧!!⑨!!⑩
|-
| 405
| [[Hello%20world%2FText|Hello world/Text]]
|①||②||③||④||⑤||⑥||⑦||⑧||⑨||⑩
| ①②③④⑤⑥⑦⑧⑨⑩
|-
| 283
|data-sort-value="0C99 bottles of beer"| [[99%20Bottles%20of%20Beer|99 Bottles of Beer]]
|①||②||③||④||⑤||⑥||⑦||⑧||⑨||⑩
| ①②③④⑤⑥⑦⑧⑨⑩
|-
| 276
| [[FizzBuzz|FizzBuzz]]
|①||②||③||④||⑤||⑥||⑦||⑧||⑨||⑩
| ①②③④⑤⑥⑦⑧⑨⑩
|-
| 273
|data-sort-value="0D100 doors"| [[100%20doors|100 doors]]
|①||②||③||④||⑤||⑥||⑦||⑧||⑨||⑩
| ①②③④⑤⑥⑦⑧⑨⑩
|-
| 251
| [[Fibonacci%20sequence|Fibonacci sequence]]
|①||②||③||④||⑤||⑥||⑦||⑧||⑨||⑩
| ①②③④⑤⑥⑦⑧⑨⑩
|-
| 246
| [[Comments|Comments]]
|①||②||③||④||⑤||⑥||⑦||⑧||⑨||⑩
| ①②③④⑤⑥⑦⑧⑨⑩
|-
| 239
| [[Factorial|Factorial]]
|①||②||③||④||⑤||⑥||⑦||⑧||⑨||⑩
| ①②③④⑤⑥⑦⑧⑨⑩
|-
| 223
| [[Empty%20program|Empty program]]
|①||②||③||④||⑤||⑥||⑦||⑧||⑨||⑩
| ①②③④⑤⑥⑦⑧⑨⑩
|-
| 222
| [[A%2BB|A+B]]
|①||②||③||④||⑤||⑥||⑦||⑧||⑨||⑩
| ①②③④⑤⑥⑦⑧⑨⑩
|-
| 214
| [[Function%20definition|Function definition]]
|①||②||③||④||⑤||⑥||⑦||⑧||⑨||⑩
| ①②③④⑤⑥⑦⑧⑨⑩
|}
 
10,327

edits