def initialize(self) -> None: """ Initializes the DataGrid. Iterates over all rows and columns, preparing cell structures. Cells then contain a graph and data queries to leaf processors. Upon providing data to a leaf, the leaf processor is calculated and propagated up the graph to the cell level. """ all_queries: List[DataQueryInfo] = [] entity_cells: List[DataCell] = [] current_row_group = None # Loop over rows, columns for row_index, row in enumerate(self.rows): if isinstance(row, RowSeparator): current_row_group = row.name continue entity: Entity = row.entity cells: List[DataCell] = [] row_overrides = row.overrides for column_index, column in enumerate(self.columns): column_name = column.name column_processor = column.processor # Get all the data coordinate overrides and apply the processor override if it exists data_overrides = _get_overrides(row_overrides, column_name, column) # Create the cell cell: DataCell = DataCell(column_name, column_processor, entity, data_overrides, column_index, row_index, current_row_group) # treat data cells different to entity if isinstance(column_processor, EntityProcessor): # store these cells to fetch entity data during poll entity_cells.append(cell) if isinstance(column_processor, CoordinateProcessor): # store these cells to fetch entity data during poll if len(data_overrides): # Get the last in the list if more than 1 override is given cell.processor.children['a'].set_dimensions( data_overrides[-1].dimensions) self._coord_processor_cells.append(cell) else: # append the required queries to the map cell.build_cell_graph(all_queries) cells.append(cell) self._cells.extend(cells) self.results.append(cells) self._data_queries = all_queries self._entity_cells = entity_cells self.is_initialized = True
def get_test_datagrid(self): spx, aapl, amzn = self.get_test_entities() datagrid = DataGrid('Test DataGrid', rows=[], columns=[DataColumn('Name', None), DataColumn('Value', None)]) results = [ [DataCell('Name', None, None, None, 0, 0), DataCell('Value', None, None, None, 1, 0)], [DataCell('Name', None, None, None, 0, 1), DataCell('Value', None, None, None, 1, 1)], [DataCell('Name', None, None, None, 0, 2), DataCell('Value', None, None, None, 1, 2)], ] results[0][0].value = ProcessorResult(True, spx.name) results[0][1].value = ProcessorResult(True, np.float64(10)) results[1][0].value = ProcessorResult(True, aapl.name) results[1][1].value = ProcessorResult(True, np.float64(0)) results[2][0].value = ProcessorResult(True, amzn.name) results[2][1].value = ProcessorResult(True, np.float64(-10)) datagrid.results = results return datagrid
def initialize(self) -> None: """ Initializes the DataGrid. Iterates over all rows and columns, preparing cell structures. Cells then contain a graph and data queries to leaf processors. Upon providing data to a leaf, the leaf processor is calculated and propagated up the graph to the cell level. """ all_queries: List[Union[DataQueryInfo, MeasureQueryInfo]] = [] entity_cells: List[DataCell] = [] current_row_group = None # Loop over rows, columns for row_index, row in enumerate(self.rows): if isinstance(row, RowSeparator): current_row_group = row.name continue entity: Entity = row.entity if isinstance(entity, Entity): self.entity_map[entity.get_marquee_id()] = entity else: self.entity_map[''] = entity cells: List[DataCell] = [] row_overrides = row.overrides for column_index, column in enumerate(self.columns): column_name = column.name column_processor = column.processor # Get all the data coordinate overrides and apply the processor override if it exists data_overrides, value_override, processor_override = _get_overrides(row_overrides, column_name) # Create the cell cell: DataCell = DataCell(column_name, column_processor, entity, data_overrides, column_index, row_index, current_row_group) if processor_override: # Check if there is a processor override and apply if so cell.processor = processor_override if value_override: cell.value = ProcessorResult(True, value_override.value) cell.updated_time = get_utc_now() elif isinstance(column_processor, EntityProcessor): # store these cells to fetch entity data during poll entity_cells.append(cell) elif isinstance(column_processor, CoordinateProcessor): # store these cells to fetch entity data during poll if len(data_overrides): # Get the last in the list if more than 1 override is given cell.processor.children['a'].set_dimensions(data_overrides[-1].dimensions) self._coord_processor_cells.append(cell) elif column_processor.measure_processor: all_queries.append(MeasureQueryInfo(attr='', entity=entity, processor=column_processor)) else: # append the required queries to the map cell.build_cell_graph(all_queries, self.rdate_entity_map) cells.append(cell) self._cells.extend(cells) self.results.append(cells) self._data_queries = all_queries self._entity_cells = entity_cells self.is_initialized = True