def _cancel_all(self): ret_code = -1 ret_value = tools.get_timestamp() error_msg = '' try: autoit.win_activate(self.wid_main) self.clean_dlg() autoit.control_click(self.wid_main, self.cid_cancel_refresh) autoit.control_click(self.wid_main, self.cid_cancel_refresh) ret_code = 1 time.sleep(5) autoit.control_click(self.wid_main, self.cid_cancel_selectall) ret_code = 2 time.sleep(0.5) autoit.control_click(self.wid_main, self.cid_cancel_do) ret_code = 3 if autoit.win_wait(self.wid_prompt, timeout=5) == 1: #autoit.win_activate(self.wid_prompt) autoit.control_click(self.wid_prompt, self.cid_prompt_ok) ret_code = 4 if autoit.win_wait(self.wid_prompt, timeout=20) == 1: #autoit.win_activate(self.wid_prompt) autoit.control_click(self.wid_prompt, self.cid_prompt_ok) ret_code = 0 except: error_msg = traceback.format_exc() return (ret_code, ret_value, error_msg, self.local_log_path) #==================================================================
def _entrust_0(self, direction, code, price, volume): ret_code = -1 ret_value = tools.get_timestamp() error_msg = '' if direction == 'b': cid_code = self.cid_buy_code cid_price = self.cid_buy_price cid_volume = self.cid_buy_volume cid_able = self.cid_buy_able cid_entrust = self.cid_buy_entrust wait_flag = True elif direction == 's': cid_code = self.cid_sell_code cid_price = self.cid_sell_price cid_volume = self.cid_sell_volume cid_able = self.cid_sell_able cid_entrust = self.cid_sell_entrust wait_flag = False else: error_msg = 'unexpected direction' return (ret_code, ret_value, error_msg, self.local_log_path) ret_code = 1 try: autoit.win_activate(self.wid_main) self.clean_dlg() autoit.control_set_text(self.wid_main, cid_code, code) if wait_flag: for count in range(30): if autoit.control_get_text(self.wid_main, cid_able) != '': ret_code = 2 break else: time.sleep(0.1) if ret_code != 2: error_msg = 'code response timeout' return (ret_code, ret_value, error_msg, self.local_log_path) ret_code = 3 autoit.control_set_text(self.wid_main, cid_price, price) autoit.control_set_text(self.wid_main, cid_volume, volume) #autoit.win_activate(self.wid_main) autoit.control_click(self.wid_main, cid_entrust) ret_code = 4 if autoit.win_wait(self.wid_prompt, timeout=3) == 1: #autoit.win_activate(self.wid_prompt) autoit.control_click(self.wid_prompt, self.cid_prompt_ok) ret_code = 0 except autoit.AutoItError: error_msg = traceback.format_exc() return (ret_code, ret_value, error_msg, self.local_log_path)
def get_chartdata(): """Collect data from a slave to build a chart on the monitoring web-page.""" callback = bottle.request.query.get('callback') y_axis = bottle.request.query.get('y_axis').strip() w_acts = [ "action='%s'" % act for act in bottle.request.query.get('actions').strip().split(',') ] w_acts = 'AND (%s)' % ' OR '.join(w_acts) if w_acts else '' f_value = 'AVG(latency)' if y_axis.startswith( 'avg') else 'COUNT(timestamp)' atomic = 1 if y_axis in ['aops', 'avgl'] else 0 db_conn = tools.get_db_conn('%s.db' % bottle.request.query.test_run_id) sql = 'SELECT test_run_status, timestamp_started, timestamp_completed FROM info LIMIT 1' status, started, finished = tools.db_query(db_conn, sql)[1][0] progress = int(float(finished) - float(started)) if finished \ else int(tools.get_timestamp() - float(started)) sql = 'SELECT substr(timestamp, 0, 11), code, %s FROM recs ' % f_value + \ 'WHERE atomic=%s %s GROUP BY code, substr(timestamp, 0, 11) ' % (atomic, w_acts) + \ 'ORDER BY id DESC LIMIT 3600' # last 1 hour activity result = tools.db_query(db_conn, sql)[1] if finished else tools.db_query( db_conn, sql)[1][:-1] result = list(reversed(result)) results = { str(abs(int(item[0]) - int(float(started)))): { 'failed': 0, 'passed': 0, 'incomplete': 0 } for item in result } for item in result: # item[0] - timestamp, item[1] - code (None if incomplete), item[2] - value timestamp = str(int(item[0]) - int(float(started))) value = item[2] or 0 results[timestamp][ 'failed'] += value if item[1] and item[1] != 200 else 0 results[timestamp]['passed'] += value if item[1] == 200 else 0 results[timestamp]['incomplete'] += value if item[1] == None else 0 results = [{ 'timestamp': key, 'failed': value['failed'], 'passed': value['passed'], 'incomplete': value['incomplete'] } for key, value in results.items()] result = { bottle.request.query.slave: results, 'status': status, 'started': started, 'finished': finished or '(not finished)', 'progress': progress } return '{0}({1})'.format(callback, result)
def start(self): """Create a test-run database on the slave and insert information about the test run.""" conn = tools.get_db_conn('%s.db' % self.test_run_id) tools.db_init(conn) sql = "INSERT INTO info " + \ "(test_run_id, slave_name, timestamp_started, total_load_info, slave_load_info) " + \ "VALUES ('%s', '%s', '%s', '%s', '%s')" tools.db_query( conn, sql % (self.test_run_id, self.name, tools.get_timestamp(), json.dumps(self.test, sort_keys=True, indent=4), json.dumps(self.load, sort_keys=True, indent=4)))
def load_config(path): with open(path) as f: config = yaml.safe_load(f) config = AttrDict(config) timestamp = get_timestamp() config.dir = pathlib.Path('.') config.resdir = pathlib.Path('.') / config.resdir config.logdir = config.resdir / timestamp config.datadir = config.dir / config.datadir config.resdir.mkdir(exist_ok=True) config.logdir.mkdir(exist_ok=True) return config
def loop(): # 检查是否到时间 global end_timestrap global request_points current_timestamp = get_timestamp() if end_timestrap is not None: #有设置结束时间 if current_timestamp > end_timestrap: sched.shutdown() current_time = timestamp_to_time(current_timestamp) logger.info("【开始爬取】{}".format(current_time)) # 爬取工作 global data for frame, value in request_points.items(): if value["extent"] is None: #该图幅没有img continue req_pnt = value["req_pnt"] imgs = do_get(*req_pnt) if imgs is None: logger.error("图幅{}出错:在该位置上没有获得imgs".format(frame)) continue # 处理imgs for img in imgs: timestamp = img[1] #时间戳 time = timestamp_to_time(timestamp) #时间 # 加入数据 if frame not in data: data[frame] = OrderedDict() if time not in data[frame]: data[frame][time] = { "timestamp": timestamp, "time": time, "url": img[0], "extent": img[2], "req_pnt": req_pnt, "file_path": "" } else: pass print data save_json(project_dir, "9 data", data) download() #下载 registration() #配准 return
def _entrust(self, direction, code, price, volume): ret_code = -1 ret_value = tools.get_timestamp() error_msg = '' if direction == 'b': cid_code = self.cid_buy_code cid_price = self.cid_buy_price cid_volume = self.cid_buy_volume cid_able = self.cid_buy_able cid_entrust = self.cid_buy_entrust wait_flag = True elif direction == 's': cid_code = self.cid_sell_code cid_price = self.cid_sell_price cid_volume = self.cid_sell_volume cid_able = self.cid_sell_able cid_entrust = self.cid_sell_entrust wait_flag = False else: error_msg = 'unexpected direction' return (ret_code, ret_value, error_msg, self.local_log_path) ret_code = 1 try: autoit.win_activate(self.wid_main) self.clean_dlg() autoit.control_set_text(self.wid_main, cid_code, code) if wait_flag: time.sleep(0.5) ret_code = 2 autoit.control_set_text(self.wid_main, cid_price, price) autoit.control_set_text(self.wid_main, cid_volume, volume) autoit.control_click(self.wid_main, cid_entrust) ret_code = 0 except autoit.AutoItError: error_msg = traceback.format_exc() return (ret_code, ret_value, error_msg, self.local_log_path)
def complete(self): """Update a local test-run database on the slave once test run is completed.""" tools.db_query( tools.get_db_conn('%s.db' % self.test_run_id), "UPDATE info SET test_run_status = 'FINISHED', timestamp_completed = '%s'" % tools.get_timestamp())