Module:MoroccoHealthTable

-- Module:MoroccoHealthTable (Advanced Version)
-- Builds a table of Moroccan healthcare institutions with multilingual, image, coordinates, and stats

local langTable = {'ar','zgh','ary','shi','fr','en'}
local p = {}

-- Helper function
local function def(bla)
    local zdef = {}
    for _, l in ipairs(bla) do zdef[l] = true end
    return zdef
end

function p.table(frame)
    local header = {
        '{| class="wikitable sortable" width=100%\n|-\n! № !! Institution',
        '!! ar !! zgh !! ary !! shi !! fr !! en !! Σ !! Image !! Coordinates !! Wikidata !! st.\n|-'
    }
    local resultTable = table.concat(header)
    local index = 1

    -- Initialize language counters
    local langCountTotal = {}
    for _, lang in ipairs(langTable) do langCountTotal[lang] = 0 end
    local totalRows = 0

    while frame.args[index] do
        local Id = frame.args[index]
        local entity = mw.wikibase.getEntityObject(Id)
        totalRows = totalRows + 1

        if not entity then
            resultTable = resultTable .. '\n|-\n| ' .. index .. ' || Entity ' .. Id .. ' not found'
        else
            local Label = entity:getLabel('ar') or entity:getLabel('en') or Id
            local row = '\n|-\n| ' .. index .. ' || ' .. Label
            local ct = 0

            -- Language columns
            for _, lang in ipairs(langTable) do
                local sitelink = entity:getSitelink(lang .. 'wiki')
                if sitelink then
                    row = row .. ' || style="background:#cfc;"|[[:'..lang..':'..sitelink..'|+]]'
                    ct = ct + 1
                    langCountTotal[lang] = langCountTotal[lang] + 1
                else
                    row = row .. ' || -'
                end
            end

            -- Σ column
            row = row .. ' || ' .. ct

            -- Image (P18)
            local img = entity:formatPropertyValues('P18').value
            if img ~= '' then
                row = row .. ' || [[File:'..img..'|50px]]'
            else
                row = row .. ' || -'
            end

            -- Coordinates (P625)
            local coord = entity:formatPropertyValues('P625').value
            if coord ~= '' and entity.claims.P625 then
                local lat = entity.claims.P625[1].mainsnak.datavalue.value.latitude
                local lon = entity.claims.P625[1].mainsnak.datavalue.value.longitude
                row = row .. ' || [[File:Geographylogo.svg|18px|view on maps|link=https://tools.wmflabs.org/geohack/geohack.php?language=en&pagename='.. mw.uri.encode(Label,"PATH") ..'&params='..lat..'_N_'..lon..'_E]]'
            else
                row = row .. ' || -'
            end

            -- Wikidata link
            row = row .. ' || [[:d:'..Id..'|'..Id..']]'

            -- Statements count
            local statements = 0
            if entity.claims then
                for _, claimList in pairs(entity.claims) do
                    if claimList and claimList[1] then
                        statements = statements + 1
                    end
                end
            end
            row = row .. ' || ' .. statements

            resultTable = resultTable .. row
        end
        index = index + 1
    end

    -- Footer: language statistics
    local footer = '\n|-\n! Σ per language'
    local totalLangArticles = 0
    for _, lang in ipairs(langTable) do
        footer = footer .. ' !! ' .. langCountTotal[lang]
        totalLangArticles = totalLangArticles + langCountTotal[lang]
    end
    footer = footer .. ' !! - !! - !! - !! -'
    resultTable = resultTable .. footer

    -- Footer: averages and percentages
    local avg = math.floor(totalLangArticles/totalRows + 0.5)
    local perc = math.floor(totalLangArticles / (#langTable * totalRows) * 100 + 0.5)
    resultTable = resultTable .. '\n|-\n! Average per row !! colspan='..(#langTable)..'| avg: '..avg..' ('..perc..'%) !! colspan=4|'

    resultTable = resultTable .. '\n|}'
    return resultTable
end

return p

Content Disclaimer

Informasi ini disarikan dari Wikipedia dan disajikan kembali untuk tujuan edukasi. Konten tersedia di bawah lisensi CC BY-SA 3.0. Kami tidak bertanggung jawab atas ketidakakuratan data yang bersumber dari kontribusi publik tersebut.

  1. The information displayed on this website is sourced in part or in whole from Wikipedia and has been adapted for the purpose of restating it. We strive to provide accurate and relevant information, however:
  2. There is no guarantee of absolute accuracy. Wikipedia is an open, collaborative project that can be edited by anyone, so information is subject to change.
  3. It is not intended to constitute professional advice. The content displayed is for informational and educational purposes only. For important decisions (e.g., medical, legal, or financial), please consult a professional.
  4. Content copyright. Wikipedia is licensed under the Creative Commons Attribution-ShareAlike License (CC BY-SA). This means that content may be reused with appropriate attribution and shared under a similar license.
  5. Responsible use. Any risk arising from the use of information from this website is entirely the responsibility of the user.