Marthee commited on
Commit
ac3cb8a
·
verified ·
1 Parent(s): e620b08

Update Doors_Schedule.py

Browse files
Files changed (1) hide show
  1. Doors_Schedule.py +97 -6
Doors_Schedule.py CHANGED
@@ -1213,7 +1213,6 @@ def mirrored_points(x, y, height_plan):
1213
  mirrored = []
1214
  mirrored.append([x, height_plan - y])
1215
  return mirrored
1216
-
1217
  def point_mupdf_to_pdf(x, y, page):
1218
  mediabox = page.mediabox
1219
  H = float(mediabox.height) # Use mediabox height, not rect height
@@ -1222,8 +1221,6 @@ def point_mupdf_to_pdf(x, y, page):
1222
  pdf_y = mediabox.y0 + (H - y)
1223
 
1224
  return [[pdf_x, pdf_y]]
1225
-
1226
-
1227
  # Modified to adjust mirrored points
1228
  def create_bb_bax_secondary(new_data, widthat, heightat, secondary_tobeprinted, CountStyles, input_user_clmn_names, page_number, height_plan):
1229
  bax_annotations = []
@@ -1346,10 +1343,100 @@ def generate_bluebeam_columns_raw(column_names):
1346
  return tostring(root, encoding="unicode", method="xml")
1347
 
1348
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1349
 
1350
  def mainRun(schedule, plan, searcharray):
1351
  print("mainRun is RUNNING")
1352
-
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1353
  #print(type(plan))
1354
  eltype = type(plan)
1355
  print(f"el type beta3 variable plan:: {eltype}")
@@ -1388,7 +1475,10 @@ def mainRun(schedule, plan, searcharray):
1388
  #width_plan = math.ceil(width_plan)
1389
  #height_plan = math.ceil(height_plan)
1390
  for k in range(len(schedule)):
1391
- dfs = extract_tables_model(schedule[k])
 
 
 
1392
  user_input_this_schedule = searcharray[k]
1393
  for j in range(len(user_input_this_schedule)):
1394
  user_input = user_input_this_schedule[j]
@@ -1533,4 +1623,5 @@ def mainRun(schedule, plan, searcharray):
1533
  v='stroke'
1534
  x,y,z=int(annot_color.get(v)[0]*255),int(annot_color.get(v)[1]*255),int(annot_color.get(v)[2]*255)
1535
  list1.loc[len(list1)] =[annot.info['content'],annot.info['id'],annot.info['subject'],[x,y,z]]
1536
- return annotatedimgs, doc2 , list1, repeated_labels , not_found, pretty_xml, column_xml
 
 
1213
  mirrored = []
1214
  mirrored.append([x, height_plan - y])
1215
  return mirrored
 
1216
  def point_mupdf_to_pdf(x, y, page):
1217
  mediabox = page.mediabox
1218
  H = float(mediabox.height) # Use mediabox height, not rect height
 
1221
  pdf_y = mediabox.y0 + (H - y)
1222
 
1223
  return [[pdf_x, pdf_y]]
 
 
1224
  # Modified to adjust mirrored points
1225
  def create_bb_bax_secondary(new_data, widthat, heightat, secondary_tobeprinted, CountStyles, input_user_clmn_names, page_number, height_plan):
1226
  bax_annotations = []
 
1343
  return tostring(root, encoding="unicode", method="xml")
1344
 
1345
 
