<reponame>yinfredyue/flower
""" Chaos class for testing SSP implementation """

import time
import random
from random import randint

from logging import DEBUG, INFO
from flwr.common.logger import log

def random_delay(min: int = 1, max: int = 10) -> None:
    """ Delay for a random period of time. """
    if max > 0:
        duration = randint(min, max)
        log(INFO, "Delay %d sec", duration)
        time.sleep(duration)

def fixed_delay(duration: int) -> None:
    """ Delay for a fixed number of seconds. """
    log(INFO, "Delay %d sec", duration)
    time.sleep(duration)


def is_straggler(client_id: int, num_clients: int, straggler_fraction: float) -> bool:
    random.seed(0)
    num_stragglers = int(num_clients * straggler_fraction)
    stragglers = random.choices(range(num_clients), k=num_stragglers)
    if client_id in stragglers:
        return True
    else:
        return False

""" Chaos class for testing SSP implementation """

import time
import random
from random import randint

from logging import DEBUG, INFO
from flwr.common.logger import log

def random_delay(min: int = 1, max: int = 10) -> None:
    """ Delay for a random period of time. """
    if max > 0:
        duration = randint(min, max)
        log(INFO, "Delay %d sec", duration)
        time.sleep(duration)

def fixed_delay(duration: int) -> None:
    """ Delay for a fixed number of seconds. """
    log(INFO, "Delay %d sec", duration)
    time.sleep(duration)


def is_straggler(client_id: int, num_clients: int, straggler_fraction: float) -> bool:
    random.seed(0)
    num_stragglers = int(num_clients * straggler_fraction)
    stragglers = random.choices(range(num_clients), k=num_stragglers)
    if client_id in stragglers:
        return True
    else:
        return False
Chaos class for testing SSP implementation Delay for a random period of time. Delay for a fixed number of seconds.