def _init_cst_instances_by_app(self): for idx, app in enumerate(self.app_list): if config.app_to_cst_dict[idx] == 'Deadline': self.csts.append(Deadline(self.app_list, app, self.pe_list)) elif config.app_to_cst_dict[idx] == 'None': self.csts.append(None) app.set_cst(self.csts[-1])
def load_deadline(self): """ This function is to load deadline object data form storage. :return: deadline object list. """ data_deadline = [] data_file = open(self.storage) deliveries_reader = csv.reader(data_file) for row in deliveries_reader: if row[0] == 'D': data_deadline.append(Deadline(row[1], True if row[2] == 'done' else False, row[3])) data_file.close() return data_deadline
def _apply_deadline_cst(self, mapping): csts = [] PE.init_apps_pe_by_mapping(self.app_list, mapping, self.pe_list) for idx, app in enumerate(self.app_list): if config.app_to_cst_dict[idx] == 'Deadline': csts.append(Deadline(self.app_list, app, self.pe_list)) # if there is deadline constraint for idx, cst in enumerate(csts): penalty = cst.constraint_function(mapping)[0] if penalty != 0: self._one_bit_flip_local_optimization(mapping, penalty, cst) return False return True
def load_tasks(self): """ This function is to lead task list date from storage. :return: task object list. """ data_task = [] data_file = open(self.storage) deliveries_reader = csv.reader(data_file) for row in deliveries_reader: if row[0] == 'T': data_task.append(ToDo(row[1], True if row[2] == 'done' else False)) elif row[0] == 'D': data_task.append(Deadline(row[1], True if row[2] == 'done' else False, row[3])) elif row[0] == 'TL': data_task.append(TimeLine(row[1], True if row[2] == 'done' else False, row[3], row[4])) data_file.close() return data_task
def get_current_progress(self): """ Obtains progress of current session, ie. how many ToDos and Deadlines tasks marked as done. Tasks marked pending after being marked done will be taken into account. Returns ------- Progress for this session. """ status = {'Todo': 0, 'Deadline': 0} status['Todo'] = td.progress_check() status['Deadline'] = dl.progress_check() return ("""Progress for this session: | ToDos: {} | Deadlines: {} |""".format(status['Todo'], status['Deadline']))
from food import Food import random from score_board import Score from deadline import Deadline screen = Screen() score = Score() screen.bgcolor("black") screen.setup(600, 600) screen.title("Snake and Food") screen.tracer(0) screen.listen() deadline = Deadline() snake = Snake() food = Food() def start_game(): is_on = True while is_on: screen.update() time.sleep(0.08) snake.move() if snake.head.distance(food) <= 15: food.refresh()
def execute_command(self, command): """ This function is to execute the command entered Do pre processing before call the execution function is need :param command: Command entered :return: value form execute function """ if command == 'exit': sys.exit() elif command.startswith('todo '): if self.current_user_level >= 2: """Team leader and above is access to add task""" description = command.split(' ', 1)[1] return self.project.add_task(ToDo(description, False)) else: raise ValueError('Team leader or above only can add task') elif command.startswith('deadline '): if self.current_user_level >= 2: """Team leader and above is access to add task""" command_part = command.split(' ', 1)[1] description = self.remove_from_word(command_part, 'by') by = self.remove_to_word(command_part, 'by') return self.project.add_task(Deadline(description, False, by)) else: raise ValueError('Team leader or above only can add task') elif command.startswith('timeline '): if self.current_user_level >= 2: """Team leader and above is access to add task""" command_part = command.split(' ', 1)[1] description = self.remove_from_word(command_part, 'from') date = self.remove_to_word(command_part, 'from') start_date = self.remove_from_word(date, 'to') end_date = self.remove_to_word(date, 'to') return self.project.add_task( TimeLine(description, False, start_date, end_date)) else: raise ValueError('Team leader or above only can add task') elif command.startswith('done '): if self.current_user_level >= 2: """Team leader and above is access to update task""" user_index = command.split(' ', 1)[1] index = int(user_index) - 1 if index < 0: raise Exception('Index must be grater then 0') else: try: self.project.tasks[index].mark_as_done() return 'Congrats on completing a task ! :-)' except Exception: raise Exception('No item at index ' + str(index + 1)) else: raise ValueError('Team leader or above only can add task') elif command.startswith('pending '): if self.current_user_level >= 2: """Team leader and above is access to update task""" user_index = command.split(' ', 1)[1] index = int(user_index) - 1 if index < 0: raise Exception('Index must be grater than 0') else: try: self.project.tasks[index].mark_as_pending() return 'Task mark as pending' except Exception: raise Exception('No item at index' + str(index + 1)) else: raise ValueError('Team leader or above only can add task') elif command.startswith('resource '): if self.current_user_level >= 2: """Team leader and above is access to add resource""" command_part = command.split(' ', 1)[1] description = self.remove_from_word(command_part, 'is') quantity = self.remove_to_word(command_part, 'is') return self.project.add_resources( Resource(description, quantity)) else: raise ValueError('Team leader or above only can add task') elif command.startswith('cost of '): if self.current_user_level >= 3: """Manager and above is access to add cost""" command_part = command.split(' ', 2)[2] description = self.remove_from_word(command_part, 'is') cost = self.remove_to_word(command_part, 'is') return self.project.add_cost(Cost(description, cost)) else: raise ValueError('Manager and above only can add cost') elif command.startswith('remove '): try: command_part = command.split(' ', 2)[1] command_index = command.split(' ', 2)[2] index = int(command_index) - 1 if command_part == 'task': if self.current_user_level >= 2: """Team leader and above to access to remove task""" return self.project.remove_task(index) else: raise ValueError( 'Team leader and above only can remove task') elif command_part == 'resource': if self.current_user_level >= 2: """Team Leader and above to access to remove resource""" return self.project.remove_resource(index) else: raise ValueError( 'Team leader and above only can remove resource') elif command_part == 'cost': if self.current_user_level >= 3: """Manager and above to access to remove cost""" return self.project.remove_cost(index) else: raise ValueError('Manager adn above only remove cost') except Exception: raise ValueError( 'Command format not recognize.\n Command: >>> remove [task/resource/cost] [index]' ) else: logging.error('Command not recognized.') raise Exception('Command not recognized')