From 8a2e2b5f14cdae296c7925e14a6b4ae9f4411c32 Mon Sep 17 00:00:00 2001 From: Sara Djordjevic <sarasdj@stud.ntnu.no> Date: Mon, 5 Feb 2024 15:16:38 +0100 Subject: [PATCH] update: working update_map endpoint --- .../__pycache__/update_map.cpython-311.pyc | Bin 1137 -> 1589 bytes server/calc_model/update_map.py | 19 ++++++++++++------ server/main.py | 10 +++++++-- 3 files changed, 21 insertions(+), 8 deletions(-) diff --git a/server/calc_model/__pycache__/update_map.cpython-311.pyc b/server/calc_model/__pycache__/update_map.cpython-311.pyc index 3459a0a2d6913cc3d8585f946f395a5140620cfe..8aaf6267163581247180825dc0703a7094785b43 100644 GIT binary patch delta 855 zcmey!v6Y8!IWI340|Ntt`r8Ak{LB;iBp8oOR8LJ|Vn}65<y^+dz_6MTBn`q*Tq&%n z9BE7`Y%MHN+^L)??Ac5p@gj*-t_3_G7CKJhSc7H;BSQ*fFc@ocO`M@we~T+6u_Q6R zAU`v&BpGfK0|Nsa0|Nsy0|UcnGe!o6=?t6<B}j%ZKvoGCU&g?|uo})YWng3|VTE%U zvOuPRxit(~EMNu$Lp=kk7i$?yxS>)E3=B1lXtGQx3?R6SiGg7?*y|v*j0}0)$_$1K z#VqAa70i(g<&2CBkqnFsj0`nQDU4}M!3@d_B}l=e!ce4N%Ur?_(mOejQJ#@|av|ds zVUAnOi3J6>xDyKs;*<09N>VFICbKaauoi(rVzLucf4wLJ0|O@m14Hp21_p)(h7U}< ztPYG%c?J68yW%hM%3a}=`@q1;sRbsUO32LNT3~fW+3cc(`4tKC4$rS_3=;A)Dldv_ zUJ=*q@c6(DQwmo95v21AhyZi35sF~JA3uJ8X>@{*K|o?M7jssO0|Ns?lcb|O!)#4Q z0p^1&JdW}V2L)IhMc5CDFoW3Qj3BlI8;C8><s`v;P*cT8nE4Pdqmu;lAz@Z03FccI z@$tEdnR)T?A)1W0SW{AyO4BuYi+CnaW45vaN#-TyrpCt?fl_V}C|GVW7nSC%WcUmU z(;^WD28Lf8Ho5sJr8%i~MT!gz450K<ym9h3=7_`xY}^g09UhJOE%^=1A6WPp9T*o_ zeqaF6SV#p17M_l(OU#lNm?dwpu(!K6xld4OaKFeReuYK+0t|g%W?+%Jz${s$z`(!& E0E)P;Z~y=R delta 354 zcmdnW^O1vZIWI340|NuYnx_X+{h226NigP2R8QqeVQpcE;!I%-X3%7t_(9VmnGvK2 zidh*L7?>Ft7(QQNU|^Wez{ya8B%1|i*Dz!;O`gao$;du=HKUAN4O0qZ8dETXGD8Um z)F1{11{H=P{aWS{?#aST%8cxj&6%b!vQ56nWWaNaD<!ccF}@%_Gp}T_Fmu19FarYv zI|Bnl@l*x|h6aWYOx&yvj88=*rg+V$x*~6MQN;L)h;aw!S2hL_=^2(6g;lQzt9Eca z;1{3l#FC{X#lXPOq^-xWj>}P<d54Ol67xYBMn`q#gG#K9>dcy4MVym4Sgq8GK(?%8 z_zZGjkq`p|!!Hh--29Z%oK(9aX$A%ckmrhvC)cn>D1Tt#VRT^pz<`}B0$B(E@Apcp diff --git a/server/calc_model/update_map.py b/server/calc_model/update_map.py index ab93991e..5ee801ed 100644 --- a/server/calc_model/update_map.py +++ b/server/calc_model/update_map.py @@ -4,16 +4,23 @@ import sys sys.path.append('..') # Add root directory to the system path from data_structs import DataPoint -def process_data_point(data_point): +app = Flask(__name__) + +def process_data_point(data_point: DataPoint): try: - # Convert DataPoint instance to JSON string - json_data = json.dumps(data_point.__dict__) + # Create a temporary application context + with app.app_context(): + # Convert DataPoint instance to JSON string + json_data = json.dumps(data_point.__dict__) - # Write JSON object to response object - response = jsonify(json_data) + # Write JSON object to response object + response = jsonify(json_data) return response, 200 except Exception as e: print(f"Error in converting point data to JSON: {e}") - return jsonify({"error": "Internal Server Error"}), 500 \ No newline at end of file + return jsonify({"error": "Internal Server Error"}), 500 + +if __name__ == "__main__": + app.run(debug=True) diff --git a/server/main.py b/server/main.py index 552c4918..b8f02260 100644 --- a/server/main.py +++ b/server/main.py @@ -43,8 +43,14 @@ class IceHTTP(BaseHTTPRequestHandler): self.send_header("Content-type", "application/json") self.end_headers() - # Write response to response object - self.wfile.write(response.encode('utf-8')) + # Write response data to the response + self.wfile.write(response.get_data()) + + elif self.path == '/test_endpoint': + self.send_response(200) + self.send_header("Content-type", "text/plain") + self.end_headers() + self.wfile.write(b"Test path hit!") # Start a server on port 8443 using defined HTTP class -- GitLab