def batch_standardize_data(project_path, data_path, save_path): utils.check_os() utils.clear_log(date) path = os.path.join(project_path, data_path) all_file_list = utils.read_recursive_dir(path) for file_dict in all_file_list: for file in file_dict['file_list']: cols = process_data(file, file_dict['path']) if cols: cols = utils.select_data_period(cols, date, time_interval) output(cols, save_path, file_dict['path'], file) else: continue
def test_shot(): size = utils.check_os() pixel_json = utils.get_pixel_config(size) blank_area = pixel_json['blank_area'] question_area = pixel_json['question_area'] blank_area_point = blank_area['x1'], blank_area['y1'], blank_area[ 'x2'], blank_area['y2'] question_area_point = question_area['x1'], question_area[ 'y1'], question_area['x2'], question_area['y2'] backup_img = None if os.path.exists('image/backup.png'): backup_img = Image.open('image/backup.png') else: print('image/backup.png位置图片不存在') exit(-1) utils.crop_image(backup_img, question_area_point, 'image/crop_test.png') utils.crop_image(backup_img, blank_area_point, 'image/blank_test.png')
def test_shot(is_ios): size = utils.check_os(is_ios) pixel_json = utils.get_pixel_config(size) blank_area = pixel_json['blank_area'] question_area = pixel_json['question_area'] blank_area_point = blank_area['x1'], blank_area['y1'], blank_area[ 'x2'], blank_area['y2'] question_area_point = question_area['x1'], question_area[ 'y1'], question_area['x2'], question_area['y2'] backup_img = None if os.path.exists('image/backup.png'): backup_img = Image.open('image/backup.png') else: utils.pull_from_screen_ios() backup_img = Image.open('image/backup.png') utils.crop_image(backup_img, question_area_point, 'image/crop_test.png') utils.crop_image(backup_img, blank_area_point, 'image/blank_test.png')
def main(): size = utils.check_os() config = get_config() is_auto = config['auto'] is_baidu_ocr = config['baidu_ocr'] is_debug = config['debug'] baidu_ocr_clint = None if is_baidu_ocr: baidu_cor_config = config['baidu_ocr_config'] baidu_ocr_clint = utils.init_baidu_ocr(baidu_cor_config) pixel_json = utils.get_pixel_config(size) blank_area = pixel_json['blank_area'] question_area = pixel_json['question_area'] blank_area_point = blank_area['x1'], blank_area['y1'], blank_area['x2'], blank_area['y2'] question_area_point = question_area['x1'], question_area['y1'], question_area['x2'], question_area['y2'] question_num = 0 crop_img_name = 'image/crop.png' while True: while True: print('开始答题') img = analyze.tell_and_get_image(is_auto, blank_area_point) if img is not None: question_num += 1 break else: # 若不是答题页 if not is_auto: print('没有发现题目页面') exit(-1) print('没有发现答题页面,继续') time.sleep(0.8) # 不是题目页面,休眠0.8秒后继续判断 # 获取题目及选项 start = datetime.datetime.now() # 记录开始时间 crop_obj = utils.crop_image(img, question_area_point, crop_img_name) question, option_arr, is_negative = analyze.image_to_str(crop_obj, is_baidu_ocr, baidu_ocr_clint) # 图片转文字 print('搜索的题目是:{} '.format(question)) print('选项为:{} '.format(option_arr)) if question is None or question == '': print('没有识别题目') continue result_list = search.search(question, option_arr, is_negative) # 搜索结果 if result_list is None: print('\n没有答案') else: print('最佳答案是: \033[1;31m{}\033[0m'.format(result_list)) run_time = (datetime.datetime.now() - start).seconds print('本次运行时间为:{}秒'.format(run_time)) crop_img = crop_obj[0] if is_debug: img.save('image/question_{}.png'.format(question_num)) crop_img.close() img.close() if is_auto: print('休息:{}秒后继续'.format(question_sleep_time)) time.sleep(question_sleep_time) # 每一道题结束,休息10秒 else: break
from pathlib import Path from typing import Final, List import pytest import yaml from utils import ( check_os, create_legacy_pull_file, create_protocol_file, get_data_from_agent, get_path_from_env, YamlDict, YieldFixture, ) check_os() _DEFAULT_CONFIG: Final = """ global: enabled: true logging: debug: true port: {} """ _INTEGRATION_PORT: Final = 25999 _HOST: Final = "localhost" _TEST_ENV_VAR: Final = "WNX_INTEGRATION_BASE_DIR" # supplied by script _ARTIFACTS_ENV_VAR: Final = "arte" # supplied by script _USER_YAML_CONFIG: Final = "check_mk.user.yml" _FACTORY_YAML_CONFIG: Final = "check_mk.yml"
def main(): pro_start = datetime.datetime.now() size = utils.check_os() config = get_config() is_auto = config['auto'] is_baidu_ocr = config['baidu_ocr'] baidu_ocr_clint = None if is_baidu_ocr: baidu_cor_config = config['baidu_ocr_config'] baidu_ocr_clint = utils.init_baidu_ocr(baidu_cor_config) pixel_json = utils.get_pixel_config(size) blank_area = pixel_json['blank_area'] question_area = pixel_json['question_area'] blank_area_point = blank_area['x1'], blank_area['y1'], blank_area[ 'x2'], blank_area['y2'] question_area_point = question_area['x1'], question_area[ 'y1'], question_area['x2'], question_area['y2'] question_num = 0 crop_img_name = 'image/crop.png' while True: while True: img = analyze.tell_and_get_image(is_auto, blank_area_point) if img is not None: question_num += 1 break else: # 若不是答题页 if not is_auto: print('没有发现题目页面') exit(-1) print('没有发现答题页面,继续') time.sleep(0.5) # 不是题目页面,休眠0.5秒后继续判断 # 获取题目及选项 start = datetime.datetime.now() # 记录开始时间 crop_img = utils.crop_image(img, question_area_point, crop_img_name) question, option_arr, is_negative = analyze.image_to_str( crop_img, is_baidu_ocr, baidu_ocr_clint) # 图片转文字 if question is None or question == '': print('\n没有识别题目') exit(-1) result_list = search.search(question) # 搜索结果 best_result = search.get_result(result_list, option_arr, question, is_negative) # 分析结果 if best_result is None: print('\n没有答案') else: print('最佳答案是: \033[1;31m{}\033[0m'.format(best_result)) run_time = (datetime.datetime.now() - start).seconds print('本次运行时间为:{}秒'.format(run_time)) if is_auto: time.sleep(10) # 每一道题结束,休息10秒 else: break total_time = (datetime.datetime.now() - pro_start).seconds print('脚本运行共运行{}秒'.format(total_time)) img.save('image/answer{}.png'.format(question_num)) img.close()