From 795d03c9525af48b1d5bbb8b79c3834df891463f Mon Sep 17 00:00:00 2001
From: wangzhengquan <wangzhengquan85@126.com>
Date: 星期二, 16 六月 2020 20:10:52 +0800
Subject: [PATCH] 修改算法

---
 algorithm/IndirectAlg.c |   32 ++++++++++++++++++++++++++++----
 1 files changed, 28 insertions(+), 4 deletions(-)

diff --git a/algorithm/IndirectAlg.c b/algorithm/IndirectAlg.c
index 24cfc67..45d95d8 100644
--- a/algorithm/IndirectAlg.c
+++ b/algorithm/IndirectAlg.c
@@ -19,6 +19,10 @@
     time_t firstInvalTime;
     //涓婃閫嗚鐨勬椂闂�
     time_t lastInvalTime;
+     //绗竴娆℃纭鐨勬椂闂�
+    time_t firstValTime;
+    //涓婃閫�=姝g‘琛岀殑鏃堕棿
+    time_t lastValTime;
     //涓婁竴娆″嚭鐜扮殑鍧愭爣
     Point lastCoordinate;
     // Status(std::string _id, time_t ftime, time_t ltime, Point coordinate): 
@@ -89,8 +93,12 @@
      
 }
 
+
+/**
+ * for debug
+ */
 void IndirectAlg::printRecord(int tag, Record &record) {
-     printf("%d  %ld : {%f, %f}\n", tag, record.timestamp, record.coordinate.x, record.coordinate.y);
+   // printf("%d  %ld : {%f, %f}\n", tag, record.timestamp, record.coordinate.x, record.coordinate.y);
 }
 
 /**
@@ -117,6 +125,8 @@
                 .lastTime = record.timestamp,
                 .firstInvalTime = 0,
                 .lastInvalTime = 0,
+                .firstValTime = 0,
+                .lastValTime = 0,
                 .lastCoordinate = record.coordinate});
 
             statusMap.insert({record.id, status});
@@ -141,13 +151,16 @@
         if(status->firstInvalTime ==0) {
             //绗竴娆″彂鐢熼�嗚
             status->firstInvalTime = status->lastInvalTime = record.timestamp;
+//printf("%绗竴娆″彂鐢熼�嗚鐨勬椂闂�=%ld\n", status->firstInvalTime);
             printRecord(4, record);
             return false;
             
         } else {
             status->lastInvalTime = record.timestamp;
+//printf("%鍚庣画鍙戠敓閫嗚鐨勬椂闂�=%ld\n", status->lastInvalTime);
             //閫嗚鏃堕棿瓒呰繃keeptime
-            if (status->lastInvalTime - status-> firstInvalTime > keepTime) {
+            if (status->lastInvalTime - status-> firstInvalTime >= keepTime) {
+                status->firstValTime = status->lastValTime = 0;
                 printRecord(5, record);
                 return true;
             } 
@@ -155,8 +168,19 @@
             return false;
         }
     } else {
-        printRecord(7, record);
-        status->firstInvalTime = status->lastInvalTime = 0;
+       
+        if(status->firstValTime ==0) {
+            status->firstValTime = status->lastValTime = record.timestamp;
+            printRecord(7, record);
+        } else {
+            status->lastValTime = record.timestamp;
+             //閫嗚鏃堕棿瓒呰繃keeptime
+            if (status->lastValTime - status-> firstValTime >= keepTime) {
+                status->firstInvalTime = status->lastInvalTime = 0;
+                printRecord(8, record);
+            } 
+        }
+
         return false;
     }
      

--
Gitblit v1.8.0