diff --git a/docs/assets/Telem_Mekanism_Panel.json b/docs/public/assets/Telem_Mekanism_Panel.json similarity index 100% rename from docs/assets/Telem_Mekanism_Panel.json rename to docs/public/assets/Telem_Mekanism_Panel.json diff --git a/src/telem/lib/middleware/CalcDeltaMiddleware.lua b/src/telem/lib/middleware/CalcDeltaMiddleware.lua index c56c92e..8debe67 100644 --- a/src/telem/lib/middleware/CalcDeltaMiddleware.lua +++ b/src/telem/lib/middleware/CalcDeltaMiddleware.lua @@ -9,6 +9,8 @@ local Middleware = require 'telem.lib.BaseMiddleware' local CalcDeltaMiddleware = o.class(Middleware) CalcDeltaMiddleware.type = 'CalcDeltaMiddleware' +CalcDeltaMiddleware.DEFAULT_ADAPTER = '_t_default' + local rateIntervalSourceFactors = { utc = 1000, ingame = 72000 } function CalcDeltaMiddleware:constructor(windowSize) @@ -53,34 +55,43 @@ function CalcDeltaMiddleware:handleCollection(collection) for _, v in ipairs(collection.metrics) do if self.forceProcess or v.source ~= 'middleware' then - self.history[v.name] = self.history[v.name] or {} - self.times[v.name] = self.times[v.name] or {} + local adapter = v.adapter or self.DEFAULT_ADAPTER + + self.history[adapter] = self.history[adapter] or {} + self.times[adapter] = self.times[adapter] or {} + + self.history[adapter][v.name] = self.history[adapter][v.name] or {} + self.times[adapter][v.name] = self.times[adapter][v.name] or {} - t.constrainAppend(self.history[v.name], v.value, self.windowSize) - t.constrainAppend(self.times[v.name], timestamp, self.windowSize) + t.constrainAppend(self.history[adapter][v.name], v.value, self.windowSize) + t.constrainAppend(self.times[adapter][v.name], timestamp, self.windowSize) end end - for k, v in pairs(self.history) do - local idelta, delta, irate, rate = 0, 0, 0, 0 + for ak, av in pairs(self.history) do + local undefaultAdapter = ak ~= self.DEFAULT_ADAPTER and ak or nil - if #v >= 2 then - local vt = self.times[k] + for mk, mv in pairs(av) do + local idelta, delta, irate, rate = 0, 0, 0, 0 - idelta = v[#v] - v[#v - 1] - delta = v[#v] - v[1] + if #mv >= 2 then + local vt = self.times[ak][mk] - local itimedelta = vt[#vt] - vt[#vt - 1] - local timedelta = vt[#vt] - vt[1] + idelta = mv[#mv] - mv[#mv - 1] + delta = mv[#mv] - mv[1] - irate = (idelta / itimedelta) * self.rateInterval - rate = (delta / timedelta) * self.rateInterval - end + local itimedelta = vt[#vt] - vt[#vt - 1] + local timedelta = vt[#vt] - vt[1] + + irate = (idelta / itimedelta) * self.rateInterval + rate = (delta / timedelta) * self.rateInterval + end - collection:insert(Metric{ name = k .. '_idelta', value = idelta, source = 'middleware' }) - collection:insert(Metric{ name = k .. '_delta', value = delta, source = 'middleware' }) - collection:insert(Metric{ name = k .. '_irate', value = irate, source = 'middleware' }) - collection:insert(Metric{ name = k .. '_rate', value = rate, source = 'middleware' }) + collection:insert(Metric{ name = mk .. '_idelta', value = idelta, adapter = undefaultAdapter, source = 'middleware' }) + collection:insert(Metric{ name = mk .. '_delta', value = delta, adapter = undefaultAdapter, source = 'middleware' }) + collection:insert(Metric{ name = mk .. '_irate', value = irate, adapter = undefaultAdapter, source = 'middleware' }) + collection:insert(Metric{ name = mk .. '_rate', value = rate, adapter = undefaultAdapter, source = 'middleware' }) + end end return collection diff --git a/src/telem/lib/output/basalt/LabelOutputAdapter.lua b/src/telem/lib/output/basalt/LabelOutputAdapter.lua index 77ed869..d0c62c9 100644 --- a/src/telem/lib/output/basalt/LabelOutputAdapter.lua +++ b/src/telem/lib/output/basalt/LabelOutputAdapter.lua @@ -19,41 +19,41 @@ function LabelOutputAdapter:constructor (frame, filter, bg, fg, fontSize) end function LabelOutputAdapter:register (bg, fg, fontSize) - self.bInnerFrame = self.bBaseFrame + self.bg = bg or 'black' + self.fg = fg or 'white' + self.fontSize = fontSize or 2 - -- TODO idk if this inner frame is necessary - self.bInnerFrame = self.bBaseFrame:addFrame() - :setBackground(bg) - :setSize('parent.w', 'parent.h') + self.bInnerFrame = self.bBaseFrame + self.bInnerFrame:setBackground(self.bg) self.bLabelValue = self.bInnerFrame :addLabel() :setText("-----") - :setFontSize(fontSize or 2) - :setBackground(bg) - :setForeground(fg) - :setPosition('parent.w/2-self.w/2', 'parent.h/2-self.h/2') + :setFontSize(self.fontSize) + :setBackground(self.bg) + :setForeground(self.fg) + :setPosition('parent.w/2-self.w/2+1', 'parent.h/2-self.h/2+1') self.bLabelName = self.bInnerFrame :addLabel() :setText(self.nameText) - :setBackground(bg) - :setForeground(fg) + :setBackground(self.bg) + :setForeground(self.fg) :setPosition(1,1) self.animThread = self.bInnerFrame:addThread() - :start(function () - while true do - local goslep = 0.2 - self.nameScroll = self.nameScroll + 1 - if self.nameScroll > self.nameText:len() + 3 then - self.nameScroll = 0 - goslep = 3 - end - self:refreshLabels() - t.sleep(goslep) + self.animThread:start(function () + while true do + local goslep = 0.2 + self.nameScroll = self.nameScroll + 1 + if self.nameScroll > self.nameText:len() + 3 then + self.nameScroll = 0 + goslep = 3 end - end) + self:refreshLabels() + t.sleep(goslep) + end + end) end function LabelOutputAdapter:refreshLabels () @@ -75,8 +75,11 @@ function LabelOutputAdapter:write (collection) local resultMetric = collection:find(self.filter) assert(resultMetric, 'could not find metric') + + self.bLabelValue + :setText(t.shortnum(resultMetric.value)) + :setFontSize(self.fontSize) - self.bLabelValue:setText(t.shortnum(resultMetric.value)) self.nameText = resultMetric.name self:refreshLabels()