Spaces:
Sleeping
Sleeping
Update google_sheet_Legend.py
Browse files- google_sheet_Legend.py +817 -284
google_sheet_Legend.py
CHANGED
|
@@ -13,6 +13,11 @@ import pygsheets
|
|
| 13 |
import ast
|
| 14 |
import re
|
| 15 |
import pandas as pd
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 16 |
|
| 17 |
def authorizeLegend():
|
| 18 |
SCOPES = [
|
|
@@ -26,291 +31,234 @@ def authorizeLegend():
|
|
| 26 |
gc = pygsheets.authorize(custom_credentials=credentials, client_secret='credentials.json')
|
| 27 |
return spreadsheet_service,drive_service,gc
|
| 28 |
|
|
|
|
| 29 |
|
| 30 |
-
def legendGoogleSheets(SimilarAreaDictionary,path ,pdfpath, spreadsheetId=0):
|
| 31 |
-
|
| 32 |
-
spreadsheet_service,drive_service,gc=authorizeLegend()
|
| 33 |
-
########
|
| 34 |
-
legendTitle= path
|
| 35 |
-
titles=gc.spreadsheet_titles()
|
| 36 |
-
|
| 37 |
-
|
| 38 |
-
|
| 39 |
-
if legendTitle in titles:
|
| 40 |
-
print('found sheet ', legendTitle)
|
| 41 |
-
ws=gc.open(str(legendTitle))
|
| 42 |
-
spreadsheetId=ws.id
|
| 43 |
-
else:
|
| 44 |
-
# ####### create new sheet
|
| 45 |
-
print('creating new sheeet')
|
| 46 |
|
|
|
|
| 47 |
spreadsheet_details = {
|
| 48 |
-
|
| 49 |
-
|
| 50 |
-
|
| 51 |
-
|
| 52 |
-
sheet = spreadsheet_service.spreadsheets().create(body=spreadsheet_details,
|
| 53 |
-
fields='spreadsheetId').execute()
|
| 54 |
-
|
| 55 |
spreadsheetId = sheet.get('spreadsheetId')
|
| 56 |
permission1 = {
|
| 57 |
-
|
| 58 |
-
|
| 59 |
-
|
| 60 |
-
|
| 61 |
-
|
| 62 |
-
# 'type': 'user',
|
| 63 |
-
# 'role': 'writer',
|
| 64 |
-
# 'emailAddress': 'marthe.adr@gmail.com',
|
| 65 |
-
# 'pendingOwner': True
|
| 66 |
-
# }
|
| 67 |
-
|
| 68 |
|
| 69 |
-
drive_service.permissions().create(fileId=spreadsheetId, body=permission1, supportsAllDrives=True ).execute()
|
| 70 |
-
ws=gc.open_by_key(spreadsheetId)
|
| 71 |
-
|
| 72 |
-
sheetId = '0' # Please set sheet ID.
|
| 73 |
-
worksheet = ws.worksheet(0)
|
| 74 |
-
worksheet.title='Legend and data created'
|
| 75 |
-
worksheet.clear()
|
| 76 |
-
print('PDFPATHHH',pdfpath)
|
| 77 |
-
ws.create_developer_metadata('path',pdfpath)
|
| 78 |
-
splittedpdfpath=re.split(r'[`\-=~!@#$%^&*()_+\[\]{};\'\\:"|<,/<>?]', pdfpath)
|
| 79 |
-
namepathArr=[legendTitle , spreadsheetId,ws.get_developer_metadata('path')[0].value]
|
| 80 |
-
if splittedpdfpath[-2].startswith('2.2') or splittedpdfpath[-2].startswith('2.1') :
|
| 81 |
-
worksheet.set_dataframe(start='A1',df=SimilarAreaDictionary)
|
| 82 |
-
print(SimilarAreaDictionary)
|
| 83 |
-
else:
|
| 84 |
-
top_header_format = [
|
| 85 |
-
{'mergeCells': { #areas
|
| 86 |
-
'mergeType': 'MERGE_ROWS',
|
| 87 |
-
'range': {
|
| 88 |
-
'sheetId': '0',
|
| 89 |
-
'startRowIndex': 1,
|
| 90 |
-
'endRowIndex': 2,
|
| 91 |
-
'startColumnIndex': 3,
|
| 92 |
-
'endColumnIndex':5
|
| 93 |
-
|
| 94 |
-
|
| 95 |
-
}
|
| 96 |
-
}},
|
| 97 |
-
|
| 98 |
-
{'mergeCells': { #perimeters
|
| 99 |
-
'mergeType': 'MERGE_ROWS',
|
| 100 |
-
'range': {
|
| 101 |
-
'sheetId': '0',
|
| 102 |
-
'startRowIndex': 1,
|
| 103 |
-
'endRowIndex': 2,
|
| 104 |
-
'startColumnIndex': 5,
|
| 105 |
-
'endColumnIndex':7
|
| 106 |
-
}
|
| 107 |
-
|
| 108 |
-
}},
|
| 109 |
-
{'mergeCells': { #lengths
|
| 110 |
-
'mergeType': 'MERGE_ROWS',
|
| 111 |
-
'range': {
|
| 112 |
-
'sheetId': '0',
|
| 113 |
-
'startRowIndex': 1,
|
| 114 |
-
'endRowIndex': 2,
|
| 115 |
-
'startColumnIndex': 7,
|
| 116 |
-
'endColumnIndex':9
|
| 117 |
-
}
|
| 118 |
-
|
| 119 |
-
}},
|
| 120 |
-
|
| 121 |
-
{'mergeCells': { # legend and data created
|
| 122 |
-
'mergeType': 'MERGE_ROWS',
|
| 123 |
-
'range': {
|
| 124 |
-
'sheetId': '0',
|
| 125 |
-
'startRowIndex': 0,
|
| 126 |
-
'endRowIndex': 1,
|
| 127 |
-
'startColumnIndex': 0,
|
| 128 |
-
'endColumnIndex':10
|
| 129 |
-
}
|
| 130 |
-
|
| 131 |
-
}}
|
| 132 |
-
]
|
| 133 |
|
| 134 |
-
|
| 135 |
-
|
| 136 |
-
worksheet.
|
| 137 |
-
worksheet.
|
| 138 |
-
worksheet.
|
| 139 |
-
|
| 140 |
-
|
| 141 |
-
|
| 142 |
-
|
| 143 |
-
|
| 144 |
-
|
| 145 |
-
|
| 146 |
-
|
| 147 |
-
|
| 148 |
-
|
| 149 |
-
|
| 150 |
-
|
| 151 |
-
|
| 152 |
-
|
| 153 |
-
|
| 154 |
-
|
| 155 |
-
|
| 156 |
-
|
| 157 |
-
|
| 158 |
-
|
| 159 |
-
|
| 160 |
-
|
| 161 |
-
|
| 162 |
-
|
| 163 |
-
|
| 164 |
-
|
| 165 |
-
|
| 166 |
-
|
| 167 |
-
|
| 168 |
-
|
| 169 |
-
|
| 170 |
-
|
| 171 |
-
|
| 172 |
-
|
| 173 |
-
|
| 174 |
-
|
| 175 |
-
|
| 176 |
-
|
| 177 |
-
|
| 178 |
-
|
| 179 |
-
|
| 180 |
-
|
| 181 |
-
|
| 182 |
-
|
| 183 |
-
|
| 184 |
-
|
| 185 |
-
|
| 186 |
-
|
| 187 |
-
|
| 188 |
-
|
| 189 |
-
|
| 190 |
-
|
| 191 |
-
|
| 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-
|
| 228 |
-
|
| 229 |
-
|
| 230 |
-
|
| 231 |
-
|
| 232 |
-
|
| 233 |
-
"
|
| 234 |
-
|
| 235 |
-
"updateBorders": {
|
| 236 |
-
"range": {
|
| 237 |
-
"sheetId": sheetId,
|
| 238 |
-
"startRowIndex": 0,
|
| 239 |
-
"endRowIndex": len(SimilarAreaDictionary)+endrow,
|
| 240 |
-
"startColumnIndex": 0,
|
| 241 |
-
"endColumnIndex": endColindex
|
| 242 |
-
},
|
| 243 |
-
"top": {
|
| 244 |
-
"style": "SOLID",
|
| 245 |
-
"width": 2,
|
| 246 |
-
"color": {
|
| 247 |
-
"red": 0.0,
|
| 248 |
-
"green":0.0,
|
| 249 |
-
"blue":0.0
|
| 250 |
-
},
|
| 251 |
-
},
|
| 252 |
-
"bottom": {
|
| 253 |
-
"style": "SOLID",
|
| 254 |
-
"width": 2,
|
| 255 |
-
"color": {
|
| 256 |
-
"red": 0.0,
|
| 257 |
-
"green":0.0,
|
| 258 |
-
"blue":0.0
|
| 259 |
-
},
|
| 260 |
-
},
|
| 261 |
-
"left":{
|
| 262 |
-
"style": "SOLID",
|
| 263 |
-
"width":2,
|
| 264 |
-
"color": {
|
| 265 |
-
"red": 0.0,
|
| 266 |
-
"green":0.0,
|
| 267 |
-
"blue":0.0
|
| 268 |
-
},
|
| 269 |
-
},
|
| 270 |
-
"right":{
|
| 271 |
-
"style": "SOLID",
|
| 272 |
-
"width": 2,
|
| 273 |
-
"color": {
|
| 274 |
-
"red": 0.0,
|
| 275 |
-
"green":0.0,
|
| 276 |
-
"blue":0.0
|
| 277 |
-
},
|
| 278 |
-
},
|
| 279 |
-
"innerHorizontal":{
|
| 280 |
-
"style": "SOLID",
|
| 281 |
-
"width":2,
|
| 282 |
-
"color": {
|
| 283 |
-
"red": 0.0,
|
| 284 |
-
"green":0.0,
|
| 285 |
-
"blue":0.0
|
| 286 |
-
},
|
| 287 |
-
},
|
| 288 |
-
"innerVertical": {
|
| 289 |
-
"style": "SOLID",
|
| 290 |
-
"width": 2,
|
| 291 |
-
"color": {
|
| 292 |
-
"red": 0.0,
|
| 293 |
-
"green":0.0,
|
| 294 |
-
"blue":0.0
|
| 295 |
-
},
|
| 296 |
-
},
|
| 297 |
-
}
|
| 298 |
-
}
|
| 299 |
-
]
|
| 300 |
-
}
|
| 301 |
-
spreadsheet_service.spreadsheets().batchUpdate(spreadsheetId=spreadsheetId, body=body2).execute()
|
| 302 |
|
| 303 |
-
|
| 304 |
-
|
| 305 |
-
model_cell.set_horizontal_alignment( pygsheets.custom_types.HorizontalAlignment.CENTER )
|
| 306 |
-
model_cell.color = (213/255, 219/255 ,255/255)
|
| 307 |
-
pygsheets.DataRange('A2','J2', worksheet=worksheet).apply_format(model_cell)
|
| 308 |
-
spreadsheet_url = "https://docs.google.com/spreadsheets/d/%s" % spreadsheetId
|
| 309 |
-
print(spreadsheet_url)
|
| 310 |
-
drive_service.permissions().update(transferOwnership=True , fileId=spreadsheetId,permissionId='11OfoB4Z6wOVII8mYmbnCbbqTQs7rYA65')
|
| 311 |
-
|
| 312 |
|
| 313 |
-
return gc,spreadsheet_service,spreadsheetId ,spreadsheet_url , namepathArr
|
| 314 |
#######################
|
| 315 |
|
| 316 |
def mapnametoLegend(McTName):
|
|
@@ -319,7 +267,7 @@ def mapnametoLegend(McTName):
|
|
| 319 |
key=sectionKey[0]
|
| 320 |
section=sectionKey[1]
|
| 321 |
|
| 322 |
-
spreadsheet_service,drive_service,gc=authorizeLegend()
|
| 323 |
spreadsheet_key =str(key) # Please set the Spreadsheet ID.
|
| 324 |
|
| 325 |
ws = gc.open_by_key(spreadsheet_key)
|
|
@@ -355,31 +303,24 @@ def mapnametoLegend(McTName):
|
|
| 355 |
# firstpart= re.split(r'[`\-=~!@#$%^&*()_+\[\]{};\'\\:"|<,./<>?]', McTName[i][0])
|
| 356 |
print('kkk' ,McTName[i][2])
|
| 357 |
if McTName[i][2].startswith('Area'):
|
| 358 |
-
if section.startswith('1.0'):
|
| 359 |
rowvalue=5# column 5
|
| 360 |
-
elif section.startswith('3.2'):
|
| 361 |
-
rowvalue=3
|
| 362 |
ar=0
|
| 363 |
unit='m2'
|
| 364 |
if McTName[i][2].startswith('Perimeter'):
|
| 365 |
-
if section.startswith('1.0'):
|
| 366 |
rowvalue=7# column 7
|
| 367 |
-
elif section.startswith('3.2'):
|
| 368 |
-
rowvalue=3
|
| 369 |
ar=0
|
| 370 |
unit='m'
|
| 371 |
if McTName[i][2].startswith('Length'):
|
| 372 |
-
if section.startswith('1.0'):
|
| 373 |
rowvalue=9# column 7
|
| 374 |
-
elif section.startswith('3.2'):
|
| 375 |
-
rowvalue=3
|
| 376 |
ar=0
|
| 377 |
unit='m'
|
| 378 |
if McTName[i][2].startswith('Count'):
|
| 379 |
-
if section.startswith('1.0'):
|
| 380 |
rowvalue=3# column 7
|
| 381 |
-
|
| 382 |
-
rowvalue=3
|
| 383 |
ar=0
|
| 384 |
unit='Nr'
|
| 385 |
|
|
@@ -588,4 +529,596 @@ def deletefromlegend(deletedrows,SimilarAreaDictionarycopy,section, areaPermArr=
|
|
| 588 |
SimilarAreaDictionarycopy.loc[idx,'Occurences'] = int(SimilarAreaDictionarycopy.loc[idx,'Occurences']) - 1
|
| 589 |
return SimilarAreaDictionarycopy
|
| 590 |
|
| 591 |
-
#############################################################
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
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|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 13 |
import ast
|
| 14 |
import re
|
| 15 |
import pandas as pd
|
| 16 |
+
from google.oauth2 import service_account
|
| 17 |
+
from googleapiclient.discovery import build
|
| 18 |
+
import pygsheets
|
| 19 |
+
import re
|
| 20 |
+
|
| 21 |
|
| 22 |
def authorizeLegend():
|
| 23 |
SCOPES = [
|
|
|
|
| 31 |
gc = pygsheets.authorize(custom_credentials=credentials, client_secret='credentials.json')
|
| 32 |
return spreadsheet_service,drive_service,gc
|
| 33 |
|
| 34 |
+
spreadsheet_service,drive_service,gc=authorizeLegend()
|
| 35 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 36 |
|
| 37 |
+
def create_new_sheet(path):
|
| 38 |
spreadsheet_details = {
|
| 39 |
+
'properties': {
|
| 40 |
+
'title': path
|
| 41 |
+
}
|
| 42 |
+
}
|
| 43 |
+
sheet = spreadsheet_service.spreadsheets().create(body=spreadsheet_details, fields='spreadsheetId').execute()
|
|
|
|
|
|
|
| 44 |
spreadsheetId = sheet.get('spreadsheetId')
|
| 45 |
permission1 = {
|
| 46 |
+
'type': 'anyone',
|
| 47 |
+
'role': 'writer',
|
| 48 |
+
}
|
| 49 |
+
drive_service.permissions().create(fileId=spreadsheetId, body=permission1, supportsAllDrives=True).execute()
|
| 50 |
+
return spreadsheetId
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 51 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 52 |
|
| 53 |
+
def update_sheet(spreadsheetId, SimilarAreaDictionary, pdfpath):
|
| 54 |
+
ws = gc.open_by_key(spreadsheetId)
|
| 55 |
+
worksheet = ws.worksheet(0)
|
| 56 |
+
worksheet.title = 'Legend and data created'
|
| 57 |
+
worksheet.clear()
|
| 58 |
+
ws.create_developer_metadata('path', pdfpath)
|
| 59 |
+
splittedpdfpath = re.split(r'[`\-=~!@#$%^&*()_+\[\]{};\'\\:"|<,/<>?]', pdfpath)
|
| 60 |
+
if splittedpdfpath[-2].startswith('2.2') or splittedpdfpath[-2].startswith('2.1'):
|
| 61 |
+
worksheet.set_dataframe(start='A1', df=SimilarAreaDictionary)
|
| 62 |
+
else:
|
| 63 |
+
top_header_format = [
|
| 64 |
+
{'mergeCells': { # areas
|
| 65 |
+
'mergeType': 'MERGE_ROWS',
|
| 66 |
+
'range': {
|
| 67 |
+
'sheetId': '0',
|
| 68 |
+
'startRowIndex': 1,
|
| 69 |
+
'endRowIndex': 2,
|
| 70 |
+
'startColumnIndex': 3,
|
| 71 |
+
'endColumnIndex': 5
|
| 72 |
+
}
|
| 73 |
+
}},
|
| 74 |
+
{'mergeCells': { # perimeters
|
| 75 |
+
'mergeType': 'MERGE_ROWS',
|
| 76 |
+
'range': {
|
| 77 |
+
'sheetId': '0',
|
| 78 |
+
'startRowIndex': 1,
|
| 79 |
+
'endRowIndex': 2,
|
| 80 |
+
'startColumnIndex': 5,
|
| 81 |
+
'endColumnIndex': 7
|
| 82 |
+
}
|
| 83 |
+
}},
|
| 84 |
+
{'mergeCells': { # lengths
|
| 85 |
+
'mergeType': 'MERGE_ROWS',
|
| 86 |
+
'range': {
|
| 87 |
+
'sheetId': '0',
|
| 88 |
+
'startRowIndex': 1,
|
| 89 |
+
'endRowIndex': 2,
|
| 90 |
+
'startColumnIndex': 7,
|
| 91 |
+
'endColumnIndex': 9
|
| 92 |
+
}
|
| 93 |
+
}},
|
| 94 |
+
{'mergeCells': { # legend and data created
|
| 95 |
+
'mergeType': 'MERGE_ROWS',
|
| 96 |
+
'range': {
|
| 97 |
+
'sheetId': '0',
|
| 98 |
+
'startRowIndex': 0,
|
| 99 |
+
'endRowIndex': 1,
|
| 100 |
+
'startColumnIndex': 0,
|
| 101 |
+
'endColumnIndex': 11
|
| 102 |
+
}
|
| 103 |
+
}}
|
| 104 |
+
]
|
| 105 |
+
spreadsheet_service.spreadsheets().batchUpdate(spreadsheetId=spreadsheetId, body={'requests': top_header_format}).execute()
|
| 106 |
+
worksheet.cell((1, 1)).value = 'Legend and Data Created'
|
| 107 |
+
worksheet.cell((2, 1)).value = 'Guess'
|
| 108 |
+
worksheet.cell((2, 2)).value = 'Color'
|
| 109 |
+
worksheet.cell((2, 3)).value = 'Count'
|
| 110 |
+
worksheet.cell((2, 4)).value = 'Areas'
|
| 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)
|
| 117 |
+
worksheet.update_col(3, list(SimilarAreaDictionary['Occurences']), row_offset=3)
|
| 118 |
+
worksheet.update_col(4, list(SimilarAreaDictionary['Area']), row_offset=3)
|
| 119 |
+
worksheet.update_col(5, list(SimilarAreaDictionary['Total Area']), row_offset=3)
|
| 120 |
+
worksheet.update_col(6, list(SimilarAreaDictionary['Perimeter']), row_offset=3)
|
| 121 |
+
worksheet.update_col(7, list(SimilarAreaDictionary['Total Perimeter']), row_offset=3)
|
| 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]]
|
| 128 |
+
for i in range(len(SimilarAreaDictionary))
|
| 129 |
+
]
|
| 130 |
+
elif splittedpdfpath[-2].startswith('3.2'):
|
| 131 |
+
colorsUsed = list(SimilarAreaDictionary['Color'])
|
| 132 |
+
rowsLen = len(SimilarAreaDictionary.values.tolist())
|
| 133 |
+
lastcell = worksheet.cell((rowsLen + 2, 1))
|
| 134 |
+
lastcellNotation = str(lastcell.address.label)
|
| 135 |
+
columnsLen = len(SimilarAreaDictionary.columns.values.tolist())
|
| 136 |
+
lastUsedCol = columnsLen + 1
|
| 137 |
+
worksheet.adjust_column_width(start=2, end=3)
|
| 138 |
+
worksheet.adjust_column_width(start=10, end=10)
|
| 139 |
+
worksheet.adjust_column_width(start=4, end=9, pixel_size=60)
|
| 140 |
+
startrow = 3
|
| 141 |
+
endColindex = 11
|
| 142 |
+
endrow = 3
|
| 143 |
+
sheetId = '0'
|
| 144 |
+
batch_requests = []
|
| 145 |
+
for i in range(len(colorsUsed)):
|
| 146 |
+
r, g, b = colorsUsed[i]
|
| 147 |
+
batch_requests.append({
|
| 148 |
+
"updateCells": {
|
| 149 |
+
"range": {
|
| 150 |
+
"sheetId": sheetId,
|
| 151 |
+
"startRowIndex": i + startrow,
|
| 152 |
+
"startColumnIndex": 1,
|
| 153 |
+
},
|
| 154 |
+
"rows": [
|
| 155 |
+
{
|
| 156 |
+
"values": [
|
| 157 |
+
{
|
| 158 |
+
"userEnteredFormat": {
|
| 159 |
+
"backgroundColor": {
|
| 160 |
+
"red": r / 255,
|
| 161 |
+
"green": g / 255,
|
| 162 |
+
"blue": b / 255,
|
| 163 |
+
"alpha": 0.4,
|
| 164 |
+
}
|
| 165 |
+
}
|
| 166 |
+
}
|
| 167 |
+
]
|
| 168 |
}
|
| 169 |
+
],
|
| 170 |
+
"fields": "userEnteredFormat.backgroundColor",
|
| 171 |
+
}
|
| 172 |
+
})
|
| 173 |
+
batch_requests.append({
|
| 174 |
+
"updateBorders": {
|
| 175 |
+
"range": {
|
| 176 |
+
"sheetId": sheetId,
|
| 177 |
+
"startRowIndex": 0,
|
| 178 |
+
"endRowIndex": len(SimilarAreaDictionary) + endrow,
|
| 179 |
+
"startColumnIndex": 0,
|
| 180 |
+
"endColumnIndex": endColindex
|
| 181 |
+
},
|
| 182 |
+
"top": {
|
| 183 |
+
"style": "SOLID",
|
| 184 |
+
"width": 2,
|
| 185 |
+
"color": {
|
| 186 |
+
"red": 0.0,
|
| 187 |
+
"green": 0.0,
|
| 188 |
+
"blue": 0.0
|
| 189 |
+
}
|
| 190 |
+
},
|
| 191 |
+
"bottom": {
|
| 192 |
+
"style": "SOLID",
|
| 193 |
+
"width": 2,
|
| 194 |
+
"color": {
|
| 195 |
+
"red": 0.0,
|
| 196 |
+
"green": 0.0,
|
| 197 |
+
"blue": 0.0
|
| 198 |
+
}
|
| 199 |
+
},
|
| 200 |
+
"left": {
|
| 201 |
+
"style": "SOLID",
|
| 202 |
+
"width": 2,
|
| 203 |
+
"color": {
|
| 204 |
+
"red": 0.0,
|
| 205 |
+
"green": 0.0,
|
| 206 |
+
"blue": 0.0
|
| 207 |
+
}
|
| 208 |
+
},
|
| 209 |
+
"right": {
|
| 210 |
+
"style": "SOLID",
|
| 211 |
+
"width": 2,
|
| 212 |
+
"color": {
|
| 213 |
+
"red": 0.0,
|
| 214 |
+
"green": 0.0,
|
| 215 |
+
"blue": 0.0
|
| 216 |
+
}
|
| 217 |
+
},
|
| 218 |
+
"innerHorizontal": {
|
| 219 |
+
"style": "SOLID",
|
| 220 |
+
"width": 2,
|
| 221 |
+
"color": {
|
| 222 |
+
"red": 0.0,
|
| 223 |
+
"green": 0.0,
|
| 224 |
+
"blue": 0.0
|
| 225 |
+
}
|
| 226 |
+
},
|
| 227 |
+
"innerVertical": {
|
| 228 |
+
"style": "SOLID",
|
| 229 |
+
"width": 2,
|
| 230 |
+
"color": {
|
| 231 |
+
"red": 0.0,
|
| 232 |
+
"green": 0.0,
|
| 233 |
+
"blue": 0.0
|
| 234 |
}
|
|
|
|
| 235 |
}
|
|
|
|
|
|
|
|
|
|
| 236 |
}
|
| 237 |
+
})
|
| 238 |
+
spreadsheet_service.spreadsheets().batchUpdate(spreadsheetId=spreadsheetId, body={'requests': batch_requests}).execute()
|
| 239 |
+
|
| 240 |
+
model_cell = worksheet.cell('A1')
|
| 241 |
+
model_cell.set_text_format('bold', True)
|
| 242 |
+
model_cell.set_horizontal_alignment(pygsheets.custom_types.HorizontalAlignment.CENTER)
|
| 243 |
+
model_cell.color = (213 / 255, 219 / 255, 255 / 255)
|
| 244 |
+
pygsheets.DataRange('A2', 'K2', worksheet=worksheet).apply_format(model_cell)
|
| 245 |
|
| 246 |
|
| 247 |
+
def legendGoogleSheets(SimilarAreaDictionary, path, pdfpath, spreadsheetId=0):
|
| 248 |
+
titles = gc.spreadsheet_titles()
|
| 249 |
+
if path in titles:
|
| 250 |
+
ws = gc.open(path)
|
| 251 |
+
spreadsheetId = ws.id
|
| 252 |
+
else:
|
| 253 |
+
spreadsheetId = create_new_sheet(path)
|
| 254 |
+
ws=gc.open_by_key(spreadsheetId)
|
| 255 |
+
update_sheet(spreadsheetId, SimilarAreaDictionary, pdfpath)
|
| 256 |
+
spreadsheet_url = f"https://docs.google.com/spreadsheets/d/{spreadsheetId}"
|
| 257 |
+
drive_service.permissions().update(transferOwnership=True, fileId=spreadsheetId, permissionId='11OfoB4Z6wOVII8mYmbnCbbqTQs7rYA65')
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 258 |
|
| 259 |
+
namepathArr = [path, spreadsheetId, ws.get_developer_metadata('path')[0].value]
|
| 260 |
+
return gc, spreadsheet_service, spreadsheetId, spreadsheet_url, namepathArr
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 261 |
|
|
|
|
| 262 |
#######################
|
| 263 |
|
| 264 |
def mapnametoLegend(McTName):
|
|
|
|
| 267 |
key=sectionKey[0]
|
| 268 |
section=sectionKey[1]
|
| 269 |
|
| 270 |
+
# spreadsheet_service,drive_service,gc=authorizeLegend()
|
| 271 |
spreadsheet_key =str(key) # Please set the Spreadsheet ID.
|
| 272 |
|
| 273 |
ws = gc.open_by_key(spreadsheet_key)
|
|
|
|
| 303 |
# firstpart= re.split(r'[`\-=~!@#$%^&*()_+\[\]{};\'\\:"|<,./<>?]', McTName[i][0])
|
| 304 |
print('kkk' ,McTName[i][2])
|
| 305 |
if McTName[i][2].startswith('Area'):
|
| 306 |
+
if section.startswith('1.0') or section.startswith('3.2'):
|
| 307 |
rowvalue=5# column 5
|
|
|
|
|
|
|
| 308 |
ar=0
|
| 309 |
unit='m2'
|
| 310 |
if McTName[i][2].startswith('Perimeter'):
|
| 311 |
+
if section.startswith('1.0') or section.startswith('3.2'):
|
| 312 |
rowvalue=7# column 7
|
|
|
|
|
|
|
| 313 |
ar=0
|
| 314 |
unit='m'
|
| 315 |
if McTName[i][2].startswith('Length'):
|
| 316 |
+
if section.startswith('1.0') or section.startswith('3.2'):
|
| 317 |
rowvalue=9# column 7
|
|
|
|
|
|
|
| 318 |
ar=0
|
| 319 |
unit='m'
|
| 320 |
if McTName[i][2].startswith('Count'):
|
| 321 |
+
if section.startswith('1.0') or section.startswith('3.2'):
|
| 322 |
rowvalue=3# column 7
|
| 323 |
+
|
|
|
|
| 324 |
ar=0
|
| 325 |
unit='Nr'
|
| 326 |
|
|
|
|
| 529 |
SimilarAreaDictionarycopy.loc[idx,'Occurences'] = int(SimilarAreaDictionarycopy.loc[idx,'Occurences']) - 1
|
| 530 |
return SimilarAreaDictionarycopy
|
| 531 |
|
| 532 |
+
#############################################################
|
| 533 |
+
|
| 534 |
+
# # -*- coding: utf-8 -*-
|
| 535 |
+
# """Google Sheet to XML.ipynb
|
| 536 |
+
|
| 537 |
+
# Automatically generated by Colaboratory.
|
| 538 |
+
|
| 539 |
+
# Original file is located at
|
| 540 |
+
# https://colab.research.google.com/drive/1T-b1N8Gq6wwbBurODzJIdhRQNeRbyBnz
|
| 541 |
+
# """
|
| 542 |
+
|
| 543 |
+
# from googleapiclient.discovery import build
|
| 544 |
+
# from google.oauth2 import service_account
|
| 545 |
+
# import pygsheets
|
| 546 |
+
# import ast
|
| 547 |
+
# import re
|
| 548 |
+
# import pandas as pd
|
| 549 |
+
|
| 550 |
+
# def authorizeLegend():
|
| 551 |
+
# SCOPES = [
|
| 552 |
+
# 'https://www.googleapis.com/auth/spreadsheets',
|
| 553 |
+
# 'https://www.googleapis.com/auth/drive',
|
| 554 |
+
# 'https://www.googleapis.com/auth/drive.metadata'
|
| 555 |
+
# ]
|
| 556 |
+
# credentials = service_account.Credentials.from_service_account_file('credentials.json', scopes=SCOPES)
|
| 557 |
+
# spreadsheet_service = build('sheets', 'v4', credentials=credentials)
|
| 558 |
+
# drive_service = build('drive', 'v3', credentials=credentials)
|
| 559 |
+
# gc = pygsheets.authorize(custom_credentials=credentials, client_secret='credentials.json')
|
| 560 |
+
# return spreadsheet_service,drive_service,gc
|
| 561 |
+
|
| 562 |
+
|
| 563 |
+
# def legendGoogleSheets(SimilarAreaDictionary,path ,pdfpath, spreadsheetId=0):
|
| 564 |
+
|
| 565 |
+
# spreadsheet_service,drive_service,gc=authorizeLegend()
|
| 566 |
+
# ########
|
| 567 |
+
# legendTitle= path
|
| 568 |
+
# titles=gc.spreadsheet_titles()
|
| 569 |
+
|
| 570 |
+
|
| 571 |
+
|
| 572 |
+
# if legendTitle in titles:
|
| 573 |
+
# print('found sheet ', legendTitle)
|
| 574 |
+
# ws=gc.open(str(legendTitle))
|
| 575 |
+
# spreadsheetId=ws.id
|
| 576 |
+
# else:
|
| 577 |
+
# # ####### create new sheet
|
| 578 |
+
# print('creating new sheeet')
|
| 579 |
+
|
| 580 |
+
# spreadsheet_details = {
|
| 581 |
+
# 'properties': {
|
| 582 |
+
# 'title': path
|
| 583 |
+
# }
|
| 584 |
+
# }
|
| 585 |
+
# sheet = spreadsheet_service.spreadsheets().create(body=spreadsheet_details,
|
| 586 |
+
# fields='spreadsheetId').execute()
|
| 587 |
+
|
| 588 |
+
# spreadsheetId = sheet.get('spreadsheetId')
|
| 589 |
+
# permission1 = {
|
| 590 |
+
# 'type': 'anyone',
|
| 591 |
+
# 'role': 'writer',
|
| 592 |
+
# # 'emailAddress': 'marthe.adr@gmail.com'
|
| 593 |
+
# }
|
| 594 |
+
# # permission2 = {
|
| 595 |
+
# # 'type': 'user',
|
| 596 |
+
# # 'role': 'writer',
|
| 597 |
+
# # 'emailAddress': 'marthe.adr@gmail.com',
|
| 598 |
+
# # 'pendingOwner': True
|
| 599 |
+
# # }
|
| 600 |
+
|
| 601 |
+
|
| 602 |
+
# drive_service.permissions().create(fileId=spreadsheetId, body=permission1, supportsAllDrives=True ).execute()
|
| 603 |
+
# ws=gc.open_by_key(spreadsheetId)
|
| 604 |
+
|
| 605 |
+
# sheetId = '0' # Please set sheet ID.
|
| 606 |
+
# worksheet = ws.worksheet(0)
|
| 607 |
+
# worksheet.title='Legend and data created'
|
| 608 |
+
# worksheet.clear()
|
| 609 |
+
# print('PDFPATHHH',pdfpath)
|
| 610 |
+
# ws.create_developer_metadata('path',pdfpath)
|
| 611 |
+
# splittedpdfpath=re.split(r'[`\-=~!@#$%^&*()_+\[\]{};\'\\:"|<,/<>?]', pdfpath)
|
| 612 |
+
# namepathArr=[legendTitle , spreadsheetId,ws.get_developer_metadata('path')[0].value]
|
| 613 |
+
# if splittedpdfpath[-2].startswith('2.2') or splittedpdfpath[-2].startswith('2.1') :
|
| 614 |
+
# worksheet.set_dataframe(start='A1',df=SimilarAreaDictionary)
|
| 615 |
+
# print(SimilarAreaDictionary)
|
| 616 |
+
# else:
|
| 617 |
+
# top_header_format = [
|
| 618 |
+
# {'mergeCells': { #areas
|
| 619 |
+
# 'mergeType': 'MERGE_ROWS',
|
| 620 |
+
# 'range': {
|
| 621 |
+
# 'sheetId': '0',
|
| 622 |
+
# 'startRowIndex': 1,
|
| 623 |
+
# 'endRowIndex': 2,
|
| 624 |
+
# 'startColumnIndex': 3,
|
| 625 |
+
# 'endColumnIndex':5
|
| 626 |
+
|
| 627 |
+
|
| 628 |
+
# }
|
| 629 |
+
# }},
|
| 630 |
+
|
| 631 |
+
# {'mergeCells': { #perimeters
|
| 632 |
+
# 'mergeType': 'MERGE_ROWS',
|
| 633 |
+
# 'range': {
|
| 634 |
+
# 'sheetId': '0',
|
| 635 |
+
# 'startRowIndex': 1,
|
| 636 |
+
# 'endRowIndex': 2,
|
| 637 |
+
# 'startColumnIndex': 5,
|
| 638 |
+
# 'endColumnIndex':7
|
| 639 |
+
# }
|
| 640 |
+
|
| 641 |
+
# }},
|
| 642 |
+
# {'mergeCells': { #lengths
|
| 643 |
+
# 'mergeType': 'MERGE_ROWS',
|
| 644 |
+
# 'range': {
|
| 645 |
+
# 'sheetId': '0',
|
| 646 |
+
# 'startRowIndex': 1,
|
| 647 |
+
# 'endRowIndex': 2,
|
| 648 |
+
# 'startColumnIndex': 7,
|
| 649 |
+
# 'endColumnIndex':9
|
| 650 |
+
# }
|
| 651 |
+
|
| 652 |
+
# }},
|
| 653 |
+
|
| 654 |
+
# {'mergeCells': { # legend and data created
|
| 655 |
+
# 'mergeType': 'MERGE_ROWS',
|
| 656 |
+
# 'range': {
|
| 657 |
+
# 'sheetId': '0',
|
| 658 |
+
# 'startRowIndex': 0,
|
| 659 |
+
# 'endRowIndex': 1,
|
| 660 |
+
# 'startColumnIndex': 0,
|
| 661 |
+
# 'endColumnIndex':10
|
| 662 |
+
# }
|
| 663 |
+
|
| 664 |
+
# }}
|
| 665 |
+
# ]
|
| 666 |
+
|
| 667 |
+
|
| 668 |
+
# spreadsheet_service.spreadsheets().batchUpdate( spreadsheetId=spreadsheetId , body={'requests': top_header_format} ).execute()
|
| 669 |
+
# worksheet.cell((1,1)).value='Legend and Data Created'
|
| 670 |
+
# worksheet.cell((2,1)).value='Guess'
|
| 671 |
+
# worksheet.cell((2,2)).value='Color'
|
| 672 |
+
# worksheet.cell((2,3)).value='Count'
|
| 673 |
+
# worksheet.cell((2,4)).value='Areas'
|
| 674 |
+
# worksheet.cell((2,6)).value='Perimeters'
|
| 675 |
+
# worksheet.cell((2,8)).value='Lengths'
|
| 676 |
+
# worksheet.cell((2,10)).value='Texts'
|
| 677 |
+
# second_row_data=['Nr','m2','Total','m','Total','m','Total']
|
| 678 |
+
# if splittedpdfpath[-2].startswith('1.0') or splittedpdfpath[-2].startswith('3.2'):
|
| 679 |
+
# worksheet.update_row(3,second_row_data,col_offset=2)
|
| 680 |
+
# worksheet.update_col(1,list(SimilarAreaDictionary['Guess']),row_offset=3)
|
| 681 |
+
# worksheet.update_col(3,list(SimilarAreaDictionary['Occurences']),row_offset=3)
|
| 682 |
+
# worksheet.update_col(4,list(SimilarAreaDictionary['Area']),row_offset=3)
|
| 683 |
+
# worksheet.update_col(5,list(SimilarAreaDictionary['Total Area']),row_offset=3)
|
| 684 |
+
# worksheet.update_col(6,list(SimilarAreaDictionary['Perimeter']),row_offset=3)
|
| 685 |
+
# worksheet.update_col(7,list(SimilarAreaDictionary['Total Perimeter']),row_offset=3)
|
| 686 |
+
|
| 687 |
+
# worksheet.update_col(8,list(SimilarAreaDictionary['Length']),row_offset=3)
|
| 688 |
+
# worksheet.update_col(9,list(SimilarAreaDictionary['Total Length']),row_offset=3)
|
| 689 |
+
# worksheet.update_col(10,list(SimilarAreaDictionary['Texts']),row_offset=3)
|
| 690 |
+
# if splittedpdfpath[-2].startswith('1.0'):
|
| 691 |
+
# colorsUsed=[]
|
| 692 |
+
# for i in range(len(SimilarAreaDictionary)):
|
| 693 |
+
# colorsUsed.append([SimilarAreaDictionary['R'].iloc[i] ,SimilarAreaDictionary['G'].iloc[i] , SimilarAreaDictionary['B'].iloc[i]] )
|
| 694 |
+
# elif splittedpdfpath[-2].startswith('3.2'):
|
| 695 |
+
# colorsUsed=list(SimilarAreaDictionary['Color'])
|
| 696 |
+
|
| 697 |
+
# #legend specs here
|
| 698 |
+
# rowsLen=len(SimilarAreaDictionary.values.tolist()) #kam row -- last row = rowsLen +1
|
| 699 |
+
# lastcell=worksheet.cell((rowsLen+2,1)) #row,col
|
| 700 |
+
# lastcellNotation=str(lastcell.address.label)
|
| 701 |
+
# # worksheet.set_data_validation('A3',lastcellNotation, condition_type='ONE_OF_LIST', condition_values=['Ground Beam','Pile Cap'], showCustomUi=True)
|
| 702 |
+
|
| 703 |
+
# #get lengths of df
|
| 704 |
+
# columnsLen=len(SimilarAreaDictionary.columns.values.tolist()) #kam column -- last col = columnsLen+1 3shan base0
|
| 705 |
+
# lastUsedCol=columnsLen+1
|
| 706 |
+
|
| 707 |
+
# worksheet.adjust_column_width(start=2,end=3)
|
| 708 |
+
# worksheet.adjust_column_width(start=10,end=10)
|
| 709 |
+
# # if splittedpdfpath[-2].startswith('1.0'):
|
| 710 |
+
# worksheet.adjust_column_width(start=4,end=9,pixel_size=60)
|
| 711 |
+
# startrow = 3
|
| 712 |
+
# # elif splittedpdfpath[-2].startswith('3.2'):
|
| 713 |
+
# # startrow=2
|
| 714 |
+
|
| 715 |
+
# sheetId = '0' # Please set sheet ID.
|
| 716 |
+
# for i in range(len(colorsUsed)):
|
| 717 |
+
|
| 718 |
+
# print(colorsUsed[i])
|
| 719 |
+
# r,g,b=colorsUsed[i]
|
| 720 |
+
# body = {
|
| 721 |
+
# "requests": [
|
| 722 |
+
# {
|
| 723 |
+
# "updateCells": {
|
| 724 |
+
# "range": {
|
| 725 |
+
# "sheetId": sheetId,
|
| 726 |
+
# "startRowIndex": i+startrow,
|
| 727 |
+
# # "endRowIndex":4 ,
|
| 728 |
+
# "startColumnIndex":1,
|
| 729 |
+
|
| 730 |
+
# # "endColumnIndex": 0
|
| 731 |
+
# },
|
| 732 |
+
|
| 733 |
+
# "rows": [
|
| 734 |
+
# {
|
| 735 |
+
# "values": [
|
| 736 |
+
# {
|
| 737 |
+
# "userEnteredFormat": {
|
| 738 |
+
# "backgroundColor": {
|
| 739 |
+
|
| 740 |
+
# "red": r/255,
|
| 741 |
+
# "green": g/255,
|
| 742 |
+
# "blue": b/255,
|
| 743 |
+
# "alpha": 0.4,
|
| 744 |
+
|
| 745 |
+
# }
|
| 746 |
+
|
| 747 |
+
# }
|
| 748 |
+
# }
|
| 749 |
+
# ]
|
| 750 |
+
# }
|
| 751 |
+
# ],
|
| 752 |
+
# "fields": "userEnteredFormat.backgroundColor",
|
| 753 |
+
|
| 754 |
+
# }
|
| 755 |
+
|
| 756 |
+
|
| 757 |
+
|
| 758 |
+
# }
|
| 759 |
+
# ]
|
| 760 |
+
# }
|
| 761 |
+
# res = spreadsheet_service.spreadsheets().batchUpdate(spreadsheetId=spreadsheetId, body=body).execute()
|
| 762 |
+
# # if splittedpdfpath[-2].startswith('1.0'):
|
| 763 |
+
# endColindex=10
|
| 764 |
+
# endrow=3
|
| 765 |
+
# body2={
|
| 766 |
+
# "requests": [
|
| 767 |
+
# {
|
| 768 |
+
# "updateBorders": {
|
| 769 |
+
# "range": {
|
| 770 |
+
# "sheetId": sheetId,
|
| 771 |
+
# "startRowIndex": 0,
|
| 772 |
+
# "endRowIndex": len(SimilarAreaDictionary)+endrow,
|
| 773 |
+
# "startColumnIndex": 0,
|
| 774 |
+
# "endColumnIndex": endColindex
|
| 775 |
+
# },
|
| 776 |
+
# "top": {
|
| 777 |
+
# "style": "SOLID",
|
| 778 |
+
# "width": 2,
|
| 779 |
+
# "color": {
|
| 780 |
+
# "red": 0.0,
|
| 781 |
+
# "green":0.0,
|
| 782 |
+
# "blue":0.0
|
| 783 |
+
# },
|
| 784 |
+
# },
|
| 785 |
+
# "bottom": {
|
| 786 |
+
# "style": "SOLID",
|
| 787 |
+
# "width": 2,
|
| 788 |
+
# "color": {
|
| 789 |
+
# "red": 0.0,
|
| 790 |
+
# "green":0.0,
|
| 791 |
+
# "blue":0.0
|
| 792 |
+
# },
|
| 793 |
+
# },
|
| 794 |
+
# "left":{
|
| 795 |
+
# "style": "SOLID",
|
| 796 |
+
# "width":2,
|
| 797 |
+
# "color": {
|
| 798 |
+
# "red": 0.0,
|
| 799 |
+
# "green":0.0,
|
| 800 |
+
# "blue":0.0
|
| 801 |
+
# },
|
| 802 |
+
# },
|
| 803 |
+
# "right":{
|
| 804 |
+
# "style": "SOLID",
|
| 805 |
+
# "width": 2,
|
| 806 |
+
# "color": {
|
| 807 |
+
# "red": 0.0,
|
| 808 |
+
# "green":0.0,
|
| 809 |
+
# "blue":0.0
|
| 810 |
+
# },
|
| 811 |
+
# },
|
| 812 |
+
# "innerHorizontal":{
|
| 813 |
+
# "style": "SOLID",
|
| 814 |
+
# "width":2,
|
| 815 |
+
# "color": {
|
| 816 |
+
# "red": 0.0,
|
| 817 |
+
# "green":0.0,
|
| 818 |
+
# "blue":0.0
|
| 819 |
+
# },
|
| 820 |
+
# },
|
| 821 |
+
# "innerVertical": {
|
| 822 |
+
# "style": "SOLID",
|
| 823 |
+
# "width": 2,
|
| 824 |
+
# "color": {
|
| 825 |
+
# "red": 0.0,
|
| 826 |
+
# "green":0.0,
|
| 827 |
+
# "blue":0.0
|
| 828 |
+
# },
|
| 829 |
+
# },
|
| 830 |
+
# }
|
| 831 |
+
# }
|
| 832 |
+
# ]
|
| 833 |
+
# }
|
| 834 |
+
# spreadsheet_service.spreadsheets().batchUpdate(spreadsheetId=spreadsheetId, body=body2).execute()
|
| 835 |
+
|
| 836 |
+
# model_cell =worksheet.cell('A1')
|
| 837 |
+
# model_cell.set_text_format('bold', True)
|
| 838 |
+
# model_cell.set_horizontal_alignment( pygsheets.custom_types.HorizontalAlignment.CENTER )
|
| 839 |
+
# model_cell.color = (213/255, 219/255 ,255/255)
|
| 840 |
+
# pygsheets.DataRange('A2','J2', worksheet=worksheet).apply_format(model_cell)
|
| 841 |
+
# spreadsheet_url = "https://docs.google.com/spreadsheets/d/%s" % spreadsheetId
|
| 842 |
+
# print(spreadsheet_url)
|
| 843 |
+
# drive_service.permissions().update(transferOwnership=True , fileId=spreadsheetId,permissionId='11OfoB4Z6wOVII8mYmbnCbbqTQs7rYA65')
|
| 844 |
+
|
| 845 |
+
|
| 846 |
+
# return gc,spreadsheet_service,spreadsheetId ,spreadsheet_url , namepathArr
|
| 847 |
+
# #######################
|
| 848 |
+
|
| 849 |
+
# def mapnametoLegend(McTName):
|
| 850 |
+
|
| 851 |
+
# sectionKey = McTName.pop()
|
| 852 |
+
# key=sectionKey[0]
|
| 853 |
+
# section=sectionKey[1]
|
| 854 |
+
|
| 855 |
+
# spreadsheet_service,drive_service,gc=authorizeLegend()
|
| 856 |
+
# spreadsheet_key =str(key) # Please set the Spreadsheet ID.
|
| 857 |
+
|
| 858 |
+
# ws = gc.open_by_key(spreadsheet_key)
|
| 859 |
+
# # guessednamesfinal=getguessnames(gc,ws)
|
| 860 |
+
# sheetnames=[]
|
| 861 |
+
# unit=''
|
| 862 |
+
# # ws.add_worksheet("Summary") # Please set the new sheet name.
|
| 863 |
+
# for i in ws._sheet_list:
|
| 864 |
+
# print(i)
|
| 865 |
+
# sheetnames.append(i.title)
|
| 866 |
+
# print(i.index)
|
| 867 |
+
# if 'XML Export Summary' in sheetnames:
|
| 868 |
+
# worksheetS = ws.worksheet_by_title('XML Export Summary')
|
| 869 |
+
# else:
|
| 870 |
+
# ws.add_worksheet("XML Export Summary") # Please set the new sheet name.
|
| 871 |
+
# worksheetw = ws.worksheet(0) #legend
|
| 872 |
+
# worksheetS = ws.worksheet_by_title('XML Export Summary')
|
| 873 |
+
# summaryId= ws[1].id
|
| 874 |
+
# print('summaryyyID',summaryId)
|
| 875 |
+
# print('summaryyyID2',worksheetS.id)
|
| 876 |
+
# worksheetS.clear()
|
| 877 |
+
|
| 878 |
+
# countnames=0
|
| 879 |
+
# row0=['MC_T Name','Qty','Unit']
|
| 880 |
+
# worksheetS.update_row(1,row0)
|
| 881 |
+
|
| 882 |
+
|
| 883 |
+
# for i in range(len(McTName)):
|
| 884 |
+
# allgbnames=''
|
| 885 |
+
# item=''
|
| 886 |
+
# print(McTName[i][0])
|
| 887 |
+
|
| 888 |
+
# # firstpart= re.split(r'[`\-=~!@#$%^&*()_+\[\]{};\'\\:"|<,./<>?]', McTName[i][0])
|
| 889 |
+
# print('kkk' ,McTName[i][2])
|
| 890 |
+
# if McTName[i][2].startswith('Area'):
|
| 891 |
+
# if section.startswith('1.0'):
|
| 892 |
+
# rowvalue=5# column 5
|
| 893 |
+
# elif section.startswith('3.2'):
|
| 894 |
+
# rowvalue=3
|
| 895 |
+
# ar=0
|
| 896 |
+
# unit='m2'
|
| 897 |
+
# if McTName[i][2].startswith('Perimeter'):
|
| 898 |
+
# if section.startswith('1.0'):
|
| 899 |
+
# rowvalue=7# column 7
|
| 900 |
+
# elif section.startswith('3.2'):
|
| 901 |
+
# rowvalue=3
|
| 902 |
+
# ar=0
|
| 903 |
+
# unit='m'
|
| 904 |
+
# if McTName[i][2].startswith('Length'):
|
| 905 |
+
# if section.startswith('1.0'):
|
| 906 |
+
# rowvalue=9# column 7
|
| 907 |
+
# elif section.startswith('3.2'):
|
| 908 |
+
# rowvalue=3
|
| 909 |
+
# ar=0
|
| 910 |
+
# unit='m'
|
| 911 |
+
# if McTName[i][2].startswith('Count'):
|
| 912 |
+
# if section.startswith('1.0'):
|
| 913 |
+
# rowvalue=3# column 7
|
| 914 |
+
# elif section.startswith('3.2'):
|
| 915 |
+
# rowvalue=3
|
| 916 |
+
# ar=0
|
| 917 |
+
# unit='Nr'
|
| 918 |
+
|
| 919 |
+
# print('mcct',McTName[i][1])
|
| 920 |
+
# if isinstance(McTName[i][1], list):
|
| 921 |
+
# guessednames=worksheetw.get_col(1, returnas='matrix', include_tailing_empty=False)
|
| 922 |
+
|
| 923 |
+
# for m in McTName[i][1]:
|
| 924 |
+
# if m:
|
| 925 |
+
# if m.startswith('text1'):
|
| 926 |
+
# name=m.removeprefix('text1')
|
| 927 |
+
# allgbnames+= name +' +'
|
| 928 |
+
# indices = [o for o, x in enumerate(guessednames) if x == name]
|
| 929 |
+
# print(indices)
|
| 930 |
+
# for j in range(len(indices)):
|
| 931 |
+
# # print('kjjjj',roww[j])
|
| 932 |
+
# ar+=float(worksheetw.cell((indices[j]+1 ,rowvalue)).value)
|
| 933 |
+
# else:
|
| 934 |
+
# item+=m + ' ,'
|
| 935 |
+
# print(item)
|
| 936 |
+
# n= McTName[i][0] + ' ( '+ allgbnames[:-2] +' , ' + item[:-1] + ' ) '
|
| 937 |
+
# else:
|
| 938 |
+
# if McTName[i][1].startswith('text1'):
|
| 939 |
+
# name=McTName[i][1].removeprefix('text1')
|
| 940 |
+
# allgbnames+= name
|
| 941 |
+
|
| 942 |
+
# roww=worksheetw.find(name)
|
| 943 |
+
# print(roww)
|
| 944 |
+
# for j in range(len(roww)):
|
| 945 |
+
# print('kjjjj',roww[j])
|
| 946 |
+
# ar+=float(worksheetw.cell((roww[j].row ,rowvalue)).value)
|
| 947 |
+
# n= McTName[i][0] + ' ( '+ allgbnames + ' ) '
|
| 948 |
+
|
| 949 |
+
# rowi=[str(n),ar,unit]
|
| 950 |
+
# worksheetS.update_row(i+2,rowi)
|
| 951 |
+
# # worksheetS.adjust_column_width(start=1,end=4)
|
| 952 |
+
# worksheetS.adjust_column_width(start=1,end=1, pixel_size=350)
|
| 953 |
+
# worksheetS.adjust_column_width(start=2,end=2, pixel_size=100)
|
| 954 |
+
# worksheetS.adjust_column_width(start=3,end=3)
|
| 955 |
+
|
| 956 |
+
# xx=(worksheetS.cell( ( len(McTName) +1 ,3)) ).address.label
|
| 957 |
+
# model_cell1 =worksheetS.cell('A2')
|
| 958 |
+
# model_cell1.set_horizontal_alignment( pygsheets.custom_types.HorizontalAlignment.LEFT )
|
| 959 |
+
# pygsheets.DataRange('A2', str(xx), worksheet=worksheetS).apply_format(model_cell1)
|
| 960 |
+
|
| 961 |
+
|
| 962 |
+
# model_cell =worksheetS.cell('A1')
|
| 963 |
+
# model_cell.set_text_format('bold', True)
|
| 964 |
+
# model_cell.set_horizontal_alignment( pygsheets.custom_types.HorizontalAlignment.CENTER )
|
| 965 |
+
# pygsheets.DataRange('A1','C1', worksheet=worksheetS).apply_format(model_cell)
|
| 966 |
+
|
| 967 |
+
# body2={
|
| 968 |
+
# "requests": [
|
| 969 |
+
# {
|
| 970 |
+
# "updateBorders": {
|
| 971 |
+
# "range": {
|
| 972 |
+
# "sheetId": str(summaryId),
|
| 973 |
+
# "startRowIndex": 0,
|
| 974 |
+
# "endRowIndex": len(McTName) +1 ,
|
| 975 |
+
# "startColumnIndex": 0,
|
| 976 |
+
# "endColumnIndex": 3
|
| 977 |
+
# },
|
| 978 |
+
# "top": {
|
| 979 |
+
# "style": "SOLID",
|
| 980 |
+
# "width": 2,
|
| 981 |
+
# "color": {
|
| 982 |
+
# "red": 0.0,
|
| 983 |
+
# "green":0.0,
|
| 984 |
+
# "blue":0.0
|
| 985 |
+
# },
|
| 986 |
+
# },
|
| 987 |
+
# "bottom": {
|
| 988 |
+
# "style": "SOLID",
|
| 989 |
+
# "width": 2,
|
| 990 |
+
# "color": {
|
| 991 |
+
# "red": 0.0,
|
| 992 |
+
# "green":0.0,
|
| 993 |
+
# "blue":0.0
|
| 994 |
+
# },
|
| 995 |
+
# },
|
| 996 |
+
# "left":{
|
| 997 |
+
# "style": "SOLID",
|
| 998 |
+
# "width":2,
|
| 999 |
+
# "color": {
|
| 1000 |
+
# "red": 0.0,
|
| 1001 |
+
# "green":0.0,
|
| 1002 |
+
# "blue":0.0
|
| 1003 |
+
# },
|
| 1004 |
+
# },
|
| 1005 |
+
# "right":{
|
| 1006 |
+
# "style": "SOLID",
|
| 1007 |
+
# "width": 2,
|
| 1008 |
+
# "color": {
|
| 1009 |
+
# "red": 0.0,
|
| 1010 |
+
# "green":0.0,
|
| 1011 |
+
# "blue":0.0
|
| 1012 |
+
# },
|
| 1013 |
+
# },
|
| 1014 |
+
# "innerHorizontal":{
|
| 1015 |
+
# "style": "SOLID",
|
| 1016 |
+
# "width":2,
|
| 1017 |
+
# "color": {
|
| 1018 |
+
# "red": 0.0,
|
| 1019 |
+
# "green":0.0,
|
| 1020 |
+
# "blue":0.0
|
| 1021 |
+
# },
|
| 1022 |
+
# },
|
| 1023 |
+
# "innerVertical": {
|
| 1024 |
+
# "style": "SOLID",
|
| 1025 |
+
# "width": 2,
|
| 1026 |
+
# "color": {
|
| 1027 |
+
# "red": 0.0,
|
| 1028 |
+
# "green":0.0,
|
| 1029 |
+
# "blue":0.0
|
| 1030 |
+
# },
|
| 1031 |
+
# },
|
| 1032 |
+
# }
|
| 1033 |
+
# }
|
| 1034 |
+
# ]
|
| 1035 |
+
# }
|
| 1036 |
+
# spreadsheet_service.spreadsheets().batchUpdate(spreadsheetId=spreadsheet_key, body=body2).execute()
|
| 1037 |
+
# return summaryId #,guessednamesfinal
|
| 1038 |
+
|
| 1039 |
+
# # print(x,xarea)
|
| 1040 |
+
|
| 1041 |
+
# def getguessnames(gc,ws):
|
| 1042 |
+
# guessednamesfinal=[]
|
| 1043 |
+
# worksheetw = ws.worksheet(0)
|
| 1044 |
+
# guessednames=worksheetw.get_col(1, returnas='matrix', include_tailing_empty=False)
|
| 1045 |
+
# print(guessednames[2:])
|
| 1046 |
+
# for item in guessednames[2:]:
|
| 1047 |
+
# if item not in guessednamesfinal:
|
| 1048 |
+
# guessednamesfinal.append(item)
|
| 1049 |
+
# print(guessednamesfinal)
|
| 1050 |
+
# return guessednamesfinal
|
| 1051 |
+
|
| 1052 |
+
# ################################################################
|
| 1053 |
+
|
| 1054 |
+
# def deletefromlegend(deletedrows,SimilarAreaDictionarycopy,section, areaPermArr=[]):
|
| 1055 |
+
# items=[]
|
| 1056 |
+
# idx=0
|
| 1057 |
+
# if section.startswith('1.0'):
|
| 1058 |
+
# areaPermArr=ast.literal_eval(areaPermArr)
|
| 1059 |
+
# myDict=eval(SimilarAreaDictionarycopy)
|
| 1060 |
+
# SimilarAreaDictionarycopy=pd.DataFrame(myDict)
|
| 1061 |
+
# # deletedrows=eval(deletedrows)
|
| 1062 |
+
# strings=deletedrows['content']
|
| 1063 |
+
# areastodelete = []
|
| 1064 |
+
# perimstodelete=[]
|
| 1065 |
+
# lengthstodelete=[]
|
| 1066 |
+
|
| 1067 |
+
|
| 1068 |
+
# for item in strings:
|
| 1069 |
+
# items.append(str(item).split('\n \n'))
|
| 1070 |
+
# # print('itemsssssss',float(re.findall("\d+\.\d+", str(items[i][0]).split()[0])[0])) #take area and perim mn hna l sec 3.2 and +/- value margin
|
| 1071 |
+
|
| 1072 |
+
# for i in range(len(items)):
|
| 1073 |
+
# print('ITEMSS',str(items[i]).split())
|
| 1074 |
+
# items=ast.literal_eval(str(items[i]))
|
| 1075 |
+
# areastodelete.append(float(re.findall("\d+\.\d+", str(items[i][0]).split()[1])[0]))
|
| 1076 |
+
# perimstodelete.append(float(re.findall("\d+\.\d+", str(items[i][1]).split()[1])[0]) )
|
| 1077 |
+
# lengthstodelete.append(float(re.findall("\d+\.\d+", str(items[i][2]).split()[1])[0]) )
|
| 1078 |
+
|
| 1079 |
+
# for i in range(len(areastodelete)):#item in areastodelete:
|
| 1080 |
+
# areamin=round(areastodelete[i],1)- 0.3
|
| 1081 |
+
# areamax=round(areastodelete[i],1)+ 0.3
|
| 1082 |
+
# perimmin=round(perimstodelete[i],1)- 0.3
|
| 1083 |
+
# perimmax=round(perimstodelete[i],1)+ 0.3
|
| 1084 |
+
# if section.startswith('1.0'):
|
| 1085 |
+
# for p in range(len(areaPermArr)):
|
| 1086 |
+
|
| 1087 |
+
# if areastodelete[i] in areaPermArr[p]:
|
| 1088 |
+
# print('AAA',areaPermArr[p])
|
| 1089 |
+
# area= areaPermArr[p][0]
|
| 1090 |
+
# width= areaPermArr[p][1]
|
| 1091 |
+
# height= areaPermArr[p][2]
|
| 1092 |
+
# # if section.startswith('1.0'):
|
| 1093 |
+
# widthMin= width -10
|
| 1094 |
+
# widthMax= width +10
|
| 1095 |
+
# heightMin = height-10
|
| 1096 |
+
# heightMax=height+10
|
| 1097 |
+
# found=SimilarAreaDictionarycopy.loc[SimilarAreaDictionarycopy.index[((SimilarAreaDictionarycopy['Rounded'] >=areamin) & (SimilarAreaDictionarycopy['Rounded']<=areamax) & (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) )) ]]
|
| 1098 |
+
# elif section.startswith('3.2'):
|
| 1099 |
+
# areamin=round(areastodelete[i],1)- 0.1
|
| 1100 |
+
# areamax= round(areastodelete[i],1) + 0.1
|
| 1101 |
+
|
| 1102 |
+
# found=SimilarAreaDictionarycopy.loc[SimilarAreaDictionarycopy.index[((SimilarAreaDictionarycopy['Area'] >=areamin) & (SimilarAreaDictionarycopy['Area']<=areamax) )]]
|
| 1103 |
+
|
| 1104 |
+
# if len(found.index.values ) >0:
|
| 1105 |
+
# occ=SimilarAreaDictionarycopy.loc[found.index.values[0],'Occurences']
|
| 1106 |
+
# if occ== 1: #drop row
|
| 1107 |
+
# print('occ=1')
|
| 1108 |
+
# SimilarAreaDictionarycopy= SimilarAreaDictionarycopy.drop(found.index.values[0])
|
| 1109 |
+
|
| 1110 |
+
# else: #occ minus 1 , total area - areavalue , total perim - perimvalue
|
| 1111 |
+
# print('occ>1')
|
| 1112 |
+
# if section.startswith('1.0'):
|
| 1113 |
+
# idx=SimilarAreaDictionarycopy.index[((SimilarAreaDictionarycopy['Rounded'] >=areamin) & (SimilarAreaDictionarycopy['Rounded']<=areamax) & (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) )) ]
|
| 1114 |
+
# elif section.startswith('3.2'):
|
| 1115 |
+
# perimmin=round(perimstodelete[i],1)- 50
|
| 1116 |
+
# perimmax=round(perimstodelete[i],1)+ 50
|
| 1117 |
+
# idx=SimilarAreaDictionarycopy.index[((SimilarAreaDictionarycopy['Area'] >=areamin) & (SimilarAreaDictionarycopy['Area']<=areamax) & (SimilarAreaDictionarycopy['Perimeter'] >=perimmin) & (SimilarAreaDictionarycopy['Perimeter']<=perimmax) )]
|
| 1118 |
+
# SimilarAreaDictionarycopy.loc[idx,'Total Area'] = SimilarAreaDictionarycopy.loc[idx,'Total Area'] - areastodelete[i]
|
| 1119 |
+
# SimilarAreaDictionarycopy.loc[idx,'Total Perimeter'] = SimilarAreaDictionarycopy.loc[idx,'Total Perimeter'] - perimstodelete[i]
|
| 1120 |
+
# SimilarAreaDictionarycopy.loc[idx,'Total Length'] = SimilarAreaDictionarycopy.loc[idx,'Total Length'] - lengthstodelete[i]
|
| 1121 |
+
# SimilarAreaDictionarycopy.loc[idx,'Occurences'] = int(SimilarAreaDictionarycopy.loc[idx,'Occurences']) - 1
|
| 1122 |
+
# return SimilarAreaDictionarycopy
|
| 1123 |
+
|
| 1124 |
+
# #############################################################
|