def __getSelectedDataItems(self) -> List[List[Any]]:
        """Returns the items based on the selected Spreadsheet cells."""

        selectedCells: List[Tuple[int, int]] = list(sorted(self.__spreadsheet.selectedCells(), key=lambda cell: cell[1]))

        if len(selectedCells) == 0:
            return list()

        columns: List[List[Any]] = list()

        currentColumn: int = selectedCells[0][1]
        column: List[Any] = list()
        for cell in selectedCells:
            if cell[1] > currentColumn:
                currentColumn = cell[1]
                columns.append(column)
                column = list()

            item: Any = self.__spreadsheet.cell(cell[0], cell[1])
            num: float = tryConvertToFloat(item)
            if isNumber(num):
                column.append(num)

        columns.append(column)

        return columns
Example #2
0
    def __sortAndReduceToNumbers(self) -> tuple:
        meta = self._metaData
        reassignMeta = True

        if not self._metaData:
            reassignMeta = False
            meta = ["" for i in range(len(self.__xValues))]

        tuples = zip(self.__xValues, self.__yValues, meta)
        numbersOnly = filter(lambda x: isNumber(x[0]) or isNumber(x[1]), tuples)
        self.__xValues, self.__yValues, meta = list(zip(*sorted(numbersOnly)))

        if reassignMeta:
            self._metaData = meta

        return self.__xValues, self.__yValues, self._metaData
    def __tryDeterminingHeaderForCoordinate(self, coordinate: str) -> str:
        """Tries to determine the header for a column. If first row is not a number assumes it is a column header."""

        for cell in self.__selectedCells[coordinate]:
            isFirstRow: bool = cell[0] == 0
            cellContent: Any = self.__spreadsheet.cell(cell[0], cell[1])
            if isFirstRow:
                if not isNumber(cellContent):
                    return str(cellContent)
                return ""
    def __getSelectedItemsForCoordinate(self, coordinate: str) -> List[Number]:
        """Returns the items for the given coordinate based on the selected Spreadsheet cells."""

        items: List = list()
        for cell in self.__selectedCells[coordinate]:
            item: Any = self.__spreadsheet.cell(cell[0], cell[1])
            if coordinate == "meta":
                items.append(str(item))
                continue

            num: float = tryConvertToFloat(item)
            if isNumber(num):
                items.append(num)
            else:
                items.append(str(item))

        return items
Example #5
0
 def __assertAllEntriesAreNumbers(self, collection: Iterable):
     for item in collection:
         if not isNumber(item):
             raise NonNumberInPlotConfigError()