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
SqrtNegInf (talk | contribs) m (→{{header|Perl 6}}: fix file open error handling) |
Thundergnat (talk | contribs) (→{{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
note "\nBuilding table...";
my $count = +%tasks;
Line 1,858 ⟶ 1,878:
# Dump table to a file
my $out = open($tablefile, :w)
# 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 {
"{ $draftcnt } </span>:: Total Tasks: { $count } :: Total Examples: { $total }\n",
"! Count !! Task !!
;
Line 1,880 ⟶ 1,905:
!! "| [[{uri-escape $task.key}|{$task.key}]]\n"
),
"| { $task.value<
}
Line 1,905 ⟶ 1,930:
sub naturally ($a) { $a.lc.subst(/(\d+)/, ->$/ {0~(65+$0.chars).chr~$0},:g) }
sub clear { "\r" ~ ' ' x
{{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>
▲|+ As of
|-
|
| [[Hello%20world%2FText|Hello world/Text]]
| ①②③④⑤⑥⑦⑧⑨⑩
|-
|
|data-sort-value="0C99 bottles of beer"| [[99%20Bottles%20of%20Beer|99 Bottles of Beer]]
| ①②③④⑤⑥⑦⑧⑨⑩
|-
|
| [[FizzBuzz|FizzBuzz]]▼
| ①②③④⑤⑥⑦⑧⑨⑩
|-▼
| 273
|data-sort-value="0D100 doors"| [[100%20doors|100 doors]]
| ①②③④⑤⑥⑦⑧⑨⑩
|-
|
| [[Fibonacci%20sequence|Fibonacci sequence]]▼
▲| [[FizzBuzz|FizzBuzz]]
| ①②③④⑤⑥⑦⑧⑨⑩
|-
|
| [[Comments|Comments]]
| ①②③④⑤⑥⑦⑧⑨⑩
|-
| 239
▲| [[Fibonacci%20sequence|Fibonacci sequence]]
▲|-
| [[Factorial|Factorial]]
| ①②③④⑤⑥⑦⑧⑨⑩
|-
|
| [[Empty%20program|Empty program]]
| ①②③④⑤⑥⑦⑧⑨⑩
|-
|
| [[A%2BB|A+B]]
| ①②③④⑤⑥⑦⑧⑨⑩
|-
|
| [[Function%20definition|Function definition]]
| ①②③④⑤⑥⑦⑧⑨⑩
|}
|