import os import random import copy from backend.class_def import panel template_specs = { "1" : { "span" : 1, "direction": "row" }, "2" : { "span" : 2, "direction": "row" }, "3" : { "span" : 3, "direction": "column" }, "4" : { "span" : 2, "direction": "column" }, # High-accuracy templates with fewer, larger panels "5" : { "span" : 4, "direction": "row" }, "6" : { "span" : 2, "direction": "row" }, "7" : { "span" : 3, "direction": "row" }, "8" : { "span" : 4, "direction": "column" } } input = '433343333343343333443333443334333343344443433' def hammingDist(str1, str2): i = 0 count = 0 while(i < len(str1)): if(str1[i] != str2[i]): count += 1 i += 1 return count def get_files_in_folder(folder_path): file_dicts = [] for root, dirs, files in os.walk(folder_path): for file in files: file_path = os.path.join(root, file) rank = random.randint(1, 3) file_dicts.append({"name": file , 'rank' : rank}) return file_dicts templates = ['14124114','312341' , '4432111' , '21411241' , '3241141' , '13411141' , '12411131' ,'1321113', '131423' , '142344' , '234241','2411413','3141214','42111131'] # High-accuracy mode: when HIGH_ACCURACY is set, use 2x2 grid layout HIGH_ACCURACY = os.getenv('HIGH_ACCURACY', '0') if HIGH_ACCURACY in ('1', 'true', 'True', 'YES', 'yes'): # Use templates with 2x2 grid layout (4 equal squares per page) templates = ['333333333333'] # 12 panels in 3x4 grid # Always 2x2 grid print("Using HIGH_ACCURACY mode with 2x2 grid layout (4 equal squares per page)") else: # Optional grid layout for efficiency: when GRID_LAYOUT is set, prefer uniform grids GRID_LAYOUT = os.getenv('GRID_LAYOUT', '0') if GRID_LAYOUT in ('1', 'true', 'True', 'YES', 'yes'): # Use simple repetitive templates that create grid-like pages templates = ['6666', '4488', '44446', '666', '67'] # Adjust minimum length based on accuracy mode if HIGH_ACCURACY in ('1', 'true', 'True', 'YES', 'yes'): min_length = 4 # Allow 4-image pages in high accuracy mode else: min_length = 6 folder_path = 'frames/final' # Specify the folder path def get_templates(input): page_templates = [] start = 0 while(start