Module:Sandbox/AnataBakka

-- local p    = {} local lib  = require('Module:Feature')

function p.getAP(frame) local args; if frame.args == nil then args = lib.arguments(frame) else args = lib.arguments(frame.args) end local values = "" local count  = 6 local fill   = 5 local i      = 1 local round  = args["round"] or 2 local temp, a, b, c   while args[i]~=nil do        if string.find(args[i],"to")~=nil and string.find(args[i],"%<")==nil then start,finish,times=args[i]:match"(.*) *to *([^ ]*) *([^ ]*)" if start~=nil and finish~=nil and pcall(expr,start.."*2")~=false and pcall(expr,finish.."*2")~=false then start=tonumber(expr(start)) finish=tonumber(expr(finish)) if times=="" or times==nil then times=fill fill=0 else times=tonumber(expr(times)) end x=1 while x<=times do                   if count==0 then i=-1 break end count=count-1 if x==1 then formula=start else formula=formula+(finish-start)/(times-1) end if values=="" then values=fd(rounding(formula,round)) else values=values.." / "..fd(rounding(formula,round)) end x=x+1 end else count=count-1 if values=="" then values=fd(rounding(args[i],round)) else values=values.." / "..fd(rounding(args[i],round)) end end else count=count-1 if values=="" then values=fd(rounding(args[i],round)) else values=values.." / "..fd(rounding(args[i],round)) end end if count==0 then break end i=i+1 end return values end

function p.getPP(frame) local args; if frame.args == nil then args = lib.arguments(frame) else args = lib.arguments(frame.args) end if string.find(args[1],"%;")~=nil or string.find(args[1],"x")~=nil or string.find(args[1],"%t%o")~=nil then size=18 orig=args[1] orig1=args[2] or "" else if string.find(args[2],"%;")~=nil or string.find(args[2],"x")~=nil or string.find(args[2],"%t%o")~=nil then size=args[1] orig=args[2] orig1=args[3] or "" else size=18 orig=args[1] orig1=args[2] or "" end end orig=mw.text.split(orig,"%;") orig1=mw.text.split(orig1,"%;") local round=args["round"] or 2 local round1=args["round1"] or 2 local key=args["key"] or "" local key1=args["key1"] or "" values="" count=22 fill=tonumber(size) i=1 local temp,a,b,c while orig[i]~=nil and orig[i]~="" do       if (string.find(orig[i],"%t%o")~=nil or string.find(orig[i],"x")~=nil) and string.find(orig[i],"%<")==nil then times=orig[i]:match"for *(.*)" if times~="" and times~=nil then times=tonumber(expr(times)) fill=fill-times end else fill=fill-1 end if fill<=0 then fill=0 break end i=i+1 end i=1 while orig[i]~=nil and orig[i]~="" do       if string.find(orig[i],"%t%o")~=nil and string.find(orig[i],"%<")==nil then start,finish,times=orig[i]:match"([^to]*)to *([^for]*)[for]* *(.*)" start=tonumber(expr(start)) finish=tonumber(expr(finish)) if times=="" or times==nil then times=fill fill=0 else times=tonumber(expr(times)) end x=1 while x<=times do               count=count-1 if count==0 then i=-1 break end if x==1 then formula=start else formula=formula+(finish-start)/(times-1) end if values=="" then values=fd(rounding(formula,round))..key else values=values.." / "..fd(rounding(formula,round))..key end x=x+1 end else if string.find(orig[i],"x")~=nil and string.find(orig[i],"%<")==nil then useformula,times=orig[i]:match"([^for]*)[for]* *(.*)" if times=="" or times==nil then times=fill fill=0 else times=tonumber(expr(times)) end x=1 while x<=times do                   count=count-1 if count==0 then i=-1 break end formula=string.gsub(useformula,"x",x) if values=="" then values=fd(rounding(expr(formula),round))..key else values=values.." / "..fd(rounding(expr(formula),round))..key end x=x+1 end else count=count-1 if count==0 then break end if values=="" then values=fd(rounding(expr(orig[i]),round))..key else values=values.." / "..fd(rounding(expr(orig[i]),round))..key end end end i=i+1 end values1="" count1=22 fill=22-count i=1 local temp,a,b,c while orig1[i]~=nil and orig1[i]~="" do       if (string.find(orig1[i],"%t%o")~=nil or string.find(orig1[i],"x")~=nil) and string.find(orig1[i],"%<")==nil then times=orig1[i]:match"for *(.*)" if times~="" and times~=nil then times=tonumber(expr(times)) fill=fill-times end else fill=fill-1 end if fill<=0 then fill=0 break end i=i+1 end i=1 while (orig1[i]~=nil and orig1[i]~="") or count1>count do       if orig1[i]==nil or orig1[i]=="" then count1=count1-1 if count1==0 or count1<count then break end if values1=="" then values1=i..key1 else values1=values1.." / "..i..key1 end else if string.find(orig1[i],"%t%o")~=nil and string.find(orig1[i],"%<")==nil then start,finish,times=orig1[i]:match"([^to]*)to *([^for]*)[for]* *(.*)" start=tonumber(expr(start)) finish=tonumber(expr(finish)) if times=="" or times==nil then times=fill fill=0 else times=tonumber(expr(times)) end x=1 while x<=times do               count1=count1-1 if count1==0 or count1<count then i=-1 break end if x==1 then formula=start else formula=formula+(finish-start)/(times-1) end if values1=="" then values1=fd(rounding(formula,round))..key1 else values1=values1.." / "..fd(rounding(formula,round))..key1 end x=x+1 end else if string.find(orig1[i],"x")~=nil and string.find(orig1[i],"%<")==nil then useformula,times=orig1[i]:match"([^for]*)[for]* *(.*)" if times=="" or times==nil then times=fill fill=0 else times=tonumber(expr(times)) end x=1 while x<=times do                   count1=count1-1 if count1==0 or count1<count then i=-1 break end formula=string.gsub(useformula,"x",x) if values1=="" then values1=fd(rounding(expr(formula),round))..key1 else values1=values1.." / "..fd(rounding(expr(formula),round))..key1 end x=x+1 end else count1=count1-1 if count1==0 or count1<count then break end if values1=="" then values1=fd(rounding(expr(orig1[i]),round))..key1 else values1=values1.." / "..fd(rounding(expr(orig1[i]),round))..key1 end end end end i=i+1 end return values1.." "..values end

