Skip to content
Snippets Groups Projects
Commit dbfcd02e authored by Sara Savanovic Djordjevic's avatar Sara Savanovic Djordjevic
Browse files

:add: update_map endpoint, not tested2

parent 61e1bcbd
No related branches found
No related tags found
No related merge requests found
File added
File added
...@@ -2,7 +2,7 @@ import json ...@@ -2,7 +2,7 @@ import json
from flask import Flask, jsonify from flask import Flask, jsonify
import sys import sys
sys.path.append('..') # Add root directory to the system path sys.path.append('..') # Add root directory to the system path
from server import DataPoint from data_structs import DataPoint
def process_data_point(data_point): def process_data_point(data_point):
try: try:
......
...@@ -20,6 +20,4 @@ class DataPoint: ...@@ -20,6 +20,4 @@ class DataPoint:
self.safety_level = safety_level self.safety_level = safety_level
self.accuracy = accuracy self.accuracy = accuracy
# Test instance
test_instance = DataPoint(longitude=1.5, latitude=2.5, precipitation=10.0, thickness = 10.0, safety_level= 5, max_weight= 80)
...@@ -3,6 +3,8 @@ from http.server import HTTPServer, BaseHTTPRequestHandler ...@@ -3,6 +3,8 @@ from http.server import HTTPServer, BaseHTTPRequestHandler
from pymongo import MongoClient from pymongo import MongoClient
from pymongo.server_api import ServerApi from pymongo.server_api import ServerApi
from consts import DB_NAME, COLLECTION, MONGO_URI, MONGO_CERT_PATH, SSL_CERT_PATH, SSL_KEY_PATH, HOST, PORT from consts import DB_NAME, COLLECTION, MONGO_URI, MONGO_CERT_PATH, SSL_CERT_PATH, SSL_KEY_PATH, HOST, PORT
from calc_model.update_map import process_data_point
from data_structs import DataPoint
import atexit import atexit
import ssl import ssl
...@@ -29,6 +31,21 @@ class IceHTTP(BaseHTTPRequestHandler): ...@@ -29,6 +31,21 @@ class IceHTTP(BaseHTTPRequestHandler):
self.send_header("Content-type", "text/plain") self.send_header("Content-type", "text/plain")
self.end_headers() self.end_headers()
self.wfile.write(b"Root path hit!") self.wfile.write(b"Root path hit!")
elif self.path == '/update_map':
# NB temporary test data
data_point_instance = DataPoint(longitude=1.0, latitude=2.0, precipitation=10.5, thickness=3.0, max_weight=50.0, safety_level=3, accuracy=8)
# Get response from process_data_point
response, status_code = process_data_point(data_point_instance)
# Send the response
self.send_response(status_code)
self.send_header("Content-type", "application/json")
self.end_headers()
# Write response to response object
self.wfile.write(response.encode('utf-8'))
# Start a server on port 8443 using defined HTTP class # Start a server on port 8443 using defined HTTP class
if __name__ == "__main__": if __name__ == "__main__":
......
import sys import sys
sys.path.append('..') # Add root directory to the system path sys.path.append('..') # Add root directory to the system path
from server import DataPoint from data_structs import DataPoint
# Test instances # Test instances
test_data1 = DataPoint(longitude=1.0, latitude=2.0, precipitation=10.5, thickness=3.0, max_weight=50.0, safety_level=2.5, accuracy=8) test_data1 = DataPoint(longitude=1.0, latitude=2.0, precipitation=10.5, thickness=3.0, max_weight=50.0, safety_level=2.5, accuracy=8)
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment