Commit 0d6e57d1 authored by Hines, Jesse's avatar Hines, Jesse
Browse files

Add helpers to get node and cdu names to dataloaders

Some fixes to the node_index_to_name functions, and add functions to the
dataloaders to get CDU names and row/col. Also add functions to
Telemetry to call these dataloader functions.
parent 62b853c3
Loading
Loading
Loading
Loading
+19 −1
Original line number Diff line number Diff line
@@ -170,7 +170,7 @@ def xname_to_index(xname: str, config: dict):
    return rack_index * config['SC_SHAPE'][2] + node_index


def index_to_name(index: int, config: dict):
def node_index_to_name(index: int, config: dict):
    """
    Converts an index value back to an xname string based on system configuration.

@@ -198,3 +198,21 @@ def index_to_name(index: int, config: dict):
    node = remaining % config['NODES_PER_BLADE']

    return f"x2{row}{col:02}c{chassis}s{slot}b{node}"


CDU_NAMES = [
    'x2002c1', 'x2003c1', 'x2006c1', 'x2009c1', 'x2102c1', 'x2103c1', 'x2106c1', 'x2109c1',
    'x2202c1', 'x2203c1', 'x2206c1', 'x2209c1', 'x2302c1', 'x2303c1', 'x2306c1', 'x2309c1',
    'x2402c1', 'x2403c1', 'x2406c1', 'x2409c1', 'x2502c1', 'x2503c1', 'x2506c1', 'x2509c1',
    'x2609c1',
]

def cdu_index_to_name(index: int, config: dict):
    return CDU_NAMES[index - 1]


def cdu_pos(index: int, config: dict) -> tuple[int, int]:
    """ Return (row, col) tuple for a cdu index """
    name = CDU_NAMES[index - 1]
    row, col = int(name[2]), int(name[3:5])
    return (row, col)
+11 −2
Original line number Diff line number Diff line
@@ -110,6 +110,15 @@ def load_data_from_df(df, **kwargs):
    return job_list


def index_to_name(index: int, config: dict):
def node_index_to_name(index: int, config: dict):
    """ Converts an index value back to an name string based on system configuration. """
    return f"node{index:.04d}"
    return f"node{index:04d}"


def cdu_index_to_name(index: int, config: dict):
    return f"cdu{index:02d}"


def cdu_pos(index: int, config: dict) -> tuple[int, int]:
    """ Return (row, col) tuple for a cdu index """
    return (0, index) # TODO
+11 −2
Original line number Diff line number Diff line
@@ -210,9 +210,18 @@ def generate_network_sequences(total_tx, total_rx, intervals, lambda_poisson):
    return tx_bursts, rx_bursts


def index_to_name(index: int, config: dict):
def node_index_to_name(index: int, config: dict):
    """ Converts an index value back to an name string based on system configuration. """
    return f"node{index:.04d}"
    return f"node{index:04d}"


def cdu_index_to_name(index: int, config: dict):
    return f"cdu{index:02d}"


def cdu_pos(index: int, config: dict) -> tuple[int, int]:
    """ Return (row, col) tuple for a cdu index """
    return (0, index) # TODO


if __name__ == "__main__":
+11 −2
Original line number Diff line number Diff line
@@ -156,6 +156,15 @@ def load_data_from_df(jobs_df: pd.DataFrame, **kwargs):
    return jobs


def index_to_name(index: int, config: dict):
def node_index_to_name(index: int, config: dict):
    """ Converts an index value back to an name string based on system configuration. """
    return f"node{index:.04d}"
    return f"node{index:04d}"


def cdu_index_to_name(index: int, config: dict):
    return f"cdu{index:02d}"


def cdu_pos(index: int, config: dict) -> tuple[int, int]:
    """ Return (row, col) tuple for a cdu index """
    return (0, index) # TODO
+22 −7
Original line number Diff line number Diff line
@@ -39,7 +39,8 @@ class Telemetry:
    def __init__(self, **kwargs):
        self.kwargs = kwargs
        self.system = kwargs.get('system')
        config = kwargs.get('config')
        self.config = kwargs.get('config')
        self.dataloader = importlib.import_module(f".dataloaders.{self.system}", package = __package__)


    def save_snapshot(self, jobs: list, filename: str):
@@ -55,20 +56,34 @@ class Telemetry:

    def load_data(self, files):
        """Load telemetry data using custom data loaders."""
        module = importlib.import_module(f".dataloaders.{self.system}", package=__package__)
        return module.load_data(files, **self.kwargs)
        return self.dataloader.load_data(files, **self.kwargs)


    def load_data_from_df(self, *args, **kwargs):
        """Load telemetry data using custom data loaders."""
        module = importlib.import_module(f".dataloaders.{self.system}", package=__package__)
        return module.load_data_from_df(*args, **kwargs)
        return self.dataloader.load_data_from_df(*args, **kwargs)


    def node_index_to_name(self, index: int):
        """ Convert node index into a name"""
        return self.dataloader.node_index_to_name(index, config = self.config)


    def cdu_index_to_name(self, index: int):
        """ Convert cdu index into a name"""
        return self.dataloader.cdu_index_to_name(index, config = self.config)

    
    def cdu_pos(self, index: int) -> tuple[int, int]:
        """ Return (row, col) tuple for a cdu index """
        return self.dataloader.cdu_pos(index, config = self.config)


if __name__ == "__main__":

    args_dict = vars(args)
    args_dict['config'] = ConfigManager(system_name=args.system).get_config()
    config = ConfigManager(system_name=args.system).get_config()
    args_dict['config'] = config
    td = Telemetry(**args_dict)
    JOB_ARRIVAL_TIME = 900