Update app.py
Browse files
app.py
CHANGED
|
@@ -56,6 +56,12 @@ global colorsused
|
|
| 56 |
global pdflink
|
| 57 |
# For 2.7
|
| 58 |
global hatched_areas2_7
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 59 |
|
| 60 |
# Configure Flask-Session for server-side session storage
|
| 61 |
app.config["SESSION_TYPE"] = "filesystem"
|
|
@@ -101,43 +107,63 @@ def getInfo2toMeasure():
|
|
| 101 |
|
| 102 |
|
| 103 |
|
| 104 |
-
@app.route('/getprojectnames/',methods=['GET'])
|
| 105 |
def getprjnamesfromTestAPI():
|
| 106 |
progress_updates = [] # Shared list to store progress
|
| 107 |
|
| 108 |
def generate_progressProjnames():
|
| 109 |
-
yield f"data: 10\n\n"
|
| 110 |
-
|
| 111 |
-
|
| 112 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 113 |
|
| 114 |
while progress_updates:
|
| 115 |
-
progress = progress_updates.pop(0)
|
| 116 |
yield f"data: {progress}\n\n"
|
| 117 |
-
# Final progress and result
|
| 118 |
yield f"data: 80\n\n"
|
| 119 |
yield f"data: 100\n\n"
|
| 120 |
-
result = json.dumps([prjnames,prjids])
|
| 121 |
yield f"data: {result}\n\n"
|
| 122 |
-
return Response(generate_progressProjnames(), content_type='text/event-stream')
|
| 123 |
|
|
|
|
| 124 |
|
| 125 |
-
@app.route('/getprojectparts/<jsdata>',methods=['GET'])
|
| 126 |
def getprjpartsfromTestAPI(jsdata):
|
| 127 |
-
|
| 128 |
-
|
| 129 |
-
|
|
|
|
|
|
|
| 130 |
|
| 131 |
-
|
|
|
|
|
|
|
| 132 |
def getprjSectionsfromTestAPI(jsdata):
|
| 133 |
-
data=json.loads(jsdata)
|
| 134 |
-
if data[0]=='testing':
|
| 135 |
-
sections=API.getprjSections()
|
| 136 |
-
|
| 137 |
-
|
| 138 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 139 |
return jsonify(sections)
|
| 140 |
|
|
|
|
|
|
|
| 141 |
@app.route('/getmethod/<jsdata>', methods=['GET'])
|
| 142 |
def get_javascript_data(jsdata):
|
| 143 |
progress_updates = [] # Shared list to store progress
|
|
@@ -1104,78 +1130,61 @@ def returnAPITables():
|
|
| 1104 |
table1,table2,table3=API.GenerateTables()
|
| 1105 |
return jsonify([table1.to_dict(),table2.to_dict(),table3.to_dict()])
|
| 1106 |
|
| 1107 |
-
|
| 1108 |
-
@app.route('/refreshAPI',methods=["GET", "POST"])
|
| 1109 |
def checktables():
|
| 1110 |
-
projectname =
|
| 1111 |
-
projectpart =
|
| 1112 |
-
projectpartid =
|
| 1113 |
-
|
| 1114 |
-
|
| 1115 |
-
|
| 1116 |
-
|
| 1117 |
-
|
| 1118 |
-
|
| 1119 |
-
|
| 1120 |
-
|
| 1121 |
-
|
| 1122 |
-
|
| 1123 |
-
|
| 1124 |
-
|
| 1125 |
-
|
| 1126 |
-
|
| 1127 |
-
|
| 1128 |
-
|
| 1129 |
-
|
| 1130 |
-
|
| 1131 |
-
|
| 1132 |
-
|
| 1133 |
-
|
| 1134 |
-
|
| 1135 |
-
|
| 1136 |
-
|
| 1137 |
-
|
| 1138 |
-
|
| 1139 |
-
|
| 1140 |
-
|
| 1141 |
-
|
| 1142 |
-
|
| 1143 |
-
|
| 1144 |
-
|
| 1145 |
-
|
| 1146 |
-
|
| 1147 |
-
|
| 1148 |
-
|
| 1149 |
-
|
| 1150 |
-
|
| 1151 |
-
|
| 1152 |
-
|
| 1153 |
-
|
| 1154 |
-
|
| 1155 |
-
|
| 1156 |
-
|
| 1157 |
-
returnString=
|
| 1158 |
-
|
| 1159 |
-
|
| 1160 |
-
|
| 1161 |
-
|
| 1162 |
-
|
| 1163 |
-
if int(t2Diff1['ProjectId'].values[i]) ==int(a[row[0]][0][0]):
|
| 1164 |
-
differentParts.append(t2Diff1['ProjectPart'].iloc[i])
|
| 1165 |
-
if len(differentParts)>0:
|
| 1166 |
-
returnString=['Changes have been made in Parts. Would you like to retrieve them in the console?','part',differentParts]
|
| 1167 |
-
|
| 1168 |
-
if (not t3Diff.empty) or (not t3Diff1.empty) :
|
| 1169 |
-
differentSections=[]
|
| 1170 |
-
if projectpart and projectname:
|
| 1171 |
-
roww=t3Diff1.iloc[np.where((t3Diff1['ProjectId']==int(prjid) ) & (t3Diff1['ProjectPartId']==int(projectpartid)) ) ]
|
| 1172 |
-
for i in range(len(roww['ProjectId'].values)):
|
| 1173 |
-
differentSections.append(str(roww['ProjectSection'].iloc[i]))
|
| 1174 |
-
if len(differentSections)>0:
|
| 1175 |
-
returnString=['Changes have been made in Sections. Would you like to retrieve them in the console?','section',differentSections]
|
| 1176 |
-
|
| 1177 |
-
print(returnString)
|
| 1178 |
-
|
| 1179 |
|
| 1180 |
return jsonify(returnString)
|
| 1181 |
|
|
@@ -1302,4 +1311,4 @@ while 1:
|
|
| 1302 |
if __name__ == "__main__":
|
| 1303 |
runn()
|
| 1304 |
|
| 1305 |
-
|
|
|
|
| 56 |
global pdflink
|
| 57 |
# For 2.7
|
| 58 |
global hatched_areas2_7
|
| 59 |
+
# Global cache to store last known tables
|
| 60 |
+
cached_tables = {
|
| 61 |
+
"projects": None,
|
| 62 |
+
"parts": None,
|
| 63 |
+
"sections": None
|
| 64 |
+
}
|
| 65 |
|
| 66 |
# Configure Flask-Session for server-side session storage
|
| 67 |
app.config["SESSION_TYPE"] = "filesystem"
|
|
|
|
| 107 |
|
| 108 |
|
| 109 |
|
| 110 |
+
@app.route('/getprojectnames/', methods=['GET'])
|
| 111 |
def getprjnamesfromTestAPI():
|
| 112 |
progress_updates = [] # Shared list to store progress
|
| 113 |
|
| 114 |
def generate_progressProjnames():
|
| 115 |
+
yield f"data: 10\n\n"
|
| 116 |
+
prjnames, prjids = API.getPrjNames(
|
| 117 |
+
progress_callback=lambda p: progress_updates.append(p)
|
| 118 |
+
)
|
| 119 |
+
|
| 120 |
+
# save in memory
|
| 121 |
+
global cached_tables
|
| 122 |
+
cached_tables["projects"] = pd.DataFrame({
|
| 123 |
+
"ProjectName": prjnames,
|
| 124 |
+
"ProjectId": prjids
|
| 125 |
+
})
|
| 126 |
|
| 127 |
while progress_updates:
|
| 128 |
+
progress = progress_updates.pop(0)
|
| 129 |
yield f"data: {progress}\n\n"
|
|
|
|
| 130 |
yield f"data: 80\n\n"
|
| 131 |
yield f"data: 100\n\n"
|
| 132 |
+
result = json.dumps([prjnames, prjids])
|
| 133 |
yield f"data: {result}\n\n"
|
|
|
|
| 134 |
|
| 135 |
+
return Response(generate_progressProjnames(), content_type='text/event-stream')
|
| 136 |
|
| 137 |
+
@app.route('/getprojectparts/<jsdata>', methods=['GET'])
|
| 138 |
def getprjpartsfromTestAPI(jsdata):
|
| 139 |
+
prjparts, partsIds = API.getprjParts(jsdata)
|
| 140 |
+
|
| 141 |
+
global cached_tables
|
| 142 |
+
df = pd.DataFrame({"ProjectPart": prjparts, "ProjectPartId": partsIds, "ProjectId": [int(jsdata)] * len(prjparts)})
|
| 143 |
+
cached_tables["parts"] = df
|
| 144 |
|
| 145 |
+
return jsonify([prjparts, partsIds])
|
| 146 |
+
|
| 147 |
+
@app.route('/getprojectsections/<jsdata>', methods=['GET'])
|
| 148 |
def getprjSectionsfromTestAPI(jsdata):
|
| 149 |
+
data = json.loads(jsdata)
|
| 150 |
+
if data[0] == 'testing':
|
| 151 |
+
sections = API.getprjSections()
|
| 152 |
+
else:
|
| 153 |
+
sections = API.getprjSections(data[0], data[1])
|
| 154 |
+
|
| 155 |
+
global cached_tables
|
| 156 |
+
df = pd.DataFrame({
|
| 157 |
+
"ProjectSection": sections,
|
| 158 |
+
"ProjectId": [data[0]] * len(sections),
|
| 159 |
+
"ProjectPartId": [data[1]] * len(sections)
|
| 160 |
+
})
|
| 161 |
+
cached_tables["sections"] = df
|
| 162 |
+
|
| 163 |
return jsonify(sections)
|
| 164 |
|
| 165 |
+
|
| 166 |
+
|
| 167 |
@app.route('/getmethod/<jsdata>', methods=['GET'])
|
| 168 |
def get_javascript_data(jsdata):
|
| 169 |
progress_updates = [] # Shared list to store progress
|
|
|
|
| 1130 |
table1,table2,table3=API.GenerateTables()
|
| 1131 |
return jsonify([table1.to_dict(),table2.to_dict(),table3.to_dict()])
|
| 1132 |
|
| 1133 |
+
@app.route('/refreshAPI', methods=["GET", "POST"])
|
|
|
|
| 1134 |
def checktables():
|
| 1135 |
+
projectname = request.args.get('prjname')
|
| 1136 |
+
projectpart = request.args.get('prjpart')
|
| 1137 |
+
projectpartid = request.args.get('prjpartid')
|
| 1138 |
+
|
| 1139 |
+
global cached_tables
|
| 1140 |
+
|
| 1141 |
+
# ✅ Fix: check properly for missing/empty DataFrame
|
| 1142 |
+
if cached_tables["projects"] is None or cached_tables["projects"].empty:
|
| 1143 |
+
return jsonify(["No cached data available yet. Please fetch projects first."])
|
| 1144 |
+
|
| 1145 |
+
# Get fresh values from API
|
| 1146 |
+
new_projects, new_parts, new_sections = API.GenerateTables()
|
| 1147 |
+
|
| 1148 |
+
returnString = None
|
| 1149 |
+
|
| 1150 |
+
# 1) Compare project names
|
| 1151 |
+
old_names = cached_tables["projects"]["ProjectName"].tolist()
|
| 1152 |
+
new_names = new_projects["ProjectName"].tolist()
|
| 1153 |
+
if set(old_names) != set(new_names):
|
| 1154 |
+
added = list(set(new_names) - set(old_names))
|
| 1155 |
+
removed = list(set(old_names) - set(new_names))
|
| 1156 |
+
returnString = ["Changes in Projects", "project", {"added": added, "removed": removed}]
|
| 1157 |
+
|
| 1158 |
+
# 2) Compare parts
|
| 1159 |
+
elif projectname and cached_tables["parts"] is not None and not cached_tables["parts"].empty:
|
| 1160 |
+
prjid = new_projects.loc[new_projects['ProjectName'] == projectname, 'ProjectId'].values[0]
|
| 1161 |
+
old_parts = cached_tables["parts"].loc[cached_tables["parts"]["ProjectId"] == prjid, "ProjectPart"].tolist()
|
| 1162 |
+
new_parts_list = new_parts.loc[new_parts["ProjectId"] == prjid, "ProjectPart"].tolist()
|
| 1163 |
+
if set(old_parts) != set(new_parts_list):
|
| 1164 |
+
added = list(set(new_parts_list) - set(old_parts))
|
| 1165 |
+
removed = list(set(old_parts) - set(new_parts_list))
|
| 1166 |
+
returnString = ["Changes in Parts", "part", {"added": added, "removed": removed}]
|
| 1167 |
+
|
| 1168 |
+
# 3) Compare sections
|
| 1169 |
+
elif projectname and projectpart and projectpartid and cached_tables["sections"] is not None and not cached_tables["sections"].empty:
|
| 1170 |
+
prjid = new_projects.loc[new_projects['ProjectName'] == projectname, 'ProjectId'].values[0]
|
| 1171 |
+
old_sections = cached_tables["sections"]["ProjectSection"].tolist()
|
| 1172 |
+
new_sections_list = new_sections[
|
| 1173 |
+
(new_sections["ProjectId"] == prjid) &
|
| 1174 |
+
(new_sections["ProjectPartId"] == int(projectpartid))
|
| 1175 |
+
]["ProjectSection"].tolist()
|
| 1176 |
+
if set(old_sections) != set(new_sections_list):
|
| 1177 |
+
added = list(set(new_sections_list) - set(old_sections))
|
| 1178 |
+
removed = list(set(old_sections) - set(new_sections_list))
|
| 1179 |
+
returnString = ["Changes in Sections", "section", {"added": added, "removed": removed}]
|
| 1180 |
+
|
| 1181 |
+
if not returnString:
|
| 1182 |
+
returnString = ["No changes detected"]
|
| 1183 |
+
|
| 1184 |
+
# ✅ update cache
|
| 1185 |
+
cached_tables["projects"] = new_projects
|
| 1186 |
+
cached_tables["parts"] = new_parts
|
| 1187 |
+
cached_tables["sections"] = new_sections
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1188 |
|
| 1189 |
return jsonify(returnString)
|
| 1190 |
|
|
|
|
| 1311 |
if __name__ == "__main__":
|
| 1312 |
runn()
|
| 1313 |
|
| 1314 |
+
|