1346
+ def pick_approach(schedule, plan, searcharray, flag):
1347
+ not_found_list = []
1348
+ missings = []
1349
+ no_tables = False
1350
+ for p in plan:
1351
+ for k in range(len(schedule)):
1352
+ if flag == 1:
1353
+ dfs = extract_tables(schedule[k])
1354
+ if flag == 2:
1355
+ dfs = extract_tables_model(schedule[k])
1356
+ user_input_this_schedule = searcharray[k]
1357
+ for j in range(len(user_input_this_schedule)):
1358
+ user_input = user_input_this_schedule[j]
1359
+ secondary_presence = False
1360
+ if user_input[4] or user_input[5]:
1361
+ secondary_presence = True
1362
+ main_info_, secondary_info_ = separate_main_secondary(user_input)
1363
+ main_info = [item for item in main_info_ if item]
1364
+ secondary_info = [item for item in secondary_info_ if item]
1365
+
1366
+ selected_columns_combined = get_selected_columns_all(dfs, user_input)
1367
+ if selected_columns_combined is None:
1368
+ dfs_normal = extract_tables(schedule[k])
1369
+ column_indices = get_column_indices_from_dfs_normal(dfs_normal, user_input)
1370
+ if column_indices is None:
1371
+ missing_clmns = check_missing(dfs, user_input)
1372
+ missing_message = f"{missing_clmns} can't be extracted from table input {j+1} in schedule {k+1}"
1373
+ missings.append(missing_message)
1374
+ no_tables = True
1375
+ continue # continue to the next user input
1376
+ if len(dfs) == 1:
1377
+ selected_columns_combined = get_selected_columns_by_index(dfs[0], column_indices, user_input)
1378
+ if len(dfs) > 1:
1379
+ index_df = get_df_index(dfs, user_input)
1380
+ selected_columns_combined = get_selected_columns_by_index(dfs[index_df], column_indices, user_input)
1381
+ selected_columns_combined = selected_columns_combined.applymap(lambda x: 'N/A' if isinstance(x, str) and x.strip() == '' else x)
1382
+ selected_columns_combined = selected_columns_combined.fillna('N/A')
1383
+ selected_columns_combined = selected_columns_combined.replace(r'(?i)\bn/a\b', 'N/A', regex=True)
1384
+ kelma = get_st_op_pattern(selected_columns_combined, user_input)
1385
+ if "door_type" in selected_columns_combined.columns:
1386
+ col_dict = get_similar_colors_all(selected_columns_combined)
1387
+ flattened_list = get_flattened_tuples_list_all(col_dict)
1388
+ else:
1389
+ if secondary_presence:
1390
+ main_info = main_info + [""]
1391
+ flattened_list = get_flattened_tuples_list_no_doortype(selected_columns_combined)
1392
+ plan_texts = read_text(p)
1393
+
1394
+ if secondary_presence:
1395
+ locations, not_found = get_word_locations_plan_secondary(flattened_list,plan_texts, main_info, secondary_info)
1396
+ not_found_list.append(not_found)
1397
+
1398
+
1399
+ else:
1400
+ locations, not_found = get_word_locations_plan(flattened_list,plan_texts)
1401
+ not_found_list.append(not_found)
1402
+
1403
+ ## Getting the not found in all plans
1404
+ flattened_not_found_list = [item for sublist in not_found_list for item in sublist]
1405
+ from collections import Counter
1406
+ counts_not_found = Counter(flattened_not_found_list)
1407
+ not_found_any_plan = []
1408
+ for key, value in counts_not_found.items():
1409
+ if value == len(plan):
1410
+ not_found_any_plan.append(key)
1411
+ return no_tables, not_found_any_plan
1412
 
1413
  def mainRun(schedule, plan, searcharray):
1414
  print("mainRun is RUNNING")
1415
+ no_tables_normal, not_found_any_plan_normal = pick_approach(schedule, plan, searcharray, 1)
1416
+ no_tables_model, not_found_any_plan_model = pick_approach(schedule, plan, searcharray, 2)
1417
+ pick_normal = False
1418
+ pick_model = False
1419
+ if no_tables_model:
1420
+ pick_normal = True
1421
+ #print("choose normal")
1422
+ elif no_tables_normal:
1423
+ pick_model = True
1424
+ #print("choose model")
1425
+ elif no_tables_model and no_tables_normal:
1426
+ print("el etneen bayzeen")
1427
+ else:
1428
+ ## Decide according to the not found labels
1429
+ #print("el etneen shaghaleen")
1430
+ if len(not_found_any_plan_model) > len(not_found_any_plan_normal):
1431
+ #print("choose not_found_any_plan_normal")
1432
+ pick_normal = True
1433
+ elif len(not_found_any_plan_model) < len(not_found_any_plan_normal):
1434
+ pick_model = True
1435
+ #print("choose not_found_any_plan_model")
1436
+ else:
1437
+ pick_normal = True
1438
+ #print("choose any")
1439
+
1440
  #print(type(plan))
1441
  eltype = type(plan)
1442
  print(f"el type beta3 variable plan:: {eltype}")
 
1475
  #width_plan = math.ceil(width_plan)
1476
  #height_plan = math.ceil(height_plan)
1477
  for k in range(len(schedule)):
1478
+ if pick_normal:
1479
+ dfs = extract_tables(schedule[k])
1480
+ if pick_model:
1481
+ dfs = extract_tables_model(schedule[k])
1482
  user_input_this_schedule = searcharray[k]
1483
  for j in range(len(user_input_this_schedule)):
1484
  user_input = user_input_this_schedule[j]
 
1623
  v='stroke'
1624
  x,y,z=int(annot_color.get(v)[0]*255),int(annot_color.get(v)[1]*255),int(annot_color.get(v)[2]*255)
1625
  list1.loc[len(list1)] =[annot.info['content'],annot.info['id'],annot.info['subject'],[x,y,z]]
1626
+ return annotatedimgs, doc2 , list1, repeated_labels , not_found, pretty_xml, column_xml
1627
+