Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- os.loadAPI("ocs/apis/sensor")
- os.loadAPI("ocs/apis/graph")
- local usedamount = 0
- local prox = sensor.wrap("left")
- local i = 0
- local usage = 0
- --print(textutils.serialize(prox.getTargets()))
- local targets = prox.getTargets()
- for name,basicDetails in pairs(targets) do
- print("Found Tank: "..name)
- tankDetails = prox.getTargetDetails(name)
- if (tankDetails ~= nil) then
- print("That Works")
- tank = name
- break
- end
- end
- local init = tankDetails.Tanks[1].Amount
- local capacity = tankDetails.Tanks[1].Capacity
- local type = tankDetails.Tanks[1].Name
- if type == "item.fuel" then
- type = "Fuel"
- 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
- function round(val, decimal)
- if (decimal) then
- return math.floor( (val * 10^decimal) + 0.5 / (10^decimal) )
- else
- return math.floor(val+0.5)
- end
- end
- function format_num(amount, decimal,prefix, neg_prefix)
- local str_amount, formatted, famount, remain
- decimal = decimal or 2
- neg_prefix = neg_prefix or "-"
- famount = math.abs(round(amount,decimal))
- famount = math.floor(famount)
- remain = round(math.abs(amount) - famount, decimal)
- formatted = comma_value(famount)
- if (decimal > 0 ) then
- remain = string.sub(tostring(remain),3)
- formatted = formatted .. "." .. remain ..
- string.rep("0", decimal - string.len(remain))
- end
- if (amount < 0 ) then
- if (neg_prefix=="()") then
- formatted = "("..formatted ..")"
- else
- formatted = neg_prefix .. formatted
- end
- end
- return formatted
- end
- function update()
- i = i + 1
- local amt = sensor.call("left", "getTargetDetails",tank)
- if amt ~= nil then
- usage = init - amt.Tanks[1].Amount
- fuelcons = ( usage / i * 12 * 60 )
- timeleft = amt.Tanks[1].Amount / fuelcons
- fuelecons = fuelcons * -1
- -- fuelcons = format_num(fuelcons,2)
- term.clear()
- term.setCursorPos(1,1)
- print("Consuming " ..fuelcons .." Fuel Per Hour")
- return amt.Tanks[1].Amount
- else
- print("amt was null")
- end
- end
- function newLine()
- local_,cY= mon.getCursorPos()
- mon.setCursorPos(1,cY+1)
- end
- mon = peripheral.wrap("top")
- graphInstance = graph.new(mon, update, type, nil, 0 , capacity)
- mon.setTextScale(5)
- while true do
- graphInstance:draw()
- newLine()
- mon.write(" Consuming: ")
- mon.setTextColor(colors.lightBlue)
- mon.write(fuelcons)
- mon.setTextColor(colors.white)
- mon.write(" /h")
- newLine()
- mon.write(" Time Remaining: ")
- mon.setTextColor(colors.yellow)
- mon.write(timeleft)
- mon.setTextColor(colors.white)
- mon.write(" Hours")
- sleep(5)
- end
Advertisement
Add Comment
Please, Sign In to add comment