Jump to content

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.
 
The output includes debugging information so we can see what requests are being made.
 
<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.DEBUGWARN)
 
# 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("Known\nKnown languages:", len(langs))
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
DEBUG:urllib3.connectionpool:Starting new HTTPS connection (1): rosettacode.org:443
2023-02-11 11:09:35: ask [[Is language::+]] offset=500
DEBUG:urllib3.connectionpool:https://rosettacode.org:443 "GET /w/api.php?action=ask&format=json&formatversion=2&api_version=3&query=%5B%5BIs+language%3A%3A%2B%5D%5D%7C%3FImplemented+in+language%7C%3FOmitted+from+language%7Climit%3D500%7Coffset%3D0 HTTP/1.1" 200 None
2023-02-11 11:09:36: ask [[Category:Programming Tasks]] offset=0
DEBUG:urllib3.connectionpool:https://rosettacode.org:443 "GET /w/api.php?action=ask&format=json&formatversion=2&api_version=3&query=%5B%5BIs+language%3A%3A%2B%5D%5D%7C%3FImplemented+in+language%7C%3FOmitted+from+language%7Climit%3D500%7Coffset%3D500 HTTP/1.1" 200 None
2023-02-11 11:09:47: ask [[Category:Programming Tasks]] offset=500
DEBUG:urllib3.connectionpool:https://rosettacode.org:443 "GET /w/api.php?action=ask&format=json&formatversion=2&api_version=3&query=%5B%5BCategory%3AProgramming+Tasks%5D%5D%7C%3FImplemented+in+language%7C%3FOmitted+from+language%7Climit%3D500%7Coffset%3D0 HTTP/1.1" 200 None
2023-02-11 11:10:04: ask [[Category:Programming Tasks]] offset=1000
DEBUG:urllib3.connectionpool:https://rosettacode.org:443 "GET /w/api.php?action=ask&format=json&formatversion=2&api_version=3&query=%5B%5BCategory%3AProgramming+Tasks%5D%5D%7C%3FImplemented+in+language%7C%3FOmitted+from+language%7Climit%3D500%7Coffset%3D500 HTTP/1.1" 200 None
2023-02-11 11:10:12: ask [[Category:Draft Programming Tasks]] offset=0
DEBUG:urllib3.connectionpool:https://rosettacode.org:443 "GET /w/api.php?action=ask&format=json&formatversion=2&api_version=3&query=%5B%5BCategory%3AProgramming+Tasks%5D%5D%7C%3FImplemented+in+language%7C%3FOmitted+from+language%7Climit%3D500%7Coffset%3D1000 HTTP/1.1" 200 None
DEBUG:urllib3.connectionpool:https://rosettacode.org:443 "GET /w/api.php?action=ask&format=json&formatversion=2&api_version=3&query=%5B%5BCategory%3ADraft+Programming+Tasks%5D%5D%7C%3FImplemented+in+language%7C%3FOmitted+from+language%7Climit%3D500%7Coffset%3D0 HTTP/1.1" 200 None
 
Known languages: 888890
Total tasks: 15981602
Total examples: 9091491075
Task | Implemented In | Not Implemented In | Omitted From
--------------------------------+----------------+--------------------+-------------
Hello world/Text | 498 | 390392 | 0
99 bottles of beer | 370371 | 518519 | 0
100 doors | 333334 | 554555 | 1
FizzBuzz | 325 | 563565 | 0
Fibonacci sequence | 307308 | 581582 | 0
Factorial | 301302 | 587588 | 0
Comments | 296297 | 591592 | 1
A+B | 293 | 595597 | 0
Empty program | 274 | 614616 | 0
Function Loops/Infinitedefinition | 254 | 633634 | 12
Function definition Loops/Infinite | 252254 | 634635 | 21
Loops/For | 248 | 639641 | 1
Loops/While | 243244 | 644645 | 1
Arrays | 237 | 650652 | 1
Ackermann function | 234 | 651653 | 3
Reverse a string | 231 | 655657 | 2
Conditional structures | 223 | 664666 | 1
Arithmetic/Integer | 213 | 675677 | 0
Greatest common divisor | 213 | 675677 | 0
Array concatenation | 208 | 680682 | 0
Greatest element of a list | 208 | 680682 | 0
Even or odd | 207 | 681683 | 0
Loops/Downward for | 204207 | 684683 | 0
Increment a numerical string Sieve of Eratosthenes | 202203 | 686687 | 0
Increment a numerical Integer comparisonstring | 202 | 686688 | 0
Sieve of Eratosthenes Integer comparison | 202 | 686688 | 0
Repeat a string | 199 | 689691 | 0
Boolean values | 198 | 689691 | 1
Loops/For with a specified step | 198 | 689691 | 1
Copy a string | 196 | 691693 | 1
</pre>
 
140

edits

Cookies help us deliver our services. By using our services, you agree to our use of cookies.