Beispiel #1
0
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
        )
    )
Beispiel #2
0
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))
Beispiel #3
0
def get_device_name_randomly() -> str:
    devices = db.select_devices()
    if len(devices) == 0:
        return ''
    return random.choice(devices).device_name
Beispiel #4
0
def get_device_n() -> str:
    return str(len(db.select_devices()))
Beispiel #5
0
def get_available_device_n() -> str:
    devices: list[db.Device] = db.select_devices()
    return str(
        sum(device.is_active for device in devices)
    )