Marthee commited on
Commit
8604dea
·
verified ·
1 Parent(s): ef6dffd

Update google_sheet_Legend.py

Browse files
Files changed (1) hide show
  1. google_sheet_Legend.py +31 -16
google_sheet_Legend.py CHANGED
@@ -312,22 +312,22 @@ def mapnametoLegend(McTName):
312
  # firstpart= re.split(r'[`\-=~!@#$%^&*()_+\[\]{};\'\\:"|<,./<>?]', McTName[i][0])
313
  print('kkk' ,McTName[i][2])
314
  if McTName[i][2].startswith('Area'):
315
- if section.startswith('1.0') or section.startswith('3.2'):
316
  rowvalue=5# column 5
317
  ar=0
318
  unit='m2'
319
  if McTName[i][2].startswith('Perimeter'):
320
- if section.startswith('1.0') or section.startswith('3.2'):
321
  rowvalue=7# column 7
322
  ar=0
323
  unit='m'
324
  if McTName[i][2].startswith('Length'):
325
- if section.startswith('1.0') or section.startswith('3.2'):
326
  rowvalue=9# column 7
327
  ar=0
328
  unit='m'
329
  if McTName[i][2].startswith('Count'):
330
- if section.startswith('1.0') or section.startswith('3.2'):
331
  rowvalue=3# column 7
332
 
333
  ar=0
@@ -348,9 +348,15 @@ def mapnametoLegend(McTName):
348
  # print('kjjjj',roww[j])
349
  ar+=float(worksheetw.cell((indices[j]+1 ,rowvalue)).value)
350
  else:
351
- item+=m + ' ,'
 
 
 
352
  print(item)
353
- n= McTName[i][0] + ' ( '+ allgbnames[:-2] +' , ' + item[:-1] + ' ) '
 
 
 
354
  else:
355
  if McTName[i][1].startswith('text1'):
356
  name=McTName[i][1].removeprefix('text1')
