Marthee commited on
Commit
831f665
·
verified ·
1 Parent(s): 4bdd7f5

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +190 -62
app.py CHANGED
@@ -18,6 +18,8 @@ from flask import Flask, Response
18
  from werkzeug.wsgi import wrap_file
19
  import tameem3_2
20
  import pypdfium2 as pdfium
 
 
21
  import pixelconversion
22
  import tameem2_1
23
  import io
@@ -129,6 +131,10 @@ def getprjpartsfromTestAPI(jsdata):
129
  @app.route('/getprojectsections/<jsdata>',methods=['GET'])
130
  def getprjSectionsfromTestAPI(jsdata):
131
  data=json.loads(jsdata)
 
 
 
 
132
  sections=API.getprjSections(data[0],data[1])
133
  return jsonify(sections)
134
 
@@ -165,6 +171,11 @@ def searchDocument():
165
  def TableDetection():
166
  return render_template('tableDetection.html')
167
 
 
 
 
 
 
168
  @app.route('/legends',methods=["GET", "POST"])
169
  def legendDirectory():
170
  return render_template('legendDirectory.html')
@@ -278,50 +289,103 @@ def table():
278
  def stringToRGB():
279
  vv = eval(request.form.get('answers'))
280
  print(vv)
281
- if ( vv[5][2].startswith('3.2') or vv[5][2].startswith('3.3') or vv[5][2].startswith('2.7')) :
282
- print('3.2 section')
283
- pdfpath,pdflink=tsadropboxretrieval.getPathtoPDF_File(nameofPDF=vv[0])
284
- dbxTeam= tsadropboxretrieval.ADR_Access_DropboxTeam('user')
285
- md, res =dbxTeam.files_download(path=pdfpath)
286
- dataDoc = res.content
287
- if 'file' not in request.files:
288
- print('error, No file part in the request')
289
- else:
290
- file = request.files['file']
291
- print('file done, measuring')
292
- arr=measureproject(vv,dataDoc,0,file)
293
- return jsonify(arr)
294
-
295
-
296
-
297
- if vv[5][2].startswith('1.0'):
298
- opencv_img,dataDoc = plan2img( str(vv[0]) )
299
- if vv[1]==220:
300
- imgdata = base64.b64decode(vv[6])
301
- img=Image.open(io.BytesIO(imgdata))
302
- opencv_img= cv2.cvtColor(np.array(img), cv2.COLOR_RGB2BGR)
303
- arr=measureproject(vv,dataDoc,opencv_img)
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
304
 
305
-
306
- if vv[5][2].startswith('2.8') or vv[5][2].startswith('2.6') or vv[5][2].startswith('2.1'):
307
- print(f"el mawgood fe vv[0]: {vv[0]}")
308
- arr_s = []
309
- dataDocs = []
310
- pls = []
311
- for v in vv[0]:
312
- pdfpath,pdflink=tsadropboxretrieval.getPathtoPDF_File(nameofPDF= str(v))
313
  dbxTeam= tsadropboxretrieval.ADR_Access_DropboxTeam('user')
314
  md, res =dbxTeam.files_download(path=pdfpath)
315
  dataDoc = res.content
316
- dataDocs.append(dataDoc)
317
- doc = fitz.open("pdf",dataDoc)
318
- page=doc[0]
319
- if page.rotation!=0:
320
- page.set_rotation(0)
321
- pix = page.get_pixmap(dpi=300) # render page to an image
322
- pl=Image.frombytes('RGB', [pix.width,pix.height],pix.samples)
323
- pls.append(pl)
324
- arr=measureproject(vv,dataDocs,pls)
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
325
  #pdfpath,pdflink=tsadropboxretrieval.getPathtoPDF_File(nameofPDF= str(vv[0]))
326
  #dbxTeam= tsadropboxretrieval.ADR_Access_DropboxTeam('user')
327
  #md, res =dbxTeam.files_download(path=pdfpath)
@@ -343,18 +407,26 @@ def measure2_1():
343
  return arr
