Zum Inhalt springen

Modul:Bewertung: Unterschied zwischen den Versionen

1.751 Bytes hinzugefügt ,  5. Mai 2019
keine Bearbeitungszusammenfassung
(Die Seite wurde neu angelegt: „function getValue(prop) local result = '' local propValue = prop.mainsnak and prop.mainsnak.datavalue if propValue and propValue.value and propValue.value.a…“)
 
Keine Bearbeitungszusammenfassung
Zeile 1: Zeile 1:
function getValue(prop)
lang = mw.getContentLanguage()
local result = ''
local propValue = prop.mainsnak and prop.mainsnak.datavalue
if propValue and propValue.value and propValue.value.amount then
result = result .. lang:formatNum(tonumber(propValue.value.amount))
end
return result
end


function renderList(claimIdentifier)
function renderList(claimIdentifier)
local totalReviewCount = 0
local totalReview = 0
local entity = mw.wikibase.getEntityObject('Q294')
local entity = mw.wikibase.getEntityObject('Q294')
result = ''
result = '{| class="wikitable fullwidth" style="width:100%;"\n!Plattform!!Bewertung\n'
if not entity or not entity.claims then return end --the entity doesnt exist or have no claims
if not entity or not entity.claims then return end --the entity doesnt exist or have no claims
local property = entity.claims[claimIdentifier]
local property = entity.claims[claimIdentifier]
Zeile 16: Zeile 11:
for key, prop in pairs(property) do
for key, prop in pairs(property) do
if prop and prop.mainsnak and prop.mainsnak.datavalue then
if prop and prop.mainsnak and prop.mainsnak.datavalue then
result = result .. "\n* " .. getValueLabel(prop.mainsnak.datavalue)
local reviewNumber = tonumber(prop.qualifiers['P76'][1].datavalue.value.amount)
totalReview = totalReview + reviewNumber
totalReviewCount = totalReviewCount + 1
result = result .. '|- style="' .. reviewStyle(reviewNumber) .. ' \n| ' .. getValueLabel(prop) .. ' || ' .. lang:formatNum(reviewNumber) .. ' von 10\n'
end
end
end
end
end
end
result = result .. "|}"
local reviewNumber = tonumber(string.format("%.1f", totalReview / totalReviewCount))
result = 'Durchschnittliche Bewertung: <span style="' .. reviewStyle(reviewNumber) .. '">' .. lang:formatNum(reviewNumber) .. "</span>\n" .. result
return result
return result
end
function reviewStyle(reviewNumber)
if reviewNumber >= 8 then
return "background:lime;color:black;"
elseif reviewNumber < 8 and reviewNumber >= 4 then
return "background:yellow;color:black;"
else
return "background:firebrick;color:white;"
end
end
function getValueLabel(prop)
local propValue = prop.mainsnak.datavalue
local linkLabel
if propValue['type'] == 'wikibase-entityid' then
        local linkTarget = mw.wikibase.sitelink( "Q" .. propValue.value['numeric-id'] )
        local linkTitle = mw.wikibase.label( "Q" ..propValue.value['numeric-id'] )
        linkLabel = linkTarget and linkTitle and mw.ustring.format( "[[%s|%s]]", linkTarget, linkTitle )
            or linkTitle
    elseif propValue and propValue['type'] == 'string' then
    linkLabel = propValue.value
else
return ""
end
if prop.references and prop.references[1] and prop.references[1].snaks['P18'] and prop.references[1].snaks['P18'][1] then
return "[" .. prop.references[1].snaks['P18'][1].datavalue.value .. " " .. linkLabel .. "]"
end
return linkLabel
end
function dump(o)
  if type(o) == 'table' then
      local s = '{ '
      for k,v in pairs(o) do
        if type(k) ~= 'number' then k = '"'..k..'"' end
        s = s .. '['..k..'] = ' .. dump(v) .. ','
      end
      return s .. '} '
  else
      return tostring(o)
  end
end
end


11.008

Bearbeitungen

Cookies helfen uns bei der Bereitstellung von Android Wiki. Durch die Nutzung von Android Wiki erklärst du dich damit einverstanden, dass wir Cookies speichern.