function p.get(frame) local args; if frame.args == nil then args = lib.arguments(frame) else args = lib.arguments(frame.args) end a=mw.text.split("x ","x ") return "a[1]="..a[1].."a[2]="..a[2] end

function expr(val) val=string.gsub(string.gsub(string.gsub(string.gsub(string.gsub(string.gsub(string.gsub(string.gsub(val," ",""),"%/"," / "),"%*"," * "),"%+"," + "),"%-"," - "),"%^ %- ","^-"),"%( %- ","(-"),"%^"," %^ ") local i=1 local j=1 local a,b,switcher,temp while i>0 do       while j>0 do            temp=val if string.find(val,"%)")~=nil then               switchertemp=mw.text.split( val, "%)") temp=last(switchertemp[1],"%(")           end            if string.find(temp," %^ ")~=nil then                a=mw.text.split(temp," %^ ")                b=mw.text.split(a[2]," ")                switcher=last( a[1]," ")                switcher2=b[1]                switcher3=switcher^switcher2                if string.find(switcher2,"%-")~=nil then                     switcher2="%-"..switcher2*(-1)                end                val=string.gsub(val,switcher.." %^ "..switcher2,switcher3)                break            end            if string.find(temp," %/ ")~=nil then                a=mw.text.split(temp," %/ ")                b=mw.text.split(a[2]," ")                switcher=last( a[1]," ")                switcher2=b[1]                switcher3=switcher/switcher2                if string.find(switcher2,"%-")~=nil then                     switcher2="%-"..switcher2*(-1) end val=string.gsub(val,switcher.." %/ "..switcher2,switcher3) break end if string.find(temp," %* ")~=nil then a=mw.text.split( temp," %* ") b=mw.text.split(a[2]," ") switcher=last( a[1]," ") switcher2=b[1] switcher3=switcher*switcher2 if string.find(switcher2,"%-")~=nil then switcher2="%-"..switcher2*(-1) end val=string.gsub(val,switcher.." %* "..switcher2,switcher3) break end if string.find(temp," %- ")~=nil then a=mw.text.split( temp," %- ") b=mw.text.split(a[2]," ") switcher=last( a[1]," ") switcher2=b[1] if swithcer=="" or switcher==nil then if string.find(switcher2,"%-")~=nil then switcher2="%-"..switcher2*(-1) end val=string.gsub(val," %- "..switcher2,"%-"..swticher2) break else switcher3=switcher-switcher2 if string.find(switcher2,"%-")~=nil then switcher2="%-"..switcher2*(-1) end val=string.gsub(val,switcher.." %- "..switcher2,switcher3) break end end if string.find(temp," %+ ")~=nil then a=mw.text.split( temp," %+ ") b=mw.text.split(a[2]," ") switcher=last( a[1]," ") switcher2=b[1] if swithcer=="" then if string.find(switcher2,"%-")~=nil then switcher2="%-"..switcher2*(-1) end val=string.gsub(val," %+ "..switcher2,swticher2) break else switcher3=switcher+switcher2 if string.find(switcher2,"%-")~=nil then switcher2="%-"..switcher2*(-1) end val=string.gsub(val,switcher.." %+ "..switcher2,switcher3) break end end if string.find(val,"%)")~=nil then               if string.find(temp,"%-")~=nil then                     temp="%-"..temp*(-1)                end                val=string.gsub(val,"%("..temp.."%)",temp)                break            else                i=0            end            break        end    end    return temp end function last(val,sign)    local a=mw.text.split(val,sign)    local j=1    while j>0 do        if a[j] ~=nil then            j=j+1        else        break        end    end    return a[j-1] end function fd(val)    if string.find(val,"[0-9]") == nil or string.find(val,"%.") == nil then        return val    end    local a,b,c    if string.find(val,"span") ~= nil then        a,b,c = val:match"([^.]*).(.*) (.*)"        if string.find(val,"span")<=string.find(val,"%.") then            return a .. ". " .. b .. " " .. c        else            return a .. ". " .. b .. " " .. c       end else a,b,c = val:match"([^.]*).([0-9]*)(.*)" return a .. ". " .. b .. " " .. c   end end function rounding(val, numDecimalPlaces) val=tostring(val) if string.find(val,"[0-9]")==nil or string.find(val,"<span")~=nil or string.find(val,"%.")==nil then return val end local a,b,c,d a,b,c,d = val:match"([^0-9]*)([0-9]*).([0-9]*)(.*)" val=tonumber(b.."."..c)   local mult = 10^(numDecimalPlaces) local round=math.floor(val * mult + 0.5) / mult return a..round..d end return p --