344
  #MAIN FUNCTION -- calls python code to measure the chosen plan from the interface
345
  # @app.route('/projecttomeasure/<jsdata>',methods=["GET","POST"])
346
- def measureproject(result,dataDoc=0,img=0,dxffile=0):
347
  colorarr=[]
348
  global pdflink
349
- # result = json.loads(jsdata)
350
  pdfpath='/'
 
 
 
 
 
 
 
 
 
 
351
  ################################# -1.0- #################################
352
 
353
- for word in result[5]:
354
- pdfpath+=word +'/'
355
  arr=[]
356
 
357
- if result[5][2].startswith('1.0'): #section value - 1.0 substructure- pile caps
358
  for item in result[2]:
359
  # item1 ='#'+item
360
  c=hexRGB(item)
@@ -380,26 +452,31 @@ def measureproject(result,dataDoc=0,img=0,dxffile=0):
380
  # _, buffer = cv2.imencode('.png', outputimg)
381
  # arr=[ base64.b64encode(buffer).decode('utf-8'),SimilarAreaDictionary.to_dict(), spreadsheet_url,spreadsheetId,[],list1.to_dict(),pdflink,hatched_areas,namepathArr]# , spreadsheetId, spreadsheet_url , list1.to_dict()]
382
  ################################# -3.3 or 3.2- #################################
383
- elif result[5][2].startswith('3.3') or result[5][2].startswith('3.2'): #section value - 3.2 floor finishes
384
  print('code of 3.3 and 3.2')
385
  dxfpath=dxffile.read()
386
  with tempfile.NamedTemporaryFile(suffix='.dxf', delete=False) as temp_file:
387
  temp_file.write(dxfpath)
388
  temp_filename = temp_file.name
389
  print(temp_filename)
390
-
391
- doc,outputimg, SimilarAreaDictionary ,spreadsheetId, spreadsheet_url , namepathArr , list1,hatched_areas=deploying_3_3.mainFunctionDrawImgPdf(dataDoc,temp_filename,result[4] , pdfpath,result[0])
 
 
392
  global colorsused
393
  colorsused=list(SimilarAreaDictionary['Color'])
394
  dbPath='/TSA JOBS/ADR Test'+pdfpath+'Measured Plan/'
395
  print(dbPath,result[0])
396
- #
397
- pdflink= tsadropboxretrieval.uploadanyFile(doc=doc,path=dbPath,pdfname=result[0]) #doc=doc,pdfname=path,pdfpath=pdfpath+'Measured Plan/'
 
 
 
398
 
399
  _, buffer = cv2.imencode('.png', outputimg)
400
  arr=[ base64.b64encode(buffer).decode('utf-8'),SimilarAreaDictionary.to_dict(), spreadsheet_url,spreadsheetId,[],list1.to_dict(),pdflink,hatched_areas,namepathArr]#,hatched_areas,namepathArr]# , spreadsheetId, spreadsheet_url , list1.to_dict()]
401
  ################################# 2.7- #################################
402
- elif result[5][2].startswith('2.7') : #section value - 2.7 floor finishes
403
  print('code of 2.7')
404
  dxfpath=dxffile.read()
405
  with tempfile.NamedTemporaryFile(suffix='.dxf', delete=False) as temp_file:
@@ -412,34 +489,43 @@ def measureproject(result,dataDoc=0,img=0,dxffile=0):
412
  print(result)
413
  print("SearchArray = ",SearchArray)
414
  global hatched_areas2_7
415
- doc,outputimg, SimilarAreaDictionary ,spreadsheetId, spreadsheet_url , namepathArr , list1,hatched_areas=Code_2_7.mainFunctionDrawImgPdf(dataDoc,temp_filename,result[4],SearchArray,Thickness, pdfpath,result[0])
 
 
 
416
  # global colorsused
417
  hatched_areas2_7=hatched_areas
418
  colorsused=list(SimilarAreaDictionary['Color'])
