Browse Source

多个分站数据更新功能 && WS_1

lixioayao 5 years ago
parent
commit
99fad6cccb

+ 6 - 6
ant.cpp

@@ -462,7 +462,7 @@ void sit_list::read_ant_path(int id)
 	test_find_path(card_path::inst(),point(4683.625,56.988),point(2200,-75));
 }
 
-void sit_list::init_site(int id)
+void sit_list::init_site(const std::string &ids /*=""*/)
 {
      std::string sql = "SELECT reader_id, reader_type_id, dat_reader.map_id, \
              area_id, device_type_id, dimension, dat_map.scale,need_power_alarm\
@@ -470,15 +470,15 @@ void sit_list::init_site(int id)
              FROM dat_reader, dat_map where \
              dat_reader.map_id=dat_map.map_id and state=0";
 
-     if(-1 == id)
+     if(ids.empty())
      {
          sql.append(";");
      }
      else
      {
-         sql.append(" AND reader_id=");
-         sql.append(std::to_string(id));
-         sql.append(";");
+         sql.append(" AND reader_id in (");
+         sql+=ids;
+         sql.append(");");
 
          std_debug("增加或修改分站 sql=%s", sql.c_str());
          log_info("增加或修改分站 sql=%s", sql.c_str());
@@ -490,7 +490,7 @@ void sit_list::init_site(int id)
      int nCount = DBRes.GetRecordCount( Error );
      if (nCount < 1)
      {
-         log_error("增加或修改失败,数据库中找不到: 分站id=%d", id);
+         log_error("增加或修改失败,数据库中找不到: 分站id=%s", ids.c_str());
          return ;
      }
 

+ 7 - 7
ant.h

@@ -319,18 +319,18 @@ struct sit_list:single_base<sit_list,int,std::shared_ptr<site>>
 {
     void load()
     {
-        read_sit_list(-1);
-        read_ant_path(-1);
+        read_sit_list();
+        read_ant_path();
     }
     ///id=-1为初始化所有
-    void load_from_db(int id=-1)
+    void load_from_db(const std::string&ids="" )
     {
-        init_site(id);
+        init_site(ids);
         load();
     }
-    void read_sit_list(int id);
-    void read_ant_path(int id);
-    void init_site(int id);
+    void read_sit_list(int id=-1);
+    void read_ant_path(int id=-1);
+    void init_site(const std::string &ids="");
 };
 #endif
 

+ 22 - 22
card_base.cpp

@@ -167,29 +167,29 @@ void card_location_base::upt_card_pos(YA::_CARD_POS_&cp, point &pt)
 	cp.Type=m_type;
 	cp.ID = m_id;
 
-    if(m_type==4 &&  m_id==1318)
-    {
-        static std::list<ld_1318> list_1318;
-        if(list_1318.size()>=60)
-        {
-            double tx=0,ty=0,ts=0;
-            std::for_each(list_1318.begin(),list_1318.end(),[&tx,&ty,&ts](const ld_1318& ld){
-                        tx+=ld.x;ty=ld.y;ts+=ld.speed;
-                        });
-            size_t n=list_1318.size();
+   // if(m_type==4 &&  m_id==1318)
+   // {
+   //     static std::list<ld_1318> list_1318;
+   //     if(list_1318.size()>=60)
+   //     {
+   //         double tx=0,ty=0,ts=0;
+   //         std::for_each(list_1318.begin(),list_1318.end(),[&tx,&ty,&ts](const ld_1318& ld){
+   //                     tx+=ld.x;ty=ld.y;ts+=ld.speed;
+   //                     });
+   //         size_t n=list_1318.size();
 
-            tx/=n;ts/=n;
-            _p.set(tx,ty,0);
-            cp.speed = ts;
-            list_1318.pop_front();
-            log_info("get_speed:%d (%f,%f), %f",m_id,tx,ty,ts);
-        }
-        else
-            _p=*this;
-        double speed = abs((int)(m_speed*10000)/10000.);
-        list_1318.emplace_back(x,y,speed);
-    }
-    else
+   //         tx/=n;ts/=n;
+   //         _p.set(tx,ty,0);
+   //         cp.speed = ts;
+   //         list_1318.pop_front();
+   //         log_info("get_speed:%d (%f,%f), %f",m_id,tx,ty,ts);
+   //     }
+   //     else
+   //         _p=*this;
+   //     double speed = abs((int)(m_speed*10000)/10000.);
+   //     list_1318.emplace_back(x,y,speed);
+   // }
+   // else
         cp.speed = abs(ceil(m_speed));
 
 	cp.x = tool_other::round(_p.x,3);

+ 0 - 2
card_car.cpp

@@ -95,9 +95,7 @@ void car::make_package()
    // if(m_mine_tool->m_is_attendance)
     on_duty=m_mine_tool->is_on_duty();
 	cp.is_on_duty=on_duty;
-    //log_info("%s,down_time:%f,today:%lu,duty:%u",tool_other::type_id_to_str(m_type,m_id).c_str(),cp.down_time,tool_time::morning_of_today_ms(),on_duty);
 	upt_card_pos(cp,pt);
-    //int sid=0; if(auto st=m_area_tool->m_site)sid=st->m_area_id; m_his_location_card->push(pt.m_time,pt,sid,cp.map_id);
     make_his_location(pt.m_time,pt);
 	uint64_t _now=tool_time::now_to_ms();
 	uint64_t t=_now>m_timeval?_now-m_timeval:m_timeval-_now;

+ 0 - 6
common_tool.h

@@ -1,12 +1,6 @@
 #ifndef COMMON_TOOL_H
 #define COMMON_TOOL_H
 
-/**
- * @brief 基楚的工具类
- * @author 戴月腾
- * @date 2018-09-15
- */
-
 
 #include <chrono>
 #include <string>

+ 3 - 1
db/db_card.cpp

@@ -99,7 +99,9 @@ namespace db_card
 			std::string strategy;
 			if(card_type_id ==CT_VEHICLE)
 				strategy = config.get("car.strategy","CS_1");
-			else
+			else if(card_type_id ==CT_COAL_CUTTER)
+				strategy = config.get("coalface.strategy","WS_1");
+            else
 				strategy = config.get("person.strategy","PS_1");
 
 			auto clb = card_location_base::make_car(strategy,vsid,need_display,card_type_id,

+ 1 - 0
his_location.cpp

@@ -149,6 +149,7 @@ void location_card::push(uint64_t timestamp,const point & p,int32_t areaid,int32
     if (bclose) //卡移除后直接更新his_location
     {
         update(p,timestamp);
+        init();
         return;
     }
     if(m_p.empty() || m_timestamp==0||m_areaid<0||m_mapid<0)

+ 101 - 1
line.h

@@ -243,7 +243,7 @@ struct line_v:line//线段
 
 	bool contain(double x,double y,double e=0.0001)const
 	{
-		return eq(v[0].dist(v[1]),v[0].dist(x,y)+v[1].dist(x,y),0.0001);
+		return eq(v[0].dist(v[1]),v[0].dist(x,y)+v[1].dist(x,y),e);
 	}
 
 	double dist(const point&v)const
@@ -260,6 +260,106 @@ struct line_v:line//线段
 		return *this;
 	}
 };
+struct line_r:line
+{
+    std::array<point,2> v;
+	line_r()
+	{
+		v[0].set(0,0);
+		v[1].set(0,0);
+	}
+
+
+	line_r(const point&p0,const point&p1)
+		:line(p0,p1)
+	{
+		v[0]=p0;
+		v[1]=p1;
+	}
+
+	point&operator[](int i) { return v[i]; }
+	const point&operator[](int i)const { return v[i]; }
+
+	std::string to_string()const
+	{
+		char buf[256];
+		int len=sprintf(buf,"[(%.3lf,%.3lf),(%.3lf,%.3lf)]",v[0].x,v[0].y,v[1].x,v[1].y);
+
+		return std::string(buf,len);
+	}
+
+	point  crossing(const line&l)const
+	{
+		point pt=line::crossing(l);
+
+		return contain(pt)?pt:point();
+	}
+
+	point  crossing(const line_r&l)const
+	{
+		point pt=line::crossing(l);
+
+		return contain(pt)&&l.contain(pt)?pt:point();
+	}
+
+	point  projection(const point&p)const
+	{
+		point pt=line::projection(p);
+		return contain(pt)?pt:point();
+	}
+
+	bool invalid()const
+	{
+        return v[0].dist(v[1])<0.01;
+	}
+
+	bool contain(const point&p,double e=0.0001)const
+	{
+		return contain(p.x,p.y,e);
+	}
+    bool is_same_direction(const line_r &lr)
+    {
+        bool f=false;
+        if(v[0]==lr[0]){
+            if(contain(lr[1]))
+                f=true;
+        }
+        else{
+            f=(contain(lr[0]) && contain(lr[1]) && !lr.contain(v[0]))|| (lr.contain(v[0]) && lr.contain(v[1]) && !contain(lr[0]));
+        }
+        return f;
+    }
+	bool contain(double x,double y,double e=0.0001)const
+	{
+        return line::contain(x,y,e)?in_contain(x,y,e)||out_contain(x,y,e):false;
+	}
+    bool in_contain(const point &p,double e=0.0001)
+    {
+        return in_contain(p.x,p.y,e);
+    }
+	bool in_contain(double x,double y,double e=0.0001)const
+    {
+        return line::contain(x,y,e)?eq(v[0].dist(v[1]),v[0].dist(x,y)+v[1].dist(x,y),e):false;
+    }
+	bool out_contain(double x,double y,double e=0.0001)const
+    {
+        return line::contain(x,y,e)?(v[0].dist(x,y)>=v[1].dist(x,y)):false;
+	}
+	double dist(const point&v)const
+	{
+		point p=projection(v);
+		if(p.empty())
+			return -1;
+
+		return v.dist(p);
+	}
+
+	const line &as_line()const
+	{
+		return *this;
+	}
+
+};
 #endif
 
 

+ 115 - 1
line_fit.cpp

@@ -1,7 +1,7 @@
 #include <algorithm>
 #include <math.h>
 #include "line_fit.h"
-
+#include "line.h"
 fit_item::fit_item()
 	:x(0)
 	,y(0)
@@ -241,4 +241,118 @@ bool card_fit::fit()
 
 	return true;
 }
+#ifdef _LINE_FIT_TEST
+#include "line_fit.h"
+int a(int x)
+{
+    return x*2+1;
+}
+double y(int x)
+{
+    return 0.25*x+13.2;
+}
+int main()
+{
+    fit_batch f;
+    f.add_tool(100,5);
+    //y=2x+1;
+    //f.add(30,a(30));
+    for(int i=0;i<15;i++)
+    {
+        f.add(i*10,a(i*10));
+    }
+    f.add(20,45);
+    f.log(); 
+    f.reset_data();
+    f.add(20,45);
+    for(int i=14;i>=0;i--)
+        f.add(i,a(i));
+    f.log(); 
+    printf("%f",f[0].testk(30,a(30)+20));
+    f.reset_data();
+    f.add(6721.744000,1273.000000);
+    f.add(6721.742000,1273.000000);
+    f.log();
+    f.add(6721.592000,1273.000000);
+    f.add(6721.545000,1273.000000);
+    f.add(6721.259000,1273.000000);
+    f.add(6721.395000,1273.000000);
+    f.add(6721.378000,1273.000000);
+    f.add(6721.081000,1273.000000);
+    f.add(6721.043000,1273.000000);
+    f.add(6720.991000,1273.000000);
+    f.add(6720.485000,1273.000000);
+    f.add(6720.633000,1273.000000);
+    f.add(6720.562000,1273.000000);
+    f.add(6720.443000,1273.000000);
+    f.add(6720.145000,1273.000000);
+    f.add(6719.575000,1273.000000);
+    f.add(6710.775000,1273.000000);
+    f.add(6710.384000,1273.000000);
+    f.add(6710.030000,1273.000000);
+    f.add(6709.847000,1273.000000);
+    f.add(6710.098000,1273.000000);
+    f.add(6706.457000,1273.000000);
+    f.add(6706.419000,1273.000000);
+    f.add(6706.608000,1273.000000);
+    f.add(6706.513000,1273.000000);
+    f.add(6706.438000,1273.000000);
+    f.add(6706.239000,1273.000000);
+    f.add(6706.048000,1273.000000);
+    f.add(6705.962000,1273.000000);
+    f.add(6705.707000,1273.000000);
+    f.add(6705.839000,1273.000000);
+    f.add(6705.594000,1273.000000);
+    f.add(6705.417000,1273.000000);
+    f.add(6705.136000,1273.000000);
+    f.add(6705.608000,1273.000000);
+    f.add(6705.505000,1273.000000);
+    f.add(6705.422000,1273.000000);
+    f.add(6705.640000,1273.000000);
+    f.add(6705.280000,1273.000000);
+    f.log();
+    zlist<int,128> m_test;
+    for(int i= 1 ;i<=20;i++)
+    {
+        m_test.grow()=i;
+        if(i%5==0) 
+        {
+            int x=0;
+            for(int j=0;j<5;j++)
+            {
+                x+=m_test(j);
+            }
+            m_test.rskip(5);
+            m_test.grow()=x;
+        }
+    }
+    for(int i=0;i<m_test.size();i++)
+      printf("%d\n",m_test(i));
+
+    line_r l(point(1,y(1)),point(13,y(13)));
+    if(l.contain(point(4,y(4))))printf("contain:%d,%f\n",4,y(4));
+    if(l.contain(point(5,y(5))))printf("contain:%d,%f\n",5,y(5));
+    if(l.contain(point(-5,y(-5))))printf("contain:%d,%f\n",-5,y(-5));
+    point p=l.projection(point(17,y(17)+1.5));
+    printf("projection:%f,%f\n",p.x,p.y);
+    p=l.projection(point(-17,y(-17)+1.5));
+    printf("projection:%f,%f\n",p.x,p.y);
+    printf("line:%s\n",l.to_string().c_str());
+    line_r ll=l;
+    printf("line:%s\n",ll.to_string().c_str());
+    bool b=l.is_same_direction(ll);
+    if(b)printf("%s [is same direction]%s\n",l.to_string().c_str(),ll.to_string().c_str());
+    line_r l2(point(4,y(4)),point(7,y(7)));
+    b=l.is_same_direction(l2);
+    if(b)printf("%s [is same direction]%s\n",l.to_string().c_str(),l2.to_string().c_str());
+    line_r l3(point(19,y(19)),point(31,y(31)));
+    b=l.is_same_direction(l3);
+    if(b)printf("%s [is same direction]%s\n",l.to_string().c_str(),l3.to_string().c_str());
+    line_r l4(point(19,y(19)),point(4,y(4)));
+    b=l.is_same_direction(l4);
+    if(!b)printf("%s [is not same direction]%s\n",l.to_string().c_str(),l4.to_string().c_str());
+
+    return 0;
+}
+#endif
 

+ 0 - 6
mine.h

@@ -1,12 +1,6 @@
 #ifndef MINE_H
 #define MINE_H
 
-/**
- * @brief 矿井里相关的业务
- * @author 戴月腾
- * @date 2018-09-24
- */
-
 #include <unordered_map>
 #include <log.h>
 #include <chrono>

+ 0 - 6
module_service/area_business_geofault.h

@@ -1,12 +1,6 @@
 #ifndef AREA_BUSINESS_GEOFAULT
 #define AREA_BUSINESS_GEOFAULT
 
-/**
- * @brief 简要说明
- * @author 戴月腾
- * @date 2019-01-15
- */
-
 #include"area_business.h"
 #include <unordered_map>
 #include<vector>

+ 0 - 6
module_service/area_business_motionless_persion.h

@@ -1,12 +1,6 @@
 #ifndef AREA_BUSINESS_MOTIONLESS_PERSION
 #define AREA_BUSINESS_MOTIONLESS_PERSION
 
-/**
- * @brief 简要说明
- * @author 戴月腾
- * @date 2019-01-12
- */
-
 //#include"module_singleton_base.h"
 //#include"module_i_thread.h"
 //#include"card.h"

+ 0 - 7
module_service/module_call.h

@@ -1,13 +1,6 @@
 #ifndef MODULE_CALL_H
 #define MODULE_CALL_H
 
-/**
- * @brief 呼叫模块
- * 用户通过WEB呼叫指定人员或者全部人员
- * @author 戴月腾
- * @date 2018-08-22
- */
-
 #include <map>
 #include <mutex>
 #include <string>

+ 0 - 7
module_service/module_call_help.h

@@ -1,13 +1,6 @@
 #ifndef MODULE_CALL_HELP_H
 #define MODULE_CALL_HELP_H
 
-/**
-  *@brief 呼救模块
-  * 把呼救消息保存到数据库,同时推送给web
-  * @author 戴月腾
-  * @date 2018-08-09
-*/
-
 #include "module_singleton_base.h"
 #include"card.h"
 #include"websocket/sio/sio_client.h"

+ 7 - 9
module_service/module_meta_date_changed.cpp

@@ -63,8 +63,7 @@ void module_meta_date_changed::accept(sio::message::ptr const& data)
         }
         else if(JSON_KEY_NAME_READER == name)
         {
-            int id = std::stoi(szParam);
-            deal_call_edit_reader(id, edit_type_id);
+            deal_call_edit_reader(szParam, edit_type_id);
         }
         else if ("antenna" == name)
         {
@@ -201,14 +200,13 @@ void module_meta_date_changed::deal_call_edit_area(const std::string& id,EDIT_TY
     }
 }
 
