completed basic recording functionality

This commit is contained in:
UpstreamData
2022-06-02 14:17:08 -06:00
parent e7d269008c
commit 64018cdad8
5 changed files with 216 additions and 32 deletions

View File

@@ -1,6 +1,6 @@
import asyncio
from tools.cfg_util.record.layout import record_window
from tools.cfg_util.record.pdf import generate_pdf
from miners.miner_factory import MinerFactory
@@ -27,14 +27,15 @@ class RecordingManager(metaclass=Singleton):
self.miners = []
self.output_file = None
self.interval = 10
self.record_window = None
async def _check_pause(self):
if self.state == PAUSING:
self.state = PAUSED
record_window["record_status"].update("Paused.")
self.record_window["record_status"].update("Paused.")
while not self.state == RESUMING and not self.state == STOPPING:
await asyncio.sleep(0.1)
record_window["record_status"].update("Recording...")
self.record_window["record_status"].update("Recording...")
async def _record_loop(self):
while True:
@@ -58,36 +59,39 @@ class RecordingManager(metaclass=Singleton):
await asyncio.sleep(0.1)
self.state = DONE
record_window["record_status"].update("Writing to file...")
await self.write_output()
record_window["record_status"].update("")
self.record_window["record_status"].update(
"Writing to file (this could take a minute)..."
)
await asyncio.sleep(0.5)
await asyncio.create_task(self.write_output())
self.record_window["record_status"].update("")
async def write_output(self):
from pprint import pprint
await generate_pdf(self.data, self.output_file)
pprint(self.data)
async def record(self, ips: List[str], output_file: str, interval: int = 10):
async def record(
self, ips: List[str], output_file: str, record_window, interval: int = 10
):
self.record_window = record_window
for ip in ips:
self.data[ip] = []
self.output_file = output_file
self.interval = interval
self.state = RECORDING
record_window["record_status"].update("Recording...")
self.record_window["record_status"].update("Recording...")
async for miner in MinerFactory().get_miner_generator(ips):
self.miners.append(miner)
print(miner)
asyncio.create_task(self._record_loop())
async def pause(self):
self.state = PAUSING
record_window["record_status"].update("Pausing...")
self.record_window["record_status"].update("Pausing...")
async def resume(self):
self.state = RESUMING
record_window["record_status"].update("Resuming...")
self.record_window["record_status"].update("Resuming...")
async def stop(self):
self.state = STOPPING
record_window["record_status"].update("Stopping...")
self.record_window["record_status"].update("Stopping...")