419
  dbPath='/TSA JOBS/ADR Test'+pdfpath+'Measured Plan/'
420
  print(dbPath,result[0])
421
- #
422
- pdflink= tsadropboxretrieval.uploadanyFile(doc=doc,path=dbPath,pdfname=result[0]) #doc=doc,pdfname=path,pdfpath=pdfpath+'Measured Plan/'
 
 
 
423
 
424
  _, buffer = cv2.imencode('.png', outputimg)
425
  arr=[ base64.b64encode(buffer).decode('utf-8'),SimilarAreaDictionary.to_dict(), spreadsheet_url,spreadsheetId,[],list1.to_dict(),pdflink,[],namepathArr]#,hatched_areas,namepathArr]# , spreadsheetId, spreadsheet_url , list1.to_dict()]
426
  # arr=[ base64.b64encode(buffer).decode('utf-8'),SimilarAreaDictionary.to_dict(), spreadsheet_url,spreadsheetId,[],list1.to_dict(),pdflink,hatched_areas,namepathArr]#,hatched_areas,namepathArr]# , spreadsheetId, spreadsheet_url , list1.to_dict()]
427
  ################################# -2.8- #################################
428
- elif result[5][2].startswith('2.8') or result[5][2].startswith('2.6'): #section value - 2.8 floor finishes
429
  #vv[0] array of pdf names
430
  imgss=[]
431
  dpxlinks=[]
432
  legendLinks=[]
433
  listofmarkups=[]
434
-
435
  pdfpathDoors,_=tsadropboxretrieval.getPathtoPDF_File(nameofPDF= str(result[6]))
436
  dbxTeam= tsadropboxretrieval.ADR_Access_DropboxTeam('user')
437
  md, resDoors =dbxTeam.files_download(path=pdfpathDoors)
438
- dataDocDoorsSchedule = resDoors.content
439
  SearchArray=result[7]
440
  print('searchhh:',SearchArray)
441
  # annotatedimg,pdf_document,spreadsheet_url, list1 , df_doors=doors_fasterrcnn.main_run(img,dataDoc,'separated_classes_all.pth',result[0],pdfpath, result[4]) #single_double.pth
442
- annotatedimg, pdf_document , list1, repeated_labels , not_found =Doors_Schedule.mainRun(dataDocDoorsSchedule, dataDoc, SearchArray)
 
 
 
443
  dbPath='/TSA JOBS/ADR Test'+pdfpath+'Measured Plan/'
444
  pdflink= tsadropboxretrieval.uploadanyFile(doc=pdf_document,path=dbPath,pdfname="combined_output.pdf") #doc=doc,pdfname=path,pdfpath=pdfpath+'Measured Plan/
445
  _, buffer = cv2.imencode('.png', annotatedimg)
@@ -451,7 +537,7 @@ def measureproject(result,dataDoc=0,img=0,dxffile=0):
451
  NotFoundReturn=not_found # , spreadsheetId, spreadsheet_url , list1.to_dict()]
452
  arr=[base64.b64encode(buffer).decode('utf-8') ,pdflink,list1.to_dict(),str(repeatedLabelsReturn), str(NotFoundReturn)] # , spreadsheetId, spreadsheet_url , list1.to_dict()]
453
  ################################# -2.1- #################################
454
- elif result[5][2].startswith('2.1'): #section value - 2.8 floor finishes
455
  #vv[0] array of pdf names
456
  imgss=[]
457
  dpxlinks=[]
@@ -634,24 +720,66 @@ def get_pdf(jsdata):
634
  return response
635
 
636
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
637
  #PIXEL CONVERSION METHOD -- SAVES DOC ON DROPBOX TO BE MEASURED BY USER
638
  @app.route("/pixelimg/<jsdata>",methods=["GET", "POST"])
639
  def getimg(jsdata):
640
  progress_updates = [] # Shared list to store progress
641
  jsdata=eval(jsdata)
 
642
  def generate_progressPixel():
643
 
