Skip to content

Commit

Permalink
Merge pull request #63 from cyberbit/hotfix/miscbugs
Browse files Browse the repository at this point in the history
Misc bugs
  • Loading branch information
cyberbit authored Jul 12, 2024
2 parents b26fc29 + 6f5159e commit 258878d
Show file tree
Hide file tree
Showing 3 changed files with 56 additions and 42 deletions.
File renamed without changes.
49 changes: 30 additions & 19 deletions src/telem/lib/middleware/CalcDeltaMiddleware.lua
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down Expand Up @@ -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
Expand Down
49 changes: 26 additions & 23 deletions src/telem/lib/output/basalt/LabelOutputAdapter.lua
Original file line number Diff line number Diff line change
Expand Up @@ -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 ()
Expand All @@ -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()

Expand Down

0 comments on commit 258878d

Please sign in to comment.