def appendTask(self, analyst, title: str, description: str, priority: Priority, progress: Progress, dueDate: datetime, associationToTask: list, analystAssignment: list, collaboratorAssignment: list, archiveStatus: bool, associationToSystem, attachment: list = [], parentId=-1, id=-1): new_task = Task(title=title, description=description, priority=priority, progress=progress, dueDate=dueDate, associationToTask=associationToTask, analystAssignment=analystAssignment, collaboratorAssignment=collaboratorAssignment, archiveStatus=archiveStatus, attachment=attachment, parentId=parentId, associationToSystem=associationToSystem, id=id) new_task.setId(self.__updateTask(analyst=analyst, task=new_task)) self.__task.append(new_task) return
def main(): presenter = PresentationClass(screen_size=SCRParams.screen_size) subject_info = presenter.present_info_box() SubjectParams.set_subject_info(subject_info) TaskParams.set_subject_data_dir(SubjectParams.subject_id) Task.initialize() Dumper.save_params(TaskParams.data_dir, '{}-params'.format(SubjectParams.subject_id)) presenter.present_instructions('start-training') Trainer.start_training(presenter) Dumper.save_training_data(TaskParams.data_dir, '{}-training'.format(SubjectParams.subject_id)) Dumper.save_quiz_phase1_data( TaskParams.data_dir, '{}-quiz-phase1'.format(SubjectParams.subject_id)) Dumper.save_quiz_phase2_data( TaskParams.data_dir, '{}-quiz-phase2'.format(SubjectParams.subject_id)) presenter.present_instructions('prediction-training') PredictionTrainer.start_training(presenter) Dumper.save_prediction_training_data( TaskParams.data_dir, '{}-prediction-training'.format(SubjectParams.subject_id)) presenter.present_instructions('phase1') Task.run_warm_up_block(presenter) Dumper.save_warmup_data(TaskParams.data_dir, '{}-warmup'.format(SubjectParams.subject_id)) presenter.present_instructions('start-task') Task.start_task(presenter) Dumper.save_phase_data(TaskParams.data_dir, '{}-task-phase1'.format(SubjectParams.subject_id)) presenter.present_rest() presenter.present_instructions('phase2') agent, agent_name = (MFAgent, 'MF') if random.random() < 0.5 else (MBAgent, 'MB') agent.initialize_trials() agent.start_agent_task(presenter) Dumper.save_phase_data(TaskParams.data_dir, '{}-task-phase2'.format(SubjectParams.subject_id), is_prediction=True, agent=agent_name) presenter.present_rest() presenter.present_instructions('phase3') Task.initialize(first_phase=False, phase=3) Task.start_task(presenter) Dumper.save_phase_data(TaskParams.data_dir, '{}-task-phase3'.format(SubjectParams.subject_id))
def create_action(self, data): if not data.has_key("target") or not data.has_key( "qps") or not data.has_key("query_path") or not data.has_key( "source") or not data.has_key( "query_type") or not data.has_key("option"): return json.dumps({ 'code': 'false', 'res': '', 'desc': 'lark of parameters: target, qps, query_path, source, query_type or option' }) query_path = data['query_path'] #query_path = Host.get_real_query(data['query_path']) #if "" == query_path: # return json.dumps({'code':'false','res':'','desc':'query not exist: %s' % data['query_path']}) logging.info("create a task") taskInfo = Task.create_task(data['target'].strip(), data['qps'], data['source'], query_path, data['query_type'], data['option'].strip()) dict = {} dict.update(taskInfo.__dict__) dict['taskid'] = taskInfo.task_id self.res['res'] = dict return json.dumps(self.res)
def init_compare(self, new_my_dir, target_dir): target_dir_tree = GlobalVariable.dir_tree[target_dir] #把自己和其它dir进行比较 for file in new_my_dir: #目标文件夹里没有此文件,新增 if not target_dir_tree.has_key(file): GlobalVariable.task_queue.put( Task(self.dir + file, target_dir + file, "add")) continue #确实被更新过,并且md5不相同的 if new_my_dir[file]['mtime'] > target_dir_tree[file]['mtime']: if md5(self.dir + file) != md5(target_dir + file): GlobalVariable.task_queue.put( Task(self.dir + file, target_dir + file, "modify")) continue
def submit(self, task_name: str, task_cfg: dict): """提交一个Task Args: task_name: task的名字,需要保证不重复,其会作为task的唯一标识符,建议传入视频或摄像头名称 task_cfg: task的数据字典 Returns: 返回是否返回值 """ # 如果超过了最多的提交数量限制 if len(self.tasks) >= TaskConfig.MAX_TASK_NUM: raise RuntimeError("超过了最多的提交数量限制".format(task_name)) if self.is_exist(task_name): raise RuntimeError("请勿重复提交task_name为{}的Task任务".format(task_name)) task = Task(task_cfg) task.build(timeout=20) self.tasks[task_name] = task
def run(self): while(True): self._lock.acquire() rand = randrange(1,20,1) print("running bluetooth thread ",rand) self._queue.put(Task("random task",rand)) self._lock.release() time.sleep(self._wait)
def set_subject(self, update: telegram.update, context): keyboard = [] for subject in Task.get_subjects_list(): keyboard.append( InlineKeyboardButton(subject, callback_data=(subject + '&'))) reply_markup = InlineKeyboardMarkup([keyboard]) context.bot.send_message(chat_id=update.effective_chat.id, text=CHOOSE_SUBJECT, reply_markup=reply_markup)
def updateTask(self, task: Task, analyst: Analyst): index = 0 while index < len(self.__task): if self.__task[index].getId() == task.getId(): self.__task[index] = task self.__updateDatabase(task=task, analyst=analyst) return index += 1
def stop_action(self, data): logging.info("stop a task") taskObj = Task.get_task(data['taskid']) taskObj.set_status('stop') return json.dumps({ 'code': 'true', 'res': '', 'desc': '' })
def task_search(owner): """Return list of Tasks wit specified owner.""" data = {"items": []} length = 0 data["table_name"] = "tasks_master" results = dynamo.tasks_master.query(owner__eq=owner, index='secondKeyIndex') for r in results: data["items"].append(dict(r.items())) t = Task("") t.from_dict(dict(r.items())) length += 1 data["items_length"] = length if length < 1: abort(404) return json.dumps(data, indent=4, cls=DecimalEncoder)
def change_action(self, data): logging.info("change task") try: taskObj = Task.get_task(data['taskid']) if taskObj == None: self.res['code'] = 1 return json.dumps(self.res) taskObj.set_qps(data['qps']) return json.dumps({'code': 'true', 'res': '', 'desc': ''}) except: return sys.exc_info()
def load(name): tasks = [] with open("tasks.txt") as file: for task in file: words = task.split() if str(words).find("#") != -1: break sp = words[0] name = ' '.join(words[1:]) tasks.append(Task(sp, name=name)) return tasks
def get_task_by_id(message): '''обновим в бд все server_task_id согласно полученному сообщению''' print('get task->', message) if message['body']['code'] == 200: creator = data['username'] name = message['body'].get('task name') description = message['body'].get('description') date_reminder = message['body'].get('date_reminder') time_reminder = message['body'].get('time_reminder') task = Task(name=name, creator=creator, viewer=creator) task.description = description task.date_reminder = date_reminder task.time_reminder = time_reminder task = task.task_dict # data['db'].add_task(task) else: print(message['body']['code'], message['body']['message']) put_message(message) release_queue()
def create_task(message): if message['body']['code'] == 201: creator = data['username'] server_task_id = message['body'].get('id') task_name = data['create_task']['body'].get('name') task_description = data['create_task']['body'].get('description') task_date_reminder = data['create_task']['body'].get('date_reminder') task_time_reminder = data['create_task']['body'].get('time_reminder') data.pop('create_task') task = Task(creator=creator, viewer=creator, name=task_name) task.date_reminder = task_date_reminder task.time_reminder = task_time_reminder task.description = task_description task.id = int(server_task_id) task = task.task_dict print('task->', task) data['db'].add_task(task) else: print(message['body']['code'], message['body']['message']) put_message(message) release_queue()
def get_all_tasks(message): '''обновим в бд все server_task_id согласно полученному сообщению''' print('get all tasks->', message) # da = data['db'].get_all_tasks() # notification(da) put_message(message) if message['body']['code'] == 200: for server_task_id, task_ in message['body']['message'].items(): task_id = data['db'].get_task_id_by_name(task_.get('name')) if task_id: data['db'].set_task_id(task_id, server_task_id) data['db'].change_date_reminder(task_id, task_.get('date_reminder')) data['db'].change_time_reminder(task_id, task_.get('time_reminder')) else: creator = data['username'] task = Task(creator=creator, viewer=creator, name=task_.get('name')) task.id = int(server_task_id) task.description = task_.get('description') task.date_reminder = task_.get('date_reminder') task.time_reminder = task_.get('time_reminder') task = task.task_dict print('task->', task) data['db'].add_task(task) da = data['db'].get_all_tasks() print('da', da) notification(da) release_queue()
def taskList_action(self, data): list = Task.get_all_task() result = [] for task in list: task_dict = task.__dict__ task_dict["agentList"] = [] for agent in task.get_all_agent(): agent_dict = agent.__dict__ agent_dict["heartbeat"] = agent.heartbeat() task_dict["agentList"].append(agent_dict) result.append(task_dict) self.res['res'] = result return json.dumps(self.res)
def convertDocument(document): return Task(title=document["title"], description=document["description"], priority= document["priority"], progress=Progress.getMember(document["progress"]), dueDate=document["dueDate"], attachment=document["attachment"], associationToTask=document["association"], analystAssignment=document["analyst_Assignment"], collaboratorAssignment=document["collaborator_Assignment"], archiveStatus=document["archive_status"], associationToSystem=document["system_Association"], parentId= document["parent_task"], id=document["_id"])
def queryTaskAgent_action(self, data): logging.info("query task agent") try: taskObj = Task.get_task(data['taskid']) if taskObj == None: return json.dumps({ 'code': 'false', 'res': '', 'desc': 'taskid not found' }) res = taskObj.get_all_agent() hosts = [] for agent in res: hosts.append(agent.__dict__) return json.dumps({'code': 'true', 'res': hosts, 'desc': ''}) except: return sys.exc_info()
def queryTask_action(self, data): logging.info("query task") try: taskObj = Task.get_task(data['taskid']) if taskObj == None: return json.dumps({ 'code': 'false', 'res': '', 'desc': 'taskid not found' }) return json.dumps({ 'code': 'true', 'res': taskObj.__dict__, 'desc': '' }) except: return sys.exc_info()
def task_create(): """Add new task to a list.""" task = Task(None) if request.method == "POST": content = request.get_json(silent=True) if not content: abort(400) task.from_dict(content) dynamo.tasks_master.put_item(data=task.as_dict()) return "Task ID: %s" % task.get_id()
def run(self, *args): dead_agents = [] task_list = Task.get_all_task() for taskObj in task_list: agent_list = taskObj.get_all_agent() for agentObj in agent_list: if not agentObj.heartbeat(): dead_agents.append(agentObj) if len(dead_agents) == 0: logging.debug("[Exit]CheckACPActiveAgents...success") return Success("CheckACPActiveAgents...success.") else: logging.debug("[Exit]CheckACPActiveAgents...failure") result = Failure(self.failureMessage(dead_agents)) info = {"dead_agents": dead_agents} result.info = info return result
def callback_query_handler(self, update, context): # Handles inline buttons pressing query: CallbackQuery = update.callback_query query.answer() user_id = query.from_user.id query_type, task_id = query.data.split('&') if query_type == 'Hint': context.bot.send_message( chat_id=user_id, text= f'Hint: {self.task_manager.get_hint(user_id, int(task_id))}') elif query_type == 'Solution': context.bot.send_message( chat_id=user_id, text= f'Solution: {self.task_manager.get_solution(user_id, int(task_id))}' ) elif query_type in Task.get_subjects_list(): self.task_manager.set_subject(user_id, query_type) context.bot.send_message(chat_id=user_id, text=f'Subject set to {query_type}')
#!/usr/bin/env python3 from task.task import Task from utils.parser import args if __name__ == "__main__": t = Task() if args.add: t.add(args.add, args.priority[0] if args.priority else "2") elif args.note: t.note(args.note) elif args.check: t.check(args.check) elif args.begin: t.begin(args.begin) elif args.remove: t.remove(args.remove) elif args.clear: t.clear() elif args.sort: t.sort_ids() else: t.show()
def read_info_from_task(mqs): try: while True: for mq in mqs: img_info = mq.get(timeout=5) except Empty: print('主进程结束') if __name__ == '__main__': # Linux平台启动 if platform.system() == 'Linux': mp.set_start_method('spawn', force=True) # 建模任务 args = parse_args() if not osp.exists(args.i): raise AttributeError('输入文件不存在') print('处理视频为{},保存环境模型到{},是否开启方向矫正:{}'.format(args.i, args.o, args.revise)) TaskCfg['head'][0]['filename'] = args.i TaskCfg['backbones'][0][1]['modelPath'] = args.o TaskCfg['backbones'][0][1]['revise'] = args.revise TaskCfg['backbones'][0][1]['dataNum'] = args.n task = Task(TaskCfg) mqs = task.build() task.start() readt = Thread(target=read_info_from_task, args=(mqs, )) readt.start() readt.join()
def is_given(self, task: Task): for it in self.given_tasks: if it.get_id() == task.get_id(): return True return False
def get_by_task(context: RuntimeContext, inp: list, opt: Task, result_set): for i in inp: if opt.execute(context, i, result_set): return i return None
def __getAllTasks(self): taskDocList = self.__database.getAllTasks() taskList = [] for document in taskDocList: taskList.append(Task.convertDocument(document)) return taskList
def __getTask(self, task): taskDoc = task.toDocument() return Task.convertDocument(self.__database.findTask(taskDoc))
def OnStartButton(self, evt): #self.test.addProcess(self.writer) task = Task(str(uuid.uuid4()), Task.__STATE_NEW__, "", "") print "add task = ", task.name self.tm.add_task(task)
import numpy import os from task.writetopwscf import varnameValue, atomic_positions from task.task import Task a_range = [ 5.67319, 5.67485, 5.67635, 5.67821, 5.67950, 5.68118, 5.68267, 5.68451, 5.68558, 5.68744, 5.68898, 5.69045, 5.69224, 5.69367, 5.69530, 5.69699, 5.69825, 5.69980, 5.70158, 5.70323, 5.70445, 5.70575, 5.70765, 5.70923, 5.71076, 5.71217, 5.71374, 5.71531, 5.71670] c_a_range = [ 1.09067, 1.09084, 1.09110, 1.09116, 1.09154, 1.09169, 1.09196, 1.09202, 1.09253, 1.09257, 1.09281, 1.09307, 1.09316, 1.09345, 1.09363, 1.09378, 1.09416, 1.09438, 1.09447, 1.09463, 1.09504, 1.09540, 1.09542, 1.09561, 1.09584, 1.09613, 1.09634, 1.09653, 1.09684] task = Task('config.ini') task.set('multiple phonon') indexRange = range(10,22,2) print indexRange for i in indexRange: varnameValue(task.pwscfInput, 'celldm(1)', a_range[i]) varnameValue(task.pwscfInput, 'celldm(2)', a_range[i]) varnameValue(task.pwscfInput, 'celldm(3)', c_a_range[i]) geometry = ['Al 0.000000000 0.0000000000000000 0.000000000', 'B 0.500000000 0.2886751345948129 '+str(c_a_range[i]/2.), 'B 0.000000000 0.5773502691896257 '+str(c_a_range[i]/2.)] atomic_positions(task.pwscfInput, geometry) task.getLauncher() Pol, Omega, qPoints = task.getEstimator() polName = "polarizations"+str(i)+".txt" omegaName = "freqs"+str(i)+".txt" qPointsName = "qpoints"+str(i)+".txt" cpMatdynModesCmdStr = "cp "+"matdyn.modes "+ "matdyn" + str(i) + ".modes" os.system(cpMatdynModesCmdStr) # save pol vectors, frequencies and qpoints: #numpy.savetxt(polName, Pol) # numpy.savetxt(omegaName, Omega) # numpy.savetxt(qPointsName, qPoints)
import time import traceback import pyautogui import action from task.down import Down from task.task import Task from task.tiaozhan import Tiaozhan from task.zhunbei import Zhunbei pyautogui.PAUSE = 0.1 task = Task() tasks = [] start_time = time.time() print('程序启动,现在时间', time.ctime()) def log(f): def wrap(*agrs, **kwagrs): try: ans = f(*agrs, **kwagrs) return ans except: traceback.print_exc() time.sleep(60) return wrap