644
  yield f"data: 10\n\n" # Initial progress
645
 
646
  pdfpath,pdflink=tsadropboxretrieval.getPathtoPDF_File(nameofPDF=jsdata[3], progress_callback=lambda p: progress_updates.append(p))
 
647
  dbxTeam= tsadropboxretrieval.ADR_Access_DropboxTeam('user')
648
  md, res =dbxTeam.files_download(path=pdfpath)
649
  data = res.content
650
- print('jsdata',jsdata)
 
651
  if str(jsdata[2]).startswith('1.0'):
652
- doc,areaPixel,perimeterPixel=pixelconversion.drawisrotated(data,300) # .openDrawPDF(data)
653
  else:
654
- doc,areaPixel,perimeterPixel=pixelconversion.drawisrotated(data) # .openDrawPDF(data)
 
655
  yield f"data: 20\n\n" # Initial progress
656
  dbPath='/TSA JOBS/ADR Test/'+jsdata[0]+'/'+jsdata[1]+'/'+jsdata[2]+'/'+'Scale Document' +'/'
657
  dburl=tsadropboxretrieval.uploadanyFile(doc=doc,pdfname=str(jsdata[3]) ,path=dbPath) #PixelConv_
 
18
  from werkzeug.wsgi import wrap_file
19
  import tameem3_2
20
  import pypdfium2 as pdfium
21
+ from urllib.parse import urlparse
22
+ import re
23
  import pixelconversion
24
  import tameem2_1
25
  import io
 
131
  @app.route('/getprojectsections/<jsdata>',methods=['GET'])
132
  def getprjSectionsfromTestAPI(jsdata):
133
  data=json.loads(jsdata)
134
+ if data[0]=='testing':
135
+ sections=API.getprjSections()
136
+ print(sections)
137
+ return jsonify(sections)
138
  sections=API.getprjSections(data[0],data[1])
139
  return jsonify(sections)
140
 
 
171
  def TableDetection():
172
  return render_template('tableDetection.html')
173
 
174
+
175
+ @app.route('/TestingMeasurement',methods=["GET", "POST"])
176
+ def TestingMeasurement():
177
+ return render_template('TestingMeasurement.html')
178
+
179
  @app.route('/legends',methods=["GET", "POST"])
180
  def legendDirectory():
181
  return render_template('legendDirectory.html')
 
289
  def stringToRGB():
290
  vv = eval(request.form.get('answers'))
291
  print(vv)
292
+ if vv[0].startswith('http'):
293
+ if ( vv[5].startswith('3.2') or vv[5].startswith('3.3') or vv[5].startswith('2.7')) :
294
+ print('3.2 section')
295
+ # pdflink=vv[0]
296
+ # encoded_url = request.args.get('url')
297
+ link = urllib.parse.unquote(vv[0].strip('"'))
298
+ if link and ('http' in link or 'dropbox' in link):
299
+ if 'dl=0' in link:
300
+ link = link.replace('dl=0', 'dl=1')
301
+ elif 'www.dropbox.com' in link and '?dl=1' not in link:
302
+ link += '?dl=1'
303
+
304
+ response = requests.get(link)
305
+
306
+ pdf_content = BytesIO(response.content)
307
+ if not pdf_content:
308
+ raise ValueError("No valid PDF content found.")
309
+ if 'file' not in request.files:
310
+ print('error, No file part in the request')
311
+ else:
312
+ file = request.files['file']
313
+ print('file done, measuring')
314
+ arr=measureproject(result=vv,dxffile=file,pdf_content=pdf_content)
315
+
316
+ return jsonify(arr)
317
+
318
+ if vv[5].startswith('2.8') or vv[5].startswith('2.6') or vv[5].startswith('2.1'):
319
+ print(f"el mawgood fe vv[0]: {vv[0]}")
320
+ # arr_s = []
321
+ # dataDocs = []
322
+
323
+ # pdfpath,pdflink=tsadropboxretrieval.getPathtoPDF_File(nameofPDF= str(v))
324
+ link = urllib.parse.unquote(vv[0].strip('"'))
325
+ if link and ('http' in link or 'dropbox' in link):
326
+ if 'dl=0' in link:
327
+ link = link.replace('dl=0', 'dl=1')
328
+ elif 'www.dropbox.com' in link and '?dl=1' not in link:
329
+ link += '?dl=1'
330
+
331
+ response = requests.get(link)
332
+
333
+ pdf_content = BytesIO(response.content)
334
+ doc = fitz.open(stream=pdf_content, filetype="pdf")
335
+ # doc = fitz.open("pdf",dataDoc)
336
+ page=doc[0]
337
+ if page.rotation!=0:
338
+ page.set_rotation(0)
339
+ pix = page.get_pixmap(dpi=300) # render page to an image
340
+ pl=Image.frombytes('RGB', [pix.width,pix.height],pix.samples)
341
+
342
+ arr=measureproject(result=vv,img=pl,pdf_content=pdf_content)
343
 
