def get_alive_device_n() -> str: devices: list[db.Device] = db.select_devices() return str( sum( dt.datetime.now(tz=dt.timezone(offset=dt.timedelta(hours=9))) - device.last_heartbeat_timestamp < dt.timedelta(hours=24) for device in devices ) )
def json_last_signal_ts() -> JSONResponse: devices: list[Device] = db.select_devices() devices = [device.dict() for device in devices] for device in devices: device['last_heartbeat_timestamp'] = str( device['last_heartbeat_timestamp']) retval = { 'devices': devices, 'heartbeat_log': db.select_heartbeat_log_summation(), } return JSONResponse(jsonable_encoder(retval))
def get_device_name_randomly() -> str: devices = db.select_devices() if len(devices) == 0: return '' return random.choice(devices).device_name
def get_device_n() -> str: return str(len(db.select_devices()))
def get_available_device_n() -> str: devices: list[db.Device] = db.select_devices() return str( sum(device.is_active for device in devices) )