|
|
| Line 6: |
Line 6: |
| Chargement des statistiques... | | Chargement des statistiques... |
| </div> | | </div> |
|
| |
| <script>
| |
| // Liste des types d'entités à compter
| |
| const entityTypes = ["Q2", "Q5", "Q6", "Q7", "Q8"];
| |
| const results = {};
| |
| const apiUrl = window.location.origin + "/w/api.php";
| |
|
| |
| // Fonction pour compter les entités via wbgetentities
| |
| async function countEntities() {
| |
| const container = document.getElementById('entity-counts-container');
| |
| if (!container) {
| |
| console.error("Conteneur introuvable !");
| |
| return;
| |
| }
| |
|
| |
| // Étape 1: Récupérer toutes les entités dans le namespace Item (ID: 120)
| |
| const allPagesUrl = `${apiUrl}?action=query&list=allpages&apnamespace=120&aplimit=500&format=json`;
| |
| const allPagesResponse = await fetch(allPagesUrl);
| |
| const allPagesData = await allPagesResponse.json();
| |
|
| |
| const entityIds = [];
| |
| if (allPagesData.query?.allpages) {
| |
| allPagesData.query.allpages.forEach(page => {
| |
| const match = page.title.match(/^Item:(Q\d+)$/);
| |
| if (match) entityIds.push(match[1]);
| |
| });
| |
| }
| |
|
| |
| if (entityIds.length === 0) {
| |
| container.innerHTML = "<p style='color: orange;'>Aucune entité trouvée dans le namespace Item (ID: 120).</p>";
| |
| return;
| |
| }
| |
|
| |
| container.innerHTML = `<p>Trouvé ${entityIds.length} entités. Comptage en cours...</p>`;
| |
|
| |
| // Étape 2: Compter les entités par type (P1)
| |
| const counts = {};
| |
| entityTypes.forEach(type => counts[type] = 0);
| |
|
| |
| // Traiter par lots de 50 (limite de wbgetentities)
| |
| for (let i = 0; i < entityIds.length; i += 50) {
| |
| const batch = entityIds.slice(i, i + 50);
| |
| const batchUrl = `${apiUrl}?action=wbgetentities&ids=${batch.join('|')}&format=json&props=claims`;
| |
| const batchResponse = await fetch(batchUrl);
| |
| const batchData = await batchResponse.json();
| |
|
| |
| if (batchData.entities) {
| |
| for (const [id, entity] of Object.entries(batchData.entities)) {
| |
| if (entity.claims?.P1) {
| |
| entity.claims.P1.forEach(claim => {
| |
| const targetId = claim.mainsnak?.datavalue?.value?.id;
| |
| if (targetId && entityTypes.includes(targetId)) {
| |
| counts[targetId]++;
| |
| }
| |
| });
| |
| }
| |
| }
| |
| }
| |
| }
| |
|
| |
| // Afficher les résultats
| |
| let html = '<ul style="list-style: none; padding: 0; margin: 0;">';
| |
| for (const [type, count] of Object.entries(counts)) {
| |
| html += `<li style="margin: 5px 0;"><b>Type ${type}:</b> ${count} éléments</li>`;
| |
| }
| |
| const total = Object.values(counts).reduce((a, b) => a + b, 0);
| |
| html += `<li style="margin: 5px 0; font-weight: bold;"><b>Total:</b> ${total} éléments</li></ul>`;
| |
|
| |
| container.innerHTML = html;
| |
| }
| |
|
| |
| // Lancer le comptage quand la page est chargée
| |
| document.addEventListener('DOMContentLoaded', countEntities);
| |
| </script>
| |
|
| |
|
| == Consulter le référentiel == | | == Consulter le référentiel == |