344
+ else:
345
+ if ( vv[5][2].startswith('3.2') or vv[5][2].startswith('3.3') or vv[5][2].startswith('2.7')) :
346
+ print('3.2 section')
347
+ pdfpath,pdflink=tsadropboxretrieval.getPathtoPDF_File(nameofPDF=vv[0])
 
 
 
 
348
  dbxTeam= tsadropboxretrieval.ADR_Access_DropboxTeam('user')
349
  md, res =dbxTeam.files_download(path=pdfpath)
350
  dataDoc = res.content
351
+ if 'file' not in request.files:
352
+ print('error, No file part in the request')
353
+ else:
354
+ file = request.files['file']
355
+ print('file done, measuring')
356
+ arr=measureproject(vv,dataDoc,0,file)
357
+ return jsonify(arr)
358
+
359
+
360
+
361
+ if vv[5][2].startswith('1.0'):
362
+ opencv_img,dataDoc = plan2img( str(vv[0]) )
363
+ if vv[1]==220:
364
+ imgdata = base64.b64decode(vv[6])
365
+ img=Image.open(io.BytesIO(imgdata))
366
+ opencv_img= cv2.cvtColor(np.array(img), cv2.COLOR_RGB2BGR)
367
+ arr=measureproject(vv,dataDoc,opencv_img)
368
+
369
+
370
+ if vv[5][2].startswith('2.8') or vv[5][2].startswith('2.6') or vv[5][2].startswith('2.1'):
371
+ print(f"el mawgood fe vv[0]: {vv[0]}")
372
+ arr_s = []
373
+ dataDocs = []
374
+ pls = []
375
+ for v in vv[0]:
376
+ pdfpath,pdflink=tsadropboxretrieval.getPathtoPDF_File(nameofPDF= str(v))
377
+ dbxTeam= tsadropboxretrieval.ADR_Access_DropboxTeam('user')
378
+ md, res =dbxTeam.files_download(path=pdfpath)
379
+ dataDoc = res.content
380
+ dataDocs.append(dataDoc)
381
+ doc = fitz.open("pdf",dataDoc)
382
+ page=doc[0]
383
+ if page.rotation!=0:
384
+ page.set_rotation(0)
385
+ pix = page.get_pixmap(dpi=300) # render page to an image
386
+ pl=Image.frombytes('RGB', [pix.width,pix.height],pix.samples)
387
+ pls.append(pl)
388
+ arr=measureproject(vv,dataDocs,pls)
389
  #pdfpath,pdflink=tsadropboxretrieval.getPathtoPDF_File(nameofPDF= str(vv[0]))
390
  #dbxTeam= tsadropboxretrieval.ADR_Access_DropboxTeam('user')
391
  #md, res =dbxTeam.files_download(path=pdfpath)
 
407
  return arr
408
  #MAIN FUNCTION -- calls python code to measure the chosen plan from the interface
409
  # @app.route('/projecttomeasure/<jsdata>',methods=["GET","POST"])
