Modulo:Demografia: differenze tra le versioni

Contenuto cancellato Contenuto aggiunto
Moroboshi (discussione | contributi)
Nessun oggetto della modifica
Moroboshi (discussione | contributi)
Nessun oggetto della modifica
Riga 1:
local mWikidata = require('Modulo:Wikidata')
 
local p = {}
 
Riga 8 ⟶ 10:
end
 
-- Converte una stringa di valori numerici separati da "," in una lista
function p.demografia(frame)
-- Eventuali valori non numerici sono ignorati
args = require('Modulo:Arguments').getArgs(frame)
local function read_array(args)
local years = {}
local populations = {}
if aargs.anni then
local list = mw.text.split(string.gsub(args.anni, "%s", ""), ",")
for _,s in ipairs(list) do
years[#years+1] = tonumber(s) or 0
end
if aargs.popolazione then
local list = mw.text.split(string.gsub(args.popolazione, "%s", ""), ",")
for _,s in ipairs(list) do
populations[#populations+1] = tonumber(s) or 0
end
end
else -- vecchio metodo di inserimento
iffor ai=1,20 thendo
p_formattedlocal index = '0'tonumber(i)
local ayear = tonumber(args['a' .. tostring(i)index])
if pyear then
years[#years+1] = years
populations[#populations+1] = args['p' .. index]
end
end
end
return years, populations
end
 
function p.get_wikidata(from)
local populations = mWikidata._getProperty({'P1082', from=from, rank='normal'}, true)
local years = {}
for i =1, #populations do -- per il momento inserisco come anni una sequenza numerica
years[i] = #populations-i+1
end
return years,populations
end
 
function p._demografia(args)
local years,populations = read_array(args)
--if #years == 0 then
-- years,populations = get_wikidta(args.from)
--end
graph = {}
local popmax = 0
for _,p in ipairs(populations) do
if p > popmax then popmax = p end
end
dump(graph, 'Colors=\n id:lightgrey value:gray(0.9)\n id:darkgrey value:gray(0.7)\n id:sfondo value:rgb(1,1,1)\n id:barra value:rgb(0.6,0.7,0.8)\n\n')
dump(graph, 'ImageSize = width:', args.dimx or '455', ' height:', args.dmy or '373', '\n')
dump(graph, 'PlotArea = left:50 bottom:50 top:30 right:30\nDateFormat = x.y\n')
dump(graph, 'Period = from:0 till:', args.popmax or '100000'tostring(popmax), '\n')
dump(graph, 'TimeAxis = orientation:vertical\nAlignBars = justify\n')
dump(graph, 'ScaleMajor = gridcolor:darkgrey increment:', args.passo1 or '10000', ' start:0\n' )
Riga 20 ⟶ 67:
dump(graph, 'BackgroundColors = canvas:sfondo\n')
dump(graph, 'BarData=\n')
for i =1_,20year in ipairs(years) do
dump(graph, string.format(' bar:', a, '%d text:%d\n', ayear, '\n'year))
local a = args['a' .. tostring(i)];
if a then
dump(graph, ' bar:', a, ' text:', a, '\n')
end
end
dump(graph, '\n')
dump(graph, 'PlotData=\n color:barra width:20 align:left\n\n')
for i = 1,20#years do
dump(graph, string.format(' bar:', a, '%d from:0 till: %d\n', p or '0'years[i], '\n'populations[i]))
local a = args['a' .. tostring(i)]
local p = args['p' .. tostring(i)]
if a then
dump(graph, ' bar:', a, ' from:0 till: ', p or '0', '\n')
end
end
dump(graph, '\n')
lang = mw.language.new('it')
dump(graph, 'PlotData=\n')
for i = 1,20#years do
p_formatted = lang:formatNum(math.floor(tonumber(ppopulations[i]) + 0,5) )
local a = args['a' .. tostring(i)]
dump(graph, string.format(' bar:', a, '%d at: ', p or '0', '%d fontsize:S text: ', p_formatted, '%s shift:(-10,5)|n.d. shift:(-8,5)\n' ),
local p = args['p' .. tostring(i)]
year[i], populations[i], p_formatted))
if a then
p_formatted = '0'
if p then
p_formatted = lang:formatNum(math.floor(tonumber(p) + 0,5) )
end
dump(graph, ' bar:', a, ' at: ', p or '0', ' fontsize:S text: ', p_formatted, ' shift:(-10,5)|n.d. shift:(-8,5)\n' )
end
end
dump(graph, '\n')
Riga 65 ⟶ 99:
end
return titolo .. draw_graph
end
 
function p.demografia(frame)
local args = require('Modulo:Arguments').getArgs(frame)
return p._demografia(args)
end