def comparison(img1, img2): init_db() color1 = get_images(img1) color2 = get_images(img2) c1 = sorted([ [ int(color1[0][1:3], 16), int(color1[0][3:5], 16), int(color1[0][5:7], 16) ], [ int(color1[1][1:3], 16), int(color1[1][3:5], 16), int(color1[1][5:7], 16) ], [ int(color1[2][1:3], 16), int(color1[2][3:5], 16), int(color1[2][5:7], 16) ], ]) c2 = sorted([ [ int(color2[0][1:3], 16), int(color2[0][3:5], 16), int(color2[0][5:7], 16) ], [ int(color2[1][1:3], 16), int(color2[1][3:5], 16), int(color2[1][5:7], 16) ], [ int(color2[2][1:3], 16), int(color2[2][3:5], 16), int(color2[2][5:7], 16) ], ]) # np.linalg.norm это функция вычисления дистанции между векторами res = [ np.linalg.norm(np.asarray(c1[0]) - np.asarray(c2[0])), np.linalg.norm(np.asarray(c1[1]) - np.asarray(c2[1])), np.linalg.norm(np.asarray(c1[2]) - np.asarray(c2[2])), ] n_c = get_index(img1) n_f = get_index(img2) if np.linalg.norm(res) < 56 and n_f >= n_c and n_f - n_c <= 3: return True else: False
def run(task_id, date, time_span=None, replace_ftp=None): """ 如果不指定replace_ftp,则使用默认的地址配置。 如果不指定time_span, 则表示周期自动任务,不走清空流程 :param task_id: :param date: :param replace_ftp: :param time_span: 格式: 19:00-20:00 :return: """ logging.info("[BEGIN]task id:%s, date:%s, ftp:%s, time:%s" % (task_id, date, replace_ftp, time_span)) task_id = int(task_id) task = task_db.CustomIndexTask(task_id) if task.task_type != "timely": logging.fatal('task type is %s' % task.task_type) exit(-1) # 若启动时输入了ftp地址则覆盖任务默认地址 if replace_ftp: ftp = replace_ftp else: ftp = task.path # 如果指定了时间跨度的处理 if time_span and len(time_span) > 1: if time_span[1] < time_span[0]: logging.error( "time_span error, end time(%s) is small than the start time(%s)" % (time_span[1], time_span[0])) return update_time = time_span[1] else: update_time = time.strftime("%H:%M") # 获取文件 try: path = base.get_index(task_id, date, ftp) except error.DownloadError: if "%s" in ftp: ftp = ftp % date addr = '*****@*****.**' % task.owner cc = '*****@*****.**' title = u'%s 指标入库失败' % task.name text = u'%s 指标【任务id:%s】入库失败\n日期:%s\nftp地址:%s' %\ (task.name, task.id, date, ftp) logging.fatal('wget error') tools.send_email(addr, title, text, cc=cc) exit(-1) else: # 时效性指标的日期格式,只是在存储入库的时候更改格式。 date = time.strftime("%Y-%m-%d", time.strptime(date, "%Y%m%d")) # 解析入库 save_index(path, task, date, time_span) # 更新最近运行时间 task.update_last_run_time(date, update_time) logging.info("[END]task id:%s, date:%s, time:%s" % (task_id, date, update_time))
def main(task_id, date, replace_ftp=None): logging.info("[BEGIN]task id:%s, date:%s" % (task_id, date)) task_id = int(task_id) task = task_db.CustomIndexTask(task_id) if task.task_type != "detail": logging.fatal('task type is %s' % task.task_type) exit(-1) # 获取数据 if replace_ftp: ftp = replace_ftp else: ftp = task.path path = base.get_index(task_id, date, ftp) # 解析入库 save_index(path, task, date) logging.info("[END]task id:%s, date:%s" % (task_id, date))
def run(task_id, date, replace_ftp=None): logging.info("[BEGIN]task id:%s, date:%s" % (task_id, date)) task_id = int(task_id) task = task_db.CustomIndexTask(task_id) if task.task_type != "index": logging.fatal('task type is %s' % task.task_type) exit(-1) # 若启动时输入了ftp地址则覆盖任务默认地址 if replace_ftp: ftp = replace_ftp else: ftp = task.path try: path = base.get_index(task_id, date, ftp) except error.DownloadError: if "%s" in ftp: ftp = ftp % date addr = '*****@*****.**' % task.owner cc = '*****@*****.**' title = u'%s 指标入库失败' % task.name text = u'%s 指标【任务id:%s】入库失败\n日期:%s\nftp地址:%s' %\ (task.name, task.id, date, ftp) logging.fatal('wget error') tools.send_email(addr, title, text, cc=cc) exit(-1) else: # 解析入库 save_index(path, task, date) # 获取待summary待更新日期 date_list = get_summary_date(task_id, date) logging.info("summary date list:%s" % date_list) run_summary_cmd(date_list, task_id) logging.info("build output!") tools.run_main_cmd("custom_original_output", [task_id, date]) task.update_last_run_date(date) logging.info("[END]task id:%s, date:%s" % (task_id, date))
dublikat = dublikat+1 os.remove(path+i) print(f"Тут {dublikat} дубликатов") ################################################## # В этой части на основе данных по цветам, мы сравниваем картинки и формируем списки картинок для альбомов # и заносим в отдельную тацлицу в базе a = os.listdir(path) for img1 in a: h = [] if os.path.isfile(path+img1): for img2 in a: if os.path.isfile(path+img2): if comparison(img1, img2): h.append(img2) for i in h: if h.index(i) != (get_index(i)-get_index(h[0])): h = h[0:h.index(i)] break slist = ' '.join(h) add_list(slist) ##################################################### # # По сформированные спискам для альбомов формируем собственно альбомы и переносим в целевую дерикторию # Одиночные картинки тоже переносим. n = count_id() for i in range(1, n+1): a = get_list(i).split(' ') for j in range(1, n+1): b = get_list(j).split(' ') if set(a) & set(b): a = sorted(list(set(a) | set(b)))