فهرست منبع

添加一人多卡日志,排查问题。增加stoull容错处理

lixioayao 6 سال پیش
والد
کامیت
5986fa1948
5فایلهای تغییر یافته به همراه269 افزوده شده و 258 حذف شده
  1. 14 6
      bindmorecard.h
  2. 4 1
      cardMgr.cpp
  3. 0 2
      cardMgr.h
  4. 249 248
      common_tool.h
  5. 2 1
      module_service/module_meta_date_changed.cpp

+ 14 - 6
bindmorecard.h

@@ -160,7 +160,7 @@ struct TcardInterface
 	}
 	bool timeout()
 	{
-		return size() == SIZE-1;
+		return size() == SIZE;
 	}
 	std::string getInfo_1()
 	{
@@ -258,7 +258,7 @@ struct CardFactory
 			  ptr = iter->second;
 			else
 			{
-				log_info("handlecard..%lld,%lld,%lld",id,cardid,cid);
+				log_info("handlecard..%lu,%d,%d",id,cardid,cid);
 				ptr = make_shared_(cardid,cid,cttime,id);
 				m_map.insert({id,ptr});
 				backup(cid,cardid);
@@ -328,12 +328,16 @@ struct CloserCardFactory : CardFactory
 		if(it != m_count.end())
 		  m_count.erase(it);
 	}
+    //查找临近卡数据信息,并进行筛选
 	virtual std::map<uint64_t,std::string> selectcard(std::vector<uint64_t> &v,uint64_t cid)
 	{
 		std::map<uint64_t,std::string> vec;
 		if(v.empty()) return vec;
 		std::vector<uint64_t> rc(v.begin(),v.end());
 		auto opcard=card_list::instance()->get(cid);
+        //去除俩卡600次临近不计入数据,防止路过
+        //卡号相同,类型不同得过滤掉
+        //时间差超过3s得过滤掉
 		rc.erase(std::remove_if(rc.begin(),rc.end(),[&](uint64_t cardid){
 						if(!getAccess(cid,cardid))
 						return true;
@@ -347,7 +351,7 @@ struct CloserCardFactory : CardFactory
 						uint64_t ct3 = ct1>ct2?ct1-ct2:ct2-ct1;
 						return ct3 > TIME_LIM_SEC; 
 						}),rc.end());
-
+        
 		vec = handlecard(rc,cid);
 		return std::move(vec);
 	}
@@ -357,6 +361,7 @@ struct CloserCardFactory : CardFactory
 	}
 	virtual std::shared_ptr<TcardInterface> make_shared_(const uint64_t cid1,const uint64_t cid2,const uint64_t ctime,uint64_t key)
 	{
+        log_info("handlecard_closer:%d,%d",cid1,cid2);
 		return std::make_shared<TcardInterface>(std::make_pair(cid1,cid2),ctime,key,m_closer_slot);
 	}
 	std::tuple<bool,std::string> checkLast(std::shared_ptr<TcardInterface> &ti)
@@ -371,15 +376,17 @@ struct RemoteCardFactory : CardFactory
 	int m_remote_slot=0;
 	virtual std::map<uint64_t,std::string> selectcard(std::vector<uint64_t> &ov,uint64_t cid)
 	{
+        //从boost图中找到与之有过临近记录得卡
 		auto vcard=m_owner->getcard(cid);
-		log_info("%d....remote%d",vcard.size(),(vcard.empty()?0:vcard[0]));
+		log_info("selectcard_remote.card_id:%d,%d...",cid,vcard.size());
 		std::sort(vcard.begin(),vcard.end());
 		std::sort(ov.begin(),ov.end());
 		std::vector<uint64_t> v(ov.size()+vcard.size());
-
+        //找到之前临近卡,现在非临近得卡
 		auto it = std::set_difference(vcard.begin(),vcard.end(),ov.begin(),ov.end(),v.begin());
 		v.resize(it-v.begin());
 		auto opcard = card_list::instance()->get(cid);
+        //过滤掉超过3s得卡信息
 		v.erase(std::remove_if(v.begin(),v.end(),[&](uint64_t cardid){
 						auto npcard = card_list::instance()->get(cardid);
 						uint64_t ct1 = opcard->time_();
@@ -387,12 +394,13 @@ struct RemoteCardFactory : CardFactory
 						uint64_t ct3 = ct1>ct2?ct1-ct2:ct2-ct1;
 						return ct3 > TIME_LIM_SEC; 
 						}),v.end());
-
+        //执行卡
 		auto vec = handlecard(v,cid);
 		return std::move(vec);
 	}
 	virtual std::shared_ptr<TcardInterface> make_shared_(const uint64_t cid1,const uint64_t cid2,const uint64_t ctime,uint64_t key)
 	{
+        log_info("handlecard_remote:%d,%d",cid1,cid2);
 		return std::make_shared<TcardInterface>(std::make_pair(cid1,cid2),ctime,key,m_remote_slot);
 	}
 	std::tuple<bool,std::string> checkLast(std::shared_ptr<TcardInterface> &ti)

+ 4 - 1
cardMgr.cpp

@@ -46,10 +46,13 @@ void cardMgr::clear(uint64_t cardid)
 }
 void cardMgr::handleMessage(const Msg &m)
 {
+    //更新卡位置信息
 	m_glist.update(m.x,m.y,m.cardid);
+    //排除车卡
     if(tool_other::is_vehicle( m.type) ) return;
+    //查找该卡1个像素点内得卡号信息(有车卡)
 	std::vector<uint64_t> rc=m_glist.find_near(m.cardid,1);
-	
+    //打印找到得卡数据信息	
 	log_info("LemonHash+..%d,size:%d,(%d,%d)",m.cardid,rc.size(),m.x,m.y);
 	std::map<uint64_t,std::string> map1;
 	std::map<uint64_t,std::string> map2;

+ 0 - 2
cardMgr.h

@@ -37,7 +37,6 @@ struct card_graph
 	}
 	std::vector<uint32_t> getcard(uint32_t c)
 	{
-		log_info("--------getcard---------num_edges:%d,%d",boost::num_edges(m_g),_count);
 		std::vector<uint32_t> tmp;
 		if(c>=_count)return tmp;
 		boost::graph_traits<myGraph_vv>::adjacency_iterator ai_it, ai_it_end;
@@ -45,7 +44,6 @@ struct card_graph
 		while(ai_it != ai_it_end)
 		{
 			log_info("get_card%d:",c);
-			log_info("get_card_%d:",*ai_it);
 			tmp.push_back(*ai_it);
 			ai_it++;
 		}

+ 249 - 248
common_tool.h

@@ -25,324 +25,325 @@
 
 class tool_other
 {
-public:
-    static double round(double dVal, int iPlaces)
-    {
-        double dRetval;
-        double dMod = 0.0000001;
-        if (dVal<0.0) dMod=-0.0000001;
-        dRetval=dVal;
-        dRetval+=(5.0/pow(10.0,iPlaces+1.0));
-        dRetval*=pow(10.0,iPlaces);
-        dRetval=floor(dRetval+dMod);
-        dRetval/=pow(10.0,iPlaces);
-        return(dRetval);
-    }
-    static std::string to13str(std::string& str)
-    {
-        uint64_t tmp = std::stoull(str);
-        return to13str(tmp);
-    }
-
-    static std::string to13str(uint64_t data)
-    {
-        char ss[20]={0};
-        sprintf(ss, "%013ld", data);
-
-        return std::string(ss);
-    }
-
-    static uint32_t id64_to_id(std::string& str)
-    {
-        return static_cast<uint32_t>(std::stoul(to13str(str).substr(3)));
-    }
-
-    static int id64_to_type(std::string& str)
-    {
-        return std::stoi(to13str(str).substr(0, 3));
-    }
-    static int card_id_to_type(const std::string &cardid)
-    {
-        return std::stoi(cardid.substr(0,3));
-    }
-    static int card_id_to_id(const std::string &cardid)
-    {
-        return atoi(cardid.substr(3).c_str());
-    }
-    static std::string type_id_to_str(int32_t type,uint32_t id)  
-    {
-        char sql[15] = {0};
-        snprintf(sql, 15,"%03d%010d", type, id);
-        return std::string(sql);
-    }
-    static uint64_t type_id_to_u64(uint64_t type,uint32_t id)
-    {
-        return type<<32|id;
-    }
-    static bool is_person(int32_t type)
-    {
-        return CT_PERSON == type;
-    }
-
-    static bool is_vehicle(int32_t type)
-    {
-        return CT_VEHICLE == type || CT_COAL_CUTTER == type || CT_HEADING_MACHINE == type;
-    }
-    static std::string get_string_cardid(uint64_t id)
-    {
-        uint64_t type = id>>32;
-        uint32_t cid = id & (~(type<<32));
-        return type_id_to_str(type,cid);
-    }
-
-    static uint64_t card_id_to_u64(const std::string & cardid)
-    {
-        return type_id_to_u64(card_id_to_type(cardid),card_id_to_id(cardid));
-    }
-
-    ///采煤机
-    static bool is_coal(int32_t type)
-    {
-        return CT_COAL_CUTTER == type;
-    }
-
-    /// 掘进机
-    static bool is_driving(int32_t type)
-    {
-        return CT_HEADING_MACHINE == type;
-    }
-
-    static bool is_coal_or_driving(int32_t type)
-    {
-        return CT_COAL_CUTTER == type || CT_HEADING_MACHINE == type;
-    }
-};
-
-class tool_map
-{
-public:
-    static bool try_get_value(sio::message::ptr& out_data,
-                const char* key, sio::message::ptr const& data)
-    {
-        auto map=data->get_map()[key];
-        if(map && sio::message::flag_object == map->get_flag())
+    public:
+        static double round(double dVal, int iPlaces)
         {
-            out_data = map;
-            return true;
+            double dRetval;
+            double dMod = 0.0000001;
+            if (dVal<0.0) dMod=-0.0000001;
+            dRetval=dVal;
+            dRetval+=(5.0/pow(10.0,iPlaces+1.0));
+            dRetval*=pow(10.0,iPlaces);
+            dRetval=floor(dRetval+dMod);
+            dRetval/=pow(10.0,iPlaces);
+            return(dRetval);
         }
-
-        return false;
-    }
-
-    static bool try_get_value(int64_t& out_data, const char* key, sio::message::ptr const& data)
-    {
-        auto map=data->get_map()[key];
-        if(map && sio::message::flag_integer == map->get_flag())
+        static std::string to13str(std::string& str)
         {
-            out_data = map->get_int();
-            return true;
+            if(str.size()<13)
+              str.insert(0,13-str.size(),'0');
+            return str;
         }
 
-        return false;
-    }
-
-    static bool try_get_value(uint32_t& out_data, const char* key, sio::message::ptr const& data)
-    {
-        auto map=data->get_map()[key];
-        if(map && sio::message::flag_integer == map->get_flag())
+        static std::string to13str(uint64_t data)
         {
-            out_data = static_cast<uint32_t>(map->get_int());
-            return true;
-        }
+            char ss[20]={0};
+            sprintf(ss, "%013ld", data);
 
-        return false;
-    }
+            return std::string(ss);
+        }
 
-    static bool try_get_value(int& out_data, const char* key, sio::message::ptr const& data)
-    {
-        auto map=data->get_map()[key];
-        if(map && sio::message::flag_integer == map->get_flag())
+        static uint32_t id64_to_id(std::string& str)
         {
-            out_data = static_cast<int>(map->get_int());
-            return true;
+            return static_cast<uint32_t>(std::stoul(to13str(str).substr(3)));
         }
 
-        return false;
-    }
-
-    static bool try_get_value(std::string& out_data, const char* key, sio::message::ptr const& data)
-    {
-        auto map=data->get_map()[key];
-        if(map && sio::message::flag_string == map->get_flag())
+        static int id64_to_type(std::string& str)
+        {
+            return std::stoi(to13str(str).substr(0, 3));
+        }
+        static int card_id_to_type(const std::string &cardid)
         {
-            out_data = map->get_string();
-            return true;
+            return std::stoi(cardid.substr(0,3));
+        }
+        static int card_id_to_id(const std::string &cardid)
+        {
+            return atoi(cardid.substr(3).c_str());
+        }
+        static std::string type_id_to_str(int32_t type,uint32_t id)  
+        {
+            char sql[15] = {0};
+            snprintf(sql, 15,"%03d%010d", type, id);
+            return std::string(sql);
+        }
+        static uint64_t type_id_to_u64(uint64_t type,uint32_t id)
+        {
+            return type<<32|id;
+        }
+        static bool is_person(int32_t type)
+        {
+            return CT_PERSON == type;
         }
 
-        return false;
-    }
+        static bool is_vehicle(int32_t type)
+        {
+            return CT_VEHICLE == type || CT_COAL_CUTTER == type || CT_HEADING_MACHINE == type;
+        }
+        static std::string get_string_cardid(uint64_t id)
+        {
+            uint64_t type = id>>32;
+            uint32_t cid = id & (~(type<<32));
+            return type_id_to_str(type,cid);
+        }
 
-    static bool try_get_value(double& out_data, const char* key, sio::message::ptr const& data)
-    {
-        auto map=data->get_map()[key];
-        if(map && sio::message::flag_double == map->get_flag())
+        static uint64_t card_id_to_u64(const std::string & cardid)
         {
-            out_data = map->get_double();
-            return true;
+            return type_id_to_u64(card_id_to_type(cardid),card_id_to_id(cardid));
         }
 
-        return false;
-    }
+        ///采煤机
+        static bool is_coal(int32_t type)
+        {
+            return CT_COAL_CUTTER == type;
+        }
 
-    static bool try_get_value(std::vector<sio::message::ptr>& out_data,
-                const char* key, sio::message::ptr const& data)
-    {
-        auto map=data->get_map()[key];
-        if(map && sio::message::flag_array == map->get_flag())
+        /// 掘进机
+        static bool is_driving(int32_t type)
         {
-            out_data = map->get_vector();
-            return true;
+            return CT_HEADING_MACHINE == type;
         }
 
-        return false;
-    }
+        static bool is_coal_or_driving(int32_t type)
+        {
+            return CT_COAL_CUTTER == type || CT_HEADING_MACHINE == type;
+        }
 };
 
-class tool_json
+class tool_map
 {
-public:
-    static void add_member(rapidjson::Value& out_data, const char* key, std::string value,
-                rapidjson::Document::AllocatorType& allocator)
-    {
-        rapidjson::Value name;
-        name.SetString(key, allocator);
-
-        rapidjson::Value data;
-        data.SetString(value.c_str(), allocator);
-
-        out_data.AddMember(name, data, allocator);
-    }
-
-    static void push_back(rapidjson::Value& out_data, std::string value,
-                rapidjson::Document::AllocatorType& allocator)
-    {
-        rapidjson::Value data;
-        data.SetString(value.c_str(), allocator);
-
-        out_data.PushBack(data, allocator);
-    }
-
-    static bool try_get_iter(const char* key, const rapidjson::Value& node,
-                rapidjson::Value::ConstMemberIterator& out_iter)
-    {
-        if(node.IsObject())
-        {
-            out_iter = node.FindMember(key);
-            if(node.MemberEnd() == out_iter)
+    public:
+        static bool try_get_value(sio::message::ptr& out_data,
+                    const char* key, sio::message::ptr const& data)
+        {
+            auto map=data->get_map()[key];
+            if(map && sio::message::flag_object == map->get_flag())
             {
-                return false;
+                out_data = map;
+                return true;
             }
 
-            return true;
+            return false;
         }
 
-        return false;
-    }
+        static bool try_get_value(int64_t& out_data, const char* key, sio::message::ptr const& data)
+        {
+            auto map=data->get_map()[key];
+            if(map && sio::message::flag_integer == map->get_flag())
+            {
+                out_data = map->get_int();
+                return true;
+            }
+
+            return false;
+        }
 
-    static bool try_get_value(int& d, const char* key, const rapidjson::Value& node)
-    {
-        rapidjson::Value::ConstMemberIterator iter;
-        if(try_get_iter(key, node, iter))
+        static bool try_get_value(uint32_t& out_data, const char* key, sio::message::ptr const& data)
         {
-            if(iter->value.IsInt())
+            auto map=data->get_map()[key];
+            if(map && sio::message::flag_integer == map->get_flag())
             {
-                d = iter->value.GetInt();
+                out_data = static_cast<uint32_t>(map->get_int());
                 return true;
             }
+
+            return false;
         }
 
-        return false;
-    }
+        static bool try_get_value(int& out_data, const char* key, sio::message::ptr const& data)
+        {
+            auto map=data->get_map()[key];
+            if(map && sio::message::flag_integer == map->get_flag())
+            {
+                out_data = static_cast<int>(map->get_int());
+                return true;
+            }
 
-    static bool try_get_value(uint64_t& d, const char* key, const rapidjson::Value& node)
-    {
-        rapidjson::Value::ConstMemberIterator iter;
-        if(try_get_iter(key, node, iter))
+            return false;
+        }
+
+        static bool try_get_value(std::string& out_data, const char* key, sio::message::ptr const& data)
         {
-            if(iter->value.IsUint64())
+            auto map=data->get_map()[key];
+            if(map && sio::message::flag_string == map->get_flag())
             {
-                d = iter->value.GetUint64();
+                out_data = map->get_string();
                 return true;
             }
+
+            return false;
         }
-        return false;
-    }
 
-    static bool try_get_value(double& d, const char* key, const rapidjson::Value& node)
-    {
-        rapidjson::Value::ConstMemberIterator iter;
-        if(try_get_iter(key, node, iter))
+        static bool try_get_value(double& out_data, const char* key, sio::message::ptr const& data)
         {
-            if(iter->value.IsDouble())
+            auto map=data->get_map()[key];
+            if(map && sio::message::flag_double == map->get_flag())
             {
-                d = iter->value.GetDouble();
+                out_data = map->get_double();
                 return true;
             }
+
+            return false;
         }
-        return false;
-    }
 
-    static bool try_get_value(std::string& d, const char* key, const rapidjson::Value& node)
-    {
-        rapidjson::Value::ConstMemberIterator iter;
-        if(try_get_iter(key, node, iter))
+        static bool try_get_value(std::vector<sio::message::ptr>& out_data,
+                    const char* key, sio::message::ptr const& data)
         {
-            if(iter->value.IsString())
+            auto map=data->get_map()[key];
+            if(map && sio::message::flag_array == map->get_flag())
             {
-                d = iter->value.GetString();
+                out_data = map->get_vector();
                 return true;
             }
+
+            return false;
         }
+};
+
+class tool_json
+{
+    public:
+        static void add_member(rapidjson::Value& out_data, const char* key, std::string value,
+                    rapidjson::Document::AllocatorType& allocator)
+        {
+            rapidjson::Value name;
+            name.SetString(key, allocator);
+
+            rapidjson::Value data;
+            data.SetString(value.c_str(), allocator);
 
-        return false;
-    }
+            out_data.AddMember(name, data, allocator);
+        }
 
-    static int get_value(const char* key, const int& default_data, const rapidjson::Value& node)
-    {
-        rapidjson::Value::ConstMemberIterator iter;
-        if(try_get_iter(key, node, iter))
+        static void push_back(rapidjson::Value& out_data, std::string value,
+                    rapidjson::Document::AllocatorType& allocator)
         {
-            if(iter->value.IsInt())
+            rapidjson::Value data;
+            data.SetString(value.c_str(), allocator);
+
+            out_data.PushBack(data, allocator);
+        }
+
+        static bool try_get_iter(const char* key, const rapidjson::Value& node,
+                    rapidjson::Value::ConstMemberIterator& out_iter)
+        {
+            if(node.IsObject())
             {
-                return  iter->value.GetInt();
+                out_iter = node.FindMember(key);
+                if(node.MemberEnd() == out_iter)
+                {
+                    return false;
+                }
+
+                return true;
             }
+
+            return false;
         }
 
-        return default_data;
-    }
+        static bool try_get_value(int& d, const char* key, const rapidjson::Value& node)
+        {
+            rapidjson::Value::ConstMemberIterator iter;
+            if(try_get_iter(key, node, iter))
+            {
+                if(iter->value.IsInt())
+                {
+                    d = iter->value.GetInt();
+                    return true;
+                }
+            }
+
+            return false;
+        }
 
-    static std::string get_value(const char* key, const std::string& default_data, const rapidjson::Value& node)
-    {
-        rapidjson::Value::ConstMemberIterator iter;
-        if(try_get_iter(key, node, iter))
+        static bool try_get_value(uint64_t& d, const char* key, const rapidjson::Value& node)
         {
-            if(iter->value.IsString())
+            rapidjson::Value::ConstMemberIterator iter;
+            if(try_get_iter(key, node, iter))
             {
-                return iter->value.GetString();
+                if(iter->value.IsUint64())
+                {
+                    d = iter->value.GetUint64();
+                    return true;
+                }
             }
+            return false;
         }
 
-        return default_data;
-    }
+        static bool try_get_value(double& d, const char* key, const rapidjson::Value& node)
+        {
+            rapidjson::Value::ConstMemberIterator iter;
+            if(try_get_iter(key, node, iter))
+            {
+                if(iter->value.IsDouble())
+                {
+                    d = iter->value.GetDouble();
+                    return true;
+                }
+            }
+            return false;
+        }
+
+        static bool try_get_value(std::string& d, const char* key, const rapidjson::Value& node)
+        {
+            rapidjson::Value::ConstMemberIterator iter;
+            if(try_get_iter(key, node, iter))
+            {
+                if(iter->value.IsString())
+                {
+                    d = iter->value.GetString();
+                    return true;
+                }
+            }
+
+            return false;
+        }
+
+        static int get_value(const char* key, const int& default_data, const rapidjson::Value& node)
+        {
+            rapidjson::Value::ConstMemberIterator iter;
+            if(try_get_iter(key, node, iter))
+            {
+                if(iter->value.IsInt())
+                {
+                    return  iter->value.GetInt();
+                }
+            }
+
+            return default_data;
+        }
 
-    static std::string doc_to_json(rapidjson::Document& doc)
-    {
-        rapidjson::StringBuffer sb;
-        rapidjson::PrettyWriter<rapidjson::StringBuffer> writer(sb);
-        doc.Accept(writer);
+        static std::string get_value(const char* key, const std::string& default_data, const rapidjson::Value& node)
+        {
+            rapidjson::Value::ConstMemberIterator iter;
+            if(try_get_iter(key, node, iter))
+            {
+                if(iter->value.IsString())
+                {
+                    return iter->value.GetString();
+                }
+            }
 
-        return sb.GetString();
-    }
+            return default_data;
+        }
+
+        static std::string doc_to_json(rapidjson::Document& doc)
+        {
+            rapidjson::StringBuffer sb;
+            rapidjson::PrettyWriter<rapidjson::StringBuffer> writer(sb);
+            doc.Accept(writer);
+
+            return sb.GetString();
+        }
 };
 
 #endif // COMMON_TOOL_H

+ 2 - 1
module_service/module_meta_date_changed.cpp

@@ -157,7 +157,8 @@ void module_meta_date_changed::deal_call_edit_vehicle_or_staff(const std::string
     }
     else
     {
-        remove_card(tool_other::id64_to_id(lsz_card_id), tool_other::id64_to_type(lsz_card_id));
+        if(!lsz_card_id.empty())
+            remove_card(tool_other::id64_to_id(lsz_card_id), tool_other::id64_to_type(lsz_card_id));
     }
 }