Spaces:
Sleeping
Sleeping
Update app.py
Browse files
app.py
CHANGED
|
@@ -21,15 +21,30 @@ from werkzeug.wsgi import wrap_file
|
|
| 21 |
import tameem3_2
|
| 22 |
import pypdfium2 as pdfium
|
| 23 |
import pixelconversion
|
|
|
|
| 24 |
import urllib.request
|
| 25 |
import base64
|
| 26 |
import io
|
| 27 |
from urllib.parse import unquote
|
| 28 |
-
|
| 29 |
-
|
| 30 |
app = Flask(__name__)
|
| 31 |
|
| 32 |
# out_file = open("static/data/myfile.json", "w")
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 33 |
|
| 34 |
#retrieves project parts
|
| 35 |
@app.route('/getmethod/<jsdata>',methods=['GET','POST'])
|
|
@@ -40,7 +55,7 @@ def get_javascript_data(jsdata):
|
|
| 40 |
print(matches)
|
| 41 |
return jsonify (list(matches))
|
| 42 |
#---------------------------------------------------------------
|
| 43 |
-
|
| 44 |
#get projects of 'project name'
|
| 45 |
def update_dropdown(section):
|
| 46 |
if section.startswith('1.0'):
|
|
@@ -49,6 +64,8 @@ def update_dropdown(section):
|
|
| 49 |
plans_inrepo=os.listdir('dropbox_plans/3.2')
|
| 50 |
elif section.startswith('2.2'):
|
| 51 |
plans_inrepo=os.listdir('dropbox_plans/2.2')
|
|
|
|
|
|
|
| 52 |
else:
|
| 53 |
return ''
|
| 54 |
#if 'foundation' in radio and project in plans_inrepo
|
|
@@ -68,7 +85,7 @@ def update_dropdown(section):
|
|
| 68 |
def getInfotoMeasure():
|
| 69 |
# db.create_folder()
|
| 70 |
mylist=[1,2,3,4]
|
| 71 |
-
return render_template("proposed-
|
| 72 |
#_________________________________________________________________________________________________________________________
|
| 73 |
#_________________________________________________________________________________________________________________________
|
| 74 |
#Hex value to RGB value
|
|
@@ -95,26 +112,25 @@ def stringToRGB():
|
|
| 95 |
# return opencv_img
|
| 96 |
return jsonify(arr)
|
| 97 |
|
| 98 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 99 |
#MAIN FUNCTION -- calls python code to measure the chosen plan from the interface
|
| 100 |
# @app.route('/projecttomeasure/<jsdata>',methods=["GET","POST"])
|
| 101 |
-
def measureproject(result,img):
|
| 102 |
colorarr=[]
|
| 103 |
# result = json.loads(jsdata)
|
| 104 |
pdfpath='/'
|
| 105 |
################################# -1.0- #################################
|
|
|
|
| 106 |
for word in result[5]:
|
| 107 |
pdfpath+=word +'/'
|
| 108 |
arr=[]
|
| 109 |
|
| 110 |
if result[5][2].startswith('1.0'): #section value - 1.0 substructure- pile caps
|
| 111 |
-
# img0 = plan2img('dropbox_plans/1.0/'+str(result[0]) )
|
| 112 |
-
|
| 113 |
-
# if (result[1]!=0):
|
| 114 |
-
# img=stringToRGB(result[6], img0.shape)
|
| 115 |
-
# print('p',result[6])
|
| 116 |
-
|
| 117 |
-
|
| 118 |
for item in result[2]:
|
| 119 |
# item1 ='#'+item
|
| 120 |
c=hexRGB(item)
|
|
@@ -142,6 +158,10 @@ def measureproject(result,img):
|
|
| 142 |
|
| 143 |
#let first result to be the img
|
| 144 |
#return results in arr=[base64.b64encode(buffer).decode('utf-8'),pdflink,spreadsheetId,spreadsheet_url] like the previous sections in the above lines
|
|
|
|
|
|
|
|
|
|
|
|
|
| 145 |
return arr
|
| 146 |
#_________________________________________________________________________________________________________________________
|
| 147 |
#_________________________________________________________________________________________________________________________
|
|
@@ -258,6 +278,8 @@ def getimg(jsdata):
|
|
| 258 |
doc = fitz.open('dropbox_plans/3.2/'+str(jsdata[3]) )
|
| 259 |
elif jsdata[2].startswith('2.2'):
|
| 260 |
doc = fitz.open('dropbox_plans/2.2/'+str(jsdata[3]) )
|
|
|
|
|
|
|
| 261 |
else:
|
| 262 |
return ''
|
| 263 |
for page in doc:
|
|
@@ -273,6 +295,8 @@ def getimg(jsdata):
|
|
| 273 |
doc=pixelconversion.openDrawPDF(path='dropbox_plans/3.2/'+str(jsdata[3]))
|
| 274 |
elif jsdata[2].startswith('2.2'):
|
| 275 |
doc=pixelconversion.openDrawPDF(path='dropbox_plans/2.2/'+str(jsdata[3]))
|
|
|
|
|
|
|
| 276 |
pdfpath='/'+jsdata[0]+'/'+jsdata[1]+'/'+jsdata[2]+'/'+'Scale Document' +'/'
|
| 277 |
dburl=db.dropbox_upload_file(doc=doc,pdfname=str(jsdata[3]) ,pdfpath=pdfpath,flag=1)
|
| 278 |
areaPixel,perimeterPixel= pixelconversion.getAreaPerimeter(pdfpath, str(jsdata[3]))
|
|
|
|
| 21 |
import tameem3_2
|
| 22 |
import pypdfium2 as pdfium
|
| 23 |
import pixelconversion
|
| 24 |
+
import tameem2_1
|
| 25 |
import urllib.request
|
| 26 |
import base64
|
| 27 |
import io
|
| 28 |
from urllib.parse import unquote
|
| 29 |
+
import API
|
|
|
|
| 30 |
app = Flask(__name__)
|
| 31 |
|
| 32 |
# out_file = open("static/data/myfile.json", "w")
|
| 33 |
+
@app.route('/getprojectnames/',methods=['GET'])
|
| 34 |
+
def getprjnamesfromTestAPI():
|
| 35 |
+
prjnames=API.getPrjNames()
|
| 36 |
+
return jsonify(prjnames)
|
| 37 |
+
|
| 38 |
+
@app.route('/getprojectparts/<jsdata>',methods=['GET'])
|
| 39 |
+
def getprjpartsfromTestAPI(jsdata):
|
| 40 |
+
prjparts=API.getprjParts(jsdata)
|
| 41 |
+
return jsonify(prjparts)
|
| 42 |
+
|
| 43 |
+
@app.route('/getprojectsections/<jsdata>',methods=['GET'])
|
| 44 |
+
def getprjSectionsfromTestAPI(jsdata):
|
| 45 |
+
sections=API.getprjSections(jsdata)
|
| 46 |
+
return jsonify(sections)
|
| 47 |
+
|
| 48 |
|
| 49 |
#retrieves project parts
|
| 50 |
@app.route('/getmethod/<jsdata>',methods=['GET','POST'])
|
|
|
|
| 55 |
print(matches)
|
| 56 |
return jsonify (list(matches))
|
| 57 |
#---------------------------------------------------------------
|
| 58 |
+
|
| 59 |
#get projects of 'project name'
|
| 60 |
def update_dropdown(section):
|
| 61 |
if section.startswith('1.0'):
|
|
|
|
| 64 |
plans_inrepo=os.listdir('dropbox_plans/3.2')
|
| 65 |
elif section.startswith('2.2'):
|
| 66 |
plans_inrepo=os.listdir('dropbox_plans/2.2')
|
| 67 |
+
elif section.startswith('2.1'):
|
| 68 |
+
plans_inrepo=os.listdir('dropbox_plans/2.1')
|
| 69 |
else:
|
| 70 |
return ''
|
| 71 |
#if 'foundation' in radio and project in plans_inrepo
|
|
|
|
| 85 |
def getInfotoMeasure():
|
| 86 |
# db.create_folder()
|
| 87 |
mylist=[1,2,3,4]
|
| 88 |
+
return render_template("proposed-GUI2.html",mylist=mylist)
|
| 89 |
#_________________________________________________________________________________________________________________________
|
| 90 |
#_________________________________________________________________________________________________________________________
|
| 91 |
#Hex value to RGB value
|
|
|
|
| 112 |
# return opencv_img
|
| 113 |
return jsonify(arr)
|
| 114 |
|
| 115 |
+
@app.route('/2.1Trial/',methods=["POST"])
|
| 116 |
+
def measure2_1():
|
| 117 |
+
name = request.get_json()
|
| 118 |
+
result=name.get('allvalues')
|
| 119 |
+
arr=measureproject(result)
|
| 120 |
+
return arr
|
| 121 |
#MAIN FUNCTION -- calls python code to measure the chosen plan from the interface
|
| 122 |
# @app.route('/projecttomeasure/<jsdata>',methods=["GET","POST"])
|
| 123 |
+
def measureproject(result,img=0):
|
| 124 |
colorarr=[]
|
| 125 |
# result = json.loads(jsdata)
|
| 126 |
pdfpath='/'
|
| 127 |
################################# -1.0- #################################
|
| 128 |
+
|
| 129 |
for word in result[5]:
|
| 130 |
pdfpath+=word +'/'
|
| 131 |
arr=[]
|
| 132 |
|
| 133 |
if result[5][2].startswith('1.0'): #section value - 1.0 substructure- pile caps
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 134 |
for item in result[2]:
|
| 135 |
# item1 ='#'+item
|
| 136 |
c=hexRGB(item)
|
|
|
|
| 158 |
|
| 159 |
#let first result to be the img
|
| 160 |
#return results in arr=[base64.b64encode(buffer).decode('utf-8'),pdflink,spreadsheetId,spreadsheet_url] like the previous sections in the above lines
|
| 161 |
+
elif result[5][2].startswith('2.1'): #section value - 2.1 frames
|
| 162 |
+
url = tameem2_1.mainfun( result[0], pdfpath)
|
| 163 |
+
return jsonify([url])
|
| 164 |
+
|
| 165 |
return arr
|
| 166 |
#_________________________________________________________________________________________________________________________
|
| 167 |
#_________________________________________________________________________________________________________________________
|
|
|
|
| 278 |
doc = fitz.open('dropbox_plans/3.2/'+str(jsdata[3]) )
|
| 279 |
elif jsdata[2].startswith('2.2'):
|
| 280 |
doc = fitz.open('dropbox_plans/2.2/'+str(jsdata[3]) )
|
| 281 |
+
elif jsdata[2].startswith('2.1'):
|
| 282 |
+
doc = fitz.open('dropbox_plans/2.1/'+str(jsdata[3]) )
|
| 283 |
else:
|
| 284 |
return ''
|
| 285 |
for page in doc:
|
|
|
|
| 295 |
doc=pixelconversion.openDrawPDF(path='dropbox_plans/3.2/'+str(jsdata[3]))
|
| 296 |
elif jsdata[2].startswith('2.2'):
|
| 297 |
doc=pixelconversion.openDrawPDF(path='dropbox_plans/2.2/'+str(jsdata[3]))
|
| 298 |
+
elif jsdata[2].startswith('2.1'):
|
| 299 |
+
doc=pixelconversion.openDrawPDF(path='dropbox_plans/2.1/'+str(jsdata[3]))
|
| 300 |
pdfpath='/'+jsdata[0]+'/'+jsdata[1]+'/'+jsdata[2]+'/'+'Scale Document' +'/'
|
| 301 |
dburl=db.dropbox_upload_file(doc=doc,pdfname=str(jsdata[3]) ,pdfpath=pdfpath,flag=1)
|
| 302 |
areaPixel,perimeterPixel= pixelconversion.getAreaPerimeter(pdfpath, str(jsdata[3]))
|