Spaces:
Sleeping
Sleeping
Update google_sheet_Legend.py
Browse files- google_sheet_Legend.py +133 -35
google_sheet_Legend.py
CHANGED
|
@@ -111,6 +111,7 @@ def update_sheet(spreadsheetId, SimilarAreaDictionary, pdfpath):
|
|
| 111 |
worksheet.cell((2, 6)).value = 'Perimeters'
|
| 112 |
worksheet.cell((2, 8)).value = 'Lengths'
|
| 113 |
worksheet.cell((2, 10)).value = 'Texts'
|
|
|
|
| 114 |
second_row_data = ['Nr', 'm2', 'Total', 'm', 'Total', 'm', 'Total']
|
| 115 |
worksheet.update_row(3, second_row_data, col_offset=2)
|
| 116 |
worksheet.update_col(1, list(SimilarAreaDictionary['Guess']), row_offset=3)
|
|
@@ -122,6 +123,8 @@ def update_sheet(spreadsheetId, SimilarAreaDictionary, pdfpath):
|
|
| 122 |
worksheet.update_col(8, list(SimilarAreaDictionary['Length']), row_offset=3)
|
| 123 |
worksheet.update_col(9, list(SimilarAreaDictionary['Total Length']), row_offset=3)
|
| 124 |
worksheet.update_col(10, list(SimilarAreaDictionary['Texts']), row_offset=3)
|
|
|
|
|
|
|
| 125 |
if splittedpdfpath[-2].startswith('1.0'):
|
| 126 |
colorsUsed = [
|
| 127 |
[SimilarAreaDictionary['R'].iloc[i], SimilarAreaDictionary['G'].iloc[i], SimilarAreaDictionary['B'].iloc[i]]
|
|
@@ -461,6 +464,7 @@ def getguessnames(gc,ws):
|
|
| 461 |
|
| 462 |
def deletefromlegend(deletedrows,SimilarAreaDictionarycopy,section, areaPermArr=[]):
|
| 463 |
items=[]
|
|
|
|
| 464 |
idx=0
|
| 465 |
if section.startswith('1.0'):
|
| 466 |
areaPermArr=ast.literal_eval(areaPermArr)
|
|
@@ -471,66 +475,160 @@ def deletefromlegend(deletedrows,SimilarAreaDictionarycopy,section, areaPermArr=
|
|
| 471 |
areastodelete = []
|
| 472 |
perimstodelete=[]
|
| 473 |
lengthstodelete=[]
|
| 474 |
-
|
| 475 |
|
| 476 |
for item in strings:
|
| 477 |
-
|
| 478 |
-
|
| 479 |
-
|
| 480 |
-
|
| 481 |
-
|
| 482 |
-
|
| 483 |
-
|
| 484 |
-
|
| 485 |
-
|
| 486 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 487 |
for i in range(len(areastodelete)):#item in areastodelete:
|
| 488 |
-
areamin=round(areastodelete[i],1)- 0.3
|
| 489 |
-
areamax=round(areastodelete[i],1)+ 0.3
|
| 490 |
-
perimmin=round(perimstodelete[i],1)- 0.3
|
| 491 |
-
perimmax=round(perimstodelete[i],1)+ 0.3
|
| 492 |
if section.startswith('1.0'):
|
| 493 |
-
|
| 494 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 495 |
if areastodelete[i] in areaPermArr[p]:
|
| 496 |
-
print('AAA',areaPermArr[p])
|
| 497 |
-
area= areaPermArr[p][0]
|
| 498 |
width= areaPermArr[p][1]
|
| 499 |
height= areaPermArr[p][2]
|
| 500 |
-
|
| 501 |
widthMin= width -10
|
| 502 |
widthMax= width +10
|
| 503 |
heightMin = height-10
|
| 504 |
heightMax=height+10
|
| 505 |
-
|
|
|
|
| 506 |
elif section.startswith('3.2'):
|
| 507 |
-
areamin=round(areastodelete[i],1)- 0.1
|
| 508 |
-
areamax= round(areastodelete[i],1) + 0.1
|
| 509 |
-
|
| 510 |
found=SimilarAreaDictionarycopy.loc[SimilarAreaDictionarycopy.index[((SimilarAreaDictionarycopy['Area'] >=areamin) & (SimilarAreaDictionarycopy['Area']<=areamax) )]]
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 511 |
|
| 512 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 513 |
occ=SimilarAreaDictionarycopy.loc[found.index.values[0],'Occurences']
|
| 514 |
if occ== 1: #drop row
|
| 515 |
print('occ=1')
|
|
|
|
| 516 |
SimilarAreaDictionarycopy= SimilarAreaDictionarycopy.drop(found.index.values[0])
|
| 517 |
|
| 518 |
else: #occ minus 1 , total area - areavalue , total perim - perimvalue
|
| 519 |
print('occ>1')
|
| 520 |
if section.startswith('1.0'):
|
| 521 |
-
|
|
|
|
| 522 |
elif section.startswith('3.2'):
|
| 523 |
-
|
| 524 |
-
|
| 525 |
-
|
| 526 |
-
|
| 527 |
-
|
| 528 |
-
|
| 529 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 530 |
return SimilarAreaDictionarycopy
|
| 531 |
|
| 532 |
-
|
| 533 |
-
|
| 534 |
# # -*- coding: utf-8 -*-
|
| 535 |
# """Google Sheet to XML.ipynb
|
| 536 |
|
|
|
|
| 111 |
worksheet.cell((2, 6)).value = 'Perimeters'
|
| 112 |
worksheet.cell((2, 8)).value = 'Lengths'
|
| 113 |
worksheet.cell((2, 10)).value = 'Texts'
|
| 114 |
+
worksheet.cell((2, 11)).value = 'Comments'
|
| 115 |
second_row_data = ['Nr', 'm2', 'Total', 'm', 'Total', 'm', 'Total']
|
| 116 |
worksheet.update_row(3, second_row_data, col_offset=2)
|
| 117 |
worksheet.update_col(1, list(SimilarAreaDictionary['Guess']), row_offset=3)
|
|
|
|
| 123 |
worksheet.update_col(8, list(SimilarAreaDictionary['Length']), row_offset=3)
|
| 124 |
worksheet.update_col(9, list(SimilarAreaDictionary['Total Length']), row_offset=3)
|
| 125 |
worksheet.update_col(10, list(SimilarAreaDictionary['Texts']), row_offset=3)
|
| 126 |
+
worksheet.update_col(11, list(SimilarAreaDictionary['Comments']), row_offset=3)
|
| 127 |
+
|
| 128 |
if splittedpdfpath[-2].startswith('1.0'):
|
| 129 |
colorsUsed = [
|
| 130 |
[SimilarAreaDictionary['R'].iloc[i], SimilarAreaDictionary['G'].iloc[i], SimilarAreaDictionary['B'].iloc[i]]
|
|
|
|
| 464 |
|
| 465 |
def deletefromlegend(deletedrows,SimilarAreaDictionarycopy,section, areaPermArr=[]):
|
| 466 |
items=[]
|
| 467 |
+
print('dletefromlegend')
|
| 468 |
idx=0
|
| 469 |
if section.startswith('1.0'):
|
| 470 |
areaPermArr=ast.literal_eval(areaPermArr)
|
|
|
|
| 475 |
areastodelete = []
|
| 476 |
perimstodelete=[]
|
| 477 |
lengthstodelete=[]
|
|
|
|
| 478 |
|
| 479 |
for item in strings:
|
| 480 |
+
newitem=str(item).split('\n \n')
|
| 481 |
+
input_str = " ".join(str(newitem).split())
|
| 482 |
+
# Search for the Area value
|
| 483 |
+
matchA = re.search(r"Area=(\d+\.\d+)", input_str)
|
| 484 |
+
matchL = re.search(r"Length=(\d+\.\d+)", input_str)
|
| 485 |
+
matchP = re.search(r"Perimeter=(\d+\.\d+)", input_str)
|
| 486 |
+
|
| 487 |
+
if matchA:
|
| 488 |
+
areastodelete.append(float(matchA.group(1)))
|
| 489 |
+
if matchP:
|
| 490 |
+
perimstodelete.append(float(matchP.group(1)))
|
| 491 |
+
if matchL:
|
| 492 |
+
lengthstodelete.append(float(matchL.group(1)))
|
| 493 |
+
print('Areas to delete:', areastodelete)
|
| 494 |
+
print('Perimeters to delete:', perimstodelete)
|
| 495 |
+
print('Lengths to delete:', lengthstodelete)
|
| 496 |
+
|
| 497 |
for i in range(len(areastodelete)):#item in areastodelete:
|
|
|
|
|
|
|
|
|
|
|
|
|
| 498 |
if section.startswith('1.0'):
|
| 499 |
+
tol=0.3
|
| 500 |
+
elif section.startswith('3.2'):
|
| 501 |
+
tol=1
|
| 502 |
+
areamin=round(areastodelete[i],1)- tol
|
| 503 |
+
areamax=round(areastodelete[i],1)+ tol
|
| 504 |
+
if section.startswith('1.0'):
|
| 505 |
+
for p in range(len(areaPermArr)):
|
| 506 |
if areastodelete[i] in areaPermArr[p]:
|
|
|
|
|
|
|
| 507 |
width= areaPermArr[p][1]
|
| 508 |
height= areaPermArr[p][2]
|
| 509 |
+
break
|
| 510 |
widthMin= width -10
|
| 511 |
widthMax= width +10
|
| 512 |
heightMin = height-10
|
| 513 |
heightMax=height+10
|
| 514 |
+
if len(areastodelete)>0:
|
| 515 |
+
found=SimilarAreaDictionarycopy.loc[SimilarAreaDictionarycopy.index[((SimilarAreaDictionarycopy['Rounded'] >=areamin) & (SimilarAreaDictionarycopy['Rounded']<=areamax) ) & ( ((SimilarAreaDictionarycopy['Width']>=widthMin) & (SimilarAreaDictionarycopy['Width']<=widthMax) & (SimilarAreaDictionarycopy['Height']>=heightMin) & (SimilarAreaDictionarycopy['Height']<=heightMax) ) | ((SimilarAreaDictionarycopy['Width']>=heightMin) & (SimilarAreaDictionarycopy['Width']<=heightMax) & (SimilarAreaDictionarycopy['Height']>=widthMin) & (SimilarAreaDictionarycopy['Height']<=widthMax) )) ]]
|
| 516 |
elif section.startswith('3.2'):
|
|
|
|
|
|
|
|
|
|
| 517 |
found=SimilarAreaDictionarycopy.loc[SimilarAreaDictionarycopy.index[((SimilarAreaDictionarycopy['Area'] >=areamin) & (SimilarAreaDictionarycopy['Area']<=areamax) )]]
|
| 518 |
+
if len(found.index.values) >0:
|
| 519 |
+
occ=SimilarAreaDictionarycopy.loc[found.index.values[0],'Occurences']
|
| 520 |
+
if occ== 1: #drop row
|
| 521 |
+
SimilarAreaDictionarycopy= SimilarAreaDictionarycopy.drop(found.index.values[0])
|
| 522 |
+
else: #occ minus 1 , total area - areavalue , total perim - perimvalue
|
| 523 |
+
print('occ>1')
|
| 524 |
+
if section.startswith('1.0'):
|
| 525 |
+
if len(areastodelete)>0:
|
| 526 |
+
idx=SimilarAreaDictionarycopy.index[((SimilarAreaDictionarycopy['Rounded'] >=areamin) & (SimilarAreaDictionarycopy['Rounded']<=areamax) ) & ( ((SimilarAreaDictionarycopy['Width']>=widthMin) & (SimilarAreaDictionarycopy['Width']<=widthMax) & (SimilarAreaDictionarycopy['Height']>=heightMin) & (SimilarAreaDictionarycopy['Height']<=heightMax) ) | ((SimilarAreaDictionarycopy['Width']>=heightMin) & (SimilarAreaDictionarycopy['Width']<=heightMax) & (SimilarAreaDictionarycopy['Height']>=widthMin) & (SimilarAreaDictionarycopy['Height']<=widthMax) )) ]
|
| 527 |
+
elif section.startswith('3.2'):
|
| 528 |
+
idx=SimilarAreaDictionarycopy.index[((SimilarAreaDictionarycopy['Area'] >=areamin) & (SimilarAreaDictionarycopy['Area']<=areamax) )]
|
| 529 |
+
if len(areastodelete)>0:
|
| 530 |
+
comment = SimilarAreaDictionarycopy.loc[idx, 'Comments']
|
| 531 |
+
if pd.notna(comment.iloc[0]) and 'Area' in str(comment.iloc[0]):
|
| 532 |
+
matches = re.findall(r'\b\d+\b', str(SimilarAreaDictionarycopy.loc[idx, 'Comments']))
|
| 533 |
+
area_occurrences = int(matches[1]) -1
|
| 534 |
+
perimeter_occurrences = int(matches[2])
|
| 535 |
+
print(area_occurrences, perimeter_occurrences)
|
| 536 |
+
SimilarAreaDictionarycopy.loc[idx, 'Comments'] = f'Area occurrences: {area_occurrences}, Perimeter occurrences: {perimeter_occurrences}'
|
| 537 |
+
if area_occurrences > perimeter_occurrences:
|
| 538 |
+
SimilarAreaDictionarycopy.loc[idx,'Occurences'] = area_occurrences
|
| 539 |
+
elif perimeter_occurrences> area_occurrences:
|
| 540 |
+
SimilarAreaDictionarycopy.loc[idx,'Occurences'] = perimeter_occurrences
|
| 541 |
+
elif int(area_occurrences)==int(perimeter_occurrences):
|
| 542 |
+
SimilarAreaDictionarycopy.loc[idx,'Occurences'] = int(SimilarAreaDictionarycopy.loc[idx,'Occurences']) - 1
|
| 543 |
+
if section.startswith('1.0'):
|
| 544 |
+
SimilarAreaDictionarycopy.loc[idx,'Total Length'] = SimilarAreaDictionarycopy.loc[idx,'Total Length'] - lengthstodelete[i]
|
| 545 |
+
|
| 546 |
+
else:
|
| 547 |
+
print('not yet')
|
| 548 |
+
area_occurrences = SimilarAreaDictionarycopy.loc[idx, 'Occurences'].iloc[0] -1
|
| 549 |
+
perimeter_occurrences = SimilarAreaDictionarycopy.loc[idx, 'Occurences'].iloc[0]
|
| 550 |
+
print(area_occurrences,perimeter_occurrences)
|
| 551 |
+
SimilarAreaDictionarycopy.loc[idx, 'Comments'] = f'Area occurrences: {area_occurrences}, Perimeter occurrences: {perimeter_occurrences}'
|
| 552 |
+
SimilarAreaDictionarycopy.loc[idx,'Total Area'] = SimilarAreaDictionarycopy.loc[idx,'Total Area'] - areastodelete[i]
|
| 553 |
+
|
| 554 |
|
| 555 |
+
for i in range(len(perimstodelete)):#item in areastodelete:
|
| 556 |
+
if section.startswith('1.0'):
|
| 557 |
+
tol=0.3
|
| 558 |
+
elif section.startswith('3.2'):
|
| 559 |
+
tol=10
|
| 560 |
+
|
| 561 |
+
if len(perimstodelete)>0:
|
| 562 |
+
print(perimstodelete[i])
|
| 563 |
+
perimmin=round(perimstodelete[i],1)- 0.3
|
| 564 |
+
perimmax=round(perimstodelete[i],1)+ 0.3
|
| 565 |
+
print('perimmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmm')
|
| 566 |
+
if section.startswith('1.0'):
|
| 567 |
+
for p in range(len(areaPermArr)):
|
| 568 |
+
if areastodelete[i] in areaPermArr[p]:
|
| 569 |
+
print('AAA',areaPermArr[p])
|
| 570 |
+
area= areaPermArr[p][0]
|
| 571 |
+
width= areaPermArr[p][1]
|
| 572 |
+
height= areaPermArr[p][2]
|
| 573 |
+
break
|
| 574 |
+
widthMin= width -10
|
| 575 |
+
widthMax= width +10
|
| 576 |
+
heightMin = height-10
|
| 577 |
+
heightMax=height+10
|
| 578 |
+
found=SimilarAreaDictionarycopy.loc[SimilarAreaDictionarycopy.index[( (SimilarAreaDictionarycopy['Perimeter'] >=perimmin) & (SimilarAreaDictionarycopy['Perimeter']<=perimmax) ) & ( ((SimilarAreaDictionarycopy['Width']>=widthMin) & (SimilarAreaDictionarycopy['Width']<=widthMax) & (SimilarAreaDictionarycopy['Height']>=heightMin) & (SimilarAreaDictionarycopy['Height']<=heightMax) ) | ((SimilarAreaDictionarycopy['Width']>=heightMin) & (SimilarAreaDictionarycopy['Width']<=heightMax) & (SimilarAreaDictionarycopy['Height']>=widthMin) & (SimilarAreaDictionarycopy['Height']<=widthMax) )) ]]
|
| 579 |
+
elif section.startswith('3.2'):
|
| 580 |
+
found=SimilarAreaDictionarycopy.loc[SimilarAreaDictionarycopy.index[( (SimilarAreaDictionarycopy['Perimeter'] >=perimmin) & (SimilarAreaDictionarycopy['Perimeter']<=perimmax) )]]
|
| 581 |
+
|
| 582 |
+
if len(found.index.values) >0:
|
| 583 |
occ=SimilarAreaDictionarycopy.loc[found.index.values[0],'Occurences']
|
| 584 |
if occ== 1: #drop row
|
| 585 |
print('occ=1')
|
| 586 |
+
print(found)
|
| 587 |
SimilarAreaDictionarycopy= SimilarAreaDictionarycopy.drop(found.index.values[0])
|
| 588 |
|
| 589 |
else: #occ minus 1 , total area - areavalue , total perim - perimvalue
|
| 590 |
print('occ>1')
|
| 591 |
if section.startswith('1.0'):
|
| 592 |
+
if len(perimstodelete)>0:
|
| 593 |
+
idx=SimilarAreaDictionarycopy.index[((SimilarAreaDictionarycopy['Perimeter'] >=perimmin) & (SimilarAreaDictionarycopy['Perimeter']<=perimmax) ) & ( ((SimilarAreaDictionarycopy['Width']>=widthMin) & (SimilarAreaDictionarycopy['Width']<=widthMax) & (SimilarAreaDictionarycopy['Height']>=heightMin) & (SimilarAreaDictionarycopy['Height']<=heightMax) ) | ((SimilarAreaDictionarycopy['Width']>=heightMin) & (SimilarAreaDictionarycopy['Width']<=heightMax) & (SimilarAreaDictionarycopy['Height']>=widthMin) & (SimilarAreaDictionarycopy['Height']<=widthMax) )) ]
|
| 594 |
elif section.startswith('3.2'):
|
| 595 |
+
if len(perimstodelete)>0:
|
| 596 |
+
perimmin=round(perimstodelete[i],1)- 1
|
| 597 |
+
perimmax=round(perimstodelete[i],1)+ 1
|
| 598 |
+
idx=SimilarAreaDictionarycopy.index[((SimilarAreaDictionarycopy['Perimeter'] >=perimmin) & (SimilarAreaDictionarycopy['Perimeter']<=perimmax) )]
|
| 599 |
+
|
| 600 |
+
|
| 601 |
+
if len(perimstodelete)>0:
|
| 602 |
+
comment = SimilarAreaDictionarycopy.loc[idx, 'Comments']
|
| 603 |
+
if pd.notna(comment.iloc[0]) and 'Area' in str(comment.iloc[0]):
|
| 604 |
+
matches = re.findall(r'\b\d+\b', str(SimilarAreaDictionarycopy.loc[idx, 'Comments']))
|
| 605 |
+
area_occurrences = int(matches[1])
|
| 606 |
+
perimeter_occurrences = int(matches[2])-1
|
| 607 |
+
print(area_occurrences, perimeter_occurrences)
|
| 608 |
+
SimilarAreaDictionarycopy.loc[idx, 'Comments'] = f'Area occurrences: {area_occurrences}, Perimeter occurrences: {perimeter_occurrences}'
|
| 609 |
+
if area_occurrences > perimeter_occurrences:
|
| 610 |
+
SimilarAreaDictionarycopy.loc[idx,'Occurences'] = area_occurrences
|
| 611 |
+
elif perimeter_occurrences> area_occurrences:
|
| 612 |
+
SimilarAreaDictionarycopy.loc[idx,'Occurences'] = perimeter_occurrences
|
| 613 |
+
elif int(area_occurrences)==int(perimeter_occurrences):
|
| 614 |
+
SimilarAreaDictionarycopy.loc[idx,'Occurences'] = int(SimilarAreaDictionarycopy.loc[idx,'Occurences']) - 1
|
| 615 |
+
if section.startswith('1.0'):
|
| 616 |
+
SimilarAreaDictionarycopy.loc[idx,'Total Length'] = SimilarAreaDictionarycopy.loc[idx,'Total Length'] - lengthstodelete[i]
|
| 617 |
+
|
| 618 |
+
else:
|
| 619 |
+
print('not yet')
|
| 620 |
+
area_occurrences = SimilarAreaDictionarycopy.loc[idx, 'Occurences'].iloc[0]
|
| 621 |
+
perimeter_occurrences = SimilarAreaDictionarycopy.loc[idx, 'Occurences'].iloc[0] -1
|
| 622 |
+
|
| 623 |
+
SimilarAreaDictionarycopy.loc[idx, 'Comments'] = f'Area occurrences: {area_occurrences}, Perimeter occurrences: {perimeter_occurrences}'
|
| 624 |
+
area_occurrences = SimilarAreaDictionarycopy.loc[idx, 'Occurences'].iloc[0] -1
|
| 625 |
+
perimeter_occurrences = SimilarAreaDictionarycopy.loc[idx, 'Occurences'].iloc[0]
|
| 626 |
+
|
| 627 |
+
|
| 628 |
+
SimilarAreaDictionarycopy.loc[idx,'Total Perimeter'] = SimilarAreaDictionarycopy.loc[idx,'Total Perimeter'] - perimstodelete[i]
|
| 629 |
return SimilarAreaDictionarycopy
|
| 630 |
|
| 631 |
+
######################
|
|
|
|
| 632 |
# # -*- coding: utf-8 -*-
|
| 633 |
# """Google Sheet to XML.ipynb
|
| 634 |
|