
--- action.py
+++ action.py
... | ... | @@ -1,16 +1,11 @@ |
1 | 1 |
|
2 | 2 |
from flask_restx import Resource, Api, Namespace, fields,reqparse |
3 |
-from fog_model.fog_predict import fog_classfication |
|
4 |
-from fog_model.fog_model import darkchannel |
|
5 | 3 |
from flask import request,jsonify |
6 | 4 |
from flask import Flask, render_template, request |
7 | 5 |
from werkzeug.utils import secure_filename |
8 | 6 |
import os |
9 | 7 |
from haversine import haversine |
10 | 8 |
from database.database import DB |
11 |
-import torch |
|
12 |
-from PIL import Image |
|
13 |
-from pothole_model.pothole import pothole |
|
14 | 9 |
from datetime import datetime |
15 | 10 |
import pandas as pd |
16 | 11 |
from io import StringIO |
... | ... | @@ -23,6 +18,8 @@ |
23 | 18 |
name="Action", |
24 | 19 |
description="노드 분석을 위해 사용하는 api.", |
25 | 20 |
) |
21 |
+ |
|
22 |
+ |
|
26 | 23 |
|
27 | 24 |
def find_node(gps_address_y,gps_address_x): |
28 | 25 |
db=DB() |
... | ... | @@ -40,7 +37,6 @@ |
40 | 37 |
nn_end = n |
41 | 38 |
end_delta = e_dist |
42 | 39 |
return nn_end |
43 |
- |
|
44 | 40 |
|
45 | 41 |
|
46 | 42 |
@Action.route('/image_summit') |
... | ... | @@ -79,91 +75,10 @@ |
79 | 75 |
}, 200 |
80 | 76 |
|
81 | 77 |
|
82 |
- |
|
83 |
-@Action.route('/image_anal') |
|
84 |
-class fileUpload(Resource): |
|
85 |
- @Action.doc(responses={200: 'Success'}) |
|
86 |
- @Action.doc(responses={500: 'Register Failed'}) |
|
87 |
- def post(self): |
|
88 |
- if request.method == 'POST': |
|
89 |
- current_time = datetime.now() |
|
90 |
- formatted_time = current_time.strftime("%Y-%m-%d %H:%M:%S") |
|
91 |
- print("현재 시간:", formatted_time) |
|
92 |
- |
|
93 |
- |
|
94 |
- fc = fog_classfication() |
|
95 |
- dir = os.getcwd() |
|
96 |
- filename = request.json['filename'] |
|
97 |
- file_type = request.json['file_type'] |
|
98 |
- gps_address_x = float(request.json['gps_x']) |
|
99 |
- gps_address_y = float(request.json['gps_y']) |
|
100 |
- total_path = dir+ "\\"+ filename + file_type |
|
101 |
- model_fc= fc.predict(total_path) |
|
102 |
- |
|
103 |
- #model_yolo= torch.hub.load(paths +'/yolov5/', 'custom', path=paths+'/yolov5/best.pt', source='local') |
|
104 |
- #im = Image.open(total_path) |
|
105 |
- #results = model_yolo(im) |
|
106 |
- #li_detect=list(results.pandas().xyxy[0]['name']) |
|
107 |
- if model_fc == "normal": |
|
108 |
- #if 'vest' in li_detect and 'cone' in li_detect: |
|
109 |
- nn_end = find_node(gps_address_y,gps_address_x) |
|
110 |
- return { |
|
111 |
- 'node': nn_end, |
|
112 |
- 'fog' : 'normal', |
|
113 |
- 'construction' : 'construction' |
|
114 |
- }, 200 |
|
115 |
- ''' |
|
116 |
- #else: |
|
117 |
- return { |
|
118 |
- 'node': None, |
|
119 |
- 'fog' : 'normal', |
|
120 |
- 'construction' : 'normal' |
|
121 |
- }, 200 |
|
122 |
- ''' |
|
123 |
- else: |
|
124 |
- # if 'vest' in li_detect and 'cone' in li_detect: |
|
125 |
- nn_end = find_node(gps_address_y,gps_address_x) |
|
126 |
- db=DB() |
|
127 |
- current_time = datetime.now() |
|
128 |
- formatted_time = current_time.strftime("%Y-%m-%d %H:%M:%S") |
|
129 |
- db.db_add_report(filename,gps_address_x,gps_address_y) |
|
130 |
- print("현재 시간:", formatted_time) |
|
131 |
- return { |
|
132 |
- 'node': nn_end, |
|
133 |
- 'fog' : 'fog', |
|
134 |
- 'construction' : 'construction' |
|
135 |
- }, 200 |
|
136 |
- |
|
137 |
- ''' |
|
138 |
- #else: |
|
139 |
- nn_end = find_node(gps_address_y,gps_address_x) |
|
140 |
- return { |
|
141 |
- 'node': nn_end, |
|
142 |
- 'fog' : 'fog', |
|
143 |
- 'construction' : 'normal' |
|
144 |
- }, 200 |
|
145 |
-''' |
|
146 |
- |
|
147 |
-@Action.route('/pothole_report') |
|
148 |
-class fileUpload(Resource): |
|
149 |
- @Action.doc(responses={200: 'Success'}) |
|
150 |
- @Action.doc(responses={500: 'Register Failed'}) |
|
151 |
- def post(self): |
|
152 |
- if request.method == 'POST': |
|
153 |
- pc = pothole() |
|
154 |
- dir = os.getcwd() |
|
155 |
- report_id = request.json['report_id'] |
|
156 |
- pothole_id = request.json['pothole_id'] |
|
157 |
- pothole_x = float(request.json['pothole_x']) |
|
158 |
- pothole_y = float(request.json['pothole_y']) |
|
159 |
- pc.report(report_id,pothole_id,pothole_x,pothole_y) |
|
160 |
- return { |
|
161 |
- 'report': 'done' # str으로 반환하여 return |
|
162 |
- }, 200 |
|
163 |
- |
|
164 | 78 |
@Action.route('/gps_update') |
165 | 79 |
class fileUpload(Resource): |
166 | 80 |
def post(self): |
81 |
+ db = DB() |
|
167 | 82 |
token = request.headers.get('Authorization') |
168 | 83 |
if not token: |
169 | 84 |
return jsonify({'result': 'fail', 'msg': '토큰이 없습니다.'}) |
... | ... | @@ -173,7 +88,7 @@ |
173 | 88 |
#print(decoded_token) |
174 | 89 |
user_id = decoded_token['id'] |
175 | 90 |
|
176 |
- db = DB() |
|
91 |
+ |
|
177 | 92 |
data = request.get_json() |
178 | 93 |
if len(data["trip_id"]) !=64: |
179 | 94 |
return jsonify({500 :"ERROR! INVALID TRIP_ID!"}) |
... | ... | @@ -199,22 +114,9 @@ |
199 | 114 |
|
200 | 115 |
columns = df.columns |
201 | 116 |
data_csv_block = df.to_csv(header=False, index=False) |
202 |
- |
|
117 |
+ print(f"recieved : {data}") |
|
203 | 118 |
# GPS 데이터베이스에 삽입 |
204 | 119 |
db.insert_gps_data(data_csv_block, columns) |
205 |
- return jsonify({'result': 'success'}) |
|
120 |
+ return jsonify({'result': f'success'}) |
|
206 | 121 |
|
207 |
- |
|
208 |
-@Action.route('/pothole_display') |
|
209 |
-class fileUpload(Resource): |
|
210 |
- @Action.doc(responses={200: 'Success'}) |
|
211 |
- @Action.doc(responses={500: 'Register Failed'}) |
|
212 |
- def get(self): |
|
213 |
- if request.method == 'GET': |
|
214 |
- pc = pothole() |
|
215 |
- dir = os.getcwd() |
|
216 |
- #timestamp = request.json['timestamp'] |
|
217 |
- value=pc.display() |
|
218 |
- return { |
|
219 |
- 'pothole': list(value) # str으로 반환하여 return |
|
220 |
- }, 200 |
|
122 |
+ |
--- app.py
+++ app.py
... | ... | @@ -1,5 +1,6 @@ |
1 | 1 |
from flask import Flask, request, abort, jsonify |
2 | 2 |
from flask_restx import Api |
3 |
+from flask_cors import CORS |
|
3 | 4 |
from auth import Auth |
4 | 5 |
from trip import Trip |
5 | 6 |
from action import Action |
... | ... | @@ -7,16 +8,17 @@ |
7 | 8 |
import json |
8 | 9 |
|
9 | 10 |
app = Flask(__name__) |
11 |
+CORS(app) |
|
10 | 12 |
cache = Cache(app, config={'CACHE_TYPE': 'simple'}) |
11 | 13 |
|
12 | 14 |
print("Api Start") |
13 | 15 |
api = Api(app, |
14 | 16 |
version='0.1', |
15 |
- title="trafficagent", |
|
17 |
+ title="PM_logger", |
|
16 | 18 |
description="API Server", |
17 | 19 |
terms_url="/", |
18 |
- contact="dhlim@takensoft.co.kr", |
|
19 |
- license="MIT") |
|
20 |
+ contact="yjyoon@takensoft.co.kr", |
|
21 |
+ license="") |
|
20 | 22 |
|
21 | 23 |
print("Api Started") |
22 | 24 |
api.add_namespace(Trip, '/trip') |
--- database/database.py
+++ database/database.py
... | ... | @@ -208,6 +208,11 @@ |
208 | 208 |
self.conn.commit() |
209 | 209 |
cur.close() |
210 | 210 |
return True |
211 |
+ |
|
212 |
+ def close_connection(self): |
|
213 |
+ cur = self.conn.cursor() |
|
214 |
+ cur.close() |
|
215 |
+ return True |
|
211 | 216 |
|
212 | 217 |
|
213 | 218 |
|
Add a comment
Delete comment
Once you delete this comment, you won't be able to recover it. Are you sure you want to delete this comment?