Модуль:Wikidata2/number: юрамалар арасында аерма

Контент бетерелгән Контент өстәлгән
Takhirgeran Umar (бәхәс | кертем)
Төзәтмә аңлатмасы юк
Takhirgeran Umar (бәхәс | кертем)
Takhirgeran Umar (бәхәс) кулланучысының 2503614 төзәтмәсе кире кагылды
Тамга: кире кайтару
 
Юл номеры - 1:
local p = {}
 
function p.formatColorIndex( context, options )
if ( not context ) then error( 'context not specified' ); end;
if ( not options ) then error( 'options not specified' ); end;
if ( options.property ) then
-- Пролучаем все claims независимо от ранга
claims = context.selectClaims( options, options.property .. '[rank:normal,rank:preferred]' );
end
if ( claims ) then
return context.formatPropertyDefault( context, options )
end
-- Вычисляем B-V либо U-B из P1215
b = context.selectClaims( options, 'P1215[P1227:Q6746395][rank:normal,rank:preferred]' )
if ( not b ) then return end
if string.find( options.property, 'Q17773035' ) then
m1 = context.selectClaims( options, 'P1215[P1227:Q15977921][rank:normal,rank:preferred]' )
m2 = b
if ( not m1 ) then return end
else
m1 = b
m2 = context.selectClaims( options, 'P1215[P1227:Q4892529][rank:normal,rank:preferred]' )
if ( not m2 ) then return end
end
for _, claim1 in ipairs(m1) do
for _, claim2 in ipairs(m2) do
newClaim = { mainsnak = { snaktype = 'value', datavalue = { type = 'quantity',
value = { unit = '1', amount = claim1.mainsnak.datavalue.value.amount -
claim2.mainsnak.datavalue.value.amount }}}}
return context.formatStatementDefault( context, options, newClaim )
end
end
end
 
function p.formatPropertyWithMostRecentClaimAndIndicator( context, options )
if ( not context ) then error( 'context not specified' ); end;
if ( not options ) then error( 'options not specified' ); end;
if ( not options.entity ) then error( 'options.entity missing' ); end;
 
local claims;
if options.property then
-- Пролучаем все claims независимо от ранга
claims = context.selectClaims( options, options.property .. '[rank:normal,rank:preferred]' );
end
if claims == nil then
return ''
end
 
-- Ищем claim с максимальным значением P585 и форматируем его в out
local maxTimestamp = 0;
local mostRecentClaim;
for i, claim in ipairs(claims) do
if (claim.qualifiers and claim.qualifiers.P585) then -- обрабатываем только claims с указанным P585
local timestamp = context.parseTimeFromSnak( claim.qualifiers.P585[1] );
if (timestamp ~= nil and maxTimestamp < timestamp) then
maxTimestamp = timestamp;
mostRecentClaim = claim
end
end
end
if (not mostRecentClaim) then -- нет ни одного claim с указанным P585
return context.formatPropertyDefault( context, options )
end
 
local out = context.formatStatement( options, mostRecentClaim )
if out ~= '' then
-- Ищем claim со значением P585 сразу после максимального и запоминаем его в secondMostRecentValue
local secondMostRecentTimestamp = 0;
local secondMostRecentValue = 0;
for i, claim in ipairs(claims) do
if (claim.qualifiers and claim.qualifiers.P585) then -- обрабатываем только claims с указанным P585
local timestamp = context.parseTimeFromSnak( claim.qualifiers.P585[1] )
if (timestamp ~= nil and secondMostRecentTimestamp < timestamp and maxTimestamp > timestamp) then
secondMostRecentTimestamp = timestamp
secondMostRecentValue = tonumber( claim.mainsnak.datavalue.value.amount )
end
end
end
if (secondMostRecentValue ~= 0) then -- если предыдущее значение нашлось
if (secondMostRecentValue < tonumber( mostRecentClaim.mainsnak.datavalue.value.amount )) then
out = '<span style="color: #0c0; font-size: larger;">▲</span>' .. out
else
out = '<span style="color: red; font-size: larger;">▼</span>' .. out
end
end
if options.before then
out = options.before .. out
end
if options.after then
out = out .. options.after
end
end
 
return out
end
 
function p.formatQuantityWithDateClaim( context, options, statement )
local snak = context.formatSnak( options, statement.mainsnak )
if not snak then return '' end
--Unit
if ( options.unit and options.unit ~= '' ) then
snak = snak .. ' ' .. options.unit
end
 
--Date
Строка 113 ⟶ 22 :
end
 
local function p.formatDMSgetUnitAbbr( context, options, value unitQid)
local entity = mw.wikibase.getEntity(unitQid)
if not value.amount then return value end
if entity and entity.claims and entity.claims.P558 then
local prefix = "+"
for _, abbr in pairs( entity.claims.P558 ) do
if tonumber( value.amount ) < 0 then
if abbr.qualifiers then
prefix = "−"
if abbr.qualifiers.P407 and abbr.qualifiers.P407[1].datavalue.value.id == "Q7737" or
abbr.qualifiers.P282 and abbr.qualifiers.P282[1].datavalue.value.id == "Q8209" then
return abbr.mainsnak.datavalue.value
end
end
end
end
return p.formatAngle ( math.abs( tonumber( value.amount ) ),
string.len( value.amount ) - string.find( value.amount, '.', 1, true ) - 5,
prefix .. "%s° %02d′ %s″")
end
 
function p.formatRA( context, options, value )
if not value.amount then return value end
return p.formatAngle (tonumber( value.amount ) / 15,
string.len( value.amount ) - string.find( value.amount, '.', 1, true ) - 4,
"%s<sup>ч</sup> %02d<sup>м</sup> %s<sup>с</sup>")
end
 
function p.formatAngle formatQuantity( anglecontext, sigoptions, formatvalue )
local d, anglesnak = mathvalue.modf( angle )amount
if snak:sub(1, 1) == '+' then
local m, angle = math.modf( angle * 60 )
snak = snak:sub(2)
local mult = 10 ^ sig;
end
local s = math.floor( angle * 60 * mult + 0.5 ) / mult;
snak = snak:gsub('[.]', ',')
local lang = mw.language.getContentLanguage();
return string.format( format, d, m, lang:formatNum( s ) )
if ( options.unit and options.unit ~= '' ) then
snak = snak .. ' ' .. options.unit
return snak
end
if value.unit ~= nil then
local unitQid = value.unit:match('Q%d+')
if unitQid ~= nil then
local abbr = getUnitAbbr(unitQid)
if abbr ~= nil then
snak = snak .. ' ' .. abbr
end
end
end
return snak
end