Modul:Vorlage:Plx2Dist2
Zur Navigation springen
Zur Suche springen
Die Dokumentation für dieses Modul kann unter Modul:Vorlage:Plx2Dist2/Doku erstellt werden
local Plx2Dist = {}
local function trim(s)
s = mw.ustring.gsub(s,"\n","");
while mw.ustring.sub(s,1,1) == " " do
s= mw.ustring.sub(s,2,-1);
end
while mw.ustring.sub(s,-1,-1) == " " do
s= mw.ustring.sub(s,1,-2);
end
return s;
end
local function round(value)
if value < 1 then
value = math.floor (100*value+0.5) / 100;
elseif value < 10 then
value = math.floor (10*value+0.5) / 10;
elseif value < 100 then
value = math.floor (value+0.5);
elseif value < 1000 then
value = 10 * math.floor (value/10+0.5)
elseif value < 10000 then
value = 100 * math.floor (value/100+0.5)
else
value = 1000 * math.floor (value/1000+0.5)
end
return value
end
local function GetMinMaxParsec(value,sigma)
local Plx= tonumber(value) or 0;
local Diff=tonumber(sigma) or 0;
local quality;
if Plx <= 0 or Diff >= Plx then
quality = 0;
elseif Diff >= 0.5 * Plx then
quality = 1;
elseif Diff >= 0.2 * Plx then
quality = 2;
elseif Diff >= 0.1 * Plx then
quality = 3;
elseif Diff >= 0.05 * Plx then
quality = 4;
elseif Diff >= 0.02 * Plx then
quality = 5;
elseif Diff >= 0.01 * Plx then
quality = 6;
else
quality = 7;
end
if quality == 0 then
return 0, 0, 0, 0, false
end
local Dist = 1000 / Plx;
if Diff > 0 then
local DistMin = 1000 / (Plx + Diff);
local DistMax = 1000 / (Plx - Diff);
return DistMin, Dist, DistMax, quality, true;
else
return Dist, Dist, Dist, 0, true;
end
end
local function CreateOutputValues(Pc1, Pc2, Pc3)
local Lj1,Lj2,Lj3
Lj1 = round(3.26156 * Pc1)
Lj2 = round(3.26156 * Pc2)
Lj3 = round(3.26156 * Pc3)
Pc1 = round(Pc1)
Pc2 = round(Pc2)
Pc3 = round(Pc3)
return Pc1,Pc2,Pc3,Lj1,Lj2,Lj3
end
function Plx2Dist.Run(frame)
local MinPc = 0;
local ValPc = 0;
local MaxPc = 0;
local MinLj = 0;
local ValLj = 0;
local MaxLj = 0;
local IsOk = false;
local value = tonumber(trim(frame.args[1])) or 0;
local sigma = tonumber(trim(frame.args[2])) or 0;
MinPc, ValPc, MaxPc, IsOk = GetMinMaxParsec(value,sigma);
local Result='<span class="error">???</span>';
if not IsOk then
return Result;
end
MinPc,ValPc,MaxPc,MinLj,ValLj,MaxLj = CreateOutputValues(MinPc,ValPc,MaxPc)
if MinPc == MaxPc then
Result = tostring(ValPc) .. ' Pc ('.. tostring(ValLj) .. ' Lj)'
else
Result = tostring(MinPc) .. ' Pc ('.. tostring(MinLj) .. ' Lj) bis ' .. tostring(MaxPc) .. ' Pc ('.. tostring(MaxLj) .. ' Lj)'
end
return Result
end
function Plx2Dist.GetPlxDist(frame)
local MinPc = 0;
local ValPc = 0;
local MaxPc = 0;
local MinLj = 0;
local ValLj = 0;
local MaxLj = 0;
local Quality = 0;
local IsOk = false;
local value = tonumber(trim(frame.args[1])) or 0;
local sigma = tonumber(trim(frame.args[2])) or 0;
MinPc, ValPc, MaxPc, Quality, IsOk = GetMinMaxParsec(value,sigma);
end
return Plx2Dist;