Rosetta Code/Count examples: Difference between revisions

→‎{{header|Perl 6}}: Modify to show the top 10 language completion rate instead of draft/task status which is denoted by color anyway
m (→‎{{header|Perl 6}}: fix file open error handling)
(→‎{{header|Perl 6}}: Modify to show the top 10 language completion rate instead of draft/task status which is denoted by color anyway)
Line 1,823:
note 'Retrieving task information...';
 
mkdir('./pages') unless './pages'.IO.e;
for %cat.keys -> $cat {
 
my %counts =
mediawiki-query(
$url, 'pages',
:generator<categorymembers>,
:gcmtitle<Category:Programming Languages>,
:gcmlimit<350>,
:rawcontinue(),
:prop<categoryinfo>
)
.map({ .<title>.subst(/^'Category:'/, '') => .<categoryinfo><pages> || 0 });
 
my @top10 = %counts.sort( -*.value ).head(10).map: *.key;
 
for %cat.keys.sort -> $cat {
mediawiki-query(
$url, 'pages',
Line 1,834 ⟶ 1,849:
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>;
})
Line 1,850 ⟶ 1,870:
%tasks = $hashfile.IO.e ?? $hashfile.IO.slurp.&from-json !! ( );
 
# Convert saved task / author info to a table
note "\nBuilding table...";
my $count = +%tasks;
Line 1,858 ⟶ 1,878:
 
# Dump table to a file
my $out = open($tablefile, :w) orelse .or die "$!\n";
 
# Show top 10
$out.say: '<pre>Top ten programming language by number of task examples:';
$out.say: "{('①' .. '⑩')[$_]} {@top10[$_]}" for ^@top10;
$out.say: "</pre>\n";
 
# Add table boilerplate and caption
$out.say:
'{|class="wikitable sortable"', "\n",
"|+ As of { DateDateTime.todaynew(time) } :: Tasks: { $taskcnt } ::<span style=\"background-color:#ffd\"> Draft Tasks:",
"{ $draftcnt } </span>:: Total Tasks: { $count } :: Total Examples: { $total }\n",
"! Count !! Task !! CategoryTop 10"
;
 
Line 1,880 ⟶ 1,905:
!! "| [[{uri-escape $task.key}|{$task.key}]]\n"
),
"| { $task.value<cattop10> }"
}
 
Line 1,905 ⟶ 1,930:
sub naturally ($a) { $a.lc.subst(/(\d+)/, ->$/ {0~(65+$0.chars).chr~$0},:g) }
 
sub clear { "\r" ~ ' ' x 100116 ~ "\r" }</lang>
 
{{out|Abridged output}}
<pre>Top ten programming language by number of task examples:
{|class="wikitable sortable" style="width:60em;"
① Go
|+ As of 2018-04-10 :: Tasks: 871 ::<span style="background-color:#ffd"> Draft Tasks:209 </span>:: Total Tasks: 1080 :: Total Examples: 55787
② Perl 6
! Count !! Task !! Category
③ Kotlin
④ Python
⑤ Phix
⑥ Racket
⑦ Perl
⑧ C
⑨ Julia
⑩ Tcl
</pre>
 
{|class="wikitable sortable" style="width:60em;"
|+ As of 20182019-0401-1020T16:46:21Z :: Tasks: 871924 ::<span style="background-color:#ffd"> Draft Tasks:209215 </span>:: Total Tasks: 10801139 :: Total Examples: 5578759971
! Count !! Task !! CategoryTop 10
|-
| 383405
| [[Hello%20world%2FText|Hello world/Text]]
| ①②③④⑤⑥⑦⑧⑨⑩
| Task
|-
| 270283
|data-sort-value="0C99 bottles of beer"| [[99%20Bottles%20of%20Beer|99 Bottles of Beer]]
| ①②③④⑤⑥⑦⑧⑨⑩
| Task
|-
| 262276
| [[FizzBuzz|FizzBuzz]]
| ①②③④⑤⑥⑦⑧⑨⑩
|-
| 273
|data-sort-value="0D100 doors"| [[100%20doors|100 doors]]
| ①②③④⑤⑥⑦⑧⑨⑩
| Task
|-
| 262251
| [[Fibonacci%20sequence|Fibonacci sequence]]
| [[FizzBuzz|FizzBuzz]]
| ①②③④⑤⑥⑦⑧⑨⑩
| Task
|-
| 239246
| [[Comments|Comments]]
| ①②③④⑤⑥⑦⑧⑨⑩
| Task
|-
| 239
| [[Fibonacci%20sequence|Fibonacci sequence]]
| Task
|-
| 230
| [[Factorial|Factorial]]
| ①②③④⑤⑥⑦⑧⑨⑩
| Task
|-
| 215223
| [[Empty%20program|Empty program]]
| ①②③④⑤⑥⑦⑧⑨⑩
| Task
|-
| 214222
| [[A%2BB|A+B]]
| ①②③④⑤⑥⑦⑧⑨⑩
| Task
|-
| 207214
| [[Function%20definition|Function definition]]
| ①②③④⑤⑥⑦⑧⑨⑩
| Task
|}
 
10,327

edits