Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- local config = {
- -- maxCoreEnergy - на этом уровне будет поддерживаться количество энергии в ядре
- -- 1000 * 10^9 соответсвунт 1000 B или 1 T
- maxCoreEnergy = 1000 * 10^9,
- maxDiffEnergy = 10000, -- максимальная скорость накапливания энергии Rf/t, тестировалось на этом значении
- step = 5000, -- шаг изменния значения на гейте
- sleepTime = 1, -- шаг замеров в сек
- }
- local com = require('component')
- local gpu = com.gpu
- gpu.setResolution(80, 25) -- lvl 2
- local function coreEnergy()
- return com.draconic_rf_storage.getEnergyStored()
- end
- local function format(num)
- if num > 10^12 then
- return string.format("%0.3f T", num/10^12)
- elseif num > 10^9 then
- return string.format("%0.3f B", num/10^9)
- elseif num > 10^6 then
- return string.format("%0.3f M", num/10^6)
- elseif num > 10^3 then
- return string.format("%0.3f K", num/10^3)
- else
- return string.format("%d", num)
- end
- end
- local filVal = 0
- function expRunningAvg(newVal)
- filVal = filVal + ((newVal-filVal) * 0.3)
- return filVal
- end
- if false == com.isAvailable("draconic_rf_storage") then
- print("Rf storage not connected!")
- os.exit()
- end
- if false == com.isAvailable("flux_gate") then
- print("Flux gate not connected!")
- os.exit()
- end
- local time = os.time()
- local energy = coreEnergy()
- local w, h = gpu.getResolution()
- function asbMax(t)
- local max = t[1]
- for _, val in ipairs(t) do
- if math.abs(val) > max then
- max = math.abs(val)
- end
- end
- return max
- end
- local _MID = h/2 + 3
- local _NUM_READ = w
- local energyLog = {}
- local current = 0
- function displayGraph(diff)
- current = current + 1
- if current > _NUM_READ then
- current = 1
- end
- energyLog[current] = diff
- local maxVal = asbMax(energyLog)
- gpu.fill(1, _MID, w, 1, '━')
- local row = 1
- for i = current, _NUM_READ + current - 1 do
- local key = i % w + 1
- if energyLog[key] then
- local d = (math.ceil(energyLog[key] / (maxVal * 0.1)))
- if d > 0 then
- gpu.fill(row, _MID-d, 1, d, '█')
- else
- gpu.fill(row, _MID+1, 1, math.abs(d), '█')
- end
- end
- row = row + 1
- end
- end
- function displayData(core, diff, action, fluxGateFlow)
- gpu.fill(1, 1, w, h, " ")
- gpu.set(2, 1, string.format(" Энергии в ядре: %s [%0.0f Rf]", format(core), core))
- gpu.set(2, 2, string.format(" Выход на гейте: %s Rf [%0.0f Rf] %s", format(fluxGateFlow), fluxGateFlow, action))
- gpu.set(2, 3, string.format(' Накопление энергии: %0.1f Rf/t', diff))
- displayGraph(diff)
- end
- local running = true
- while running do
- os.sleep(config.sleepTime)
- local tmpEnergy = coreEnergy()
- local tmpTime = os.time()
- local energyDiff = tmpEnergy - energy
- local timeDiff = tmpTime - time
- local diff = expRunningAvg(energyDiff / timeDiff)
- local fluxGateFlow = com.flux_gate.getFlow();
- local action = ""
- if tmpEnergy > config.maxCoreEnergy then
- if diff > (config.maxDiffEnergy * -1) then
- action = 'Повышаю ▲'
- com.flux_gate.setSignalLowFlow(fluxGateFlow + config.step)
- end
- else
- if diff < config.maxDiffEnergy then
- action = 'Понижаю ▼'
- com.flux_gate.setSignalLowFlow(fluxGateFlow - config.step)
- end
- end
- displayData(tmpEnergy, diff, action, fluxGateFlow)
- time = tmpTime
- energy = tmpEnergy
- end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement