Module:Validate platter capacity

From Australian Enthusiasts Wiki
Revision as of 01:56, 12 September 2022 by TheDragonFire123 (talk | contribs) (Replace native convertCapacity functions with imported module)
(diff) ← Older revision | Latest revision (diff) | Newer revision → (diff)

This module verifies Template:Infobox hard drive's capacity versus its platter capacity, and tries to find discrepancies. It returns true if no error, false if there is discrepancy.


-- This module validates the platter capacity is correct and makes sense.
-- Returns "true" on successful validation, "false" on failed validation.

-- Validation rules:
-- 1. The total capacity must be equal to (head count / 2 * platter capacity) - short stroked capacity. If the units are different, we must convert them to the same unit before doing validation.
-- 2. There must not be more heads than double the number of platters (otherwise we'd have floating heads)
local p = {}

-- Main entry point for this module.
function p.invokeMain(frame)
	return p.validatePlatterCapacity(tonumber(frame.args[1]), frame.args[2], tonumber(frame.args[3]), frame.args[4], tonumber(frame.args[5]), tonumber(frame.args[6]), tonumber(frame.args[7]), frame.args[8])
end

-- Validates platter capacity. Note that you should not #invoke this, as it won't be passed essential parameters.
function p.validatePlatterCapacity(totalCapacity, totalCapacityUnit, platterCapacity, platterCapacityUnit, platters, heads, shortStrokedCapacity, shortStrokedCapacityUnit)
	-- Because Lua has no default params...
	shortStrokedCapacity = shortStrokedCapacity or 0
	
	local CapacityConverter = require("Module:ConvertCapacity")
	platterCapacity = CapacityConverter.convertCapacity(platterCapacity, platterCapacityUnit, totalCapacityUnit)
	
	if (shortStrokedCapacityUnit ~= nil or shortStrokedCapacityUnit ~= nil) then
		shortStrokedCapacity = CapacityConverter.convertCapacity(shortStrokedCapacity, shortStrokedCapacityUnit, totalCapacityUnit)
	end
	
	if (p.validateNoPlatterlessHeads(platters, heads) == false) then
		return false
	end
	
    return p.resultIsWithinTolerance(platterCapacity * (heads / 2) - shortStrokedCapacity, totalCapacity)
end

-- Validate there are no "platterless" heads, i.e. there are not less platters than heads. Note that we don't rule out a Seagate-style two platters, yet only two heads.
-- Returns true if there are no platterless heads.
function p.validateNoPlatterlessHeads(platters, heads)
	return heads <= platters * 2
end

-- Since we sometimes cannot equal exactly a platter capacity, build in some tolerance.
function p.resultIsWithinTolerance(number, target)
	return (target * 0.99) < number and number < (target * 1.01)
end

return p
Cookies help us deliver our services. By using our services, you agree to our use of cookies.