Content deleted Content added
BrokenSegue (talk | contribs) refactor |
BrokenSegue (talk | contribs) factor out logic into newestMatching |
||
Line 154:
end
-- for a given property and qualifier pair returns the newest statement that matches
function newestMatching(
--if v['qualifiers'] and v['qualifiers'][POINT_IN_TIME_PID] then ▼
local statements = e:getBestStatements(prop)
local newestStatement = nil
local newestStatementYr = nil
local newestStatementMo = nil
local newestStatementDay = nil
for k, v in pairs(statements) do
local quals = v['qualifiers'][qual]
-- should only have one instance of the qualifier on a statement
if #quals == 1 then
local qual = quals[1]
if qual['datavalue'] and qual['datavalue']['value'] then
local qualValue = qual['datavalue']['value']
if qualValue == targetQualValue then
local targetYr, targetMo, targetDay = getClaimDate(v)
if targetYr then
local older = datePrecedesDate(targetYr, targetMo, targetDay, newestStatementYr, newestStatementMo, newestStatementDay)
mw.logObject(qual)
if older == nil or not older then
mw.logObject(v)
newestStatementYr, newestStatementMo, newestStatementDay = targetYr, targetMo, targetDay
newestStatement = v
end
end
end
end
end
end
end
if newestStatement then
return newestStatement
end
return nil
end
Line 223 ⟶ 257:
local chanId = getBestYtChanId(e)
if chanId then
local bestStatement = newestMatching(e, SUB_COUNT_PID, YT_CHAN_ID_PID, chanId)
mw.logObject(bestStatement)
local subCounts = e:getBestStatements(SUB_COUNT_PID)
for k, v in pairs(subCounts) do
|