Spaces:
Sleeping
Sleeping
Update Doors_Schedule.py
Browse files- Doors_Schedule.py +47 -10
Doors_Schedule.py
CHANGED
|
@@ -223,6 +223,8 @@ def get_selected_columns(dfs, user_patterns):
|
|
| 223 |
|
| 224 |
#clmn_name = map_user_input_to_standard_labels(user_patterns)
|
| 225 |
#if len(clmn_name) < len(user_patterns):
|
|
|
|
|
|
|
| 226 |
if len(user_patterns) == 4:
|
| 227 |
clmn_name = ["door_id", "door_type", "width", "height"]
|
| 228 |
if len(user_patterns) == 3:
|
|
@@ -333,6 +335,9 @@ def get_similar_colors(selected_columns_new):
|
|
| 333 |
col_dict = defaultdict(lambda: {'values': [], 'color': None, 'widths': []})
|
| 334 |
else:
|
| 335 |
col_dict = defaultdict(lambda: {'values': [], 'color': None, 'widths': [], 'heights': []})
|
|
|
|
|
|
|
|
|
|
| 336 |
|
| 337 |
for _, row in selected_columns_new.iterrows():
|
| 338 |
key = row['door_type']
|
|
@@ -340,29 +345,41 @@ def get_similar_colors(selected_columns_new):
|
|
| 340 |
if 'structural_opening' in selected_columns_new.columns:
|
| 341 |
col_dict[key]['widths'].append(row['structural_opening']) # Add structural opening
|
| 342 |
else:
|
| 343 |
-
|
| 344 |
-
|
|
|
|
| 345 |
col_dict[key]['color'] = key_colors[key] # Assign the unique RGB color
|
| 346 |
|
| 347 |
# Convert defaultdict to a normal dictionary
|
| 348 |
col_dict = dict(col_dict)
|
| 349 |
return col_dict
|
| 350 |
-
|
| 351 |
def get_flattened_tuples_list(col_dict):
|
| 352 |
tuples_list = []
|
|
|
|
| 353 |
for key, values_dict in col_dict.items():
|
| 354 |
-
if 'heights' in values_dict
|
|
|
|
| 355 |
tuples_list.append([
|
| 356 |
-
(value, width, height, values_dict["color"])
|
| 357 |
for value, width, height in zip(values_dict['values'], values_dict['widths'], values_dict['heights'])
|
| 358 |
])
|
| 359 |
-
|
|
|
|
| 360 |
tuples_list.append([
|
| 361 |
-
(value, width, values_dict["color"])
|
| 362 |
for value, width in zip(values_dict['values'], values_dict['widths'])
|
| 363 |
])
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 364 |
|
|
|
|
| 365 |
flattened_list = [item for sublist in tuples_list for item in sublist]
|
|
|
|
| 366 |
return flattened_list
|
| 367 |
|
| 368 |
def find_text_in_plan(label, x):
|
|
@@ -380,6 +397,14 @@ def find_text_in_plan(label, x):
|
|
| 380 |
def get_word_locations_plan(flattened_list, plan_texts):
|
| 381 |
locations = []
|
| 382 |
not_found = []
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 383 |
if len(flattened_list[0]) == 3:
|
| 384 |
for lbl, w, clr in flattened_list:
|
| 385 |
location,worz, txt_pt = find_text_in_plan(lbl, plan_texts)
|
|
@@ -393,7 +418,7 @@ def get_word_locations_plan(flattened_list, plan_texts):
|
|
| 393 |
not_found.append(lbl)
|
| 394 |
locations.append((location, lbl, clr, w, h))
|
| 395 |
return locations, not_found
|
| 396 |
-
|
| 397 |
def get_repeated_labels(locations):
|
| 398 |
seen_labels = set()
|
| 399 |
repeated_labels = set()
|
|
@@ -408,8 +433,18 @@ def get_repeated_labels(locations):
|
|
| 408 |
|
| 409 |
def get_cleaned_data(locations):
|
| 410 |
processed = defaultdict(int)
|
| 411 |
-
|
| 412 |
new_data = []
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 413 |
if len(locations[0]) == 4:
|
| 414 |
for coords, label, color, w in locations:
|
| 415 |
if len(coords)>1:
|
|
@@ -428,7 +463,7 @@ def get_cleaned_data(locations):
|
|
| 428 |
processed[label] += 1 # Move to the next coordinate for this label
|
| 429 |
if len(coords)==1:
|
| 430 |
new_data.append((coords, label, color, w, h))
|
| 431 |
-
|
| 432 |
return new_data
|
| 433 |
|
| 434 |
'''def get_width_info_tobeprinted(new_data):
|
|
@@ -620,6 +655,8 @@ def mainRun(schedule, plan, searcharray):
|
|
| 620 |
width_info_tobeprinted = get_width_info_tobeprinted(new_data)
|
| 621 |
cleaned_width = get_cleaned_width(width_info_tobeprinted)
|
| 622 |
widths = get_widths_bb_format(cleaned_width, kelma)
|
|
|
|
|
|
|
| 623 |
final_pdf_bytes= process_pdf(plan, "final_output_width.pdf", new_data, widths)
|
| 624 |
|
| 625 |
|
|
|
|
| 223 |
|
| 224 |
#clmn_name = map_user_input_to_standard_labels(user_patterns)
|
| 225 |
#if len(clmn_name) < len(user_patterns):
|
| 226 |
+
if len(user_patterns) == 2:
|
| 227 |
+
clmn_name = ["door_id", "door_type"]
|
| 228 |
if len(user_patterns) == 4:
|
| 229 |
clmn_name = ["door_id", "door_type", "width", "height"]
|
| 230 |
if len(user_patterns) == 3:
|
|
|
|
| 335 |
col_dict = defaultdict(lambda: {'values': [], 'color': None, 'widths': []})
|
| 336 |
else:
|
| 337 |
col_dict = defaultdict(lambda: {'values': [], 'color': None, 'widths': [], 'heights': []})
|
| 338 |
+
if selected_columns_new.shape[1] == 2:
|
| 339 |
+
col_dict = defaultdict(lambda: {'values': [], 'color': None})
|
| 340 |
+
|
| 341 |
|
| 342 |
for _, row in selected_columns_new.iterrows():
|
| 343 |
key = row['door_type']
|
|
|
|
| 345 |
if 'structural_opening' in selected_columns_new.columns:
|
| 346 |
col_dict[key]['widths'].append(row['structural_opening']) # Add structural opening
|
| 347 |
else:
|
| 348 |
+
if selected_columns_new.shape[1] > 2:
|
| 349 |
+
col_dict[key]['widths'].append(row['width']) # Assuming 'widht' is a typo for 'width'
|
| 350 |
+
col_dict[key]['heights'].append(row['height'])
|
| 351 |
col_dict[key]['color'] = key_colors[key] # Assign the unique RGB color
|
| 352 |
|
| 353 |
# Convert defaultdict to a normal dictionary
|
| 354 |
col_dict = dict(col_dict)
|
| 355 |
return col_dict
|
| 356 |
+
|
| 357 |
def get_flattened_tuples_list(col_dict):
|
| 358 |
tuples_list = []
|
| 359 |
+
|
| 360 |
for key, values_dict in col_dict.items():
|
| 361 |
+
if 'heights' in values_dict and 'widths' in values_dict:
|
| 362 |
+
# Case: Both widths and heights present
|
| 363 |
tuples_list.append([
|
| 364 |
+
(value, width, height, values_dict["color"])
|
| 365 |
for value, width, height in zip(values_dict['values'], values_dict['widths'], values_dict['heights'])
|
| 366 |
])
|
| 367 |
+
elif 'widths' in values_dict:
|
| 368 |
+
# Case: Only widths present
|
| 369 |
tuples_list.append([
|
| 370 |
+
(value, width, values_dict["color"])
|
| 371 |
for value, width in zip(values_dict['values'], values_dict['widths'])
|
| 372 |
])
|
| 373 |
+
else:
|
| 374 |
+
# Case: Neither widths nor heights
|
| 375 |
+
tuples_list.append([
|
| 376 |
+
(value, values_dict["color"])
|
| 377 |
+
for value in values_dict['values']
|
| 378 |
+
])
|
| 379 |
|
| 380 |
+
# Flatten the list of lists
|
| 381 |
flattened_list = [item for sublist in tuples_list for item in sublist]
|
| 382 |
+
|
| 383 |
return flattened_list
|
| 384 |
|
| 385 |
def find_text_in_plan(label, x):
|
|
|
|
| 397 |
def get_word_locations_plan(flattened_list, plan_texts):
|
| 398 |
locations = []
|
| 399 |
not_found = []
|
| 400 |
+
|
| 401 |
+
if len(flattened_list[0]) == 2:
|
| 402 |
+
for lbl, clr in flattened_list:
|
| 403 |
+
location,worz, txt_pt = find_text_in_plan(lbl, plan_texts)
|
| 404 |
+
if len(location) ==0:
|
| 405 |
+
not_found.append(lbl)
|
| 406 |
+
locations.append((location, lbl, clr))
|
| 407 |
+
|
| 408 |
if len(flattened_list[0]) == 3:
|
| 409 |
for lbl, w, clr in flattened_list:
|
| 410 |
location,worz, txt_pt = find_text_in_plan(lbl, plan_texts)
|
|
|
|
| 418 |
not_found.append(lbl)
|
| 419 |
locations.append((location, lbl, clr, w, h))
|
| 420 |
return locations, not_found
|
| 421 |
+
|
| 422 |
def get_repeated_labels(locations):
|
| 423 |
seen_labels = set()
|
| 424 |
repeated_labels = set()
|
|
|
|
| 433 |
|
| 434 |
def get_cleaned_data(locations):
|
| 435 |
processed = defaultdict(int)
|
| 436 |
+
|
| 437 |
new_data = []
|
| 438 |
+
if len(locations[0]) == 3:
|
| 439 |
+
for coords, label, color in locations:
|
| 440 |
+
if len(coords)>1:
|
| 441 |
+
index = processed[label] % len(coords) # Round-robin indexing
|
| 442 |
+
new_coord = [coords[index]] # Pick the correct coordinate
|
| 443 |
+
new_data.append((new_coord, label, color))
|
| 444 |
+
processed[label] += 1 # Move to the next coordinate for this label
|
| 445 |
+
if len(coords)==1:
|
| 446 |
+
new_data.append((coords, label, color))
|
| 447 |
+
|
| 448 |
if len(locations[0]) == 4:
|
| 449 |
for coords, label, color, w in locations:
|
| 450 |
if len(coords)>1:
|
|
|
|
| 463 |
processed[label] += 1 # Move to the next coordinate for this label
|
| 464 |
if len(coords)==1:
|
| 465 |
new_data.append((coords, label, color, w, h))
|
| 466 |
+
|
| 467 |
return new_data
|
| 468 |
|
| 469 |
'''def get_width_info_tobeprinted(new_data):
|
|
|
|
| 655 |
width_info_tobeprinted = get_width_info_tobeprinted(new_data)
|
| 656 |
cleaned_width = get_cleaned_width(width_info_tobeprinted)
|
| 657 |
widths = get_widths_bb_format(cleaned_width, kelma)
|
| 658 |
+
if selected_columns_new.shape[1] == 2:
|
| 659 |
+
widths = []
|
| 660 |
final_pdf_bytes= process_pdf(plan, "final_output_width.pdf", new_data, widths)
|
| 661 |
|
| 662 |
|