윤영준 윤영준 2024-07-31
incremental chagnes and CORS
@41e50a8a04a16ecdd37b5701628640dd4982a180
action.py
--- action.py
+++ action.py
@@ -1,16 +1,11 @@
 
 from flask_restx import Resource, Api, Namespace, fields,reqparse
-from fog_model.fog_predict import fog_classfication
-from fog_model.fog_model import darkchannel
 from flask import request,jsonify
 from flask import Flask, render_template, request
 from werkzeug.utils import secure_filename
 import os
 from haversine import haversine
 from database.database import DB
-import torch
-from PIL import Image
-from pothole_model.pothole import pothole
 from datetime import datetime
 import pandas as pd
 from io import StringIO
@@ -23,6 +18,8 @@
     name="Action",
     description="노드 분석을 위해 사용하는 api.",
 )
+
+
 
 def find_node(gps_address_y,gps_address_x):
   db=DB()
@@ -40,7 +37,6 @@
       nn_end = n
       end_delta = e_dist
   return nn_end
-
 
 
 @Action.route('/image_summit')
@@ -79,91 +75,10 @@
             }, 200
 
 
-
-@Action.route('/image_anal')
-class fileUpload(Resource):
-    @Action.doc(responses={200: 'Success'})
-    @Action.doc(responses={500: 'Register Failed'})
-    def post(self):
-      if request.method == 'POST':
-         current_time = datetime.now()
-         formatted_time = current_time.strftime("%Y-%m-%d %H:%M:%S")
-         print("현재 시간:", formatted_time)
-
-
-         fc = fog_classfication()
-         dir = os.getcwd()
-         filename = request.json['filename']
-         file_type = request.json['file_type']
-         gps_address_x = float(request.json['gps_x'])
-         gps_address_y = float(request.json['gps_y'])
-         total_path = dir+ "\\"+ filename + file_type
-         model_fc= fc.predict(total_path)
-         
-         #model_yolo= torch.hub.load(paths +'/yolov5/', 'custom', path=paths+'/yolov5/best.pt', source='local')
-         #im = Image.open(total_path)
-         #results = model_yolo(im)
-         #li_detect=list(results.pandas().xyxy[0]['name'])
-         if model_fc == "normal":
-          #if 'vest' in li_detect and 'cone' in li_detect:
-            nn_end = find_node(gps_address_y,gps_address_x)
-            return {
-                'node': nn_end,  
-                'fog' : 'normal',
-                'construction' : 'construction'
-            }, 200
-            '''
-          #else:
-            return {
-                'node': None,  
-                'fog' : 'normal',
-                'construction' : 'normal'
-            }, 200
-            '''
-         else:
-           # if 'vest' in li_detect and 'cone' in li_detect:
-              nn_end = find_node(gps_address_y,gps_address_x)
-              db=DB()
-              current_time = datetime.now()
-              formatted_time = current_time.strftime("%Y-%m-%d %H:%M:%S")
-              db.db_add_report(filename,gps_address_x,gps_address_y)
-              print("현재 시간:", formatted_time)
-              return {
-                'node': nn_end,  
-                'fog' : 'fog',
-                'construction' : 'construction'
-            }, 200
-              
-              '''
-            #else:
-              nn_end = find_node(gps_address_y,gps_address_x)
-              return {
-                'node': nn_end,  
-                'fog' : 'fog',
-                'construction' : 'normal'
-              }, 200
-'''
-              
-@Action.route('/pothole_report')
-class fileUpload(Resource):
-    @Action.doc(responses={200: 'Success'})
-    @Action.doc(responses={500: 'Register Failed'})
-    def post(self):
-      if request.method == 'POST':
-         pc = pothole()
-         dir = os.getcwd()
-         report_id = request.json['report_id']
-         pothole_id = request.json['pothole_id']
-         pothole_x = float(request.json['pothole_x'])
-         pothole_y = float(request.json['pothole_y'])
-         pc.report(report_id,pothole_id,pothole_x,pothole_y)       
-         return {
-                'report': 'done'  # str으로 반환하여 return
-            }, 200
-
 @Action.route('/gps_update')
 class fileUpload(Resource):
     def post(self):
+        db = DB()
         token = request.headers.get('Authorization')
         if not token:
             return jsonify({'result': 'fail', 'msg': '토큰이 없습니다.'})
@@ -173,7 +88,7 @@
             #print(decoded_token)
             user_id = decoded_token['id']
     
-        db = DB()
+
         data = request.get_json()
         if len(data["trip_id"]) !=64:
             return jsonify({500 :"ERROR! INVALID TRIP_ID!"})
@@ -199,22 +114,9 @@
        	
         columns = df.columns
         data_csv_block = df.to_csv(header=False, index=False)
-        
+        print(f"recieved : {data}")
         # GPS 데이터베이스에 삽입
         db.insert_gps_data(data_csv_block, columns)
-        return jsonify({'result': 'success'})
+        return jsonify({'result': f'success'})
             
-            
-@Action.route('/pothole_display')
-class fileUpload(Resource):
-    @Action.doc(responses={200: 'Success'})
-    @Action.doc(responses={500: 'Register Failed'})
-    def get(self):
-      if request.method == 'GET':
-         pc = pothole()
-         dir = os.getcwd()
-         #timestamp = request.json['timestamp']
-         value=pc.display()       
-         return {
-                'pothole': list(value)  # str으로 반환하여 return
-            }, 200
+
app.py
--- app.py
+++ app.py
@@ -1,5 +1,6 @@
 from flask import Flask, request, abort, jsonify
 from flask_restx import Api
+from flask_cors import CORS 
 from auth import Auth
 from trip import Trip
 from action import Action
@@ -7,16 +8,17 @@
 import json
 
 app = Flask(__name__)
+CORS(app)
 cache = Cache(app, config={'CACHE_TYPE': 'simple'})
 
 print("Api Start")
 api = Api(app,
           version='0.1',
-          title="trafficagent",
+          title="PM_logger",
           description="API Server",
           terms_url="/",
-          contact="dhlim@takensoft.co.kr",
-          license="MIT")
+          contact="yjyoon@takensoft.co.kr",
+          license="")
 
 print("Api Started")
 api.add_namespace(Trip, '/trip')
database/database.py
--- database/database.py
+++ database/database.py
@@ -208,6 +208,11 @@
         self.conn.commit()
         cur.close()
         return True             
+        
+    def close_connection(self):
+        cur = self.conn.cursor()
+        cur.close()
+        return True
 
 
     
Add a comment
List