Module:BrandSeries: Difference between revisions
Fix Unassigned link - use full URL for wikitext external link (via update-page on MediaWiki MCP Server) |
Fix unassigned count - calculate as total minus assigned (via update-page on MediaWiki MCP Server) |
||
| Line 38: | Line 38: | ||
return '<span class="error">Error: brand parameter required</span>' | return '<span class="error">Error: brand parameter required</span>' | ||
end | end | ||
-- Query total count of all CRTs for this brand | |||
local totalQuery = string.format( | |||
'{{#ask:[[Category:CRT models]][[Has brand::%s]]|format=count}}', | |||
brand | |||
) | |||
local totalResult = frame:preprocess(totalQuery) | |||
local totalCount = tonumber(trim(totalResult)) or 0 | |||
-- Query all CRTs for this brand with their series using broadtable | -- Query all CRTs for this brand with their series using broadtable | ||
| Line 48: | Line 56: | ||
-- Count occurrences of each series by parsing HTML table | -- Count occurrences of each series by parsing HTML table | ||
local seriesCounts = {} | local seriesCounts = {} | ||
local assignedCount = 0 | |||
if crtResult and crtResult ~= '' then | if crtResult and crtResult ~= '' then | ||
-- Parse each table row | -- Parse each table row | ||
| Line 63: | Line 72: | ||
if series and series ~= '' and series ~= '+' then | if series and series ~= '' and series ~= '+' then | ||
seriesCounts[series] = (seriesCounts[series] or 0) + 1 | seriesCounts[series] = (seriesCounts[series] or 0) + 1 | ||
assignedCount = assignedCount + 1 | |||
end | end | ||
end | end | ||
| Line 68: | Line 78: | ||
end | end | ||
-- | -- Calculate unassigned as total minus assigned | ||
local unassignedCount = totalCount - assignedCount | |||
local unassignedCount = | |||
-- Convert to sorted array | -- Convert to sorted array | ||
| Line 89: | Line 94: | ||
-- If no series found and no unassigned, return nothing | -- If no series found and no unassigned, return nothing | ||
if #rows == 0 and unassignedCount | if #rows == 0 and unassignedCount <= 0 then | ||
return "" | return "" | ||
end | end | ||