윤영준 윤영준 2024-09-09
rebulding server
@f5e18f3cfa0749e0834a650151eb784369804abd
action.py
--- action.py
+++ action.py
@@ -74,6 +74,8 @@
 @Action.route('/trip_and_score_update')
 class TRIP_insert(Resource):
     @Action.expect(trip_log_model)
+    @Action.doc(responses={200: 'Success'})
+    @Action.doc(responses={500: 'Internal Error'})
     def post(self):
         token = request.headers.get('Authorization')
 
@@ -93,10 +95,7 @@
         db = DB()
         data = request.get_json()
         if len(data["trip_id"]) != 64:
-            return {500: "ERROR! INVALID TRIP_ID!"}
-
-        if len(data["trip_log"]["timestamp"]) == 0:
-            return {500: "ERROR! 'trip_log' is empty!"}
+            return {"result" : "ERROR! INVALID TRIP_ID!"}, 500
 
         trip_id = data["trip_id"]
         trip_distance_m = data["trip_distance_m"]
@@ -105,12 +104,11 @@
         abrupt_stop_count = data["abrupt_stop_count"]
         abrupt_acceleration_count = data["abrupt_acceleration_count"]
         abrupt_deceleration_count = data["abrupt_deceleration_count"]
-        helmet_on = data["helmet_on"]
+        helmet_on = int(data["helmet_on"])
         final_score = data["final_score"]
 
