moonyeju 2023-11-20
Fix: z축 전달
@2b19a37e9c7d8e1e4e1c4f9aa0f7fe8f0d50e594
pothole_client/src/context/MapContext.js
--- pothole_client/src/context/MapContext.js
+++ pothole_client/src/context/MapContext.js
@@ -45,7 +45,7 @@
   //id임의값
   let id = 1;
 
-  const potholeReport = () => {
+  const potholeReport = z => {
     fetch(`${url}/action/pothole_report`, {
       method: 'POST',
       headers: {
@@ -56,6 +56,7 @@
         pothole_id: id,
         pothole_x: location.latitude,
         pothole_y: location.longitude,
+        z: z,
       }),
     })
       .then(response => response.json())
@@ -76,10 +77,10 @@
       setUpdateIntervalForType(SensorTypes.accelerometer, 1000); //임의 1초에 1번으로 변경
 
       const subscription = accelerometer.subscribe(({z}) => {
-        if (z >= 15) {
-          console.log(z, ' z 축이 15g 이상입니다. Bump'); //임의 15, 원래30 테스트용
+        if (z >= 20) {
+          console.log(z, ' z 축이 20g 이상입니다. Bump'); //임의 15, 원래30 테스트용
           Alert.alert('알림', 'bump 발생');
-          potholeReport();
+          potholeReport(z);
         }
       });
 
@@ -115,14 +116,14 @@
     if (location) {
       const speed = location.speed * 3.6; // km/hour로 계산
 
-      console.log('Current speed:' + speed + ' km/hour');
-      setIsAccelerometerActive(true); //현재 움직일 수 없으니 임의주석처리
-      // if (speed >= 8) {
-      //   console.log('8이상:' + speed + ' km/hour');
-      //   setIsAccelerometerActive(true); // 속도가 8 이상일 때 가속도 센서 활성화
-      // } else {
-      //   setIsAccelerometerActive(false); // 속도가 8 미만일 때 가속도 센서 비활성화
-      // }
+      // console.log('Current speed:' + speed + ' km/hour');
+      // setIsAccelerometerActive(true); //현재 움직일 수 없으니 임의주석처리
+      if (speed >= 8) {
+        console.log('8이상:' + speed + ' km/hour');
+        setIsAccelerometerActive(true); // 속도가 8 이상일 때 가속도 센서 활성화
+      } else {
+        setIsAccelerometerActive(false); // 속도가 8 미만일 때 가속도 센서 비활성화
+      }
     } else {
       console.log('Location is not available yet.');
     }
pothole_server/action.py
--- pothole_server/action.py
+++ pothole_server/action.py
@@ -112,7 +112,8 @@
          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)       
+         z = float(request.json['z'])
+         pc.report(report_id,pothole_id,pothole_x,pothole_y,z)       
          return {
                 'report': 'done'  # str으로 반환하여 return
             }, 200
pothole_server/database/database.py
--- pothole_server/database/database.py
+++ pothole_server/database/database.py
@@ -121,13 +121,13 @@
 
         return (float(result[2]),float(result[3]))
     
-    def db_add_report(self,report_id,report_x,report_y) :
+    def db_add_report(self,report_id,report_x,report_y,z) :
         cur = self.conn.cursor() # 커서를 생성한다
         now=time.localtime()
         d=time.strftime('%Y-%m-%d %X', now)
         cur.execute(f'''
-        insert into "TRAFFICAGENCY".report (report_id,report_x,report_y,timestamp)
-        values ('{report_id}','{report_x}','{report_y}','{d}')
+        insert into "TRAFFICAGENCY".report (report_id,report_x,report_y,timestamp,z)
+        values ('{report_id}','{report_x}','{report_y}','{d}','{z}')
         ''')
         
     def db_get_near_point(self,dest_x,dest_y):
pothole_server/pothole_model/pothole.py
--- pothole_server/pothole_model/pothole.py
+++ pothole_server/pothole_model/pothole.py
@@ -9,9 +9,9 @@
         start_time=time.time()
         self.db=DB()
 
-    def report(self,report_id,pothole_id,pothole_x,pothole_y):
+    def report(self,report_id,pothole_id,pothole_x,pothole_y,z):
         self.db = DB()
-        self.db.db_add_report(report_id,pothole_x,pothole_y)
+        self.db.db_add_report(report_id,pothole_x,pothole_y,z)
         result=self.db.db_get_near_point(pothole_x,pothole_y)
         if len(result) >3 :
             value = 0
Add a comment
List