410
+ def measureproject(result,dataDoc=0,img=0,dxffile=0,pdf_content=0):
411
  colorarr=[]
412
  global pdflink
 
413
  pdfpath='/'
414
+ # result = json.loads(jsdata)
415
+ if pdf_content:
416
+ section=result[5]
417
+ pdfpath+='testinglink/'
418
+ else:
419
+ section=result[5][2]
420
+ for word in result[5]:
421
+ pdfpath+=word +'/'
422
+
423
+
424
  ################################# -1.0- #################################
425
 
426
+
 
427
  arr=[]
428
 
429
+ if section.startswith('1.0'): #section value - 1.0 substructure- pile caps
430
  for item in result[2]:
431
  # item1 ='#'+item
432
  c=hexRGB(item)
 
452
  # _, buffer = cv2.imencode('.png', outputimg)
453
  # arr=[ base64.b64encode(buffer).decode('utf-8'),SimilarAreaDictionary.to_dict(), spreadsheet_url,spreadsheetId,[],list1.to_dict(),pdflink,hatched_areas,namepathArr]# , spreadsheetId, spreadsheet_url , list1.to_dict()]
454
  ################################# -3.3 or 3.2- #################################
455
+ elif section.startswith('3.3') or section.startswith('3.2'): #section value - 3.2 floor finishes
456
  print('code of 3.3 and 3.2')
457
  dxfpath=dxffile.read()
458
  with tempfile.NamedTemporaryFile(suffix='.dxf', delete=False) as temp_file:
459
  temp_file.write(dxfpath)
460
  temp_filename = temp_file.name
461
  print(temp_filename)
462
+ if pdf_content:
463
+ doc,outputimg, SimilarAreaDictionary ,spreadsheetId, spreadsheet_url , namepathArr , list1,hatched_areas=deploying_3_3.mainFunctionDrawImgPdf(dataDoc,temp_filename,result[4] , pdfpath,result[0],pdf_content)
464
+ else:
465
+ doc,outputimg, SimilarAreaDictionary ,spreadsheetId, spreadsheet_url , namepathArr , list1,hatched_areas=deploying_3_3.mainFunctionDrawImgPdf(dataDoc,temp_filename,result[4] , pdfpath,result[0])
466
  global colorsused
467
  colorsused=list(SimilarAreaDictionary['Color'])
468
  dbPath='/TSA JOBS/ADR Test'+pdfpath+'Measured Plan/'
469
  print(dbPath,result[0])
470
+ parsed_url = urlparse(result[0])
471
+ filename = parsed_url.path.split('/')[-1]
472
+ print(filename)
473
+ nameofpdf=filename
474
+ pdflink= tsadropboxretrieval.uploadanyFile(doc=doc,path=dbPath,pdfname=nameofpdf)
475
 
476
  _, buffer = cv2.imencode('.png', outputimg)
477
  arr=[ base64.b64encode(buffer).decode('utf-8'),SimilarAreaDictionary.to_dict(), spreadsheet_url,spreadsheetId,[],list1.to_dict(),pdflink,hatched_areas,namepathArr]#,hatched_areas,namepathArr]# , spreadsheetId, spreadsheet_url , list1.to_dict()]
478
  ################################# 2.7- #################################
479
+ elif section.startswith('2.7') : #section value - 2.7 floor finishes
480
  print('code of 2.7')
481
  dxfpath=dxffile.read()
482
  with tempfile.NamedTemporaryFile(suffix='.dxf', delete=False) as temp_file:
 
489
  print(result)
490
  print("SearchArray = ",SearchArray)
491
  global hatched_areas2_7
492
+ if pdf_content:
493
+ doc,outputimg, SimilarAreaDictionary ,spreadsheetId, spreadsheet_url , namepathArr , list1,hatched_areas=Code_2_7.mainFunctionDrawImgPdf(dataDoc,temp_filename,result[4],SearchArray,Thickness, pdfpath,result[0],pdf_content)
494
+ else:
495
+ doc,outputimg, SimilarAreaDictionary ,spreadsheetId, spreadsheet_url , namepathArr , list1,hatched_areas=Code_2_7.mainFunctionDrawImgPdf(dataDoc,temp_filename,result[4],SearchArray,Thickness, pdfpath,result[0])
496
  # global colorsused
