Parcourir la source

人员曲线增加真实人数曲线

lixioayao il y a 6 ans
Parent
commit
ae0533bbfa
14 fichiers modifiés avec 150 ajouts et 31 suppressions
  1. 2 0
      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. 6 5
      card_person.cpp
  8. 1 0
      card_person.h
  9. 93 0
      configure
  10. 6 1
      configure.ac
  11. 2 1
      db/db_tool.cpp
  12. 26 13
      mine_business.cpp
  13. 1 1
      mine_business.h
  14. 6 5
      net-service.cpp

+ 2 - 0
Makefile.am

@@ -1,4 +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();

+ 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);

+ 93 - 0
configure

@@ -629,6 +629,7 @@ LIBOBJS
 EGREP
 GREP
 CPP
+RANLIB
 am__fastdepCC_FALSE
 am__fastdepCC_TRUE
 CCDEPMODE
@@ -4258,6 +4259,98 @@ else
 fi
 
 
+if test -n "$ac_tool_prefix"; then
+  # Extract the first word of "${ac_tool_prefix}ranlib", so it can be a program name with args.
+set dummy ${ac_tool_prefix}ranlib; ac_word=$2
+{ $as_echo "$as_me:${as_lineno-$LINENO}: checking for $ac_word" >&5
+$as_echo_n "checking for $ac_word... " >&6; }
+if ${ac_cv_prog_RANLIB+:} false; then :
+  $as_echo_n "(cached) " >&6
+else
+  if test -n "$RANLIB"; then
+  ac_cv_prog_RANLIB="$RANLIB" # Let the user override the test.
+else
+as_save_IFS=$IFS; IFS=$PATH_SEPARATOR
+for as_dir in $PATH
+do
+  IFS=$as_save_IFS
+  test -z "$as_dir" && as_dir=.
+    for ac_exec_ext in '' $ac_executable_extensions; do
+  if as_fn_executable_p "$as_dir/$ac_word$ac_exec_ext"; then
+    ac_cv_prog_RANLIB="${ac_tool_prefix}ranlib"
+    $as_echo "$as_me:${as_lineno-$LINENO}: found $as_dir/$ac_word$ac_exec_ext" >&5
+    break 2
+  fi
+done
+  done
+IFS=$as_save_IFS
+
+fi
+fi
+RANLIB=$ac_cv_prog_RANLIB
+if test -n "$RANLIB"; then
+  { $as_echo "$as_me:${as_lineno-$LINENO}: result: $RANLIB" >&5
+$as_echo "$RANLIB" >&6; }
+else
+  { $as_echo "$as_me:${as_lineno-$LINENO}: result: no" >&5
+$as_echo "no" >&6; }
+fi
+
+
+fi
+if test -z "$ac_cv_prog_RANLIB"; then
+  ac_ct_RANLIB=$RANLIB
+  # Extract the first word of "ranlib", so it can be a program name with args.
+set dummy ranlib; ac_word=$2
+{ $as_echo "$as_me:${as_lineno-$LINENO}: checking for $ac_word" >&5
+$as_echo_n "checking for $ac_word... " >&6; }
+if ${ac_cv_prog_ac_ct_RANLIB+:} false; then :
+  $as_echo_n "(cached) " >&6
+else
+  if test -n "$ac_ct_RANLIB"; then
+  ac_cv_prog_ac_ct_RANLIB="$ac_ct_RANLIB" # Let the user override the test.
+else
+as_save_IFS=$IFS; IFS=$PATH_SEPARATOR
+for as_dir in $PATH
+do
+  IFS=$as_save_IFS
+  test -z "$as_dir" && as_dir=.
+    for ac_exec_ext in '' $ac_executable_extensions; do
+  if as_fn_executable_p "$as_dir/$ac_word$ac_exec_ext"; then
+    ac_cv_prog_ac_ct_RANLIB="ranlib"
+    $as_echo "$as_me:${as_lineno-$LINENO}: found $as_dir/$ac_word$ac_exec_ext" >&5
+    break 2
+  fi
+done
+  done
+IFS=$as_save_IFS
+
+fi
+fi
+ac_ct_RANLIB=$ac_cv_prog_ac_ct_RANLIB
+if test -n "$ac_ct_RANLIB"; then
+  { $as_echo "$as_me:${as_lineno-$LINENO}: result: $ac_ct_RANLIB" >&5
+$as_echo "$ac_ct_RANLIB" >&6; }
+else
+  { $as_echo "$as_me:${as_lineno-$LINENO}: result: no" >&5
+$as_echo "no" >&6; }
+fi
+
+  if test "x$ac_ct_RANLIB" = x; then
+    RANLIB=":"
+  else
+    case $cross_compiling:$ac_tool_warned in
+yes:)
+{ $as_echo "$as_me:${as_lineno-$LINENO}: WARNING: using cross tools not prefixed with host triplet" >&5
+$as_echo "$as_me: WARNING: using cross tools not prefixed with host triplet" >&2;}
+ac_tool_warned=yes ;;
+esac
+    RANLIB=$ac_ct_RANLIB
+  fi
+else
+  RANLIB="$ac_cv_prog_RANLIB"
+fi
+
 
 
 { $as_echo "$as_me:${as_lineno-$LINENO}: checking for main in -lev" >&5

+ 6 - 1
configure.ac

@@ -11,6 +11,7 @@ AC_CONFIG_MACRO_DIR([m4])
 # Checks for programs.
 AC_PROG_CXX
 AC_PROG_CC
+AC_PROG_RANLIB
 
 AC_CHECK_LIB([ev], [main])
 AC_CHECK_LIB([zlog], [main])
@@ -36,7 +37,11 @@ AC_FUNC_MALLOC
 AC_FUNC_REALLOC
 AC_CHECK_FUNCS([inet_ntoa memset socket])
 
-AC_CONFIG_FILES([db/Makefile websocket/Makefile Makefile])
+AC_CONFIG_FILES([
+	db/Makefile
+	websocket/Makefile
+	Makefile
+])
 AC_OUTPUT
 
 

+ 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);

+ 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;