Modul:Bewertung: Unterschied zwischen den Versionen
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: | ||
lang = mw.getContentLanguage() | |||
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 | 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 | ||