Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- -- Tracking Dashboard (tracking_dashboard.lua)
- -- Runs in a separate tab on the server to monitor student locations
- local disk = peripheral.find("drive")
- if not disk then
- print("Error: No disk drive found.")
- -- Continue anyway as we might not need disk if API works
- end
- -- Load API using dofile for compatibility
- local ndisk = dofile("ndisk_api.lua")
- -- Initialize NDisk
- ndisk.init()
- local function getStudents()
- local students = ndisk.list("students")
- local data = {}
- for _, id in ipairs(students) do
- -- Check if it's a valid student (not strictly needed as list returns items in students/)
- -- Assuming id is the folder name
- local historyPath = "students/" .. id .. "/location_history.txt"
- if ndisk.exists(historyPath) then
- local content = ndisk.read(historyPath)
- if content and #content > 0 then
- -- Get last line
- local lastLine = nil
- for line in content:gmatch("[^\r\n]+") do
- lastLine = line
- end
- if lastLine then
- local timestamp, coords = lastLine:match("([^|]+)|(.+)")
- if timestamp and coords then
- table.insert(data, {id = id, time = timestamp, coords = coords})
- end
- end
- end
- end
- end
- return data
- end
- local function drawDashboard()
- term.clear()
- term.setCursorPos(1, 1)
- print("MtnLabs Student Tracking")
- print("========================")
- local students = getStudents()
- if #students == 0 then
- print("No active tracking data found.")
- else
- print(string.format("%-10s | %-15s | %s", "ID", "Time", "Location"))
- print(string.rep("-", 40))
- for _, s in ipairs(students) do
- -- Format time (simple epoch to string if needed, or raw)
- -- os.epoch("local") returns milliseconds.
- -- Maybe convert to readable? For now raw.
- local timeStr = s.time
- if tonumber(s.time) then
- timeStr = os.date("%H:%M:%S", tonumber(s.time)/1000)
- end
- print(string.format("%-10s | %-15s | %s", s.id, timeStr, s.coords))
- end
- end
- print("========================")
- print("Press 'q' to exit.")
- end
- while true do
- drawDashboard()
- local timer = os.startTimer(60) -- Refresh every 60s
- local event, p1 = os.pullEvent()
- if event == "char" and p1 == "q" then
- break
- elseif event == "timer" and p1 == timer then
- -- Refresh
- end
- end
Advertisement
Add Comment
Please, Sign In to add comment