Modulo:Codice statistico: differenze tra le versioni

Contenuto cancellato Contenuto aggiunto
+tabella HTML
m modulo no globals obsoleto
 
(28 versioni intermedie di un altro utente non mostrate)
Riga 3:
]]--
 
require('Modulo:No globalsstrict')
 
local getArgs = require('Modulo:Arguments').getArgs
local mWikidata = require('Modulo:Wikidata')
 
-- Funzione di formattazione del codice municipale austriaco (Statistik Austria).
local p = {}
--
 
-- @param {string} id
-- Funzione di formattazione del codice municipale austriaco (Statistik Austria)
-- @return {string}
local function formatSA(id)
local function formatP964(id)
local formatted_id = string.gsub(id, "'(%d)(%d%d)(%d%d)"', "'%1 %2 %3"')
return string.format('[http://www.statistik.at/blickgem/gemDetail.do?gemnr=%s %s]', id, formatted_id)
end
 
-- Funzione di formattazione del codice municipale tedesco (Statistisches Bundesamt).
--
local function formatDestatis(id)
-- @param {string} id
local formatted_id = string.gsub(id, "(%d%d)(%d)(%d%d)(%d%d%d)", "%1 %2 %3 %4")
-- @return {string}
local function formatP439(id)
local formatted_id = string.gsub(id, '(%d%d)(%d)(%d%d)(%d%d%d)', '%1 %2 %3 %4')
return string.format('[http://www.statistik-portal.de/Statistik-Portal/gemeindeverz.asp?G=%s %s]', id, formatted_id)
end
 
-- Funzione di formattazione del codice dei distretti tedesco (Statistisches Bundesamt).
--
-- @param {string} id
-- @return {string}
local function formatP440(id)
return string.gsub(id, '(%d%d)(%d)(%d%d)', '%1 %2 %3')
end
 
-- Funzione di formattazione del codice INSEE
-- (Institut national de la statistique et des études économiques).
--
-- @param {string} id
-- @return {string}
local function formatP374(id)
return string.format('[http://www.insee.fr/fr/themes/dossier_complet.asp?codgeo=COM-%s %s]', id, id)
end
 
-- Funzione di formattazione del codice municipale IBGE
-- (Instituto Brasileiro de Geografia e Estatística).
--
-- @param {string} id
-- @return {string}
local function formatP1585(id)
return string.format('[http://cidades.ibge.gov.br/xtras/perfil.php?codmun=%s %s]', id, id)
end
 
-- Funzione di formattazione del codice KSH (Központi Statisztikai Hivatal).
--
-- @param {string} id
-- @return {string}
local function formatP939(id)
return string.format('[http://www.ksh.hu/apps/hntr.telepules?p_id=%s %s]', id, id)
end
 
-- Funzione di confronto predefinita per le categorie Wikidata.
--
-- @param {string} wdval
-- @param {string} userval
-- @return {boolean}
local function compareDefault(wdval, userval)
return string.gsub(wdval, ' ', '') == string.gsub(userval, ' ', '')
end
 
-- Funzione di confronto del codice OFS per le categorie Wikidata.
--
-- @param {string} wdval
-- @param {string} userval
-- @return {boolean}
local function compareP771(wdval, userval)
wdval = string.gsub(wdval, ' ', '')
userval = string.gsub(userval, ' ', '')
return wdval == userval or (tonumber(userval) and wdval == string.format('%04d', userval))
end
 
-- Codici statistici configurati
local statCodes = {
AUT = {
AUT = { prop = 'P964', catprefix = 'Codice municipale austriaco', format = formatSA },
CHE default = { prop = 'P771P964', catprefixformat = 'Codice OFS'formatP964 },
},
DEU = { prop = 'P439', catprefix = 'Codice municipale tedesco', format = formatDestatis },
BEL = {
ESP = { prop = 'P772', catprefix = 'Codice INE' },
FRA default = { prop = 'P374', catprefix = 'Codice INSEEP1567' },
},
ITA = { prop = 'P635', catprefix = 'Codice ISTAT' }
BRA = {
default = { prop = 'P1585', format = formatP1585 }
},
CHE = {
default = { prop = 'P771', compare = compareP771 }
},
CHN = {
default = { prop = 'P442' }
},
CZE = {
default = { prop = 'P782' }
},
DEU = {
['1'] = {}, -- disabilitato
['3'] = { prop = 'P440', format = formatP440 },
default = { prop = 'P439', format = formatP439 }
},
DNK = {
default = { prop = 'P1168' }
},
ESP = {
default = { prop = 'P772' }
},
FRA = {
['1'] = { prop = 'P2585' },
['2'] = { prop = 'P2586' },
['3'] = { prop = 'P3423' },
['4'] = { prop = 'P2506' },
default = { prop = 'P374', format = formatP374 }
},
HUN = {
default = { prop = 'P939', format = formatP939 }
},
ITA = {
default = { prop = 'P635' }
},
NLD = {
default = { prop = 'P382' }
},
NOR = {
default = { prop = 'P2504' }
},
UKR = {
default = { prop = 'P1077' }
}
}
 
-- Restituisce la categoria Wikidata appropriata in base
-- al valore utente, a quello su Wikidata e al tipo di codice.
--
-- @param {string} userval
-- @param {string} wdval
-- @param {table} code
-- @return {string}
local function getWikidataCategory(userval, wdval, code)
local cat
-- consente di definire funzioni di confronto per proprietà specifiche
local comparefunc = code.compare or compareDefault
 
if userval then
userval = string.gsub(userval, ' ', '')
if not wdval then
cat = string.format('%s assente su Wikidata', code.catprefixprop)
elseif comparefunc(wdval ==, userval) then
cat = code.catuguali and string.format('%s uguale asu Wikidata', code.catprefixprop)
else
cat = string.format('%s differente dasu Wikidata', code.catprefixprop)
end
elseif wdval then
cat = string.format('%s lettoletta da Wikidata', code.catprefixprop)
end
 
return cat and string.format('[[Categoria:%s]]', cat) or ''
end
 
-- =============================================================================
-- Restituisce una tabella HTML con i codici statistici configurati
-- Funzioni esportate
-- =============================================================================
 
local p = {}
 
-- Funzione di utilità per il manuale, restituisce una tabella HTML
-- con i codici statistici configurati.
function p.report()
local tableNode
Line 69 ⟶ 189:
:tag('th')
:wikitext('Paese')
:done()
:tag('th')
:wikitext('Grado amministrativo')
:done()
:tag('th')
:wikitext('Proprietà Wikidata')
:done()
:tag('th')
:wikitext('Dati letti')
:done()
 
for idx_, keyiso3166 in ipairs(sortedCodes) do
local codecodes = statCodes[keyiso3166]
for key, value in pairs(codes) do
tableNode
if value.prop then
:tag('tr')
local catLetto = value.prop .. ' letta da Wikidata'
:tag('td')
local pagesInCat = mw.site.stats.pagesInCategory(catLetto, 'pages')
:wikitext(code.catprefix)
:done()tableNode
:tag('tdtr')
:wikitexttag(key'td')
:wikitext(mw.wikibase.getLabel(value.prop))
:done()
:tagdone('td')
:tag('td')
:wikitext(string.format('[[d:p:%s|%s (%s)]]', code.prop, mWikidata._getLabel( { code.prop } ), code.prop))
:donewikitext(iso3166)
:done()
:tag('td')
:wikitext(key == 'default' and 'predefinito' or key)
:done()
:tag('td')
:wikitext(string.format('[[d:p:%s|%s (%s)]]',
value.prop, mWikidata._getLabel({ value.prop }), value.prop))
:done()
:tag('td')
:css('text-align', 'right')
:wikitext(string.format('[[:Categoria:%s|%s]]', catLetto, pagesInCat))
:done()
end
end
end
 
Line 92 ⟶ 232:
end
 
-- PerFunzione per l'utilizzo da un altro modulo.
function p._main(args)
local code, userval, wdval, formatted_userval, formatted_wdval
Line 99 ⟶ 239:
-- valore utente
userval = args[1]
formatted_userval = userval
 
-- ricerca paese
Line 108 ⟶ 249:
code = statCodes[iso3166]
end
-- ricerca grado amministrativo
 
if code then
code = code[args.grado] or code.default
-- valore letto da Wikidata
end
 
-- codice presente e abilitato
if code and code.prop then
-- valore letto da Wikidata
wdval = mWikidata._getProperty({ code.prop, from = args.from, n = 1 })
formatted_wdval = (wdval and code.format) and code.format(wdval) or wdval
Line 124 ⟶ 270:
end
 
-- Entry-pointFunzione per il template {{Codice statistico}}.
function p.main(frame)
return p._main(getArgs(frame, { parentOnly = true }))
end