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|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 2 |
#_________________________________________________________________________________________________________________________
|
| 3 |
#_________________________________________________________________________________________________________________________
|
| 4 |
|
|
|
|
| 1 |
from __future__ import print_function
|
| 2 |
+
from flask import Flask, render_template,request,flash , json, url_for,g , redirect , jsonify , send_file ,make_response
|
| 3 |
+
import json
|
| 4 |
+
import fitz
|
| 5 |
+
from PIL import Image
|
| 6 |
+
import cv2
|
| 7 |
+
import numpy as np
|
| 8 |
+
import pilecaps_adr
|
| 9 |
+
import base64
|
| 10 |
+
from db import dropbox_connect
|
| 11 |
+
import cv2
|
| 12 |
+
import pandas as pd
|
| 13 |
+
import time
|
| 14 |
+
from io import BytesIO, StringIO
|
| 15 |
+
import urllib
|
| 16 |
+
import tempfile
|
| 17 |
+
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
|
| 24 |
+
from urllib.parse import unquote
|
| 25 |
+
import API
|
| 26 |
+
import MC_Templates_API
|
| 27 |
+
import tsadropboxretrieval
|
| 28 |
+
import doc_search
|
| 29 |
+
import google_sheet_Legend
|
| 30 |
+
import dxf__omar3_2
|
| 31 |
+
import requests
|
| 32 |
+
import google_sheet_to_xml
|
| 33 |
+
from threading import Thread
|
| 34 |
+
import mainDBAlaa
|
| 35 |
+
import datetime
|
| 36 |
+
import doors_fasterrcnn
|
| 37 |
+
import deploying_3_3
|
| 38 |
+
import Doors_Schedule
|
| 39 |
+
import Code_2_7
|
| 40 |
+
import Counting_Columns_2_1
|
| 41 |
+
import Find_Hyperlinking_text
|
| 42 |
+
import ezdxf
|
| 43 |
+
from flask import Flask, render_template, session, redirect, url_for
|
| 44 |
+
from flask_session import Session # Capital "S"
|
| 45 |
+
app = Flask(__name__)
|
| 46 |
+
|
| 47 |
+
prjnamesURL = 'https://docs.google.com/spreadsheets/d/1nsIgi9o9VSBKQlNxbxihPzG_N7s4um0eNVfgL4gaGPc/export?format=csv&gid=0'
|
| 48 |
+
prjpartsURL = 'https://docs.google.com/spreadsheets/d/1nsIgi9o9VSBKQlNxbxihPzG_N7s4um0eNVfgL4gaGPc/export?format=csv&gid=34865056'
|
| 49 |
+
prjsectionsURL = 'https://docs.google.com/spreadsheets/d/1nsIgi9o9VSBKQlNxbxihPzG_N7s4um0eNVfgL4gaGPc/export?format=csv&gid=1751466819'
|
| 50 |
+
|
| 51 |
+
# Global variables (example)
|
| 52 |
+
global colorsused
|
| 53 |
+
global pdflink
|
| 54 |
+
# For 2.7
|
| 55 |
+
global hatched_areas2_7
|
| 56 |
+
|
| 57 |
+
# Configure Flask-Session for server-side session storage
|
| 58 |
+
app.config["SESSION_TYPE"] = "filesystem"
|
| 59 |
+
app.config["SESSION_PERMANENT"] = False
|
| 60 |
+
app.config["SESSION_FILE_DIR"] = "./flask_session_files"
|
| 61 |
+
app.secret_key = "your_secret_key"
|
| 62 |
+
|
| 63 |
+
# Initialize Flask-Session
|
| 64 |
+
sess = Session()
|
| 65 |
+
sess.init_app(app)
|
| 66 |
+
|
| 67 |
+
@app.route("/", methods=["GET", "POST"])
|
| 68 |
+
def getInfotoMeasure():
|
| 69 |
+
return render_template("gui2.html")
|
| 70 |
+
|
| 71 |
+
@app.route("/password", methods=["GET", "POST"])
|
| 72 |
+
def password_page():
|
| 73 |
+
return render_template("gui2.html")
|
| 74 |
+
|
| 75 |
+
@app.route("/check_password", methods=["POST"])
|
| 76 |
+
def check_password():
|
| 77 |
+
password = request.form.get("password")
|
| 78 |
+
correct_password = "c900"
|
| 79 |
+
|
| 80 |
+
if password == correct_password:
|
| 81 |
+
session["authenticated"] = True
|
| 82 |
+
return jsonify({"authenticated": True}), 200
|
| 83 |
+
else:
|
| 84 |
+
return jsonify({"authenticated": False}), 200
|
| 85 |
+
|
| 86 |
+
@app.route("/mainGUI", methods=["GET", "POST"])
|
| 87 |
+
def main_gui():
|
| 88 |
+
if "authenticated" not in session or not session["authenticated"]:
|
| 89 |
+
return redirect(url_for("password_page"))
|
| 90 |
+
return render_template("proposed-GUI.html")
|
| 91 |
+
|
| 92 |
+
|
| 93 |
+
|
| 94 |
+
@app.route("/WordSearch",methods=["GET", "POST"])
|
| 95 |
+
def getInfo2toMeasure():
|
| 96 |
+
# API.AppendtablestoSheets()
|
| 97 |
+
return render_template("wordSearch.html")
|
| 98 |
+
|
| 99 |
+
|
| 100 |
+
|
| 101 |
+
@app.route('/getprojectnames/',methods=['GET'])
|
| 102 |
+
def getprjnamesfromTestAPI():
|
| 103 |
+
progress_updates = [] # Shared list to store progress
|
| 104 |
+
|
| 105 |
+
def generate_progressProjnames():
|
| 106 |
+
yield f"data: 10\n\n" # Initial progress
|
| 107 |
+
# Call retrieveProjects and pass a callback to update the shared list
|
| 108 |
+
prjnames,prjids=API.getPrjNames( progress_callback=lambda p: progress_updates.append(p))
|
| 109 |
+
# Continuously yield progress updates from the shared list
|
| 110 |
+
|
| 111 |
+
while progress_updates:
|
| 112 |
+
progress = progress_updates.pop(0) # Get the next progress value
|
| 113 |
+
yield f"data: {progress}\n\n"
|
| 114 |
+
# Final progress and result
|
| 115 |
+
yield f"data: 80\n\n"
|
| 116 |
+
yield f"data: 100\n\n"
|
| 117 |
+
result = json.dumps([prjnames,prjids])
|
| 118 |
+
yield f"data: {result}\n\n"
|
| 119 |
+
return Response(generate_progressProjnames(), content_type='text/event-stream')
|
| 120 |
+
|
| 121 |
+
|
| 122 |
+
@app.route('/getprojectparts/<jsdata>',methods=['GET'])
|
| 123 |
+
def getprjpartsfromTestAPI(jsdata):
|
| 124 |
+
print('kkkk',jsdata)
|
| 125 |
+
prjparts,partsIds=API.getprjParts(jsdata)
|
| 126 |
+
return jsonify([prjparts,partsIds])
|
| 127 |
+
|
| 128 |
+
@app.route('/getprojectsections/<jsdata>',methods=['GET'])
|
| 129 |
+
def getprjSectionsfromTestAPI(jsdata):
|
| 130 |
+
data=json.loads(jsdata)
|
| 131 |
+
sections=API.getprjSections(data[0],data[1])
|
| 132 |
+
return jsonify(sections)
|
| 133 |
+
|
| 134 |
+
@app.route('/getmethod/<jsdata>', methods=['GET'])
|
| 135 |
+
def get_javascript_data(jsdata):
|
| 136 |
+
progress_updates = [] # Shared list to store progress
|
| 137 |
+
|
| 138 |
+
def generate_progress():
|
| 139 |
+
yield f"data: 5\n\n" # Initial progress
|
| 140 |
+
yield f"data: 10\n\n" # Initial progress
|
| 141 |
+
# Call retrieveProjects and pass a callback to update the shared list
|
| 142 |
+
documentsToMeasure, RelevantDocuments, extracted_path = tsadropboxretrieval.retrieveProjects(
|
| 143 |
+
jsdata,
|
| 144 |
+
progress_callback=lambda p: progress_updates.append(p)
|
| 145 |
+
)
|
| 146 |
+
|
| 147 |
+
# Continuously yield progress updates from the shared list
|
| 148 |
+
while progress_updates:
|
| 149 |
+
progress = progress_updates.pop(0) # Get the next progress value
|
| 150 |
+
yield f"data: {progress}\n\n"
|
| 151 |
+
# Final progress and result
|
| 152 |
+
yield f"data: 100\n\n"
|
| 153 |
+
result = json.dumps([documentsToMeasure, RelevantDocuments, extracted_path])
|
| 154 |
+
yield f"data: {result}\n\n"
|
| 155 |
+
|
| 156 |
+
return Response(generate_progress(), content_type='text/event-stream')
|
| 157 |
+
|
| 158 |
+
#---------------------------------------------------------------
|
| 159 |
+
@app.route('/WordSearch',methods=["GET", "POST"])
|
| 160 |
+
def searchDocument():
|
| 161 |
+
return render_template('wordSearch.html')
|
| 162 |
+
|
| 163 |
+
@app.route('/legends',methods=["GET", "POST"])
|
| 164 |
+
def legendDirectory():
|
| 165 |
+
return render_template('legendDirectory.html')
|
| 166 |
+
|
| 167 |
+
@app.route('/searchInDocs',methods=["GET", "POST"])
|
| 168 |
+
def getSearchinDocs():
|
| 169 |
+
arr=[]
|
| 170 |
+
values = request.get_json()
|
| 171 |
+
keyword=values.get('keyword')
|
| 172 |
+
listpfProjs=values.get('listofprojs')
|
| 173 |
+
print(keyword,listpfProjs)
|
| 174 |
+
df,img_list=doc_search.search_docs(keyword,listpfProjs)
|
| 175 |
+
for img in img_list:
|
| 176 |
+
_, buffer = cv2.imencode('.png', img)
|
| 177 |
+
arr.append(base64.b64encode(buffer).decode('utf-8'))
|
| 178 |
+
return jsonify([df.to_html(index=False, escape=False),arr])
|
| 179 |
+
|
| 180 |
+
@app.route('/searchInFolder',methods=["GET", "POST"])
|
| 181 |
+
def getSearchinFolder():
|
| 182 |
+
arr=[]
|
| 183 |
+
values = request.get_json()
|
| 184 |
+
keyword=values.get('keyword')
|
| 185 |
+
projname=values.get('ProjectName')
|
| 186 |
+
df,img_list=doc_search.slow_search(keyword=keyword,project=projname)
|
| 187 |
+
for img in img_list:
|
| 188 |
+
_, buffer = cv2.imencode('.png', img)
|
| 189 |
+
arr.append(base64.b64encode(buffer).decode('utf-8'))
|
| 190 |
+
return jsonify([df.to_html(index=False, escape=False),arr])
|
| 191 |
+
|
| 192 |
+
|
| 193 |
+
|
| 194 |
+
@app.route("/measurementConsole",methods=["GET", "POST"])
|
| 195 |
+
def measurementConsoleFn():
|
| 196 |
+
return render_template("proposed-GUI.html")
|
| 197 |
+
|
| 198 |
+
@app.route('/RetrieveMCTNames/',methods=['GET'])
|
| 199 |
+
def CallAPIforMCTNames():
|
| 200 |
+
# print(jsdata)
|
| 201 |
+
DictionaryOfTemplates=MC_Templates_API.RetrieveMC_Templates_API()
|
| 202 |
+
# jsdata=jsdata.replace('"', '')
|
| 203 |
+
print('here')
|
| 204 |
+
return jsonify(DictionaryOfTemplates) #[str(jsdata).lower()]
|
| 205 |
+
|
| 206 |
+
#_________________________________________________________________________________________________________________________
|
| 207 |
+
#_________________________________________________________________________________________________________________________
|
| 208 |
+
#Hex value to RGB value
|
| 209 |
+
def hexRGB(color):
|
| 210 |
+
color=color.lstrip('#')
|
| 211 |
+
color= tuple(int(color[i:i+2], 16) for i in (0, 2, 4)) #hex to rgb
|
| 212 |
+
color=list(color) #rgb to bgr
|
| 213 |
+
return color
|
| 214 |
+
#_________________________________________________________________________________________________________________________
|
| 215 |
+
#_________________________________________________________________________________________________________________________
|
| 216 |
+
@app.route('/updatepreviewimg/<jsdata>',methods=["GET", "POST"])
|
| 217 |
+
def getfromdropboxImg(jsdata):
|
| 218 |
+
# vv = eval(request.form.get('pdflink'))
|
| 219 |
+
pdfpath=''
|
| 220 |
+
# jsdata=jsdata.replace('"', '')
|
| 221 |
+
jsdata=eval(jsdata)
|
| 222 |
+
print('pdfnameeee==',jsdata)
|
| 223 |
+
|
| 224 |
+
dbPath='/TSA JOBS/ADR Test/'+jsdata[0][0]+'/'+jsdata[0][1]+'/'+jsdata[0][2]+'/Measured Plan/'+'Measured_'+jsdata[1]
|
| 225 |
+
print(dbPath)
|
| 226 |
+
dbxTeam= tsadropboxretrieval.ADR_Access_DropboxTeam('user')
|
| 227 |
+
md, res =dbxTeam.files_download(path=dbPath)
|
| 228 |
+
data = res.content
|
| 229 |
+
doc = fitz.open("pdf",data)
|
| 230 |
+
page=doc[0]
|
| 231 |
+
pix = page.get_pixmap() # render page to an image
|
| 232 |
+
pl=Image.frombytes('RGB', [pix.width,pix.height],pix.samples)
|
| 233 |
+
img=np.array(pl)
|
| 234 |
+
img = cv2.cvtColor(img, cv2.COLOR_RGB2BGR)
|
| 235 |
+
_, buffer = cv2.imencode('.png', img)
|
| 236 |
+
return base64.b64encode(buffer).decode('utf-8')
|
| 237 |
+
|
| 238 |
+
|
| 239 |
+
@app.route('/savebase64Img/',methods=["POST"])
|
| 240 |
+
def stringToRGB():
|
| 241 |
+
vv = eval(request.form.get('answers'))
|
| 242 |
+
print(vv)
|
| 243 |
+
if ( vv[5][2].startswith('3.2') or vv[5][2].startswith('3.3') or vv[5][2].startswith('2.7')) :
|
| 244 |
+
print('3.2 section')
|
| 245 |
+
pdfpath,pdflink=tsadropboxretrieval.getPathtoPDF_File(nameofPDF=vv[0])
|
| 246 |
+
dbxTeam= tsadropboxretrieval.ADR_Access_DropboxTeam('user')
|
| 247 |
+
md, res =dbxTeam.files_download(path=pdfpath)
|
| 248 |
+
dataDoc = res.content
|
| 249 |
+
if 'file' not in request.files:
|
| 250 |
+
print('error, No file part in the request')
|
| 251 |
+
else:
|
| 252 |
+
file = request.files['file']
|
| 253 |
+
print('file done, measuring')
|
| 254 |
+
arr=measureproject(vv,dataDoc,0,file)
|
| 255 |
+
return jsonify(arr)
|
| 256 |
+
|
| 257 |
+
|
| 258 |
+
|
| 259 |
+
if vv[5][2].startswith('1.0'):
|
| 260 |
+
opencv_img,dataDoc = plan2img( str(vv[0]) )
|
| 261 |
+
if vv[1]==220:
|
| 262 |
+
imgdata = base64.b64decode(vv[6])
|
| 263 |
+
img=Image.open(io.BytesIO(imgdata))
|
| 264 |
+
opencv_img= cv2.cvtColor(np.array(img), cv2.COLOR_RGB2BGR)
|
| 265 |
+
arr=measureproject(vv,dataDoc,opencv_img)
|
| 266 |
+
|
| 267 |
+
|
| 268 |
+
if vv[5][2].startswith('2.8') or vv[5][2].startswith('2.6') or vv[5][2].startswith('2.1'):
|
| 269 |
+
pdfpath,pdflink=tsadropboxretrieval.getPathtoPDF_File(nameofPDF= str(vv[0]))
|
| 270 |
+
dbxTeam= tsadropboxretrieval.ADR_Access_DropboxTeam('user')
|
| 271 |
+
md, res =dbxTeam.files_download(path=pdfpath)
|
| 272 |
+
dataDoc = res.content
|
| 273 |
+
doc = fitz.open("pdf",dataDoc)
|
| 274 |
+
page=doc[0]
|
| 275 |
+
if page.rotation!=0:
|
| 276 |
+
page.set_rotation(0)
|
| 277 |
+
pix = page.get_pixmap(dpi=300) # render page to an image
|
| 278 |
+
pl=Image.frombytes('RGB', [pix.width,pix.height],pix.samples)
|
| 279 |
+
arr=measureproject(vv,dataDoc,pl)
|
| 280 |
+
return jsonify(arr)
|
| 281 |
+
|
| 282 |
+
@app.route('/2.1Trial/',methods=["POST"])
|
| 283 |
+
def measure2_1():
|
| 284 |
+
name = request.get_json()
|
| 285 |
+
result=name.get('allvalues')
|
| 286 |
+
arr=measureproject(result)
|
| 287 |
+
return arr
|
| 288 |
+
#MAIN FUNCTION -- calls python code to measure the chosen plan from the interface
|
| 289 |
+
# @app.route('/projecttomeasure/<jsdata>',methods=["GET","POST"])
|
| 290 |
+
def measureproject(result,dataDoc=0,img=0,dxffile=0):
|
| 291 |
+
colorarr=[]
|
| 292 |
+
global pdflink
|
| 293 |
+
# result = json.loads(jsdata)
|
| 294 |
+
pdfpath='/'
|
| 295 |
+
################################# -1.0- #################################
|
| 296 |
+
|
| 297 |
+
for word in result[5]:
|
| 298 |
+
pdfpath+=word +'/'
|
| 299 |
+
arr=[]
|
| 300 |
+
|
| 301 |
+
if result[5][2].startswith('1.0'): #section value - 1.0 substructure- pile caps
|
| 302 |
+
for item in result[2]:
|
| 303 |
+
# item1 ='#'+item
|
| 304 |
+
c=hexRGB(item)
|
| 305 |
+
colorarr.append(c)
|
| 306 |
+
print('RATIOS=',result[3], result[4])
|
| 307 |
+
# cv2.imwrite(img,'imgg.png')
|
| 308 |
+
# global pdflink
|
| 309 |
+
imgPerimeter1,image_new1,SimilarAreaDictionary , colorsUsed,spreadsheet_url, spreadsheetId,list1, pdflink, areas_Perimeters, namepathArr =pilecaps_adr.drawAllContours(dataDoc,img,result[1],colorarr, result[3], result[4], result[0],pdfpath)
|
| 310 |
+
_, buffer = cv2.imencode('.png', image_new1)
|
| 311 |
+
arr=[base64.b64encode(buffer).decode('utf-8'),SimilarAreaDictionary.to_dict(),spreadsheet_url , spreadsheetId,colorsUsed,list1.to_dict(), pdflink, areas_Perimeters, namepathArr]
|
| 312 |
+
################################# -3.2- #################################
|
| 313 |
+
# elif result[5][2].startswith('3.2'): #section value - 3.2 floor finishes
|
| 314 |
+
# print('IN HEREEEE 3.2')
|
| 315 |
+
# dxfpath=dxffile.read()
|
| 316 |
+
# with tempfile.NamedTemporaryFile(suffix='.dxf', delete=False) as temp_file:
|
| 317 |
+
# temp_file.write(dxfpath)
|
| 318 |
+
# temp_filename = temp_file.name
|
| 319 |
+
# print(temp_filename)
|
| 320 |
+
# doc,outputimg, SimilarAreaDictionary ,spreadsheetId, spreadsheet_url , namepathArr , list1,hatched_areas=dxf__omar3_2.mainFunctionDrawImgPdf(dataDoc,temp_filename,result[4] , pdfpath,result[0])
|
| 321 |
+
# dbPath='/TSA JOBS/ADR Test'+pdfpath+'Measured Plan/'
|
| 322 |
+
# pdflink= tsadropboxretrieval.uploadanyFile(doc=doc,path=dbPath,pdfname=result[0]) #doc=doc,pdfname=path,pdfpath=pdfpath+'Measured Plan/'
|
| 323 |
+
|
| 324 |
+
# _, buffer = cv2.imencode('.png', outputimg)
|
| 325 |
+
# 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()]
|
| 326 |
+
################################# -3.3 or 3.2- #################################
|
| 327 |
+
elif result[5][2].startswith('3.3') or result[5][2].startswith('3.2'): #section value - 3.2 floor finishes
|
| 328 |
+
print('code of 3.3 and 3.2')
|
| 329 |
+
dxfpath=dxffile.read()
|
| 330 |
+
with tempfile.NamedTemporaryFile(suffix='.dxf', delete=False) as temp_file:
|
| 331 |
+
temp_file.write(dxfpath)
|
| 332 |
+
temp_filename = temp_file.name
|
| 333 |
+
print(temp_filename)
|
| 334 |
+
|
| 335 |
+
doc,outputimg, SimilarAreaDictionary ,spreadsheetId, spreadsheet_url , namepathArr , list1,hatched_areas=deploying_3_3.mainFunctionDrawImgPdf(dataDoc,temp_filename,result[4] , pdfpath,result[0])
|
| 336 |
+
global colorsused
|
| 337 |
+
colorsused=list(SimilarAreaDictionary['Color'])
|
| 338 |
+
dbPath='/TSA JOBS/ADR Test'+pdfpath+'Measured Plan/'
|
| 339 |
+
print(dbPath,result[0])
|
| 340 |
+
#
|
| 341 |
+
pdflink= tsadropboxretrieval.uploadanyFile(doc=doc,path=dbPath,pdfname='Measured_'+result[0]) #doc=doc,pdfname=path,pdfpath=pdfpath+'Measured Plan/'
|
| 342 |
+
|
| 343 |
+
_, buffer = cv2.imencode('.png', outputimg)
|
| 344 |
+
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()]
|
| 345 |
+
################################# 2.7- #################################
|
| 346 |
+
elif result[5][2].startswith('2.7') : #section value - 2.7 floor finishes
|
| 347 |
+
print('code of 2.7')
|
| 348 |
+
dxfpath=dxffile.read()
|
| 349 |
+
with tempfile.NamedTemporaryFile(suffix='.dxf', delete=False) as temp_file:
|
| 350 |
+
temp_file.write(dxfpath)
|
| 351 |
+
temp_filename = temp_file.name
|
| 352 |
+
print(temp_filename)
|
| 353 |
+
|
| 354 |
+
SearchArray=result[6]
|
| 355 |
+
print(result)
|
| 356 |
+
print("SearchArray = ",SearchArray)
|
| 357 |
+
global hatched_areas2_7
|
| 358 |
+
doc,outputimg, SimilarAreaDictionary ,spreadsheetId, spreadsheet_url , namepathArr , list1,hatched_areas=Code_2_7.mainFunctionDrawImgPdf(dataDoc,temp_filename,result[4],SearchArray, pdfpath,result[0])
|
| 359 |
+
# global colorsused
|
| 360 |
+
hatched_areas2_7=hatched_areas
|
| 361 |
+
colorsused=list(SimilarAreaDictionary['Color'])
|
| 362 |
+
dbPath='/TSA JOBS/ADR Test'+pdfpath+'Measured Plan/'
|
| 363 |
+
print(dbPath,result[0])
|
| 364 |
+
#
|
| 365 |
+
pdflink= tsadropboxretrieval.uploadanyFile(doc=doc,path=dbPath,pdfname='Measured_'+result[0]) #doc=doc,pdfname=path,pdfpath=pdfpath+'Measured Plan/'
|
| 366 |
+
|
| 367 |
+
_, buffer = cv2.imencode('.png', outputimg)
|
| 368 |
+
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()]
|
| 369 |
+
# 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()]
|
| 370 |
+
################################# -2.8- #################################
|
| 371 |
+
elif result[5][2].startswith('2.8') or result[5][2].startswith('2.6'): #section value - 2.8 floor finishes
|
| 372 |
+
#vv[0] array of pdf names
|
| 373 |
+
imgss=[]
|
| 374 |
+
dpxlinks=[]
|
| 375 |
+
legendLinks=[]
|
| 376 |
+
listofmarkups=[]
|
| 377 |
+
|
| 378 |
+
pdfpathDoors,_=tsadropboxretrieval.getPathtoPDF_File(nameofPDF= str(result[6]))
|
| 379 |
+
dbxTeam= tsadropboxretrieval.ADR_Access_DropboxTeam('user')
|
| 380 |
+
md, resDoors =dbxTeam.files_download(path=pdfpathDoors)
|
| 381 |
+
dataDocDoorsSchedule = resDoors.content
|
| 382 |
+
SearchArray=result[7]
|
| 383 |
+
print('searchhh:',SearchArray)
|
| 384 |
+
# 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
|
| 385 |
+
annotatedimg, pdf_document , list1, repeated_labels , not_found =Doors_Schedule.mainRun(dataDocDoorsSchedule, dataDoc,SearchArray)
|
| 386 |
+
dbPath='/TSA JOBS/ADR Test'+pdfpath+'Measured Plan/'
|
| 387 |
+
pdflink= tsadropboxretrieval.uploadanyFile(doc=pdf_document,path=dbPath,pdfname='Measured_'+result[0]) #doc=doc,pdfname=path,pdfpath=pdfpath+'Measured Plan/
|
| 388 |
+
_, buffer = cv2.imencode('.png', annotatedimg)
|
| 389 |
+
repeatedLabelsReturn=''
|
| 390 |
+
NotFoundReturn=''
|
| 391 |
+
if len(repeated_labels)>0:
|
| 392 |
+
repeatedLabelsReturn=repeated_labels
|
| 393 |
+
if len(not_found)>0:
|
| 394 |
+
NotFoundReturn=not_found # , spreadsheetId, spreadsheet_url , list1.to_dict()]
|
| 395 |
+
arr=[base64.b64encode(buffer).decode('utf-8') ,pdflink,list1.to_dict(),str(repeatedLabelsReturn), str(NotFoundReturn)] # , spreadsheetId, spreadsheet_url , list1.to_dict()]
|
| 396 |
+
################################# -2.1- #################################
|
| 397 |
+
elif result[5][2].startswith('2.1'): #section value - 2.8 floor finishes
|
| 398 |
+
#vv[0] array of pdf names
|
| 399 |
+
imgss=[]
|
| 400 |
+
dpxlinks=[]
|
| 401 |
+
legendLinks=[]
|
| 402 |
+
listofmarkups=[]
|
| 403 |
+
|
| 404 |
+
annotatedimg,pdf_document,spreadsheet_url, list1 , df_doors=Counting_Columns_2_1.mainfun(dataDoc,pdfpath,result[0])
|
| 405 |
+
|
| 406 |
+
# dbPath='/TSA JOBS/ADR Test'+pdfpath+'Measured Plan/'
|
| 407 |
+
# pdflink= tsadropboxretrieval.uploadanyFile(doc=pdf_document,path=dbPath,pdfname=result[0]) #doc=doc,pdfname=path,pdfpath=pdfpath+'Measured Plan/
|
| 408 |
+
# _, buffer = cv2.imencode('.png', annotatedimg)
|
| 409 |
+
arr=[base64.b64encode(buffer).decode('utf-8') ,pdflink,spreadsheet_url,list1.to_dict(), df_doors.to_dict()]# , spreadsheetId, spreadsheet_url , list1.to_dict()]
|
| 410 |
+
|
| 411 |
+
################################# -2.2- #################################
|
| 412 |
+
# elif result[5][2].startswith('2.2'): #section value - 2.2 rc slabs
|
| 413 |
+
#add here python code
|
| 414 |
+
#
|
| 415 |
+
#link (add this to ur code)
|
| 416 |
+
# pdflink= db.dropbox_upload_file(doc=doc,pdfname=path,pdfpath=pdfpath)
|
| 417 |
+
# gc,spreadsheet_service,spreadsheetId, spreadsheet_url , namepathArr= pilecaps_adr.legendGoogleSheets(df,plan ,pdfpath)
|
| 418 |
+
#output img
|
| 419 |
+
# _, buffer = cv2.imencode('.png', outputimg)
|
| 420 |
+
#let first result to be the img
|
| 421 |
+
#return results in arr=[base64.b64encode(buffer).decode('utf-8'),pdflink,spreadsheetId,spreadsheet_url] like the previous sections in the above lines
|
| 422 |
+
# elif result[5][2].startswith('2.1'): #section value - 2.1 frames
|
| 423 |
+
# url = tameem2_1.mainfun( result[0], pdfpath)
|
| 424 |
+
# return jsonify([url])
|
| 425 |
+
|
| 426 |
+
return arr
|
| 427 |
+
#_________________________________________________________________________________________________________________________
|
| 428 |
+
#_________________________________________________________________________________________________________________________
|
| 429 |
+
|
| 430 |
+
@app.route("/canvaspdftoimgBackground/<jsdata>",methods=["GET", "POST"])
|
| 431 |
+
def pdftoimgCanvas(jsdata):
|
| 432 |
+
img=plan2img(jsdata)[0]
|
| 433 |
+
_, buffer = cv2.imencode('.png', img)
|
| 434 |
+
arr=[base64.b64encode(buffer).decode('utf-8') , img.shape[0],img.shape[1]]
|
| 435 |
+
return jsonify(arr)
|
| 436 |
+
|
| 437 |
+
|
| 438 |
+
#pdf to img
|
| 439 |
+
def plan2img(nameofpdf):
|
| 440 |
+
|
| 441 |
+
pdfpath,pdflink=tsadropboxretrieval.getPathtoPDF_File(nameofPDF=nameofpdf)
|
| 442 |
+
dbxTeam= tsadropboxretrieval.ADR_Access_DropboxTeam('user')
|
| 443 |
+
md, res =dbxTeam.files_download(path=pdfpath)
|
| 444 |
+
data = res.content
|
| 445 |
+
doc = fitz.open("pdf",data)
|
| 446 |
+
page=doc[0]
|
| 447 |
+
if page.rotation!=0:
|
| 448 |
+
page.set_rotation(0)
|
| 449 |
+
pix = page.get_pixmap(dpi=300) # render page to an image
|
| 450 |
+
pl=Image.frombytes('RGB', [pix.width,pix.height],pix.samples)
|
| 451 |
+
img=np.array(pl)
|
| 452 |
+
img = cv2.cvtColor(img, cv2.COLOR_RGB2BGR)
|
| 453 |
+
return img ,data
|
| 454 |
+
#_________________________________________________________________________________________________________________________
|
| 455 |
+
#_________________________________________________________________________________________________________________________
|
| 456 |
+
|
| 457 |
+
#not used in 1.0
|
| 458 |
+
def convert2img(path):
|
| 459 |
+
pdf = pdfium.PdfDocument(path)
|
| 460 |
+
page = pdf.get_page(0)
|
| 461 |
+
pil_image = page.render().to_pil()
|
| 462 |
+
pl1=np.array(pil_image)
|
| 463 |
+
img = cv2.cvtColor(pl1, cv2.COLOR_RGB2BGR)
|
| 464 |
+
return img
|
| 465 |
+
#_________________________________________________________________________________________________________________________
|
| 466 |
+
#_________________________________________________________________________________________________________________________
|
| 467 |
+
|
| 468 |
+
#User-made MC-T NAME - in the second part of the interface
|
| 469 |
+
@app.route("/mctnametoGoogleSheet/<jsdata>",methods=["GET", "POST"])
|
| 470 |
+
def sendmctnametoLegend(jsdata):
|
| 471 |
+
result = json.loads(jsdata)
|
| 472 |
+
print(result)
|
| 473 |
+
global pdflink
|
| 474 |
+
summaryid=google_sheet_Legend.mapnametoLegend(result,colorsused,pdflink)
|
| 475 |
+
allreturns=[summaryid]
|
| 476 |
+
return jsonify(allreturns)
|
| 477 |
+
|
| 478 |
+
@app.route("/getguessednamepath/",methods=["GET", "POST"])
|
| 479 |
+
def getguessedNames():
|
| 480 |
+
guessednamesDrpdwn=google_sheet_Legend.getallguessednames()
|
| 481 |
+
return jsonify(guessednamesDrpdwn)
|
| 482 |
+
#_________________________________________________________________________________________________________________________
|
| 483 |
+
#_________________________________________________________________________________________________________________________
|
| 484 |
+
#NOT USED (pixel conversion instead)
|
| 485 |
+
def calcRef(img):
|
| 486 |
+
blk = np.ones(img.shape, dtype="uint8") * [[[np.uint8(0), np.uint8(0), np.uint8(0)]]]
|
| 487 |
+
|
| 488 |
+
start_point = (50, 100)
|
| 489 |
+
end_point = (120, 200)
|
| 490 |
+
color = (255, 255, 255) # white BGR
|
| 491 |
+
thickness = -1 # Thickness of -1 will fill the entire shape
|
| 492 |
+
|
| 493 |
+
blk = cv2.rectangle(blk, start_point, end_point, color, thickness)
|
| 494 |
+
|
| 495 |
+
blk = cv2.cvtColor(blk, cv2.COLOR_BGR2GRAY)
|
| 496 |
+
|
| 497 |
+
contourzz, hierarchy = cv2.findContours(image=blk, mode=cv2.RETR_EXTERNAL, method=cv2.CHAIN_APPROX_NONE)
|
| 498 |
+
for i, cnt3 in enumerate(contourzz):
|
| 499 |
+
M = cv2.moments(cnt3)
|
| 500 |
+
if M['m00'] != 0.0:
|
| 501 |
+
x2 = int(M['m10']/M['m00'])
|
| 502 |
+
y2 = int(M['m01']/M['m00'])
|
| 503 |
+
area = cv2.contourArea(cnt3)
|
| 504 |
+
perimeter = cv2.arcLength(cnt3, True)
|
| 505 |
+
return area,perimeter , blk
|
| 506 |
+
|
| 507 |
+
#NOT USED (pixel conversion instead)
|
| 508 |
+
def modifyingcalcRefDynamic(img):
|
| 509 |
+
imgcopy = img.copy()
|
| 510 |
+
|
| 511 |
+
blk = np.ones(img.shape, dtype="uint8") * [[[np.uint8(0), np.uint8(0), np.uint8(0)]]]
|
| 512 |
+
|
| 513 |
+
x = 50
|
| 514 |
+
y = 100
|
| 515 |
+
xD = int(img.shape[1] * 0.10)
|
| 516 |
+
yD = int(img.shape[0] * 0.10)
|
| 517 |
+
start_point = (x, y)
|
| 518 |
+
end_point = (x+xD, y+yD)
|
| 519 |
+
blue = (255, 0, 0) # BGR
|
| 520 |
+
white = (255, 255, 255) # BGR
|
| 521 |
+
thickness = -1 # Thickness of -1 will fill the entire shape
|
| 522 |
+
|
| 523 |
+
imgcopy = cv2.rectangle(imgcopy, start_point, end_point, blue, thickness)
|
| 524 |
+
blk = cv2.rectangle(blk, start_point, end_point, white, thickness)
|
| 525 |
+
|
| 526 |
+
blk = cv2.cvtColor(blk, cv2.COLOR_BGR2GRAY)
|
| 527 |
+
|
| 528 |
+
contourzz, hierarchy = cv2.findContours(image=blk, mode=cv2.RETR_EXTERNAL, method=cv2.CHAIN_APPROX_NONE)
|
| 529 |
+
for i, cnt3 in enumerate(contourzz):
|
| 530 |
+
M = cv2.moments(cnt3)
|
| 531 |
+
if M['m00'] != 0.0:
|
| 532 |
+
x2 = int(M['m10']/M['m00'])
|
| 533 |
+
y2 = int(M['m01']/M['m00'])
|
| 534 |
+
area = cv2.contourArea(cnt3)
|
| 535 |
+
perimeter = cv2.arcLength(cnt3, True)
|
| 536 |
+
return area, perimeter, blk , imgcopy
|
| 537 |
+
#_________________________________________________________________________________________________________________________
|
| 538 |
+
#_________________________________________________________________________________________________________________________
|
| 539 |
+
@app.route('/downloadPDFfromLink')
|
| 540 |
+
def downloadPDFfromLinkFunc():
|
| 541 |
+
encoded_url = request.args.get('url')
|
| 542 |
+
link = urllib.parse.unquote(encoded_url)
|
| 543 |
+
|
| 544 |
+
if link and ('http' in link or 'dropbox' in link):
|
| 545 |
+
if 'dl=0' in link:
|
| 546 |
+
link = link.replace('dl=0', 'dl=1')
|
| 547 |
+
elif 'www.dropbox.com' in link and '?dl=1' not in link:
|
| 548 |
+
link += '?dl=1'
|
| 549 |
+
|
| 550 |
+
try:
|
| 551 |
+
res = requests.get(link)
|
| 552 |
+
res.raise_for_status()
|
| 553 |
+
except Exception as e:
|
| 554 |
+
return f"Error downloading PDF from link: {e}", 400
|
| 555 |
+
|
| 556 |
+
pdf_data = res.content
|
| 557 |
+
filename = link.split("/")[-1].split("?")[0] or "downloaded.pdf"
|
| 558 |
+
|
| 559 |
+
response = make_response(io.BytesIO(pdf_data).getvalue())
|
| 560 |
+
response.headers.set('Content-Type', 'application/pdf')
|
| 561 |
+
response.headers.set('Content-Disposition', f'attachment; filename="{filename}"')
|
| 562 |
+
return response
|
| 563 |
+
|
| 564 |
+
@app.route('/get-pdf/<jsdata>')
|
| 565 |
+
def get_pdf(jsdata):
|
| 566 |
+
print('pdfname',jsdata)
|
| 567 |
+
# Download PDF from Dropbox
|
| 568 |
+
pdfpath,pdflink=tsadropboxretrieval.getPathtoPDF_File(nameofPDF=jsdata)
|
| 569 |
+
print('pdfpath',pdfpath)
|
| 570 |
+
dbxTeam= tsadropboxretrieval.ADR_Access_DropboxTeam('user')
|
| 571 |
+
md, res =dbxTeam.files_download(path=pdfpath)
|
| 572 |
+
pdf_data = res.content # Ensure this is your correct PDF data from Dropbox
|
| 573 |
+
response = make_response(io.BytesIO(pdf_data).getvalue())
|
| 574 |
+
response.headers.set('Content-Type', 'application/pdf')
|
| 575 |
+
response.headers.set('Content-Disposition', 'attachment', filename='filename.pdf') # Replace with your desired file name
|
| 576 |
+
# return response
|
| 577 |
+
return response
|
| 578 |
+
|
| 579 |
+
|
| 580 |
+
#PIXEL CONVERSION METHOD -- SAVES DOC ON DROPBOX TO BE MEASURED BY USER
|
| 581 |
+
@app.route("/pixelimg/<jsdata>",methods=["GET", "POST"])
|
| 582 |
+
def getimg(jsdata):
|
| 583 |
+
progress_updates = [] # Shared list to store progress
|
| 584 |
+
jsdata=eval(jsdata)
|
| 585 |
+
def generate_progressPixel():
|
| 586 |
+
|
| 587 |
+
yield f"data: 10\n\n" # Initial progress
|
| 588 |
+
|
| 589 |
+
pdfpath,pdflink=tsadropboxretrieval.getPathtoPDF_File(nameofPDF=jsdata[3], progress_callback=lambda p: progress_updates.append(p))
|
| 590 |
+
dbxTeam= tsadropboxretrieval.ADR_Access_DropboxTeam('user')
|
| 591 |
+
md, res =dbxTeam.files_download(path=pdfpath)
|
| 592 |
+
data = res.content
|
| 593 |
+
print('jsdata',jsdata)
|
| 594 |
+
if str(jsdata[2]).startswith('1.0'):
|
| 595 |
+
doc,areaPixel,perimeterPixel=pixelconversion.drawisrotated(data,300) # .openDrawPDF(data)
|
| 596 |
+
else:
|
| 597 |
+
doc,areaPixel,perimeterPixel,pdfdata=pixelconversion.drawisrotated(data) # .openDrawPDF(data)
|
| 598 |
+
yield f"data: 20\n\n" # Initial progress
|
| 599 |
+
dbPath='/TSA JOBS/ADR Test/'+jsdata[0]+'/'+jsdata[1]+'/'+jsdata[2]+'/'+'Scale Document' +'/'
|
| 600 |
+
dburl=tsadropboxretrieval.uploadanyFile(doc=doc,pdfname=str(jsdata[3]) ,path=dbPath)
|
| 601 |
+
# areaPixel,perimeterPixel= pixelconversion.getAreaPerimeter(dbPath, str(jsdata[3]))
|
| 602 |
+
yield f"data: 40\n\n" # Initial progress
|
| 603 |
+
outputs=[areaPixel,perimeterPixel , dburl]
|
| 604 |
+
while progress_updates:
|
| 605 |
+
progress = progress_updates.pop(0) # Get the next progress value
|
| 606 |
+
yield f"data: {progress}\n\n"
|
| 607 |
+
# Final progress and result
|
| 608 |
+
yield f"data: 80\n\n"
|
| 609 |
+
yield f"data: 100\n\n"
|
| 610 |
+
result = json.dumps(outputs)
|
| 611 |
+
yield f"data: {result}\n\n"
|
| 612 |
+
|
| 613 |
+
return Response(generate_progressPixel(), content_type='text/event-stream')
|
| 614 |
+
#_________________________________________________________________________________________________________________________
|
| 615 |
+
#_________________________________________________________________________________________________________________________
|
| 616 |
+
#get sunburst from doc_search
|
| 617 |
+
@app.route('/getsunburst',methods=["GET", "POST"])
|
| 618 |
+
def getSunburst():
|
| 619 |
+
|
| 620 |
+
# df=tsadropboxretrieval.GetParquetDF()
|
| 621 |
+
tree=doc_search.prepare_sunburst()
|
| 622 |
+
return jsonify(tree.to_dict())
|
| 623 |
+
#_________________________________________________________________________________________________________________________
|
| 624 |
+
#_________________________________________________________________________________________________________________________
|
| 625 |
+
#DELETE MARKUPS (for comparison)
|
| 626 |
+
@app.route('/_submission',methods=["GET", "POST"])
|
| 627 |
+
def getnewlegend():
|
| 628 |
+
pdfpth=''
|
| 629 |
+
alljson = request.get_json()
|
| 630 |
+
list1=alljson.get('dict1')
|
| 631 |
+
print('list1',list1)
|
| 632 |
+
# list1 = request.args.get('dict1')
|
| 633 |
+
path=alljson.get('path')
|
| 634 |
+
# path = request.args.get('path')
|
| 635 |
+
spreadsheetId=alljson.get('spreadsheetId')
|
| 636 |
+
# spreadsheetId =request.args.get('spreadsheetId')
|
| 637 |
+
pdfpathpath=alljson.get('pdfpathpath')
|
| 638 |
+
# pdfpathpath=request.args.get('pdfpathpath')
|
| 639 |
+
print(pdfpathpath,type(pdfpathpath))
|
| 640 |
+
pdfname=request.args.get('pdfname')
|
| 641 |
+
for word in eval(pdfpathpath):
|
| 642 |
+
pdfpth+='/' +word
|
| 643 |
+
pdfpth+='/'
|
| 644 |
+
dbPath='/TSA JOBS/ADR Test'+pdfpth+'Measured Plan/'
|
| 645 |
+
print(pdfpth)
|
| 646 |
+
deletedrows1=google_sheet_Legend.deletemarkups(list1=list1,dbPath=dbPath,path=path)
|
| 647 |
+
arr1=[deletedrows1.to_dict()]
|
| 648 |
+
print('arr,',arr1)
|
| 649 |
+
return jsonify(arr1)
|
| 650 |
+
#---------------------------------------------------------------------------
|
| 651 |
+
#if user wishes to delete
|
| 652 |
+
@app.route('/deletemarkupsroute',methods=["GET", "POST"])
|
| 653 |
+
def dltmarkupslegend():
|
| 654 |
+
print('IN deletemarkupsroute')
|
| 655 |
+
pdfpth=''
|
| 656 |
+
alljson = request.get_json()
|
| 657 |
+
SimilarAreaDictionary=alljson.get('dict')
|
| 658 |
+
# SimilarAreaDictionary = request.args.get('dict')
|
| 659 |
+
deletedrows=alljson.get('deletedrows')
|
| 660 |
+
print('deletedrowsssssssssssssssssssssssssssssss',deletedrows)
|
| 661 |
+
# deletedrows = request.args.get('deletedrows')
|
| 662 |
+
path=alljson.get('path')
|
| 663 |
+
# path = request.args.get('path')
|
| 664 |
+
spreadsheetId=alljson.get('spreadsheetId')
|
| 665 |
+
# spreadsheetId =request.args.get('spreadsheetId')
|
| 666 |
+
areaPermArr=alljson.get('areaPermArr')
|
| 667 |
+
print('aaaaaaaaaaaaa',areaPermArr)
|
| 668 |
+
# areaPermArr=request.args.get('areaPermArr')
|
| 669 |
+
section=alljson.get('section')
|
| 670 |
+
# section=request.args.get('section')
|
| 671 |
+
pdfpathpath=alljson.get('pdfpathpath')
|
| 672 |
+
# pdfpathpath=request.args.get('pdfpathpath')
|
| 673 |
+
for word in eval(pdfpathpath):
|
| 674 |
+
pdfpth+='/' +word
|
| 675 |
+
pdfpth+='/'
|
| 676 |
+
# myDict=eval(deletedrows)
|
| 677 |
+
deletedrows=pd.DataFrame(deletedrows)
|
| 678 |
+
print('deletedrows',deletedrows)
|
| 679 |
+
if section.startswith('2.7'):
|
| 680 |
+
areaPermArr=hatched_areas2_7
|
| 681 |
+
if section.startswith('1.0') or section.startswith('3.2') or section.startswith('3.3'):
|
| 682 |
+
newlgnd=google_sheet_Legend.deletefromlegend(deletedrows=deletedrows,SimilarAreaDictionarycopy=SimilarAreaDictionary, section=section,areaPermArr=areaPermArr)
|
| 683 |
+
elif section.startswith('2.8') or section.startswith('2.6'):
|
| 684 |
+
newlgnd=google_sheet_Legend.deletedoors(deletedrows,SimilarAreaDictionary)
|
| 685 |
+
print('done wit 2.8 in deleting, didnt append yet ')
|
| 686 |
+
else:
|
| 687 |
+
newlgnd=google_sheet_Legend.deletefromlegend(deletedrows=deletedrows,SimilarAreaDictionarycopy=SimilarAreaDictionary, section=section)
|
| 688 |
+
try:
|
| 689 |
+
newlgnd=google_sheet_Legend.legendGoogleSheets(SimilarAreaDictionary=newlgnd,path=path,spreadsheetId=spreadsheetId ,pdfpath=pdfpth) #new legend
|
| 690 |
+
except:
|
| 691 |
+
|
| 692 |
+
print("An exception occurred")
|
| 693 |
+
time.sleep(20)
|
| 694 |
+
newlgnd=google_sheet_Legend.legendGoogleSheets(SimilarAreaDictionary=newlgnd,path=path,spreadsheetId=spreadsheetId,pdfpath=pdfpth)
|
| 695 |
+
|
| 696 |
+
return jsonify('donee')
|
| 697 |
+
|
| 698 |
+
#_________________________________________________________________________________________________________________________
|
| 699 |
+
#_________________________________________________________________________________________________________________________
|
| 700 |
+
#get pdf dropbox url after measurement is done
|
| 701 |
+
@app.route('/getdropboxurl/<jsdata>',methods=["GET", "POST"])
|
| 702 |
+
def calldropboxurl(jsdata):
|
| 703 |
+
print('jsdata',jsdata)
|
| 704 |
+
pdfurl=tsadropboxretrieval.getPathtoPDF_File(nameofPDF=jsdata)[1]
|
| 705 |
+
print('urll',pdfurl)
|
| 706 |
+
if pdfurl and ('http' in pdfurl or 'dropbox' in pdfurl):
|
| 707 |
+
if 'dl=0' in pdfurl:
|
| 708 |
+
pdfurl = pdfurl.replace('dl=0', 'dl=1')
|
| 709 |
+
print('urll1',pdfurl)
|
| 710 |
+
# Download the PDF content from the shareable link
|
| 711 |
+
response = requests.get(pdfurl)
|
| 712 |
+
pdf_content = BytesIO(response.content) # Store the content in memory
|
| 713 |
+
if pdf_content is None:
|
| 714 |
+
raise ValueError("No valid PDF content found.")
|
| 715 |
+
|
| 716 |
+
# Open the PDF using PyMuPDF
|
| 717 |
+
pdf_document = fitz.open(stream=pdf_content, filetype="pdf")
|
| 718 |
+
pdf_bytes = BytesIO()
|
| 719 |
+
pdf_document.save(pdf_bytes)
|
| 720 |
+
return Response(pdf_bytes.getvalue(), content_type='application/pdf')
|
| 721 |
+
|
| 722 |
+
#_________________________________________________________________________________________________________________________
|
| 723 |
+
#_________________________________________________________________________________________________________________________
|
| 724 |
+
|
| 725 |
+
pdf_content = None
|
| 726 |
+
pageNumTextFound = 0
|
| 727 |
+
BASE_URL = "https://marthee-nbslink.hf.space" # Hugging Face Spaces base URL
|
| 728 |
+
|
| 729 |
+
@app.route("/", methods=["GET", "POST"])
|
| 730 |
+
def thismain():
|
| 731 |
+
print('ayhaga')
|
| 732 |
+
return render_template("gui.html")
|
| 733 |
+
|
| 734 |
+
@app.route('/view-pdf', methods=['GET'])
|
| 735 |
+
def download_pdf():
|
| 736 |
+
|
| 737 |
+
# Manually parse the query parameters
|
| 738 |
+
full_query_string = request.query_string.decode() # Get raw query string
|
| 739 |
+
parsed_params = urllib.parse.parse_qs(full_query_string) # Parse it
|
| 740 |
+
|
| 741 |
+
# Extract pdfLink and keyword manually
|
| 742 |
+
pdf_link = parsed_params.get('pdfLink', [None])[0]
|
| 743 |
+
keyword = parsed_params.get('keyword', [None])[0]
|
| 744 |
+
|
| 745 |
+
if not pdf_link or not keyword:
|
| 746 |
+
return "Missing required parameters.", 400
|
| 747 |
+
|
| 748 |
+
# Decode the extracted values
|
| 749 |
+
pdf_link = urllib.parse.unquote(pdf_link)
|
| 750 |
+
keyword = urllib.parse.unquote(keyword)
|
| 751 |
+
|
| 752 |
+
# If the keyword is a JSON string, convert it back to a list
|
| 753 |
+
try:
|
| 754 |
+
keyword = json.loads(keyword)
|
| 755 |
+
except json.JSONDecodeError:
|
| 756 |
+
keyword = [keyword] # Treat it as a single keyword if not JSON
|
| 757 |
+
|
| 758 |
+
print("Extracted PDF Link:", pdf_link)
|
| 759 |
+
print("Extracted Keywords:", keyword)
|
| 760 |
+
createDF=False
|
| 761 |
+
pdf_content = Find_Hyperlinking_text.annotate_text_from_pdf([pdf_link], keyword)[0]
|
| 762 |
+
if pdf_content is None:
|
| 763 |
+
return "PDF content not found.", 404
|
| 764 |
+
|
| 765 |
+
pdf_bytes = BytesIO(pdf_content)
|
| 766 |
+
return send_file(
|
| 767 |
+
pdf_bytes,
|
| 768 |
+
mimetype='application/pdf',
|
| 769 |
+
as_attachment=False,
|
| 770 |
+
download_name=f"annotated_page_{pageNumTextFound}.pdf"
|
| 771 |
+
)
|
| 772 |
+
|
| 773 |
+
@app.route('/api/process-data', methods=['POST'])
|
| 774 |
+
def receive_pdf_data():
|
| 775 |
+
global pdf_content, pageNumTextFound
|
| 776 |
+
|
| 777 |
+
# Get PDF link and keyword from finddata()
|
| 778 |
+
pdfLink, keyword = finddata()
|
| 779 |
+
|
| 780 |
+
if not pdfLink or not keyword:
|
| 781 |
+
return jsonify({"error": "Both 'pdfLink' and 'keyword' must be provided."}), 400
|
| 782 |
+
|
| 783 |
+
try:
|
| 784 |
+
print(pdfLink, keyword)
|
| 785 |
+
|
| 786 |
+
|
| 787 |
+
pdfbytes, pdf_document , df ,tablepdfoutput= Find_Hyperlinking_text.annotate_text_from_pdf([pdfLink], keyword)
|
| 788 |
+
dbxTeam= tsadropboxretrieval.ADR_Access_DropboxTeam('user')
|
| 789 |
+
|
| 790 |
+
# Get metadata using the shared link
|
| 791 |
+
metadata = dbxTeam.sharing_get_shared_link_metadata(pdfLink)
|
| 792 |
+
dbPath='/TSA JOBS/ADR Test/FIND/'
|
| 793 |
+
pdflink= tsadropboxretrieval.uploadanyFile(doc=pdf_document,path=dbPath,pdfname=metadata.name) #doc=doc,pdfname=path,pdfpath=pdfpath+'Measured Plan/
|
| 794 |
+
print('LINKS0',pdflink)
|
| 795 |
+
|
| 796 |
+
dbPath='/TSA JOBS/ADR Test/FIND/'
|
| 797 |
+
tablepdfLink=tsadropboxretrieval.uploadanyFile(doc=tablepdfoutput,path=dbPath,pdfname=metadata.name.rsplit(".pdf", 1)[0] +' Markup Summary'+'.pdf')
|
| 798 |
+
print(f"PDF successfully uploaded to Dropbox at")
|
| 799 |
+
print('LINKS1',tablepdfLink)
|
| 800 |
+
return jsonify({
|
| 801 |
+
"message": "PDF processed successfully.",
|
| 802 |
+
"PDF_MarkedUp": pdflink,
|
| 803 |
+
'Table_PDF_Markup_Summary': tablepdfLink
|
| 804 |
+
})
|
| 805 |
+
|
| 806 |
+
except Exception as e:
|
| 807 |
+
return jsonify({"error": str(e)}), 500
|
| 808 |
+
|
| 809 |
+
def finddata():
|
| 810 |
+
pdfLink = 'https://www.dropbox.com/scl/fi/hnp4mqigb51a5kp89kgfa/00801-ARC-20-ZZ-S-A-0002.pdf?rlkey=45abeoebzqw4qwnslnei6dkd6&st=m4yrcjm2&dl=1'
|
| 811 |
+
keyword = ['115 INTEGRATED MRI ROOM LININGS', '310 ACCURACY']
|
| 812 |
+
return pdfLink, keyword
|
| 813 |
+
|
| 814 |
+
|
| 815 |
+
#_________________________________________________________________________________________________________________________
|
| 816 |
+
#_________________________________________________________________________________________________________________________
|
| 817 |
+
|
| 818 |
+
#Google sheet links
|
| 819 |
+
@app.route('/getdrivelinks/<jsdata>',methods=["GET", "POST"])
|
| 820 |
+
def getlinkscreated(jsdata):
|
| 821 |
+
spreadsheet_service,drive_service,gc= google_sheet_Legend.authorizeLegend()
|
| 822 |
+
ids=gc.spreadsheet_ids()
|
| 823 |
+
titles=gc.spreadsheet_titles()
|
| 824 |
+
allpaths=[]
|
| 825 |
+
print('HEREEEEEEEEEE')
|
| 826 |
+
# for title in titles:
|
| 827 |
+
for i in range(0,len(titles)):
|
| 828 |
+
print('titles',titles[i])
|
| 829 |
+
if not (titles[i].startswith('API') or (titles[i].startswith('Dropbox')) ) :
|
| 830 |
+
|
| 831 |
+
ws=gc.open(titles[i])
|
| 832 |
+
path_metadata = ws.get_developer_metadata('path')
|
| 833 |
+
print(path_metadata)
|
| 834 |
+
allpaths.append([titles[i], ws.get_developer_metadata('path')[0].value , drive_service.files().get(fileId=ids[i],fields="createdTime, modifiedTime").execute() ,ids[i] ])
|
| 835 |
+
|
| 836 |
+
return jsonify(allpaths)
|
| 837 |
+
#_________________________________________________________________________________________________________________________
|
| 838 |
+
#_________________________________________________________________________________________________________________________
|
| 839 |
+
@app.route('/getAPITables/',methods=["GET", "POST"])
|
| 840 |
+
def returnAPITables():
|
| 841 |
+
# API.update_df()
|
| 842 |
+
table1,table2,table3=API.GenerateTables()
|
| 843 |
+
return jsonify([table1.to_dict(),table2.to_dict(),table3.to_dict()])
|
| 844 |
+
|
| 845 |
+
|
| 846 |
+
@app.route('/refreshAPI',methods=["GET", "POST"])
|
| 847 |
+
def checktables():
|
| 848 |
+
projectname = request.args.get('prjname')
|
| 849 |
+
projectpart = request.args.get('prjpart')
|
| 850 |
+
projectpartid = request.args.get('prjpartid')
|
| 851 |
+
print('hgh',projectname , projectpart)
|
| 852 |
+
table1,table2,table3=API.GenerateTables()
|
| 853 |
+
url_1 = prjnamesURL.replace('/edit#gid=', '/export?format=csv&gid=')
|
| 854 |
+
url_2 = prjpartsURL.replace('/edit#gid=', '/export?format=csv&gid=')
|
| 855 |
+
url_3 = prjsectionsURL.replace('/edit#gid=', '/export?format=csv&gid=')
|
| 856 |
+
|
| 857 |
+
table1N = pd.read_csv(url_1)
|
| 858 |
+
table2N = pd.read_csv(url_2)
|
| 859 |
+
table3N = pd.read_csv(url_3)
|
| 860 |
+
|
| 861 |
+
t1Diff=table1N[~table1N.isin(table1)].dropna()
|
| 862 |
+
t1Diff1=table1[~table1.isin(table1N)].dropna()
|
| 863 |
+
|
| 864 |
+
t2Diff=pd.DataFrame()
|
| 865 |
+
t2Diff1=pd.DataFrame()
|
| 866 |
+
|
| 867 |
+
t3Diff=pd.DataFrame()
|
| 868 |
+
t3Diff1=pd.DataFrame()
|
| 869 |
+
|
| 870 |
+
|
| 871 |
+
if projectname:
|
| 872 |
+
print('here')
|
| 873 |
+
differentParts=[]
|
| 874 |
+
a = table1N.to_numpy()
|
| 875 |
+
row = np.where(a == projectname)
|
| 876 |
+
print(projectname,row)
|
| 877 |
+
returnString=''
|
| 878 |
+
t2Diff1=table2[~table2.isin(table2N)].dropna()
|
| 879 |
+
t2Diff=table2N[~table2N.isin(table2)].dropna()
|
| 880 |
+
|
| 881 |
+
if projectpart and projectname:
|
| 882 |
+
|
| 883 |
+
a1 = table1N.to_numpy()
|
| 884 |
+
row1 = np.where(a1 == projectname)
|
| 885 |
+
prjid=a1[row1[0]][0][0]
|
| 886 |
+
t3Diff1=table3[~table3.isin(table3N)].dropna()
|
| 887 |
+
t3Diff=table3N[~table3N.isin(table3)].dropna()
|
| 888 |
+
|
| 889 |
+
returnString=''
|
| 890 |
+
if not t1Diff.empty or not t1Diff1.empty :
|
| 891 |
+
if not t1Diff.empty:
|
| 892 |
+
newvalues= t1Diff['ProjectName'].values
|
| 893 |
+
else:
|
| 894 |
+
newvalues= t1Diff1['ProjectName'].values
|
| 895 |
+
returnString=''
|
| 896 |
+
returnString=['Changes have been made in Projects. Would you like to retrieve them in the console? By saying yes, you may need to repeat the website related processes(if any).','project',(newvalues).tolist(),table2.to_dict()]
|
| 897 |
+
|
| 898 |
+
if (not t2Diff.empty)or( not t2Diff1.empty) :
|
| 899 |
+
if projectname:
|
| 900 |
+
for i in range(len(t2Diff1['ProjectId'].values)):
|
| 901 |
+
if int(t2Diff1['ProjectId'].values[i]) ==int(a[row[0]][0][0]):
|
| 902 |
+
differentParts.append(t2Diff1['ProjectPart'].iloc[i])
|
| 903 |
+
if len(differentParts)>0:
|
| 904 |
+
returnString=['Changes have been made in Parts. Would you like to retrieve them in the console?','part',differentParts]
|
| 905 |
+
|
| 906 |
+
if (not t3Diff.empty) or (not t3Diff1.empty) :
|
| 907 |
+
differentSections=[]
|
| 908 |
+
if projectpart and projectname:
|
| 909 |
+
roww=t3Diff1.iloc[np.where((t3Diff1['ProjectId']==int(prjid) ) & (t3Diff1['ProjectPartId']==int(projectpartid)) ) ]
|
| 910 |
+
for i in range(len(roww['ProjectId'].values)):
|
| 911 |
+
differentSections.append(str(roww['ProjectSection'].iloc[i]))
|
| 912 |
+
if len(differentSections)>0:
|
| 913 |
+
returnString=['Changes have been made in Sections. Would you like to retrieve them in the console?','section',differentSections]
|
| 914 |
+
|
| 915 |
+
print(returnString)
|
| 916 |
+
|
| 917 |
+
|
| 918 |
+
return jsonify(returnString)
|
| 919 |
+
|
| 920 |
+
@app.route('/refreshDropbox',methods=["GET", "POST"])
|
| 921 |
+
def checkdropbox():
|
| 922 |
+
print('checkingggdf')
|
| 923 |
+
dfFromDropbox=tsadropboxretrieval.DropboxItemstoDF("/TSA JOBS")[0]
|
| 924 |
+
dfParquet=tsadropboxretrieval.GetParquetDF()
|
| 925 |
+
|
| 926 |
+
dfParquet1 = dfParquet[['name', 'path_display', 'client_modified', 'server_modified']]
|
| 927 |
+
|
| 928 |
+
deletedrows = pd.concat([dfFromDropbox, dfParquet1]).drop_duplicates(keep=False)
|
| 929 |
+
deletedrows = deletedrows.reset_index(drop=True)
|
| 930 |
+
deletedrows.columns = ['name', 'path_display', 'client_modified', 'server_modified']
|
| 931 |
+
differences = deletedrows[~deletedrows.isin(dfFromDropbox)].dropna()
|
| 932 |
+
if (len(differences)>0):
|
| 933 |
+
print(differences)
|
| 934 |
+
dbxTeam=tsadropboxretrieval.dropbox_upload_file(dfFromDropbox)
|
| 935 |
+
stringReturned= 'Updated Sucessfully.'
|
| 936 |
+
else:
|
| 937 |
+
stringReturned= 'Nothing to update.'
|
| 938 |
+
return 'stringReturned'
|
| 939 |
+
|
| 940 |
+
def refreshDropboxRetrievals(extractedPath):
|
| 941 |
+
dfFromDropbox = tsadropboxretrieval.DropboxItemstoDF(extractedPath)[0]
|
| 942 |
+
dfParquet = tsadropboxretrieval.GetParquetDF()
|
| 943 |
+
|
| 944 |
+
# print("Original Parquet size:", len(dfParquet))
|
| 945 |
+
|
| 946 |
+
# Keep only relevant columns
|
| 947 |
+
dfParquet = dfParquet[['name', 'path_display', 'client_modified', 'server_modified']]
|
| 948 |
+
dfFromDropbox = dfFromDropbox[['name', 'path_display', 'client_modified', 'server_modified']]
|
| 949 |
+
|
| 950 |
+
# **Drop rows that start with extractedPath**
|
| 951 |
+
dfParquetUpdated = dfParquet[~dfParquet['path_display'].str.startswith(extractedPath)]
|
| 952 |
+
|
| 953 |
+
# **Append new data from Dropbox**
|
| 954 |
+
dfParquetUpdated = pd.concat([dfParquetUpdated, dfFromDropbox], ignore_index=True)
|
| 955 |
+
|
| 956 |
+
# print("Updated Parquet size:", len(dfParquetUpdated),dfParquetUpdated)
|
| 957 |
+
|
| 958 |
+
# **Save the updated Parquet file**
|
| 959 |
+
tsadropboxretrieval.dropbox_upload_file(dfParquetUpdated)
|
| 960 |
+
|
| 961 |
+
if len(dfFromDropbox) > 0:
|
| 962 |
+
print("Updated entries:", dfFromDropbox)
|
| 963 |
+
return 'Updated Successfully.'
|
| 964 |
+
else:
|
| 965 |
+
return 'Nothing to update.'
|
| 966 |
+
|
| 967 |
+
|
| 968 |
+
|
| 969 |
+
|
| 970 |
+
|
| 971 |
+
@app.route('/postdropboxprojects/<path:encoded_path>')
|
| 972 |
+
def handle_path(encoded_path):
|
| 973 |
+
decoded_path = urllib.parse.unquote(encoded_path) # Decode URL encoding
|
| 974 |
+
extracted_path = json.loads(decoded_path) # Convert back to Python object
|
| 975 |
+
print('path to refresh',extracted_path)
|
| 976 |
+
stringReturned=refreshDropboxRetrievals(extracted_path)
|
| 977 |
+
print(stringReturned)
|
| 978 |
+
return stringReturned
|
| 979 |
+
|
| 980 |
+
|
| 981 |
+
|
| 982 |
+
@app.route('/refreshAPIAppendNewTables',methods=["GET", "POST"])
|
| 983 |
+
def appendNewTables():
|
| 984 |
+
# value = request.args.get('keyword')
|
| 985 |
+
# print(value)
|
| 986 |
+
API.AppendtablestoSheets()
|
| 987 |
+
return jsonify('appended')
|
| 988 |
+
|
| 989 |
+
|
| 990 |
+
@app.route('/summarytoXML/<jsdata>',methods=["GET", "POST"])
|
| 991 |
+
def cvtSummarytoXML(jsdata):
|
| 992 |
+
path='/TSA JOBS/ADR Test/'
|
| 993 |
+
result = json.loads(jsdata)
|
| 994 |
+
for word in result[0]:
|
| 995 |
+
path+=word +'/'
|
| 996 |
+
print(path)
|
| 997 |
+
path=path+'XML/'
|
| 998 |
+
# print(result[0])
|
| 999 |
+
# print(result[1])
|
| 1000 |
+
xmllink=google_sheet_to_xml.create_xml(documentname=result[1],dbPath=path)
|
| 1001 |
+
return jsonify(xmllink)
|
| 1002 |
+
|
| 1003 |
+
|
| 1004 |
#_________________________________________________________________________________________________________________________
|
| 1005 |
#_________________________________________________________________________________________________________________________
|
| 1006 |
|