Module:Progression rainbow: Difference between revisions

Content deleted Content added
add some comments with questions I have
clean up a var name, use a local in one of the functions
Line 13:
end
 
local function class_percent(param, divisortotal)
return tostring(round(100 * param / divisortotal)) .. '%'
end
 
local function percent_remaining(sum, divisortotal)
sumlocal remaining = sum - divisortotal
if sumremaining ~= 0 then -- find this a bit specious
return tostring(round(-100 * sumremaining / divisortotal)) .. '%'
else
return nil
Line 58:
}
 
-- generally, I think if there were more 'project' orthogonal attributes
-- there would be a case for object-orientation here
Line 85 ⟶ 84:
-- I'm not sure if it's clear in this for loop that I want to get
-- parameters 1 to 8, which I could also do instead as 'for 1,8...'' ]]
-- unfortunately can't do for i, class in ipairs(args) because of
-- parameter 9, which is the total non-project
for i, class in pairs(classes) do
if args[i] then
Line 93 ⟶ 94:
end
 
local divisortotal
if project then
-- I think it makes more sense to do this sum here rather than in the
-- project loop above, because I initialized divisortotal here in the non-
-- project case
divisortotal = sum_classes + category_count(
project_classes[2]['category'],
project
)
else
divisortotal = args[9] or 100
end
Line 112 ⟶ 113:
for i, class in pairs(classes) do
if class['count'] ~= 0 then
local percentage = class_percent(class['count'], divisortotal)
root:newline() -- sprinkled through to make the HTML easier to read
:tag('td')
Line 129 ⟶ 130:
root:newline()
local remaining = percent_remaining(sum_classes, divisortotal)
if remaining then
root:tag('td')