FANDOM


local p = {}
 
function p.test()
    TestString = "-, 2/26499, 4, 3/1901, 2/2325, 2/1921, 2/2776, 3/38293"
    _, _, d1, d2, d3, d4, d5, d6, d7, w1 = string.find(TestString, "(.-),(.-),(.-),(.-),(.-),(.-),(.-),(.*)")
    --a1, a2, a3, a4, a5, a6, a7, d1, d2, d3, d4, d5, d6, d7, w1 = string.find(TestString, "(.-),(.-),(.-),(.-),(.-),(.-),(.-),(.-)")
    --return "Tuesday: " .. d2 .. " and Friday: " .. d5
    --return "Bob"
    return "d1 " .. d1 .. " d2 " .. d2 .. " d3 " .. d3 .. " d4 " .. d4 .. " d5 " .. d5 .. " d6 " .. d6 .. " d7 " .. d7 .. " w1 " .. w1
end
 
function p.test2()
    TestString = "-, 2/26499, 4, 3/1901, 2/2325, 2/1921, 2/2776, 3/38293"
    _, _, d1, d2, d3, d4, d5, d6, d7, w1 = string.find(TestString, "(.-),(.-),(.-),(.-),(.-),(.-),(.-),(.*)")
    --a1, a2, a3, a4, a5, a6, a7, d1, d2, d3, d4, d5, d6, d7, w1 = string.find(TestString, "(.-),(.-),(.-),(.-),(.-),(.-),(.-),(.-)")
    --return "Tuesday: " .. d2 .. " and Friday: " .. d5
    --return "Bob"
    --return "d1 " .. d1 .. " d2 " .. d2 .. " d3 " .. d3 .. " d4 " .. d4 .. " d5 " .. d5 .. " d6 " .. d6 .. " d7 " .. d7 .. " w1 " .. w1
    output = "|-\n"
    output = output .. "| " .. ProcessDay(d1) .. "\n"
    output = output .. "| " .. ProcessDay(d2) .. "\n"
    output = output .. "| " .. ProcessDay(d3) .. "\n"
    output = output .. "| " .. ProcessDay(d4) .. "\n"
    output = output .. "| " .. ProcessDay(d5) .. "\n"
    output = output .. "| " .. ProcessDay(d6) .. "\n"
    output = output .. "| " .. ProcessDay(d7) .. "\n"
    output = output .. "| " .. ProcessWeek(w1) .. "\n"
    return output
end
 
function p.OriconWeek(frame)
    local WeekData = frame.args[1]
    _, _, d1, d2, d3, d4, d5, d6, d7, w1 = string.find(WeekData, "(.-),(.-),(.-),(.-),(.-),(.-),(.-),(.*)")
    output = "|-\n"
    output = output .. "| " .. ProcessDay(d1) .. "\n"
    output = output .. "| " .. ProcessDay(d2) .. "\n"
    output = output .. "| " .. ProcessDay(d3) .. "\n"
    output = output .. "| " .. ProcessDay(d4) .. "\n"
    output = output .. "| " .. ProcessDay(d5) .. "\n"
    output = output .. "| " .. ProcessDay(d6) .. "\n"
    output = output .. "| " .. ProcessDay(d7) .. "\n"
    output = output .. "| " .. ProcessWeek(w1) .. "\n"
    return output
end
 
function p.test3()
    --return "<nowiki>" .. ProcessWeek("2/26499") .. "</nowiki>"
    return "<nowiki>" .. ProcessWeek("/26499") .. "</nowiki>"
end
 
function p.test4()
    Day = "2/26499"
    _, count = string.gsub(Day, "/", "/")
    if count==0 then return Day else
        _, _, rank, sales = string.find(Day, "(%d*)/(%d*)")
        sales = sales + 0 --turn into number for further formatting
        sales = comma_value(sales)
        return rank .. "<br /><small>" .. sales .. "</small>"
    end
 
end
 
function ProcessDay (Day)
    _, count = string.gsub(Day, "/", "/")
    if count==0 then return Day else
        _, _, rank, sales = string.find(Day, "(%d*)/(%d*)")
        sales = sales + 0 --turn into number for further formatting
        sales = comma_value(sales)
        return rank .. "<br /><small>" .. sales .. "</small>"
    end
end
 
function ProcessWeek (Week)
    _, count = string.gsub(Week, "/", "/")
    if count==0 then return Week .. " | " else
        _, _, rank, sales = string.find(Week, "(%d*)/(%d*)")
        sales = sales + 0 --turn into number for further formatting
        sales = comma_value(sales)
        return rank .. "\n| " .. sales
    end
end
 
function comma_value(amount)
  local formatted = amount
  while true do  
    formatted, k = string.gsub(formatted, "^(-?%d+)(%d%d%d)", '%1,%2')
    if (k==0) then
      break
    end
  end
  return formatted
end
 
 
return p