Exemplo n.º 1
0
    def drop_users_tasks(self):
        """
		Function clean all tasks which set in [users]
		and add `remain_points` to the data
		---------------------------
        {
            "tasks": {
                "First task": {
                    "points": 45
                }
            },
            "users": {
                "John": {
                    "points": 0,
                    "efficiency": 0,
                    "tasks": {},
                    "remain_points", 0
                }
            }
        }
        ---------------------------
		:return: None
		"""

        users = self.data['users']

        for name in users:
            users[name]['tasks'].clear()
            self.remain_points = {'remain_points': users[name]['points']}
            users[name].update(self.remain_points)
        logger.debug('Old user tasks was successfully dropped.')
Exemplo n.º 2
0
    def _set_max_users_point(self):
        """
		Set maximum task point

		:return: None
		"""
        self.max_users_point = self.users[0][1]
        logger.debug('Maximum user points: %d', self.max_users_point)
Exemplo n.º 3
0
    def _set_users_number(self):
        """
		Count number of users and set to `users_number`

		:return: None
		"""
        self.users_number = len(self.users)
        logger.debug('Users number: %d', self.users_number)
Exemplo n.º 4
0
    def set_users_efficiency(self, user, eff):
        """
        Sets to global json data an efficiency work of user tasks.

        :param user: str -> user nickname
        :param eff: int -> % of efficiency work
        :return None
        """
        self.data['users'][user]['efficiency'] = eff
        logger.debug('The efficiency of work user %s is established.' % user)
Exemplo n.º 5
0
    def remain_usr_points(self):
        """
		This functions adding to the list of users `remain_points`
		--------------------------------------------------
		Ex. [User_name, point, remain_point]
		--------------------------------------------------
		:return: None
		"""
        for n in self.users:
            n.append(self.data['users'][n[0]]['remain_points'])
        logger.debug('`remain_point` was successfully added to users list.')
Exemplo n.º 6
0
    def _set_max_remain_user_point(self):
        """
		Function find and set maximum of remain points of users
		It's need for exit from while loop in `task_allocator`
		--------------------------------------------------
		Ex. [User_name, point, remain_point]
		`self.max_remain_user_point` -> remain_point
		--------------------------------------------------
		:return: None
		"""
        self.max_remain_user_point = max(self.users, key=lambda x: x[2])[2]
        logger.debug('Maximum of remain points of users: %d',
                     self.max_remain_user_point)
Exemplo n.º 7
0
 def test_set_logging(self):
     """
     Testing the correct configs of logging file, if it was given.
     """
     set_logging(LOG_FILENAME)
     # check for created file
     self.assertTrue(
         os.path.exists(os.path.join(self.abs_dir_path, LOG_FILENAME)))
     # check logging into `LOG_FILENAME`
     logger.debug('test_set_logging message')
     with open(LOG_FILENAME) as fp:
         self.assertTrue(
             fp.readlines()[-1],
             '2018-03-01 18:21:51,760 -> DEBUG :  test_set_logging message')
Exemplo n.º 8
0
    def _set_initial_config(self):
        """
		Function set initial configuration

		:return: None
		"""
        self._set_users_number()
        self._set_tasks_number()
        self._set_min_task_point()
        self._set_max_users_point()

        logger.debug('Tasks number: %d', self.tasks_number)
        logger.debug('Minimum points of tasks: %d', self.min_task_point)
        # Set max remain user points equal max users point
        self.max_remain_user_point = self.max_users_point
Exemplo n.º 9
0
def check_input_file():
    """
    If file exists, function will skip.
    Otherwise, creates empty file with `INPUT_FILENAME` value and add
    empty json data.

    :return: None
    """
    if os.path.exists('sb_info.json'):
        logger.debug('Input file `%s` exists.', consts.INPUT_FILENAME)
        return False

    # will create file if it doesn't exist.
    with open(consts.INPUT_FILENAME, 'w') as fp:
        # adds to file empty tasks and users data with pretty intend in file
        json.dump(
            {'tasks': {}, 'users': {}}, fp, indent=True
        )
    logger.debug('Input file `%s` created.', consts.INPUT_FILENAME)
    return True