Module:Interval edo approximation: Difference between revisions

Pailiaq (talk | contribs)
No edit summary
Pailiaq (talk | contribs)
m hiding tables, sorting by column, adding cent values
Line 142: Line 142:


     -- Build the wikitable
     -- Build the wikitable
    -- mw-collapsible: adds [hide] toggle button
    -- sortable: makes columns sortable by clicking headers
     local output = {}
     local output = {}
     table.insert(output, '{| class="wikitable"')
     table.insert(output, '{| class="wikitable mw-collapsible sortable"')
     table.insert(output, '|+ EDO Approximations for ' .. interval_str)
     table.insert(output, '|+ EDO Approximations for ' .. interval_str)
     table.insert(output, '|-')
     table.insert(output, '|-')
     table.insert(output, string.format('| colspan="4" style="text-align:center; font-size:90%%;" | \'\'EDO ≤ %d, Relative Error ≤%g%%\'\'', max_edo, tolerance))
     table.insert(output, string.format('| colspan="5" style="text-align:center; font-size:90%%;" | \'\'Up to %dedo, Tolerance: ≤%g%%%%\'\'', max_edo, tolerance))
     table.insert(output, '|-')
     table.insert(output, '|-')
     table.insert(output, '! EDO !! Step size !! Absolute Error ([[Cent|¢]]) !! [[Relative_interval_error|Relative Error]] ([[Relative_cent|%]])')
     table.insert(output, '! EDO !! Step size !! ([[Cent|Cent Value]]) !! Absolute Error ([[Cent|¢]]) !! [[Relative_interval_error|Relative Error]] ([[Relative_cent|%]])')


     for _, result in ipairs(results) do
     for _, result in ipairs(results) do
Line 156: Line 158:
         -- Python: step_str = f"{steps}\\{edo}"
         -- Python: step_str = f"{steps}\\{edo}"
         local step_size = string.format("%d\\%d", result.steps, result.edo)
         local step_size = string.format("%d\\%d", result.steps, result.edo)
        -- Calculate approximation in cents: steps * (1200/edo)
        local approximation_cents = result.steps * (1200 / result.edo)
        local approx_str = string.format("%.2f", approximation_cents)


         -- Python: abs_err = f"{result['abs_error']:+.2f}"
         -- Python: abs_err = f"{result['abs_error']:+.2f}"
Line 164: Line 170:


         table.insert(output, '|-')
         table.insert(output, '|-')
         table.insert(output, string.format('| %s || %s || %s || %s', edo_link, step_size, abs_err, rel_err))
         table.insert(output, string.format('| %s || %s || %s || %s || %s', edo_link, step_size, approx_str, abs_err, rel_err))
     end
     end