497
  hatched_areas2_7=hatched_areas
498
  colorsused=list(SimilarAreaDictionary['Color'])
499
  dbPath='/TSA JOBS/ADR Test'+pdfpath+'Measured Plan/'
500
  print(dbPath,result[0])
501
+ parsed_url = urlparse(result[0])
502
+ filename = parsed_url.path.split('/')[-1]
503
+ print(filename)
504
+ nameofpdf=filename
505
+ pdflink= tsadropboxretrieval.uploadanyFile(doc=doc,path=dbPath,pdfname=nameofpdf) #doc=doc,pdfname=path,pdfpath=pdfpath+'Measured Plan/'
506
 
507
  _, buffer = cv2.imencode('.png', outputimg)
508
  arr=[ base64.b64encode(buffer).decode('utf-8'),SimilarAreaDictionary.to_dict(), spreadsheet_url,spreadsheetId,[],list1.to_dict(),pdflink,[],namepathArr]#,hatched_areas,namepathArr]# , spreadsheetId, spreadsheet_url , list1.to_dict()]
509
  # arr=[ base64.b64encode(buffer).decode('utf-8'),SimilarAreaDictionary.to_dict(), spreadsheet_url,spreadsheetId,[],list1.to_dict(),pdflink,hatched_areas,namepathArr]#,hatched_areas,namepathArr]# , spreadsheetId, spreadsheet_url , list1.to_dict()]
510
  ################################# -2.8- #################################
511
+ elif section.startswith('2.8') or section.startswith('2.6'): #section value - 2.8 floor finishes
512
  #vv[0] array of pdf names
513
  imgss=[]
514
  dpxlinks=[]
515
  legendLinks=[]
516
  listofmarkups=[]
517
+
518
  pdfpathDoors,_=tsadropboxretrieval.getPathtoPDF_File(nameofPDF= str(result[6]))
519
  dbxTeam= tsadropboxretrieval.ADR_Access_DropboxTeam('user')
520
  md, resDoors =dbxTeam.files_download(path=pdfpathDoors)
521
+ dataDocDoorsSchedule = resDoors.content
522
  SearchArray=result[7]
523
  print('searchhh:',SearchArray)
524
  # annotatedimg,pdf_document,spreadsheet_url, list1 , df_doors=doors_fasterrcnn.main_run(img,dataDoc,'separated_classes_all.pth',result[0],pdfpath, result[4]) #single_double.pth
525
+ if pdf_content:
526
+ annotatedimg, pdf_document , list1, repeated_labels , not_found =Doors_Schedule.mainRun(dataDocDoorsSchedule, dataDoc, SearchArray,pdf_content)
527
+ else:
528
+ annotatedimg, pdf_document , list1, repeated_labels , not_found =Doors_Schedule.mainRun(dataDocDoorsSchedule, dataDoc, SearchArray)
529
  dbPath='/TSA JOBS/ADR Test'+pdfpath+'Measured Plan/'
530
  pdflink= tsadropboxretrieval.uploadanyFile(doc=pdf_document,path=dbPath,pdfname="combined_output.pdf") #doc=doc,pdfname=path,pdfpath=pdfpath+'Measured Plan/
531
  _, buffer = cv2.imencode('.png', annotatedimg)
 
537
  NotFoundReturn=not_found # , spreadsheetId, spreadsheet_url , list1.to_dict()]
538
  arr=[base64.b64encode(buffer).decode('utf-8') ,pdflink,list1.to_dict(),str(repeatedLabelsReturn), str(NotFoundReturn)] # , spreadsheetId, spreadsheet_url , list1.to_dict()]
539
  ################################# -2.1- #################################
