Modul:Vorlage:Plx2Dist2
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 (1000*value+0.5) / 1000;
elseif value < 10 then
value = math.floor (100*value+0.5) / 100;
elseif value < 100 then
value = math.floor (10* value+0.5) /10;
elseif value < 1000 then
value = math.floor (value+0.5)
elseif value < 10000 then
value = 10 * math.floor (value/10+0.5)
else
value = 100 * math.floor (value/100+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;
local format = frame.args[fmt] or "";
MinPc, ValPc, MaxPc, Quality, IsOk = GetMinMaxParsec(value,sigma);
if IsOk then
return round(ValPc);
else
return "???";
end
end
function Plx2Dist.GetPc(frame)
local IsOk = false;
local Parsec = 0;
local Plx = tonumber(trim(string.gsub(frame.args[1],',','.'))) or 0;
if Plx > 0 then
Parsec = round(1000 / Plx);
IsOk = true;
end
if IsOk then
return Parsec;
else
return '???';
end
end
function Plx2Dist.GetLj(frame)
local IsOk = false;
local Lj = 0;
local Plx = tonumber(trim(string.gsub(frame.args[1],',','.'))) or 0;
if Plx > 0 then
Lj = round(3261.56 / Plx);
IsOk = true;
end
if IsOk then
return Lj;
else
return '???';
end
end
return Plx2Dist;
Content Disclaimer
Informasi ini disarikan dari Wikipedia dan disajikan kembali untuk tujuan edukasi. Konten tersedia di bawah lisensi CC BY-SA 3.0. Kami tidak bertanggung jawab atas ketidakakuratan data yang bersumber dari kontribusi publik tersebut.
- The information displayed on this website is sourced in part or in whole from Wikipedia and has been adapted for the purpose of restating it. We strive to provide accurate and relevant information, however:
- There is no guarantee of absolute accuracy. Wikipedia is an open, collaborative project that can be edited by anyone, so information is subject to change.
- It is not intended to constitute professional advice. The content displayed is for informational and educational purposes only. For important decisions (e.g., medical, legal, or financial), please consult a professional.
- Content copyright. Wikipedia is licensed under the Creative Commons Attribution-ShareAlike License (CC BY-SA). This means that content may be reused with appropriate attribution and shared under a similar license.
- Responsible use. Any risk arising from the use of information from this website is entirely the responsibility of the user.