Beispiel #1
0
    def __validate_from_and_to_date_ms(
            cls, from_date_ms: int, to_date_ms: int):
        if from_date_ms > to_date_ms:
            raise ApplicationException(
                f'from_date_ms [{from_date_ms}] should not be'
                f' higher from to_date_ms [{to_date_ms}]')

        if from_date_ms < 0:
            raise ApplicationException(
                f'from_date_ms [{from_date_ms}] cannot be negative')
Beispiel #2
0
 def instance(cls):
     if ApplicationLogger.__instance is None:
         raise ApplicationException(f'Bug: {cls.__name__} was not initiated'
                                    ' so cannot get active instance.\n'
                                    'Constructor should be run one time'
                                    ' before calling to instance()')
     return ApplicationLogger.__instance
Beispiel #3
0
    def add_frame_grid(
            self,
            name: str,
            frame_position: FrameGridPositionEnum,
            width: int = None,
            height: int = None,
            column_weight: int = 0,
            row_weight: int = 0,
            padx: int = None,
            pady: int = None,
            row: int = None,
            column: int = None,
            sticky: GridPositionEnum = GridPositionEnum.NONE) -> FrameAndName:

        if frame_position != FrameGridPositionEnum.CUSTOM_POSITION:
            if self.__is_custom_grid:
                raise ApplicationException(
                    'Bug: [frame_position] must be CUSTOM_POSITION'
                    ' because it was in that state previously'
                    f'but its value is [{frame_position.name}]')
        logger().debug(f'Add frame_and_name [{name}] in'
                       f' parent frame_and_name [{self.__frame_and_name.name}]'
                       f' in position [{frame_position.name}]')
        return FrameAndName(
            self.__create_frame_grid(frame_position,
                                     width=width,
                                     height=height,
                                     column_weight=column_weight,
                                     row_weight=row_weight,
                                     padx=padx,
                                     pady=pady,
                                     row=row,
                                     column=column,
                                     sticky=sticky), name)
Beispiel #4
0
    def __init__(self, collection_name: str = None):
        if self.db is None:
            raise ApplicationException(
                'set_db should run first to set Database')

        if collection_name:
            self.__collection = self.db[collection_name]
            self.__collection_name = collection_name
Beispiel #5
0
    def __get_uri_username_and_password(cls, db_username: str,
                                        db_password: str):
        if (db_username and not db_password) \
                or (db_password and not db_username):
            raise ApplicationException(
                f'Both Username [{db_username}] and Password [{db_password}]'
                ' must be with values, or both of them must be None')

        if db_username and db_password:
            return db_username + ':' + db_password + '@'

        return ''
Beispiel #6
0
    def update(self, value: DecimalNumber, date_ms: int):
        if not self.is_exist(date_ms):
            raise ApplicationException(
                f'History in [{date_ms}] not exist'
                f' in collection {self.collection_name}')

        filter = \
            {ValueHistory.DATE_MS: {MongoDbModifierEnum.EQ.value: date_ms}}
        value_history = ValueHistory.build(value, date_ms)
        update = {'$set': value_history.document}

        self.collection.update_one(
            filter=filter, update=update)
    def average(cls, numbers: list, weights: list) -> DecimalNumber:
        MathUtil.__verify_all_list_are_numbers(numbers)
        MathUtil.__verify_all_list_are_numbers(weights)

        if len(numbers) != len(weights):
            raise ApplicationException(
                f'Numbers list len [{len(numbers)}]'
                f' is different from weights list len [{len(weights)}]')
        numbers_weighted = DecimalNumber(0)

        for i in range(len(numbers)):
            numbers_weighted += numbers[i] * weights[i]

        return numbers_weighted / DecimalNumber(sum(weights))
Beispiel #8
0
    def add(self, value: DecimalNumber, date_ms: int):
        """
        Add history document that not exist.

        :param value: Value.
        :param date_ms: Date in ms.
        :return:
        """

        if self.is_exist(date_ms):
            raise ApplicationException(
                f'History in date ms [{date_ms}] already exist'
                f' in collection {self.collection_name}')
        value_history = ValueHistory.build(value, date_ms)
        self.collection.insert_one(value_history.document)
