Módulo:Infobox/Funções/Central elétrica

Documentação do módulo[ver] [editar] [histórico] [purgar]


Descrição editar

Este módulo tem funções auxiliares para criar infocaixas de diversos assuntos.

Uso editar

Outra documentação:

local p = {}
local general = require "Module:Infobox/Funções"
local localdata = require "Module:Infobox/Localdata"
local wikidata = require "Module:Infobox/Wikidata"
local address = require "Module:Endereço"
local countrymodule = require "Module:Country data"
local linguistique = require "Module:Linguística"

function p.operador() -- se o operador é o mesmo que o proprietário no wikidata : não mostrar
    if localdata['operador'] then
        return {type = 'row', label = 'Operador', value = 'operador'}
    elseif localdata['concessionário'] then
        return {type = 'row', label = 'Operador', value = 'concessionário'}
    elseif (wikidata.formatStatements{property = "P127", displayformat = "raw", entity= localdata.item} == wikidata.formatStatements{property = "P137", displayformat = "raw", entity = localdata.item}) then
        return nil
    else
        return {type = 'row', label = 'Operador', value = 'operador', property = 'P137'}
    end
end

function p.fatorcarga() --fator de capacidade : valor dentro 'Fator capacidade' ou calculo a partir de P4131 e P2109
    if localdata['fator capacidade'] then
        return {type = 'row', label = '[[Fator de capacidade]]', value = 'fator capacidade'}
    elseif localdata['fator utilização'] then
        return {type = 'row', label = '[[Fator de capacidade]]', value = 'fator utilização'}
    else
        local production = wikidata.formatStatements{entity = localdata.item, property = 'P4131', numval = 1, sorttype = "inverted", showunit = '-', targetunit = 'Wh', displayformat = "raw"}
        local potencia = wikidata.formatStatements{entity = localdata.item, property = 'P2109', numval = 1, sorttype = "inverted", showunit = '-', targetunit = 'w', displayformat = "raw"}
        if tonumber(production) and tonumber(potencia) then
            local fcharge = tonumber(production) / (tonumber(potencia) * 365 * 24)*100
            return {type = 'row', label = '[[Fator de capacidade]]', value = function() return math.floor(fcharge+0.5).." %" end}
        else
            return nil
        end
    end
end

function p.densidadepotencia() --densidade de potencia : valor dentro 'Densidade potência' ou calculo a partir de P4131 et P2046
    if localdata['densidade potência'] then
        return {type = 'row', label = 'Densidade de potência de superfície', value = 'densidade potência'}
    else
        local production = wikidata.formatStatements{entity = localdata.item, property = 'P4131', numval = 1, sorttype = "inverted", showunit = '-', targetunit = 'Wh', displayformat = "raw"}
        local surface = wikidata.formatStatements{entity = localdata.item, property = 'P2046', numval = 1, sorttype = "inverted", showunit = '-', targetunit = 'sqm', displayformat = "raw"}
        if tonumber(production) and tonumber(surface) then
            local dpuis = tonumber(production) / (tonumber(surface) * 365 * 24)
            return {type = 'row', label = 'Densidade de potência de superfície', value = function() return math.floor(dpuis+0.5).." W/m²" end}
        else
            return nil
        end
    end
end

function p.adminlocation() -- Função copiada de Module:Infobox/Funções/Edifício e adaptada a infocaixa barragem e central

    if not (localdata['província'] or localdata['subdivisão 1'] or localdata['subdivisão 2'] or localdata['subdivisão 3']) then
        local country = wikidata.getIds(localdata.item, {property = "P17"})
        if country and #country > 1 then
             local countries = {}
            for i, j in pairs(country) do
                newcountry = countrymodule.standarddisplay(j)
                table.insert(countries, newcountry)
            end
            return {type = 'row', label = "País", value = function() return linguistique.conj(countries, 'new line') end }
        else
            return {type = 'row', label = "Localização", value = function() return address.fullAddress(localdata.item) end }
        end
    end
    local function formatCountry(country)
        if not country then
            return nil
        end
        local val, success = countrymodule.standarddisplay(country) -- val = nil se país não reconhecido
        if success then
            return val
        end
    end
    local countries = {}
    newcountry = formatCountry(localdata['país'])
    table.insert(countries, newcountry)
    if localdata['país 2'] then
        newcountry = formatCountry(localdata['país 2'])
        table.insert(countries, newcountry)
    end
    return {
        type = 'multi',
        rows = {
            {type = 'row', label = "País", value = function() return linguistique.conj(countries, 'new line') end },
            {type = 'row', label = 'Província', value = 'província'},
            {
                type = 'row',
                label = function ( localdata )
                    return localdata[ "rótulo subdivisão" ]
                end,
                value = function ( localdata )
                    return localdata[ "subdivisão" ]
                end,
            },
            {
                type = 'row',
                label = function ( localdata )
                    return localdata[ "rótulo subdivisão2" ] or localdata[ "subdivisão 2 tipo" ]
                end,
                value = function ( localdata )
                    return localdata[ "subdivisão2" ]
                end,
            },
            {
                type = 'row',
                label = function ( localdata )
                    return localdata[ "rótulo subdivisão3" ] or localdata[ "subdivisão 3 tipo" ]
                end,
                value = function ( localdata )
                    return localdata[ "subdivisão3" ]
                end,
            },
            {
                type = 'row',
                label = function ( localdata )
                    return localdata[ "rótulo subdivisão4" ]
                end,
                value = function ( localdata )
                    return localdata[ "subdivisão4" ]
                end,
            },
        }
    }
end

return p