-        if not (helmet_on == 1) or (helmet_on == 0):
-            return{500: f"ERROR! INVALID 'helmet_on'! \n helmet_on : {helmet_on}"}
-
+        if (helmet_on != 1) and (helmet_on != 0):
+            return {"result" : f"ERROR! INVALID 'helmet_on'! \n helmet_on : {helmet_on}"}, 500
         db.insert_trip_data(
             user_id,
             trip_id,
auth.py
--- auth.py
+++ auth.py
@@ -1,4 +1,3 @@
-import hashlib
 from flask import request,jsonify,render_template,redirect,url_for
 from flask_restx import Resource, Api, Namespace, fields
 from database.database import DB
database/database.py
--- database/database.py
+++ database/database.py
@@ -7,7 +7,7 @@
 import re
 import os
 from io import StringIO
-from datetime import datetime, timedelta
+from datetime import datetime
 
 config_file_path = "database/db_config.json"
 
 
gcity.py (deleted)
--- gcity.py
@@ -1,153 +0,0 @@
-import networkx as nx
-import math
-from itertools import tee
-from numpy import Inf, Infinity, inf
-from database.database import DB
-import pandas as pd
-from haversine import haversine
-import time
-import pandas as pd
-import os
-
-paths= os.getcwd()
-
-def dist(a, b):
-    (x1, y1) = a
-    (x2, y2) = b
-    return ((x1 - x2) ** 2 + (y1 - y2) ** 2) ** 0.5
-
-def swith_xy(tuples):
-    x,y=tuples
-    return (y,x)
-    
-def pairwise( iterable ):
-    """Returns an iterable access binary tuple
-    s -> (s0,s1), (s1,s2), (s2, s3), ..."""
-    a, b = tee( iterable )
-    next(b, None)
-    return zip(a, b)
-
-
-
-class path_finder():
-    def __init__(self):
-        start_time=time.time()
-        self.db=DB()
-        self.G=nx.read_gpickle(paths + '\\navigation_model\\OSM_gpickle.gpickle')
-        
-        print("done")
-        print(time.time()-start_time)
-
-
-    
-    def get_trip(self,dest1,dest2):
-
-        start_time=time.time()
-        dest1=swith_xy(self.db.db_get_dest(dest1))
-        dest2=swith_xy(self.db.db_get_dest(dest2))
-        value=0.0001
-
-        start_near_nodes=[]
-        while start_near_nodes == []:
-            value=value*10
-            start_near_nodes=self.db.db_get_near_node(dest1[1],dest1[0],value)
-        else: 
-            start_near_nodes=self.db.db_get_near_node(dest1[1],dest1[0],value)
-
-        nn_start = None
-        nn_end = None
-        start_delta = float("inf")
-        end_delta = float("inf")
-        
-
-
-        for n in start_near_nodes:
-            s_dist = haversine(dest1, n)
-            if s_dist < start_delta :
-                    nn_start = n
-                    start_delta = s_dist
-        value=0.0001
-        end_near_nodes=[]
-        while end_near_nodes==[]:
-            value=value*10
-            self.db.db_get_near_node(dest2[1],dest2[0],value)
-            end_near_nodes=self.db.db_get_near_node(dest2[1],dest2[0],value)
-
-        for n in end_near_nodes:
-            e_dist = haversine(dest2, n)
-            if e_dist < end_delta :
-                    nn_end = n
-                    end_delta = e_dist
-            
-        path = list(nx.astar_path(self.G,nn_start,nn_end,heuristic=dist,weight='length'))
-        return path
-    
-    def get_dest(self, dest1):
-        dest1=swith_xy(self.db.db_get_address(dest1))
-        return dest1
-
-db=DB()
-df = pd.read_csv('D:\\takensoft\\project2\\경산 길찾기\\경산시_체크.csv',encoding='euc-kr')
-li_start=[]
-li_dest1=[]
-for i in range(len(df)):
-    try:
-        print(i)
-        dest1=df['start'][i]
-        li_dest1.append(dest1)
-        dest1=swith_xy(db.db_get_dest(dest1))
-        value=0.0001
-        start_near_nodes=[]
-        while start_near_nodes == []:
-            value=value*10
-            start_near_nodes=db.db_get_near_node(dest1[1],dest1[0],value)
-        nn_start = None
-        start_delta = float("inf")
-        for n in start_near_nodes:
-            s_dist = haversine(dest1, n)
-            if s_dist < start_delta :
-                    nn_start = n
-                    start_delta = s_dist
-        li_start.append(nn_start)
-    except:
-        continue
-
-df_check=pd.DataFrame({'start':li_dest1,'시작지점':li_start})
-
-df_check.to_csv('test.csv',encoding='euc-kr')
-
-
-'''
-df=pd.read_csv('D:\\takensoft\\project2\\경산 길찾기\\경산시.csv',encoding='euc-kr')
-
-p=path_finder()
-li_path=[]
-for i in range(len(df)):
-    try:
-        if i%100 ==0:
-            print(i)
-            df2=pd.DataFrame(li_path)
-            df2.to_csv(f'D:\\takensoft\\project2\\경산 길찾기\\길찾기 결과{i}.csv',encoding='euc-kr')
-            li_path=[]
-        start=df['start'][i]
-        end=df['end'][i]
-        li_path.append(p.get_trip(start,end))
-    except:
-        continue
-li_start_x = []
-li_start_y = []
-li_end_x = []
-li_end_y = []
-
-db=DB()
-#df.to_csv('D:\\takensoft\\project2\\경산 길찾기\\길찾기 결과.csv',encoding='euc-kr')
-
-df=pd.read_csv('D:\\takensoft\\project2\\경산 길찾기\\경산시.csv',encoding='euc-kr')
-for i in range(len(df)):
-    li_start_x.append(db.db_get_dest(df['start'][i])[0])
-    li_start_y.append(db.db_get_dest(df['start'][i])[1])
-    li_end_x.append(db.db_get_dest(df['end'][i])[0])
-    li_end_y.append([db.db_get_dest(df['end'][i])[1]])
-df2 = pd.DataFrame({'start_point_x':li_start_x,'start_point_y':li_start_y,'end_point_x':li_end_x,'end_point_y':li_end_y})
-df2.to_csv('D:\\takensoft\\project2\\경산 길찾기\\출발지도착지좌표.csv',encoding='euc-kr')
-'''(파일 끝에 줄바꿈 문자 없음)
Add a comment
List