Beispiel #9
0
    def _add_frame_to_parent_frame_grid(
            self,
            name: str,
            parent_frame_name: str,
            frame_position: FrameGridPositionEnum,
            width: int = None,
            height: int = None,
            column_weight: int = 0,
            row_weight: int = 0,
            padx: int = None,
            pady: int = None,
            row: int = None,
            column: int = None,
            sticky: GridPositionEnum = GridPositionEnum.NONE,
            is_add_to_parent_frames_dict: bool = True) -> FrameAndName:
        if not self._parent_frames_dict.get(parent_frame_name):
            raise ApplicationException(
                'Bug: Cannot add frame_and_name because'
                f' parent frame_and_name [{parent_frame_name}] not exists')

        frame_organizer = self._parent_frames_dict[parent_frame_name]

        frame = frame_organizer.\
            add_frame_grid(
                name,
                frame_position,
                width=width,
                height=height,
                column_weight=column_weight,
                row_weight=row_weight,
                padx=padx,
                pady=pady,
                row=row,
                column=column,
                sticky=sticky)

        if is_add_to_parent_frames_dict:
            if frame_position != FrameGridPositionEnum.CUSTOM_POSITION:
                row = frame_organizer.row
                column = frame_organizer.column

            self._add_to_parent_frames_dict(frame.frame,
                                            name,
                                            row=row,
                                            column=column)

        return frame
Beispiel #10
0
    def __create_frame_grid(
            self,
            frame_position: FrameGridPositionEnum,
            width: int = None,
            height: int = None,
            column_weight: int = 0,
            row_weight: int = 0,
            padx: int = None,
            pady: int = None,
            row: int = None,
            column: int = None,
            sticky: GridPositionEnum = GridPositionEnum.NONE) -> Frame:
        if frame_position == FrameGridPositionEnum.CUSTOM_POSITION \
                and (row is None or column is None):
            raise ApplicationException(
                'Bug: row and column parameters must have values'
                ' when frame_position is CUSTOM_POSITION')

        frame = Frame(self.__frame_and_name.frame)
        self.update_row_and_column(frame_position)

        if frame_position != FrameGridPositionEnum.CUSTOM_POSITION:
            row = self.__row
            column = self.__column

        logger().debug(
            f'Create new frame_and_name. Parent [{self.__frame_and_name.name}]'
            f' Row [{row}] Column [{column}]'
            f' Sticky [{sticky.value}]')

        frame.rowconfigure(row, weight=row_weight)
        frame.columnconfigure(column, weight=column_weight)

        frame.grid(row=row,
                   column=column,
                   padx=padx,
                   pady=pady,
                   sticky=sticky.value)

        if width:
            frame.config(width=width)

        if height:
            frame.config(height=height)

        return frame
Beispiel #11
0
    def _add_to_parent_frames_dict(self,
                                   parent_frame: Frame,
                                   name: str,
                                   row: int = -1,
                                   column: int = -1):
        """
        Add frame_and_name to be in _parent_frames_dict

        :param parent_frame: Frame object.
        :param name: Frame name.
        :param row:
        :param column:
        :return:
        """

        if name in self._parent_frames_dict:
            raise ApplicationException(
                f'Bug: Parent frame_and_name [{name}] already exists')

        self._parent_frames_dict[name] = \
            FramesOrganizer(parent_frame, name, row, column)
 def __verify_all_list_are_numbers(cls, numbers: list):
     if not NumbersUtil.is_all_numbers(numbers):
         raise ApplicationException(
             f'Not all numbers in list [{numbers}] are numbers.')
Beispiel #13
0
 def __validate_logger_not_closed(self):
     if self.is_logger_closed:
         raise ApplicationException('Logger is closed')
Beispiel #14
0
 def __init__(self):
     raise ApplicationException(
         'Bug: Use GuiAttributesUpdateAfterDelay.update')