Module:Validate platter capacity: Difference between revisions
From Australian Enthusiasts Wiki
No edit summary |
Replace native convertCapacity functions with imported module |
||
| (2 intermediate revisions by the same user not shown) | |||
| Line 9: | Line 9: | ||
-- Main entry point for this module. | -- Main entry point for this module. | ||
function p.invokeMain(frame) | 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 | 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 | end | ||
| Line 17: | Line 17: | ||
shortStrokedCapacity = shortStrokedCapacity or 0 | shortStrokedCapacity = shortStrokedCapacity or 0 | ||
platterCapacity = | local CapacityConverter = require("Module:ConvertCapacity") | ||
platterCapacity = CapacityConverter.convertCapacity(platterCapacity, platterCapacityUnit, totalCapacityUnit) | |||
if (shortStrokedCapacityUnit ~= nil or shortStrokedCapacityUnit ~= nil) then | if (shortStrokedCapacityUnit ~= nil or shortStrokedCapacityUnit ~= nil) then | ||
shortStrokedCapacity = CapacityConverter.convertCapacity(shortStrokedCapacity, shortStrokedCapacityUnit, totalCapacityUnit) | |||
end | end | ||
| Line 34: | Line 35: | ||
function p.validateNoPlatterlessHeads(platters, heads) | function p.validateNoPlatterlessHeads(platters, heads) | ||
return heads <= platters * 2 | return heads <= platters * 2 | ||
end | end | ||
Latest revision as of 11:56, 12 September 2022
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