@@ -478,19 +484,20 @@ def deletefromlegend(deletedrows, SimilarAreaDictionarycopy, section, areaPermAr
478
  items = []
479
  print('deletefromlegend',deletedrows)
480
  idx = 0
481
- if section.startswith('1.0') or section.startswith('3.2'):
482
  areaPermArr = ast.literal_eval(areaPermArr)
483
  myDict = eval(SimilarAreaDictionarycopy)
484
  SimilarAreaDictionarycopy = pd.DataFrame(myDict)
485
  strings = deletedrows['content']
486
  colors = deletedrows['color']
487
  indicies_toDelete=[]
488
- print(colors)
489
  # Define your tolerance value
490
  tolerance = 2 # Allowable tolerance for RGB differences
491
- print(SimilarAreaDictionarycopy)
492
  color_list = list(SimilarAreaDictionarycopy['Color']) # Convert Index/Series to list
493
- if section.startswith('1.0'):
 
494
  color_list = [ast.literal_eval(color) for color in color_list]
495
 
496
  for j in range(len(colors)):
@@ -503,19 +510,24 @@ def deletefromlegend(deletedrows, SimilarAreaDictionarycopy, section, areaPermAr
503
  existing_color = tuple(existing_color) # Ensure it's a tuple for comparison
504
 
505
 
506
- print('eee',existing_color,color)
507
  if is_color_within_tolerance(existing_color, color, tolerance):
508
  print(f'Color {color} found close to {existing_color} at index {idx}')
509
  found = True
510
- print(strings[j])
511
  matchA = re.search(r"Area=(\d+\.\d+)", strings[j])
512
  matchP = re.search(r"Perimeter=(\d+\.\d+)", strings[j])
513
  matchL = re.search(r"Length=(\d+\.\d+)", strings[j])
 
 
 
 
514
  comment = SimilarAreaDictionarycopy.iloc[int(idx), SimilarAreaDictionarycopy.columns.get_loc('Comments')]
515
  occ = SimilarAreaDictionarycopy.iloc[int(idx), SimilarAreaDictionarycopy.columns.get_loc('Occurences')]
516
 
517
  # Only subtract area if the area value is found
518
  if matchA:
 
519
  SimilarAreaDictionarycopy.iloc[int(idx), SimilarAreaDictionarycopy.columns.get_loc('Total Area')] =SimilarAreaDictionarycopy.iloc[int(idx), SimilarAreaDictionarycopy.columns.get_loc('Total Area')] - float(matchA.group(1))
520
  # Update area occurrences
521
  if pd.notna(comment) and 'Area' in str(comment):
@@ -535,6 +547,7 @@ def deletefromlegend(deletedrows, SimilarAreaDictionarycopy, section, areaPermAr
535
  area_occurrences = int(matches[0])
536
  perimeter_occurrences = int(matches[1]) -1
537
  else:
 
538
  area_occurrences = int(SimilarAreaDictionarycopy.iloc[int(idx), SimilarAreaDictionarycopy.columns.get_loc('Occurences')])
539
  perimeter_occurrences = SimilarAreaDictionarycopy.iloc[int(idx), SimilarAreaDictionarycopy.columns.get_loc('Occurences')]-1
540
  # print(area_occurrences,perimeter_occurrences)
@@ -571,6 +584,7 @@ def deletefromlegend(deletedrows, SimilarAreaDictionarycopy, section, areaPermAr
571
  if not found:
572
  print(f'Color {color} not found within tolerance')
573
  print('indicies_toDelete',indicies_toDelete)
 
574
  SimilarAreaDictionarycopy.drop(index=indicies_toDelete, axis=0, inplace=True)
575
  print('SimilarAreaDictionarycopy',SimilarAreaDictionarycopy)
576
  return SimilarAreaDictionarycopy
@@ -691,18 +705,18 @@ def delete3_2(deletedrows,dictionary):
691
  df_doors.loc[df_doors['Type'] == 'Single Doors', 'Quantity'] = str(new_value)
692
 
693
  # Print the updated DataFrame to verify the change
694
- print(df_doors)
695
  elif 'double' in str(newitem):
696
  current_value = df_doors.loc[df_doors['Type'] == 'Double Doors', 'Quantity'].values[0]
697
- print(current_value)
698
  # Step 2: Subtract one from the current value
699
  new_value = int(current_value) - 1
700
- print(new_value)
701
  # Step 3: Update the DataFrame with the new value
702
  df_doors.loc[df_doors['Type'] == 'Double Doors', 'Quantity'] = str(new_value)
703
 
704
  # Print the updated DataFrame to verify the change
705
- print(df_doors)
706
  df_doors = df_doors[['Type', 'Quantity']]
707
  return df_doors
708
 
@@ -719,6 +733,7 @@ def deletemarkups(list1, dbPath, path):
719
  list1 = pd.DataFrame(myDict1)
720
 
721
  dbxTeam = tsadropboxretrieval.ADR_Access_DropboxTeam('user')
 
722
  md, res = dbxTeam.files_download(path=dbPath + path)
723
  data = res.content
724
  doc = fitz.open("pdf", data)
 
312
  # firstpart= re.split(r'[`\-=~!@#$%^&*()_+\[\]{};\'\\:"|<,./<>?]', McTName[i][0])
313
  print('kkk' ,McTName[i][2])
314
  if McTName[i][2].startswith('Area'):
315
+ if section.startswith('1.0') or section.startswith('3.2') or section.startswith('3.3'):
316
  rowvalue=5# column 5
317
  ar=0
318
  unit='m2'
319
  if McTName[i][2].startswith('Perimeter'):
320
+ if section.startswith('1.0') or section.startswith('3.2') or section.startswith('3.3'):
321
  rowvalue=7# column 7
322
  ar=0
323
  unit='m'
324
  if McTName[i][2].startswith('Length'):
325
+ if section.startswith('1.0') or section.startswith('3.2') or section.startswith('3.3'):
326
  rowvalue=9# column 7
327
  ar=0
328
  unit='m'
329
  if McTName[i][2].startswith('Count'):
330
+ if section.startswith('1.0') or section.startswith('3.2') or section.startswith('3.3'):
331
  rowvalue=3# column 7
332
 
333
  ar=0
 
348
  # print('kjjjj',roww[j])
349
  ar+=float(worksheetw.cell((indices[j]+1 ,rowvalue)).value)
350
  else:
351
+ if section.startswith('3.2') or section.startswith('3.3'):
352
+ item+=m
353
+ else:
354
+ item+=m + ' ,'
355
  print(item)
356
+ if section.startswith('3.2') or section.startswith('3.3'):
357
+ n= McTName[i][0] + ' ( '+ allgbnames[:-2]+ ' ) '
358
+ else:
359
+ n= McTName[i][0] + ' ( '+ allgbnames[:-2] +' , ' + item[:-1] + ' ) '
360
  else:
361
  if McTName[i][1].startswith('text1'):
362
  name=McTName[i][1].removeprefix('text1')
 
484
  items = []
485
  print('deletefromlegend',deletedrows)
486
  idx = 0
487
+ if section.startswith('1.0') or section.startswith('3.2') or section.startswith('3.3'):
488
  areaPermArr = ast.literal_eval(areaPermArr)
489
  myDict = eval(SimilarAreaDictionarycopy)
490
  SimilarAreaDictionarycopy = pd.DataFrame(myDict)
491
  strings = deletedrows['content']
492
  colors = deletedrows['color']
493
  indicies_toDelete=[]
494
+ # print(colors)
495
  # Define your tolerance value
496
  tolerance = 2 # Allowable tolerance for RGB differences
497
+ # print(SimilarAreaDictionarycopy)
498
  color_list = list(SimilarAreaDictionarycopy['Color']) # Convert Index/Series to list
499
+ if section.startswith('1.0'):
500
+
501
  color_list = [ast.literal_eval(color) for color in color_list]
502
 
503
  for j in range(len(colors)):
 
510
  existing_color = tuple(existing_color) # Ensure it's a tuple for comparison
511
 
512
 
513
+ # print('eee',existing_color,color)
514
  if is_color_within_tolerance(existing_color, color, tolerance):
515
  print(f'Color {color} found close to {existing_color} at index {idx}')
516
  found = True
517
+ # print(strings[j])
518
  matchA = re.search(r"Area=(\d+\.\d+)", strings[j])
519
  matchP = re.search(r"Perimeter=(\d+\.\d+)", strings[j])
520
  matchL = re.search(r"Length=(\d+\.\d+)", strings[j])
521
+ if matchA:
522
+ print('matchingcontentAA ',float(matchA.group(1)),int(idx))
523
+ if matchP:
524
+ print('matchingcontentPP ',float(matchP.group(1)),int(idx))
525
  comment = SimilarAreaDictionarycopy.iloc[int(idx), SimilarAreaDictionarycopy.columns.get_loc('Comments')]
526
  occ = SimilarAreaDictionarycopy.iloc[int(idx), SimilarAreaDictionarycopy.columns.get_loc('Occurences')]
527
 
528
  # Only subtract area if the area value is found
529
  if matchA:
530
+ print(' SimilarAreaDictionaryArea', float(matchA.group(1)), SimilarAreaDictionarycopy.iloc[int(idx), SimilarAreaDictionarycopy.columns.get_loc('Total Area')])
531
  SimilarAreaDictionarycopy.iloc[int(idx), SimilarAreaDictionarycopy.columns.get_loc('Total Area')] =SimilarAreaDictionarycopy.iloc[int(idx), SimilarAreaDictionarycopy.columns.get_loc('Total Area')] - float(matchA.group(1))
532
  # Update area occurrences
533
  if pd.notna(comment) and 'Area' in str(comment):
 
547
  area_occurrences = int(matches[0])
548
  perimeter_occurrences = int(matches[1]) -1
549
  else:
550
+
551
  area_occurrences = int(SimilarAreaDictionarycopy.iloc[int(idx), SimilarAreaDictionarycopy.columns.get_loc('Occurences')])
552
  perimeter_occurrences = SimilarAreaDictionarycopy.iloc[int(idx), SimilarAreaDictionarycopy.columns.get_loc('Occurences')]-1
553
  # print(area_occurrences,perimeter_occurrences)
 
584
  if not found:
585
  print(f'Color {color} not found within tolerance')
586
  print('indicies_toDelete',indicies_toDelete)
587
+
588
  SimilarAreaDictionarycopy.drop(index=indicies_toDelete, axis=0, inplace=True)
589
  print('SimilarAreaDictionarycopy',SimilarAreaDictionarycopy)
590
  return SimilarAreaDictionarycopy
 
705
  df_doors.loc[df_doors['Type'] == 'Single Doors', 'Quantity'] = str(new_value)
706
 
707
  # Print the updated DataFrame to verify the change
708
+ # print(df_doors)
709
  elif 'double' in str(newitem):
710
  current_value = df_doors.loc[df_doors['Type'] == 'Double Doors', 'Quantity'].values[0]
711
+ # print(current_value)
712
  # Step 2: Subtract one from the current value
713
  new_value = int(current_value) - 1
714
+ # print(new_value)
715
  # Step 3: Update the DataFrame with the new value
716
  df_doors.loc[df_doors['Type'] == 'Double Doors', 'Quantity'] = str(new_value)
717
 
718
  # Print the updated DataFrame to verify the change
719
+ # print(df_doors)
720
  df_doors = df_doors[['Type', 'Quantity']]
721
  return df_doors
722
 
 
733
  list1 = pd.DataFrame(myDict1)
734
 
735
  dbxTeam = tsadropboxretrieval.ADR_Access_DropboxTeam('user')
736
+
737
  md, res = dbxTeam.files_download(path=dbPath + path)
738
  data = res.content
739
  doc = fitz.open("pdf", data)