박민혁 박민혁 07-22
new variables in apis - turn_noslow_cnt
@6ce31494c9d0d0e307e876372650135293bc0726
action.py
--- action.py
+++ action.py
@@ -23,6 +23,7 @@
     'abrupt_stop_count': fields.Integer(required=True, description='Count of abrupt stops'),
     'abrupt_acceleration_count': fields.Integer(required=True, description='Count of abrupt accelerations'),
     'abrupt_deceleration_count': fields.Integer(required=True, description='Count of abrupt decelerations'),
+    'turn_noslow_cnt' : fields.Integer(required=True, description='count of abrupt truns'),
     'helmet_on': fields.Integer(required=True, description='Whether the helmet was worn during the trip, must be 0 or 1 with 1 is the helmet on.'),
     'final_score': fields.Float(required=True, description='The final safety score for the trip')
 })
@@ -69,8 +70,8 @@
             return {
                     500: f"ERROR! Mismatching length of data in trip_log! \n timestamp : {time_stamp_len} \n latitude : {latitude_len} \n longitude : {longitude_len}"
                    }
-        with pd.option_context('display.max_rows', None, 'display.max_columns', None):
-            print(data)
+        # with pd.option_context('display.max_rows', None, 'display.max_columns', None):
+        #     print(data)
         df = pd.DataFrame(data["trip_log"])
         df["user_id"] = data["user_id"]
         df["trip_id"] = data["trip_id"]
@@ -158,15 +159,16 @@
         data = request.get_json()
         if len(data["trip_id"]) != 64:
             return {"result" : "ERROR! INVALID TRIP_ID!"}, 500
-
+        print(data)
         trip_id = data["trip_id"]
         trip_distance_m = data["total_distance_m"]
-        trip_time_s = data["total_time_s"]
-        abrupt_start_count = data["abrupt_start_count"]
-        abrupt_stop_count = data["abrupt_stop_count"]
-        abrupt_acceleration_count = data["abrupt_acceleration_count"]
-        abrupt_deceleration_count = data["abrupt_deceleration_count"]
+        trip_time_s = data["total_time_sec"]
+        abrupt_start_count = data["sudden_start_cnt"]
+        abrupt_stop_count = data["sudden_stop_cnt"]
+        abrupt_acceleration_count = data["sudden_accel_cnt"]
+        abrupt_deceleration_count = data["sudden_decel_cnt"]
         helmet_on = helmet_on = 1 if data["helmet_on"] == "true" else 0
+        trun_noslow_cnt = data["turn_noslow_cnt"]
         final_score = data["final_score"]
 
         if (helmet_on != 1) and (helmet_on != 0):
@@ -180,6 +182,7 @@
             abrupt_stop_count,
             abrupt_acceleration_count,
             abrupt_deceleration_count,
+            trun_noslow_cnt,
             helmet_on,
             final_score
         )
database/database.py
--- database/database.py
+++ database/database.py
@@ -301,13 +301,14 @@
             abrupt_acceleration_count,
             abrupt_deceleration_count,
             helmet_on,
+            turn_noslow_cnt,
             final_score
     ):
 
         self.cur.execute(f"""
             INSERT INTO trip_log (user_id, trip_id, timestamp, total_distance_m, total_time_s, abrupt_start_count, abrupt_stop_count,
-             abrupt_acceleration_count, abrupt_deceleration_count, helmet_on, final_score)
-            VALUES (%s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s)
+             abrupt_acceleration_count, abrupt_deceleration_count, helmet_on, turn_noslow_cnt, final_score)
+            VALUES (%s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s)
         """, (
             username,
             trip_id,
@@ -319,6 +320,7 @@
             abrupt_acceleration_count,
             abrupt_deceleration_count,
             helmet_on,
+            turn_noslow_cnt,
             final_score
             )
         )
@@ -408,7 +410,7 @@
             self.cur.execute("""
                 SELECT trip_id, timestamp, total_distance_m, total_time_s, abrupt_start_count, 
                        abrupt_stop_count, abrupt_acceleration_count, abrupt_deceleration_count, 
-                       helmet_on, final_score
+                       helmet_on, turn_noslow_cnt, final_score
                 FROM trip_log
                 WHERE user_id = %s
                 ORDER BY timestamp DESC
Add a comment
List