540
+ elif section.startswith('2.1'): #section value - 2.8 floor finishes
541
  #vv[0] array of pdf names
542
  imgss=[]
543
  dpxlinks=[]
 
720
  return response
721
 
722
 
723
+ @app.route('/pixeltestingimg')
724
+ def pixeltesting():
725
+ encoded_url = request.args.get('url')
726
+ link = urllib.parse.unquote(encoded_url.strip('"'))
727
+ if link and ('http' in link or 'dropbox' in link):
728
+ if 'dl=0' in link:
729
+ link = link.replace('dl=0', 'dl=1')
730
+ elif 'www.dropbox.com' in link and '?dl=1' not in link:
731
+ link += '?dl=1'
732
+
733
+ pdf_path=link
734
+ response = requests.get(pdf_path)
735
+ pdf_content = BytesIO(response.content)
736
+ if not pdf_content:
737
+ raise ValueError("No valid PDF content found.")
738
+ progress_updates = [] # Shared list to store progress
739
+ def generate_progressPixel():
740
+
741
+ yield f"data: 10\n\n" # Initial progress
742
+
743
+ doc,areaPixel,perimeterPixel=pixelconversion.drawisrotated(pdf_content=pdf_content) # .openDrawPDF(data)
744
+
745
+ yield f"data: 20\n\n" # Initial progress
746
+ dbPath='/TSA JOBS/ADR Test/'+'TestingLinks'+'/'+'Scale Document' +'/'
747
+ dburl=tsadropboxretrieval.uploadanyFile(doc=doc,pdfname=str('testinglink') ,path=dbPath) #PixelConv_
748
+ # areaPixel,perimeterPixel= pixelconversion.getAreaPerimeter(dbPath, str(jsdata[3]))
749
+ yield f"data: 40\n\n" # Initial progress
750
+ outputs=[areaPixel,perimeterPixel , dburl]
751
+ while progress_updates:
752
+ progress = progress_updates.pop(0) # Get the next progress value
753
+ yield f"data: {progress}\n\n"
754
+ # Final progress and result
755
+ yield f"data: 80\n\n"
756
+ yield f"data: 100\n\n"
757
+ result = json.dumps(outputs)
758
+ yield f"data: {result}\n\n"
759
+
760
+ return Response(generate_progressPixel(), content_type='text/event-stream')
761
  #PIXEL CONVERSION METHOD -- SAVES DOC ON DROPBOX TO BE MEASURED BY USER
762
  @app.route("/pixelimg/<jsdata>",methods=["GET", "POST"])
763
  def getimg(jsdata):
764
  progress_updates = [] # Shared list to store progress
765
  jsdata=eval(jsdata)
766
+ print('piexxxeell',jsdata)
767
  def generate_progressPixel():
768
 
769
  yield f"data: 10\n\n" # Initial progress
770
 
771
  pdfpath,pdflink=tsadropboxretrieval.getPathtoPDF_File(nameofPDF=jsdata[3], progress_callback=lambda p: progress_updates.append(p))
772
+
773
  dbxTeam= tsadropboxretrieval.ADR_Access_DropboxTeam('user')
774
  md, res =dbxTeam.files_download(path=pdfpath)
775
  data = res.content
776
+
777
+
778
  if str(jsdata[2]).startswith('1.0'):
779
+ doc,areaPixel,perimeterPixel=pixelconversion.drawisrotated(data=data,dpi=300) # .openDrawPDF(data)
780
  else:
781
+ doc,areaPixel,perimeterPixel=pixelconversion.drawisrotated(data=data) # .openDrawPDF(data)
782
+
783
  yield f"data: 20\n\n" # Initial progress
784
  dbPath='/TSA JOBS/ADR Test/'+jsdata[0]+'/'+jsdata[1]+'/'+jsdata[2]+'/'+'Scale Document' +'/'
785
  dburl=tsadropboxretrieval.uploadanyFile(doc=doc,pdfname=str(jsdata[3]) ,path=dbPath) #PixelConv_