Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- -- Initial Config
- local storage_side = "top"
- local display_side = "monitor_6"
- local s = peripheral.wrap(storage_side)
- local d = peripheral.wrap(display_side)
- local storage_values = {}
- -- DONT TOUCH THIS
- d.setTextScale(0.5)
- local width, height = d.getSize()
- -- CHANGE THESE AS YOU LIKE
- -- Color variables
- local text_color = colors.white
- local background_color = colors.black
- -- Variables for Graph X and Y Axis
- local base_row = height - 2
- local base_col = 3
- -- Graph Labels
- local x_label = "Time"
- local y_label = "Potions"
- d.clear()
- graph_x_start = height - base_row + 2
- graph_x_max = width - base_col
- graph_y_start = height - base_col
- graph_y_max = 1
- d.setTextColor(text_color)
- d.setBackgroundColor(background_color)
- function debug()
- for j=1, #storage_values do
- print("values["..(j-1).."] = "..storage_values[j])
- end
- end
- function getNbrOfPots()
- local stored = s.getStoredItems()
- table.insert(storage_values, stored.qty)
- if table.getn(storage_values) == nbr_of_stored_values + 1 then
- table.remove(storage_values, 1)
- end
- debug()
- end
- function calcMeanSS(list, period)
- sum = 0
- for i=1, #list do
- sum = sum + list[i]
- end
- mean = sum / #list
- sumsq = 0
- for j=1, #list do
- sq = list[j] - mean
- sq = sq * sq
- sumsq = sumsq + sq
- end
- mean_ss = sumsq / #list
- return mean_ss
- end
- function calcPPM(list, period)
- first = list[1]
- last = list[period]
- diff = last - first
- ppm = 60/period
- return diff * ppm
- end
- function normalizeList(list)
- local result = {}
- local min = list[1]
- local max = list[#list]
- for i, value in pairs(list) do
- if value > max then
- max = value
- end
- if value < min then
- min = value
- end
- end
- local range = max - min
- for j = 1, #list do
- result[j] = list[j] - min + 1
- end
- return result
- end
- function displayPots()
- printGraph(normalizeList(storage_values))
- -- d.setTextColor(colors.red)
- printCenter("PPM: "..math.floor(calcPPM(storage_values, #storage_values)), 0)
- -- d.setTextColor(text_color)
- end
- function printAt(str, x, y)
- d.setCursorPos(x, y)
- d.write(str)
- end
- function printCenter(str, yOffset)
- centerX = math.floor(width/2)
- centerY = math.floor(height/2) + yOffset
- offsetX = math.floor(#str/2)
- printAt(str, centerX - offsetX, centerY)
- end
- function printChartBars()
- -- Print X Axis
- for x=base_col, width - 1 do
- printAt("-",x, base_row)
- end
- printAt(">", width, base_row)
- -- Print X Label
- center_x = math.floor((width - base_col )/2) - math.floor(#x_label/2)
- printAt(x_label, center_x, base_row + 1)
- -- Print Y Axis
- printAt("^", base_col,1)
- for y=2, base_row - 1 do
- printAt("|", base_col, y)
- end
- -- Print Y label (horizontally)
- center_y = math.floor((height - base_col)/2)
- label_y = center_y - math.floor(#y_label/2)
- label_idx = 1
- for i=1, #y_label do
- c = y_label:sub(label_idx, label_idx)
- printAt(c, math.floor(base_col/2), i + label_y)
- label_idx = label_idx + 1
- end
- end
- function clearGraph()
- for x=graph_x_start, graph_x_max do
- for y=1, graph_y_start do
- printAt(" ", x, y)
- end
- end
- end
- function printGraph(list)
- -- X is static-isch
- clearGraph()
- y_base = graph_y_start
- idx = 1
- for x=graph_x_start, graph_x_max do
- sign = ""
- if list[idx] then
- printGraphPoint("=", x, y_base - list[idx])
- end
- idx = idx + 1
- end
- end
- function printGraphPoint(content, x, y)
- -- d.setTextColor(colors.green)
- printAt(content, x, y)
- -- d.setTextColor(text_color)
- end
- printChartBars()
- while true do
- getNbrOfPots()
- displayPots()
- os.sleep(1)
- end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement