Bladeren bron

Merge branch 'master' of http://local.beijingyongan.com:3000/linux-dev/ya-serv

chensongchao 6 jaren geleden
bovenliggende
commit
07a1f1bf8e
15 gewijzigde bestanden met toevoegingen van 62 en 42 verwijderingen
  1. 0 1
      Makefile.am
  2. 1 1
      card.cpp
  3. 1 0
      card.h
  4. 1 1
      card_base.h
  5. 3 2
      card_car.cpp
  6. 1 1
      card_car.h
  7. 9 9
      card_path.cpp
  8. 6 5
      card_person.cpp
  9. 1 0
      card_person.h
  10. 2 1
      db/db_tool.cpp
  11. 26 13
      mine_business.cpp
  12. 1 1
      mine_business.h
  13. 2 0
      module_service/area_business_speed_checker.cpp
  14. 6 5
      net-service.cpp
  15. 2 2
      select_tool.h

+ 0 - 1
Makefile.am

@@ -1,7 +1,6 @@
 
 SUBDIRS=db websocket
 
-
 bin_PROGRAMS=yals 
 noinst_PROGRAMS=client async test 
 

+ 1 - 1
card.cpp

@@ -359,7 +359,7 @@ void card_list::on_message(zloop<task*> *loop,const message_locinfo&loc,bool is_
 
 bool card_list_visit::visit(std::shared_ptr<card_location_base> c)
 {
-	c->get_card();
+	c->get_card(_flag);
 	return true;	
 }
 

+ 1 - 0
card.h

@@ -9,6 +9,7 @@
 struct card_list_visit:visitor<std::shared_ptr<card_location_base>>
 {
 	bool visit(std::shared_ptr<card_location_base> c);
+    bool _flag{false};
 };
 
 struct card_list:single_base<card_list,uint64_t,std::shared_ptr<card_location_base>>

+ 1 - 1
card_base.h

@@ -84,7 +84,7 @@ struct card_location_base:card,std::enable_shared_from_this<card_location_base>
     virtual std::shared_ptr<area_tool> get_area_tool()=0;
     virtual int get_vehicle_category_id(){return -1;}
     virtual int get_workline(){return -1;}
-	virtual void get_card(){};
+	virtual void get_card(bool f)=0;
 	virtual void site_hover(int sid){}
 
     void on_message(zloop<task*> * loop,const message_locinfo&loc,bool is_history);

+ 3 - 2
card_car.cpp

@@ -121,9 +121,10 @@ void car::make_package()
 //		swsClientMgr.SendSpecialAreaProcess(cp);
 //	}
 }
-void car::get_card()
+void car::get_card(bool f)
 {
-	mine_business::inst()->put(shared_from_this());
+    if(f)
+	    mine_business::inst()->put(shared_from_this());
 }
 loc_point car::getSmoothPoint()
 {

+ 1 - 1
card_car.h

@@ -41,7 +41,7 @@ public:
     }
 
 	virtual void set_area_info(int mapid,double scale,int areaid,uint64_t t,int type);
-	virtual void get_card();
+	virtual void get_card(bool);
 private:
 	void handle_three_rates(const point &pt);
 	void on_timer();

+ 9 - 9
card_path.cpp

@@ -96,7 +96,7 @@ struct vertex_list
 
 	void log()
 	{
-		printf("%s",to_string().c_str());
+		log_info("%s",to_string().c_str());
 	}
 
 
@@ -192,11 +192,11 @@ point  base_path::cross(const vertex_list&v, const base_path&o)const
 #ifdef __DEBUG__
 void log_path(const std::vector<base_path>&path,const vertex_list&v_list)
 {
-	printf("%s\n","----------------------------------------------------------------");
+	log_info("%s\n","----------------------------------------------------------------");
 	for(int i=0,len=path.size();i<len;i++)
 	{
 		double c=path[i].arg(v_list)/PI*180;
-		printf("base_path %.6lf, %03d,(%d,%s),(%d,%s)\n",c,i,path[i][0],v_list[path[i][0]].to_string().c_str(),path[i][1],v_list[path[i][1]].to_string().c_str());
+		log_info("base_path %.6lf, %03d,(%d,%s),(%d,%s)\n",c,i,path[i][0],v_list[path[i][0]].to_string().c_str(),path[i][1],v_list[path[i][1]].to_string().c_str());
 	}
 }
 #endif
@@ -648,7 +648,7 @@ struct graph
 
 			line_v lv(v[from],v[to]);
 
-			printf("line:%s\n",lv.to_string().c_str());
+			log_info("line:%s\n",lv.to_string().c_str());
 
 			double cos=lv.cos_k();
 			double sin=lv.sin_k();
@@ -873,9 +873,9 @@ std::vector<line_v>  card_path::find_possible_path(const point&from,double dist)
 void test_at_path(card_path&cp,const point&pt)
 {
 	if(cp.is_at_path(pt))
-		printf("test (%.3lf,%.3lf) is-at-path:true\n",pt.x,pt.y);
+		log_info("test (%.3lf,%.3lf) is-at-path:true\n",pt.x,pt.y);
 	else
-		printf("test (%.3lf,%.3lf) is-at-path:false\n",pt.x,pt.y);
+		log_info("test (%.3lf,%.3lf) is-at-path:false\n",pt.x,pt.y);
 }
 
 void test_find_path(card_path&cp,const point&p1,const point&p2)
@@ -883,16 +883,16 @@ void test_find_path(card_path&cp,const point&p1,const point&p2)
 	printf("\nfind-path:  from=(%.3lf,%.3lf),to=(%.3lf,%.3lf)\n",p1.x,p1.y,p2.x,p2.y);
 	std::vector<point> rc=cp.find_path(p1,p2);
 	for(uint32_t i=0;i<rc.size();i++)
-		printf("x=%.3lf,y=%.3lf\n",rc[i].x,rc[i].y);
+		log_info("x=%.3lf,y=%.3lf\n",rc[i].x,rc[i].y);
 }
 
 void test_find_poss_path(const card_path&cp ,const point&from)
 {
-	printf("\nfind-poss_path:  from=(%.3lf,%.3lf)\n",from.x,from.y);
+	log_info("\nfind-poss_path:  from=(%.3lf,%.3lf)\n",from.x,from.y);
 	std::vector<line_v> rc=cp.find_possible_path(from,3);
 	for(uint32_t i=0;i<rc.size();i++)
 	{
-		printf("poss path from=(%.3lf,%.3lf) to=(%.3lf,%.3lf)\n", rc[i][0].x,rc[i][0].y, rc[i][1].x,rc[i][1].y);
+		log_info("poss path from=(%.3lf,%.3lf) to=(%.3lf,%.3lf)\n", rc[i][0].x,rc[i][0].y, rc[i][1].x,rc[i][1].y);
 	}
 }
 

+ 6 - 5
card_person.cpp

@@ -112,14 +112,9 @@ void person::handle_three_rates(const point & pt)
 
 void person::on_timer()
 {
-	//人员井下超时
-//    m_mine_tool->on_check_overtime(this->m_id,this->m_type);
-
     if(!m_mine_tool->m_is_attendance)
 		return;
 	YA::_CARD_POS_ cp;
-	if(m_display)
-	  mine_business::inst()->fetch_add();
 	uint64_t _time=0;
 	point pt = getSmoothPoint(_time);
     
@@ -166,4 +161,10 @@ point person::getSmoothPoint(uint64_t& t)
 	}
 	return pt;
 }
+void person::get_card(bool f)
+{
+    if(!m_mine_tool->m_is_attendance)
+		return;
+	mine_business::inst()->fetch_add(m_display);
+}
 

+ 1 - 0
card_person.h

@@ -23,6 +23,7 @@ struct person:card_location_base, card_area
     point getSmoothPoint(uint64_t& t);
 
     virtual void site_hover(int sid);
+	virtual void get_card(bool f);
     virtual std::shared_ptr<mine_tool> get_mine_tool();
     virtual void do_business(const std::shared_ptr<site>&site,const point &pt,double acc);
 	virtual void set_area_info(int mapid,double scale,int areaid,uint64_t t,int type);

+ 2 - 1
db/db_tool.cpp

@@ -8,11 +8,12 @@
 
 #include "tool_time.h"
 #include "db_tool.h"
-//#include "../common_tool.h"
+
 namespace db_tool
 {
     void PushAsync(const char* sql)
     {
+        logn_info(2,"sql:[%s]",sql);
         if(!sDBConnPool.PushAsync(sql))
         {
             log_error( "PushAsync记录到队列中失败\n");

+ 26 - 13
mine_business.cpp

@@ -130,15 +130,21 @@ struct card_sensor_mgr
 struct staffer_num_business
 {
 	void record_staffer_num();
-	void fetch_add(){m_staff_num++;}
+	void fetch_add(bool f)
+    {
+        if(f)
+            m_staff_num++;
+		m_staff_num_real++;
+        
+    }
 	staffer_num_business()
 	{
-		m_staff_num = 0;
+        reset();
 		m_record_staffer_timeval = 0;
 	}
 	private:
-	void reset(){m_staff_num=0;}
-	std::atomic<uint32_t> m_staff_num;
+	void reset(){m_staff_num=0;m_staff_num_real=0;}
+	std::atomic<uint32_t> m_staff_num,m_staff_num_real;
 	std::time_t m_record_staffer_timeval;
 };
 
@@ -243,9 +249,9 @@ void mine_business::run_business()
     handle_reverse_alarm();
     handle_rear_end();
 }
-void mine_business::fetch_add()
+void mine_business::fetch_add(bool f)
 {
-    m_staffer_num_ptr->fetch_add();
+    m_staffer_num_ptr->fetch_add(f);
 }
 void mine_business::record_staffer_num()
 {
@@ -287,31 +293,38 @@ void mine_business::clear_vehicle()
  *********************************/
 void staffer_num_business::record_staffer_num()
 {
-    static uint32_t min_num=0,max_num=0;
+    static uint32_t min_num=0,max_num=0,min_num_real=0,max_num_real=0;
     std::time_t t = time(NULL);
     char ti[64] = { 0 };
     strftime(ti,sizeof(ti),"%Y/%m/%d %H:%M:%S",localtime(&t));
     std::string sti(ti);
     int minute = atoi(sti.substr(sti.find_first_of(':')+1,2).c_str());
+    uint32_t a=m_staff_num.load();
+    uint32_t ar=m_staff_num_real.load();
     if(m_record_staffer_timeval==0)
     {
-        min_num=max_num=m_staff_num;
+        min_num=max_num=a;
+        min_num_real=max_num_real=ar;
         m_record_staffer_timeval = t;
     }
     if(t-m_record_staffer_timeval>=120 && minute%2 == 0)
     {
         std::stringstream ss;
-        ss<< "INSERT INTO his_staff_number(max_num,min_num,ave_num) VALUES("<<max_num<<','<<min_num<<','<<std::lround((max_num+min_num)/2)<<");";
-        logn_info(2,"staff_number:%s",ss.str().c_str());
+        ss<< "INSERT INTO his_staff_number(max_num,min_num,ave_num,max_num_real,min_num_real,ave_num_real) VALUES("
+            <<max_num<<','<<min_num<<','<<std::lround((max_num+min_num)/2)<<','
+            <<max_num_real<<','<<min_num_real<<','<<std::lround((max_num_real+min_num_real)/2)<<");";
         db_tool::PushAsync(ss.str().c_str());
 
-        min_num=max_num=m_staff_num;
+        min_num=max_num=a;
+        min_num_real=max_num_real=ar;
         m_record_staffer_timeval = t;
     }
     else
     {
-        if (min_num>m_staff_num)   min_num = m_staff_num;
-        if (max_num < m_staff_num) max_num = m_staff_num;
+        if (min_num>a)min_num = a;
+        if (max_num<a)max_num = a;
+        if (min_num_real>ar)min_num_real = ar;
+        if (max_num_real<ar)max_num_real = ar;
     }
     reset();
     return;

+ 1 - 1
mine_business.h

@@ -15,7 +15,7 @@ struct mine_business
 	static mine_business *inst();
 	void run_business();
 //人员数量曲线功能
-	void fetch_add();
+	void fetch_add(bool);
 //天线反向功能
 	void load();
 	void make_reverse_condition(uint64_t type,uint32_t id,int32_t antid,uint32_t ct,uint64_t tof,uint32_t sid);

+ 2 - 0
module_service/area_business_speed_checker.cpp

@@ -69,6 +69,7 @@ void area_business_speed_checker::on_hover(const std::shared_ptr<area_hover>&are
     if(limit < card_ptr->m_speed)//超速
     {
         ptr_temp->m_normal_speed_count=0;
+        log_info("[speed_checker:on_hover_1]%d %.2f,%.2f",card_ptr->m_id,limit,card_ptr->m_speed);
         if(!ptr_temp->m_is_warning && ++ptr_temp->m_over_speed_count>=SPEED_COUNT_LIMIT)
         {
             EVENT_TYPE ev_type =area_hover_ptr->m_area->is_mine()?ET_CARD_OVER_SPEED: ET_CARD_AREA_OVER_SPEED;
@@ -83,6 +84,7 @@ void area_business_speed_checker::on_hover(const std::shared_ptr<area_hover>&are
     else//速度正常
     {
         ptr_temp->m_over_speed_count=0;
+        log_info("[speed_checker:on_hover_2]%d %.2f,%.2f",card_ptr->m_id,limit,card_ptr->m_speed);
         if(ptr_temp->m_is_warning && ++ptr_temp->m_normal_speed_count>=SPEED_COUNT_LIMIT)
         {
             EVENT_TYPE ev_type =area_hover_ptr->m_area->is_mine()?ET_CARD_OVER_SPEED: ET_CARD_AREA_OVER_SPEED;

+ 6 - 5
net-service.cpp

@@ -35,13 +35,14 @@ void net_service::on_timer()
 	visit_site_status vss;
 	sit_list::instance()->accept(vss);
 	int v = card_list::instance()->version();
+	card_list_visit clv;
 	if(v != version)
 	{
-		version=v;
-		mine_business::inst()->clear_vehicle();
-		card_list_visit clv;
-		card_list::instance()->accept(clv);
+        version=v;
+        clv._flag=true;
+        mine_business::inst()->clear_vehicle();
 	}
+	card_list::instance()->accept(clv);
 	mine_business::inst()->run_business();
 }
 
@@ -85,9 +86,9 @@ void net_service::on_message(std::shared_ptr<client> clt,const char*data,size_t
 
 						t->m_cmd_code=cmd;
 						t->m_hash_id=m.m_card_id;
-						m_loc_worker->request(t);
 						if(m.m_card_type==5)
 							mine_business::inst()->make_reverse_condition(m.m_card_type,m.m_card_id,m.m_ant_id,m.m_card_ct,m.m_tof,m.m_site_id);
+						m_loc_worker->request(t);
 					}
 				}
 				break;

+ 2 - 2
select_tool.h

@@ -722,7 +722,7 @@ struct car_point_filter:select_point_object
 			// turning angle must be correct
 			if(angle*delta>0 && fabs(angle)>fabs(delta)*detect_para)
 			{
-				printf("turning:(%.5f,%.5f)(%.5f,%.5f)(%.5f,%.5f),a1:%f,a2:%f,delta:%f,angle:%f\n",
+				log_info("turning:(%.5f,%.5f)(%.5f,%.5f)(%.5f,%.5f),a1:%f,a2:%f,delta:%f,angle:%f\n",
 							pt1.x,pt1.y,l.v[0].x,l.v[0].y,l.v[1].x,l.v[1].y,angle1,angle2,delta,angle);
 				m_if_turning=true;
 				m_turning_pt.set(l.v[0]);
@@ -758,7 +758,7 @@ struct smooth_tool
 	point smooth_last_true_position;
 
 	line smooth_line;
-	bool smooth_line_reset;	//if line reset
+	bool smooth_line_reset=false;	//if line reset
 
 	bool smooth_halt_condition;	//if halting
 	int smooth_halt_count;	//halting count