We are about to release a newsletter article outlining how lua can be used to track the time a tool is used, and send that information to your computer so that you can track it. https://www.masso.com.au/campaigns/tool-life-tracking-with-lua/
here are the scripts that needs to be in the Tool Change → Before Tool Change lua trigger, and in the Job → End Of Job lua trigger.
This will send the information in a message to myWorkshop PRO, and it can by copied and pasted into a table or other location to tally up the totals.
My question is, what do you think is the best format to output the data? At the moment it is just output in a message, but the message can be formatted in any way so that it can be passed off to another program to be organised and made useful. How should the data be structured?
--===================
-- Before Tool Change
--===================
toolUsage = toolUsage or {}
lastToolTime = lastToolTime or 0
-- Capture current tool usage one last time
local currentTool = M.tool.get_current()
if currentTool then
local toolName = M.tool.get_name(currentTool) or "Unnamed"
local runTimeTable = M.sys.get_job_runtime() or {}
local hh = runTimeTable.hour or 0
local mm = runTimeTable.min or 0
local ss = runTimeTable.sec or 0
local totalSeconds = (hh * 3600) + (mm * 60) + ss
local deltaSeconds = totalSeconds
if lastToolTime then
deltaSeconds = totalSeconds - lastToolTime
if deltaSeconds < 0 then deltaSeconds = 0 end
end
-- Add or update table entry
local entry = toolUsage[currentTool]
if entry then
entry.seconds = entry.seconds + deltaSeconds
else
toolUsage[currentTool] = { name = toolName, seconds = deltaSeconds }
end
lastToolTime = totalSeconds
end
return true
-- ============================
-- END OF JOB TOOL REPORT
-- ============================
toolUsage = toolUsage or {}
lastToolTime = lastToolTime or 0
-- Capture current tool usage one last time
local currentTool = M.tool.get_current()
if currentTool then
local toolName = M.tool.get_name(currentTool) or "Unnamed"
local runTimeTable = M.sys.get_job_runtime() or {}
local hh = runTimeTable.hour or 0
local mm = runTimeTable.min or 0
local ss = runTimeTable.sec or 0
local totalSeconds = (hh * 3600) + (mm * 60) + ss
local deltaSeconds = totalSeconds
if lastToolTime then
deltaSeconds = totalSeconds - lastToolTime
if deltaSeconds < 0 then deltaSeconds = 0 end
end
-- Add or update table entry
local entry = toolUsage[currentTool]
if entry then
entry.seconds = entry.seconds + deltaSeconds
else
toolUsage[currentTool] = { name = toolName, seconds = deltaSeconds }
end
end
-- ============================
-- SEND TOOL USAGE IN ONE LINE
-- ============================
local msg = "Tool Usage Report: "
for toolNum, data in pairs(toolUsage) do
local seconds = data.seconds or 0
local hh = math.floor(seconds / 3600)
local mm = math.floor((seconds % 3600) / 60)
local ss = math.floor(seconds % 60)
local formatted = string.format("%02d:%02d:%02d", hh, mm, ss)
-- Add this tool to the message, separated by " | "
msg = msg .. string.format("T%02d-%s:%s | ", toolNum, data.name or "?", formatted)
end
-- Remove the trailing separator
msg = msg:sub(1, -4)
-- Send all in one message
M.sys.send_myworkshop_message(msg)
-- Clear table for next job
M.sys.delay(1000)
toolUsage = nil
lastToolTime = nil
here are the scripts that needs to be in the Tool Change → Before Tool Change lua trigger, and in the Job → End Of Job lua trigger.
This will send the information in a message to myWorkshop PRO, and it can by copied and pasted into a table or other location to tally up the totals.
My question is, what do you think is the best format to output the data? At the moment it is just output in a message, but the message can be formatted in any way so that it can be passed off to another program to be organised and made useful. How should the data be structured?
--===================
-- Before Tool Change
--===================
toolUsage = toolUsage or {}
lastToolTime = lastToolTime or 0
-- Capture current tool usage one last time
local currentTool = M.tool.get_current()
if currentTool then
local toolName = M.tool.get_name(currentTool) or "Unnamed"
local runTimeTable = M.sys.get_job_runtime() or {}
local hh = runTimeTable.hour or 0
local mm = runTimeTable.min or 0
local ss = runTimeTable.sec or 0
local totalSeconds = (hh * 3600) + (mm * 60) + ss
local deltaSeconds = totalSeconds
if lastToolTime then
deltaSeconds = totalSeconds - lastToolTime
if deltaSeconds < 0 then deltaSeconds = 0 end
end
-- Add or update table entry
local entry = toolUsage[currentTool]
if entry then
entry.seconds = entry.seconds + deltaSeconds
else
toolUsage[currentTool] = { name = toolName, seconds = deltaSeconds }
end
lastToolTime = totalSeconds
end
return true
-- ============================
-- END OF JOB TOOL REPORT
-- ============================
toolUsage = toolUsage or {}
lastToolTime = lastToolTime or 0
-- Capture current tool usage one last time
local currentTool = M.tool.get_current()
if currentTool then
local toolName = M.tool.get_name(currentTool) or "Unnamed"
local runTimeTable = M.sys.get_job_runtime() or {}
local hh = runTimeTable.hour or 0
local mm = runTimeTable.min or 0
local ss = runTimeTable.sec or 0
local totalSeconds = (hh * 3600) + (mm * 60) + ss
local deltaSeconds = totalSeconds
if lastToolTime then
deltaSeconds = totalSeconds - lastToolTime
if deltaSeconds < 0 then deltaSeconds = 0 end
end
-- Add or update table entry
local entry = toolUsage[currentTool]
if entry then
entry.seconds = entry.seconds + deltaSeconds
else
toolUsage[currentTool] = { name = toolName, seconds = deltaSeconds }
end
end
-- ============================
-- SEND TOOL USAGE IN ONE LINE
-- ============================
local msg = "Tool Usage Report: "
for toolNum, data in pairs(toolUsage) do
local seconds = data.seconds or 0
local hh = math.floor(seconds / 3600)
local mm = math.floor((seconds % 3600) / 60)
local ss = math.floor(seconds % 60)
local formatted = string.format("%02d:%02d:%02d", hh, mm, ss)
-- Add this tool to the message, separated by " | "
msg = msg .. string.format("T%02d-%s:%s | ", toolNum, data.name or "?", formatted)
end
-- Remove the trailing separator
msg = msg:sub(1, -4)
-- Send all in one message
M.sys.send_myworkshop_message(msg)
-- Clear table for next job
M.sys.delay(1000)
toolUsage = nil
lastToolTime = nil