-void module_meta_date_changed::deal_call_edit_reader(int id, EDIT_TYPE_ID edit_type_id)
+void module_meta_date_changed::deal_call_edit_reader(const std::string &ids, EDIT_TYPE_ID edit_type_id)
 {
-    if(ET_INSERT == edit_type_id || ET_UPDATE == edit_type_id)
-    {
-        sit_list::instance()->init_site(id);
+    if(ET_INSERT == edit_type_id || ET_UPDATE == edit_type_id){
+        sit_list::instance()->init_site(ids);
     }
-    else if(ET_DELETE == edit_type_id)
-    {
+    else if(ET_DELETE == edit_type_id){
+        int id =std::stoi(ids);
         sit_list::instance()->remove(id);
         card_path::init();
     }
@@ -250,7 +248,7 @@ void module_meta_date_changed::deal_call_edit_map(int id, EDIT_TYPE_ID edit_type
             return;
         }
 
-        update_map_info(id);
+        //update_map_info(id);
     }
     else if(ET_DELETE == edit_type_id)
     {

+ 1 - 7
module_service/module_meta_date_changed.h

@@ -1,11 +1,5 @@
 #ifndef MODULE_META_DATE_CHANGED_H
 #define MODULE_META_DATE_CHANGED_H
-/**
- * @brief 简要说明
- * @author 戴月腾
- * @date 2018-10-18
- */
-
 #include"module_singleton_base.h"
 #include"websocket/sio/sio_client.h"
 
@@ -52,7 +46,7 @@ private:
     ///id64格式为10000006666
     void deal_call_edit_card(std::string & id64, EDIT_TYPE_ID edit_type_id);
 
-    void deal_call_edit_reader(int id, EDIT_TYPE_ID edit_type_id);
+    void deal_call_edit_reader(const std::string & areaids, EDIT_TYPE_ID edit_type_id);
 
     ///待实现
     void deal_call_edit_path(int id, EDIT_TYPE_ID edit_type_id);

+ 0 - 9
module_service/module_mgr.h

@@ -1,15 +1,6 @@
 #ifndef MODULE_MGR_H
 #define MODULE_MGR_H
 
-/**
- * @brief 业务模块的管理类,包括:
- * 1、初始化(init:注册web回调函数,读数据库初始化事件列表)
- * 2、启动线程start:向web发送事件
- * 3、结束线程stop
- * @author 戴月腾
- * @date 2018-08-25
- */
-
 #include "module_singleton_base.h"
 #include "websocket/wsClientMgr.h"
 #include "common.h"

+ 0 - 6
module_service/module_other_alarm.h

@@ -1,11 +1,5 @@
 #ifndef MODULE_OTHER_ALARM_H
 #define MODULE_OTHER_ALARM_H
-/**
- * @brief 简要说明
- * @author 戴月腾
- * @date 2018-10-11
- */
-
 #include "module_singleton_base.h"
 #include "card.h"
 

+ 0 - 6
module_service/module_web.h

@@ -1,12 +1,6 @@
 #ifndef MODULE_WEB_H
 #define MODULE_WEB_H
 
-/**
- * @brief 与web通信的接口类,以及json工具类:tool_json
- * @author 戴月腾
- * @date 2018-08-25
- */
-
 #include <memory>
 #include <string>
 #include<vector>