Rosetta Code/Count examples: Difference between revisions
m
→{{header|Python}}: More readable logging
(→{{header|Python}}: SMW alternative) |
m (→{{header|Python}}: More readable logging) |
||
Line 2,270:
We only count task examples that have a corresponding category page AND that page has the "Is Language" property set to True. In other words, <code>Implemented In</code> + <code>Not Implemented In</code> + <code>Omitted From</code> is always equal to the total number of languages.
<syntaxhighlight lang="python">"""Count Rosetta Code tasks implementations using the Semantic MediaWiki API.
Line 2,280 ⟶ 2,278:
from dataclasses import dataclass
from dataclasses import field
from datetime import datetime
from typing import Any
Line 2,292:
from requests.adapters import Retry
logging.basicConfig(level=logging.
# See https://www.semantic-mediawiki.org/wiki/Help:API:ask
Line 2,375:
),
}
# Display some progress
log(f"ask [[Category:{category}]] offset={offset}")
response = session.get(url, params=query_params)
response.raise_for_status()
Line 2,422 ⟶ 2,426:
),
}
# Display some progress
log(f"ask [[Is language::+]] offset={offset}")
response = session.get(url, params=query_params)
response.raise_for_status()
Line 2,572 ⟶ 2,580:
session.mount("http://", adapter)
return session
def log(msg: str) -> None:
print(f"{datetime.now().isoformat(' ', 'seconds')}: {msg}")
Line 2,614 ⟶ 2,626:
pad = max([len(task.fulltext) for task, _ in top])
print("
print("Total tasks:", len(all_tasks))
print("Total examples:", total)
Line 2,656 ⟶ 2,668:
{{out}}
<pre>
2023-02-11 11:09:34: ask [[Is language::+]] offset=0
2023-02-11 11:09:35: ask [[Is language::+]] offset=500
2023-02-11 11:09:36: ask [[Category:Programming Tasks]] offset=0
2023-02-11 11:09:47: ask [[Category:Programming Tasks]] offset=500
2023-02-11 11:10:04: ask [[Category:Programming Tasks]] offset=1000
2023-02-11 11:10:12: ask [[Category:Draft Programming Tasks]] offset=0
Known languages:
Total tasks:
Total examples:
Task | Implemented In | Not Implemented In | Omitted From
--------------------------------+----------------+--------------------+-------------
Hello world/Text | 498 |
99 bottles of beer |
100 doors |
FizzBuzz | 325 |
Fibonacci sequence |
Factorial |
Comments |
A+B | 293 |
Empty program | 274 |
Function
Loops/For | 248 |
Loops/While |
Arrays | 237 |
Ackermann function | 234 |
Reverse a string | 231 |
Conditional structures | 223 |
Arithmetic/Integer | 213 |
Greatest common divisor | 213 |
Array concatenation | 208 |
Greatest element of a list | 208 |
Even or odd | 207 |
Loops/Downward for |
Increment a numerical
Repeat a string | 199 |
Boolean values | 198 |
Loops/For with a specified step | 198 |
Copy a string | 196 |
</pre>
|