123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758 |
- #include "regularcycle_rate.h"
- #include "db_api/CDBSingletonDefine.h"
- #include "log.h"
- #include "three_rates_impl.h"
- #include "common_data.h"
- #include <iostream>
- #include <float.h>
- regularcycle_rate::regularcycle_rate()
- {
- }
- void regularcycle_rate::init()
- {
- m_coalmining_regularcycle_list.clear();
- m_coalmining_area_list.clear();
- init_data_coalmining_RegularCycle();
- init_data_coalminingface_RegularCycle();
- init_restart_halfcoalmining_regularcycle();
- init_data_pre_coalmining_RegularCycle();
- }
- /*初始化采煤机有关正规循环率计算的先前参数
- * param
- * return
- * 函数正常执行返回0,否则返回1
- */
- int regularcycle_rate::init_data_pre_coalmining_RegularCycle()
- {
- const char * sql = "SELECT work_face_id, start_time,start_x,start_y,move_direction \
- FROM his_regular_cycle_detail\
- where detail_type=1 and end_time is NULL and end_x is NULL;";
- std::shared_ptr<CoalMiningRegularCycle> pCoalRegularCycle = nullptr;
- std::string Error;
- YADB::CDBResultSet DBRes;
- if (0 == sDBConnPool.Query(sql,DBRes,Error))
- {
- logn_error(2,"TR-init_data_pre_coalmining_RegularCycle Query exist error, error: %s", Error.c_str());
-
- return 1;
- }
- int nCount = DBRes.GetRecordCount( Error );
- if (nCount > 0)
- {
- while ( DBRes.GetNextRecod(Error) )
- {
- bool bRet = true;
- int work_face_id = -1;
- bRet = DBRes.GetField( "work_face_id",work_face_id, Error );
- std::string str_start_time = "";
- bRet = DBRes.GetField( "start_time",str_start_time, Error );
- time_t start_time = tr_helper::string_switch_time_t(str_start_time);
- time_t tCurTime = time(NULL);
- if (tCurTime - start_time > 3600 *24*3)
- {
- continue;
- }
- CoalMiningRegularCycleMap::iterator it = m_coalmining_regularcycle_list.find(work_face_id);
- if(it != m_coalmining_regularcycle_list.end())
- {
- pCoalRegularCycle = it->second;
- }
- else
- {
- continue;
- }
- pCoalRegularCycle->coalface_id = work_face_id;
- pCoalRegularCycle->start_time = start_time;
- pCoalRegularCycle->last_time = time_t(0);
- pCoalRegularCycle->IsWorking = true;
- pCoalRegularCycle->bHalfKnife = true;
- bRet = DBRes.GetField("move_direction",pCoalRegularCycle->bDirection,Error);
- bRet = DBRes.GetField( "start_x",pCoalRegularCycle->start_x, Error );
- bRet = DBRes.GetField( "start_y",pCoalRegularCycle->start_y, Error );
- if(!bRet)
- {
- logn_error(2,"TR-init_data_pre_coalmining_RegularCycle GetField exist error, error: %s", Error.c_str());
- }
- pCoalRegularCycle->mindis_time = time(NULL);
- pCoalRegularCycle->mindistance = FLT_MAX;
- }
- }
- return 0;
- }
- /*初始化半刀未完成的正规循环率情况
- *
- * param
- *
- * return
- * 函数正常执行返回0,否则返回1
- */
- int regularcycle_rate::init_restart_halfcoalmining_regularcycle()
- {
- const char * sql = "SELECT work_face_id, start_time,start_x,start_y,move_direction \
- FROM his_regular_cycle_detail\
- where detail_type=1 and end_x = 1.0 and end_time is NULL;";
- std::shared_ptr<CoalMiningRegularCycle> pCoalRegularCycle = nullptr;
- std::string Error;
- YADB::CDBResultSet DBRes;
- sDBConnPool.Query(sql,DBRes,Error);
- int nCount = DBRes.GetRecordCount( Error );
- if (nCount >0)
- {
- while ( DBRes.GetNextRecod(Error) )
- {
- bool bRet = false;
- int workface_id = -1;
- DBRes.GetField( "work_face_id",workface_id, Error );
- std::string str_start_time = "";
- DBRes.GetField( "start_time",str_start_time, Error );
- time_t start_time = tr_helper::string_switch_time_t(str_start_time);
- time_t tCurTime = time(NULL);
- if (tCurTime - start_time > 3600 *24*3)
- {
- continue;
- }
- CoalMiningRegularCycleMap::iterator it = m_coalmining_regularcycle_list.find(workface_id);
- if(it != m_coalmining_regularcycle_list.end())
- {
- pCoalRegularCycle = it->second;
- }
- else
- {
- continue;
- }
- pCoalRegularCycle->coalface_id = workface_id;
- pCoalRegularCycle->start_time = start_time;
- pCoalRegularCycle->last_time = time_t(0);
- pCoalRegularCycle->IsWorking = true;
- pCoalRegularCycle->bHalfKnife = false;
- bRet = DBRes.GetField("move_direction",pCoalRegularCycle->bDirection,Error);
- bRet = DBRes.GetField( "start_x",pCoalRegularCycle->start_x, Error );
- bRet = DBRes.GetField( "start_y",pCoalRegularCycle->start_y, Error );
- if(!bRet)
- {
- logn_error(2,"TR-init_data_pre_coalmining_RegularCycle GetField exist error, error: %s", Error.c_str());
- }
- pCoalRegularCycle->mindis_time = time(NULL);
- pCoalRegularCycle->mindistance = FLT_MAX;
- }
- }
- return 0;
- }
- /*初始化采煤机有关正规循环率计算的中间参数
- * param
- * return
- * 函数正常执行返回0,否则返回1
- */
- int regularcycle_rate::init_data_coalmining_RegularCycle(const std::string& face_id)
- {
- std::string sql = "SELECT vehicle_id, coalface_id FROM dat_coalface_vehicle where state=1";
- if(face_id=="-1")
- {
- sql += ";";
- }
- else
- {
- sql += " and coalface_id = " + face_id+";";
- }
- std::shared_ptr<CoalMiningRegularCycle> pCoalRegularCycle = nullptr;
- std::string Error;
- YADB::CDBResultSet DBRes;
- if (0 == sDBConnPool.Query(sql.c_str(),DBRes,Error))
- {
- logn_error(2,"TR-init_data_coalmining_RegularCycle Query exist error, error: %s", Error.c_str());
- printf("sql=%s", sql.c_str());
- return 1;
- }
- int nCount = DBRes.GetRecordCount( Error );
- if (nCount > 0)
- {
- while ( DBRes.GetNextRecod(Error) )
- {
- bool bRet = true;
- int vehicle_id = -1;
- int workface_id = -1;
- bRet = DBRes.GetField( "vehicle_id",vehicle_id, Error );
- if (!bRet)
- {
- logn_error(2, "TR-init_data_coalmining_RegularCycle GetField exist error, error: %s", Error.c_str());
- continue;
- }
- bRet = DBRes.GetField( "coalface_id",workface_id, Error );
- if (!bRet)
- {
- logn_error(2, "TR-init_data_coalmining_RegularCycle GetField exist error, error: %s", Error.c_str());
- continue;
- }
- CoalMiningRegularCycleMap::iterator it = m_coalmining_regularcycle_list.find(workface_id);
- if(it != m_coalmining_regularcycle_list.end())
- {
- pCoalRegularCycle = it->second;
- logn_info(2, "TR-update_data_coalmining_RegularCycle workface_id: %s", face_id.c_str());
- }
- else
- {
- pCoalRegularCycle = std::make_shared<CoalMiningRegularCycle>();
- pCoalRegularCycle->last_time = time_t(0);
- pCoalRegularCycle->avg_distance = 0;
- pCoalRegularCycle->dis_num = 0;
- pCoalRegularCycle->IsWorking = false;
- pCoalRegularCycle->bDirection = 0;
- pCoalRegularCycle->bHalfKnife = false;
- pCoalRegularCycle->mindistance = FLT_MAX;
- m_coalmining_regularcycle_list.insert(std::make_pair(workface_id,pCoalRegularCycle));
- logn_info(2, "TR-add_data_coalmining_RegularCycle workface_id: %s", face_id.c_str());
- }
- pCoalRegularCycle->vehicle_id = vehicle_id;
- pCoalRegularCycle->coalface_id = workface_id;
- }
- }
- return 0;
- }
- void regularcycle_rate::remove_data_coalmining_RegularCycle(int face_id)
- {
- auto it_face = m_coalmining_regularcycle_list.find(face_id);
- if (it_face != m_coalmining_regularcycle_list.end())
- {
- m_coalmining_regularcycle_list.erase(it_face);
- }
- }
- void regularcycle_rate::remove_data_coalminingface_RegularCycle(int face_id)
- {
- auto it_face = m_coalmining_area_list.find(face_id);
- if (it_face != m_coalmining_area_list.end())
- {
- m_coalmining_area_list.erase(it_face);
- }
- }
- /*初始化综采面有关正规循环率计算的参数
- * param
- * return
- * 函数正常执行返回0,否则返回1
- */
- int regularcycle_rate::init_data_coalminingface_RegularCycle(const std::string& face_id)
- {
- std::string sql = "SELECT coalface_id, head_x , head_y, tail_x, tail_y, ht_radius FROM dat_coalface";//x_offset,y_offset
- if (face_id == "-1")
- {
- sql += ";";
- }
- else
- {
- sql += " where coalface_id = " + face_id + ";";
- }
- std::shared_ptr<CoalMiningArea> pCoalMiningArea = nullptr;
- std::string Error;
- YADB::CDBResultSet DBRes;
- if (0 == sDBConnPool.Query(sql.c_str(),DBRes,Error))
- {
- logn_error(2,"TR-init_data_coalminingface_RegularCycle Query exist error, error: %s", Error.c_str());
- return 1;
- }
- int nCount = DBRes.GetRecordCount( Error );
- if (nCount > 0)
- {
- while ( DBRes.GetNextRecod(Error) )
- {
- bool bRet = true;
- int coalface_id = -1;
- bRet = DBRes.GetField( "coalface_id",coalface_id, Error );
- if (!bRet)
- {
- logn_error(2, "TR-init_data_coalminingface_RegularCycle GetField exist error, error: %s", Error.c_str());
- continue;
- }
- CoalMiningAreaMap::iterator it = m_coalmining_area_list.find(coalface_id);
- if(it != m_coalmining_area_list.end())
- {
- pCoalMiningArea = it->second;
- logn_info(2,"TR-update_data_coalminingface_RegularCycle workface_id: %d", coalface_id);
- }
- else
- {
- pCoalMiningArea = std::make_shared<CoalMiningArea>();
- m_coalmining_area_list.insert(make_pair(coalface_id, pCoalMiningArea));
- logn_info( 2,"TR-add_data_coalminingface_RegularCycle workface_id: %d", coalface_id);
- }
- pCoalMiningArea->coalface_id = coalface_id;
- bRet = DBRes.GetField( "head_x",pCoalMiningArea->x1, Error );
- bRet = DBRes.GetField( "head_y",pCoalMiningArea->y1, Error );
- bRet = DBRes.GetField( "tail_x",pCoalMiningArea->x2, Error );
- bRet = DBRes.GetField( "tail_y",pCoalMiningArea->y2, Error );
- bRet = DBRes.GetField( "ht_radius",pCoalMiningArea->distance, Error );
- pCoalMiningArea->m_max_distance=sqrt((pCoalMiningArea->x1-pCoalMiningArea->x2)*(pCoalMiningArea->x1-pCoalMiningArea->x2)+(pCoalMiningArea->y1-pCoalMiningArea->y2)*(pCoalMiningArea->y1-pCoalMiningArea->y2))*2;
- if(!bRet)
- {
- logn_error(2,"TR-init_data_coalminingface_RegularCycle GetField exist error, error: %s", Error.c_str());
- }
- }
- }
- return 0;
- }
- /*获取采煤机的计划刀数
- * param
- * return
- * 函数正常执行返回0,否则返回1
- */
- int regularcycle_rate::get_data_coalmining_scheduletimes(int workface_id,double& scheduletimes)
- {
- time_t tCurTime = time(NULL);
- std::string curDate = tr_helper::time_t2string_date(tCurTime);
- char strsql[tr_helper::SQL_LENGTH] = {0};
- snprintf(strsql, sizeof(strsql),"SELECT a.schedule_mine_times FROM dat_workface_scheduling a,dat_work_face b where a.workface_id = %d and\
- schedule_date ='%s' and b.work_face_type = 1 and a.workface_id = b.work_face_id;",
- workface_id,curDate.c_str());
- std::shared_ptr<CoalMiningRegularCycle> pCoalRegularCycle = nullptr;
- std::string Error;
- YADB::CDBResultSet DBRes;
- if (0 == sDBConnPool.Query(strsql,DBRes,Error))
- {
- logn_error(2,"TR-get_data_coalmining_scheduletimes Query exist error, error: %s", Error.c_str());
- return 1;
- }
- int nCount = DBRes.GetRecordCount( Error );
- if (nCount > 0)
- {
- while ( DBRes.GetNextRecod(Error) )
- {
- bool bRet = true;
- bRet = DBRes.GetField( "schedule_mine_times",scheduletimes, Error );
- if(!bRet)
- {
- logn_error(2,"TR-get_data_coalmining_scheduletimes GetField exist error, error: %s", Error.c_str());
- }
- break;
- }
- }
- return 0;
- }
- /* 完成半刀,更新刀数值为0.5
- * param
- * reguilarCycle --- 采煤机0.5刀的参数
- * return
- * 函数正常执行返回0,否则返回1
- */
- int regularcycle_rate::update_halfknife_coalmining_Regular_cycle(std::shared_ptr<CoalminingRegularCycleDetail> reguilarCycle )
- {
- char sql_log[tr_helper::SQL_LENGTH] = {'\0'};
- std::string strstarttime = tr_helper::time_t_switch_string(reguilarCycle->start_time);
- time_t tCurTime = time(NULL);
- time_t tStartTime = tCurTime - 3000;
- std::string strCurTime = tr_helper::time_t_switch_string(tCurTime);
- std::string strStartTime = tr_helper::time_t_switch_string(tStartTime);
- snprintf(sql_log, sizeof(sql_log),
- "update his_regular_cycle_detail set detail_value=0.5, end_time = '%s',start_time = '%s' where work_face_id = %d and start_time = '%s';",
- strCurTime.c_str(),
- strStartTime.c_str(),
- reguilarCycle->coalface_id,
- strstarttime.c_str()
- );
- std::string error = "";
- if (sDBConnPool.ExecuteSql(sql_log,error ) < 0 )
- {
- logn_error(2,"TR-update_halfknife_coalmining_Regular_cycle Failed to ExecuteSql:%s,Err=%s\n", sql_log, error.c_str());
- }
- logn_info(2,"TR-update_halfknife_coalmining_Regular_cycle, -update- sql: %s",sql_log);
- return 0;
- }
- /*存储采煤机完成1刀的情况
- * param
- * reguilarCycle --- 采煤机1刀的参数
- * return
- * 函数正常执行返回0,否则返回1
- */
- int regularcycle_rate::Update_data_coalmining_Regular_cycle(std::shared_ptr<CoalminingRegularCycleDetail> reguilarCycle )
- {
- char sql_log[tr_helper::SQL_LENGTH] = {'\0'};
- std::string strstarttime = tr_helper::time_t_switch_string(reguilarCycle->start_time);
- std::string strendtime = tr_helper::time_t_switch_string(reguilarCycle->end_time);
- snprintf(sql_log, sizeof(sql_log),
- "update his_regular_cycle_detail set end_time ='%s', detail_value=0.5,end_x=%.4f,end_y=%.4f \
- where work_face_id = %d and start_time = '%s';",
- strendtime.c_str(),
- reguilarCycle->end_x,
- reguilarCycle->end_y,
- reguilarCycle->coalface_id,
- strstarttime.c_str()
- );
- std::string error = "";
- if (sDBConnPool.ExecuteSql(sql_log,error ) < 0 )
- {
- logn_error(2,"TR-Update_data_coalmining_Regular_cycle Failed to Execute -update- SQL sql=%s,error: %s", sql_log, error.c_str());
- }
- logn_info(2,"TR-Update_data_coalmining_Regular_cycle -update- sql=%s", sql_log);
- return 0;
- }
- /*存储采煤机半刀开始的情况
- *
- * param
- * reguilarCycle --- 采煤机1刀的参数
- *
- * return
- * 函数正常执行返回0,否则返回1
- */
- int regularcycle_rate::store_halfknife_coalmining_Regular_cycle(std::shared_ptr<CoalminingRegularCycleDetail> reguilarCycle )
- {
- char sql_log[tr_helper::SQL_LENGTH] = {'\0'};
- //获取综采面参数
- double schedule_times =5.0;// 数据库未配置,默认取5
- get_data_coalmining_scheduletimes(reguilarCycle->coalface_id,schedule_times);
- std::string strstarttime = tr_helper::time_t_switch_string(reguilarCycle->start_time);
- snprintf( sql_log, sizeof(sql_log),
- "insert IGNORE into his_regular_cycle_detail (work_face_id,detail_type,start_time,detail_value,schedule_value,dept_id,start_x,start_y,end_x,end_y,move_direction) \
- values(%d,%d,'%s',%.4f,%.4f,%d,%.4f,%.4f,%.4f,%.4f,%d);",
- reguilarCycle->coalface_id,
- 1,
- strstarttime.c_str(),
- 0.0,
- schedule_times,
- reguilarCycle->dept_id,
- reguilarCycle->start_x,
- reguilarCycle->start_y,
- 1.0,
- 1.0,
- reguilarCycle->move_direction
- );
- std::string error = "";
- if (sDBConnPool.ExecuteSql(sql_log,error ) < 0 )
- {
- logn_error(2,"TR-store_halfknife_coalmining_Regular_cycle Failed to Execute -insert- SQL sql=%s,error: %s", sql_log, error.c_str());
- return 1;
- }
- logn_info(2,"TR-store_halfknife_coalmining_Regular_cycle -insert- sql=%s", sql_log);
- return 0;
- }
- /*存储采煤机1刀开始的情况
- * param
- * reguilarCycle --- 采煤机1刀的参数
- * return
- * 函数正常执行返回0,否则返回1
- */
- int regularcycle_rate::store_data_coalmining_Regular_cycle(std::shared_ptr<CoalminingRegularCycleDetail> reguilarCycle )
- {
- char sql_log[tr_helper::SQL_LENGTH] = {'\0'};
- //获取综采面参数
- double schedule_times =5.0;// 数据库未配置,默认取5
- get_data_coalmining_scheduletimes(reguilarCycle->coalface_id,schedule_times);
- std::string strstarttime = tr_helper::time_t_switch_string(reguilarCycle->start_time);
- snprintf( sql_log, sizeof(sql_log),
- "insert IGNORE into his_regular_cycle_detail (work_face_id,detail_type,start_time,detail_value,schedule_value,dept_id,start_x,start_y,move_direction) \
- values(%d,%d,'%s',%.4f,%.4f,%d,%.4f,%.4f,%d);",
- reguilarCycle->coalface_id,
- 1,
- strstarttime.c_str(),
- 0.0,
- schedule_times,
- reguilarCycle->dept_id,
- reguilarCycle->start_x,
- reguilarCycle->start_y,
- reguilarCycle->move_direction
- );
- std::string error = "";
- if (sDBConnPool.ExecuteSql(sql_log,error ) < 0 )
- {
- logn_error(2,"TR-store_data_coalmining_Regular_cycle Failed to Execute -insert- SQL sql=%s,error: %s", sql_log, error.c_str());
- return 1;
- }
- logn_info(2,"TR-store_data_coalmining_Regular_cycle -insert- sql=%s", sql_log);
- return 0;
- }
- /*发送采煤机距离固定点距离(现在设置为机头)
- * param
- * vehicle_id --- 车ID
- * dis_record --- 过去一分钟记录的位置的平均距离
- * return
- * 函数正常执行返回0,否则返回1
- */
- int regularcycle_rate::store_data_coalmining_Pos(int workface_id, double dis_record)
- {
- char sql_log[tr_helper::SQL_LENGTH] = {'\0'};
- time_t tCurTime = time(NULL);
- std::string strcurTime = tr_helper::time_t_switch_string(tCurTime);
- CoalMiningAreaMap::iterator it_w= m_coalmining_area_list.find(workface_id);
- double maxdistance =300.0;
- if (it_w!= m_coalmining_area_list.end())
- {
- maxdistance=it_w->second->m_max_distance;
- if (maxdistance < dis_record)
- {
- maxdistance = dis_record;
- }
- }
- snprintf( sql_log, sizeof(sql_log),
- "insert IGNORE into his_draw_position (work_face_id,write_time,avg_distance,max_distance )values(%d,'%s','%f',%f);",
- workface_id,
- strcurTime.c_str(),
- dis_record,
- maxdistance
- );
- std::string error = "";
- if (sDBConnPool.ExecuteSql(sql_log,error ) < 0 )
- {
- logn_error(2,"TR-store_data_coalmining_Pos Failed to Execute -insert- SQL sql=%s,error: %s", sql_log, error.c_str());
- }
- return 0;
- }
- /*计算采煤机的正规循环率
- * param
- * card --- 车卡信息
- * return
- */
- void regularcycle_rate::Calc_CoalMining_RegularCycleRate(std::shared_ptr<coaldrivingface_card> card)
- {
- //当前地图缩放
- double _cur_map_scale = G_CommonData->m_map_scale;
- //求到目的点的距离,和开始点的距离;
- int work_face_id = G_CommonData->get_workface_id(card->m_scard_id);
- CoalMiningRegularCycleMap::iterator it_s = m_coalmining_regularcycle_list.find(work_face_id);
- if (it_s == m_coalmining_regularcycle_list.end())
- {
- return;
- }
- std::shared_ptr<CoalMiningArea> area;
- CoalMiningAreaMap::iterator it_area = m_coalmining_area_list.find(it_s->second->coalface_id);
- if (it_area == m_coalmining_area_list.end())
- {
- return;
- }
- area = it_area->second;
- //获取机头机尾位置
- double x1= area->x1;
- double x2 = area->x2;
- double y1 = area->y1;
- double y2 = area->y2;
- //记录采煤机位置
- time_t loctime = card->rec_time/1000;
- std::string strrecTime = tr_helper::time_t_switch_string(loctime);
- double distance = sqrt((card->x-x1)*(card->x-x1) + (card->y-y1)*(card->y - y1))* _cur_map_scale;
- //char strdistance[60]= {'\0'};
- // snprintf(strdistance, sizeof(strdistance), "%s,%.4f,%.4f",strrecTime.c_str(),distance,fabs(card->final_v));
- //it_s->second->pos_record = it_s->second->pos_record + strdistance;
- string time1 = tr_helper::time_t_switch_string(loctime);
- string time2 = tr_helper::time_t_switch_string(it_s->second->last_time);
- int time_int = loctime - it_s->second->last_time;
- //nt itSize = it_s->second->pos_record.size();
- logn_info(2,"regular_cycle_coalmining: card: %s, time1: %s, time2: %s, time_intervel: %d, size: %d", card->m_scard_id.c_str(),time1.c_str(),time2.c_str(),time_int);
- it_s->second->avg_distance+=distance;
- it_s->second->dis_num++;
- //每隔60秒发送一次采煤机位置信息
- if (loctime - it_s->second->last_time >= 60 )
- {
- it_s->second->avg_distance/=it_s->second->dis_num;
- store_data_coalmining_Pos(work_face_id,it_s->second->avg_distance);
- it_s->second->avg_distance = 0;
- it_s->second->dis_num=0;
- it_s->second->last_time = loctime;
- }
- //只处理位置有变化时
- //if (card->b_pos_change)
- {
- // 刀数统计逻辑
- bool stateChanged = false;
- //判断是否已经开始计算刀数
- if (it_s->second->IsWorking)
- {
- double x = 0.0,y = 0.0;
- if (1 == it_s->second->bDirection) // 机头《-》机尾
- {
- x = x2;
- y = y2;
- //tagNum = 1;
- }
- else if(2 == it_s->second->bDirection) // 机尾《-》机头
- {
- x = x1;
- y = y1;
- //tagNum = 2;
- }
- else
- {
- logn_info(2,"regular_cycle_coalmining error direction1: vehicle_id:%d ",it_s->second->vehicle_id);
- }
- //判断半刀是否完成,完成半刀则更新起始存储位置的刀数值0 - 0.5
- if(!it_s->second->bHalfKnife)
- {
- // 机身中心区域位置
- double center_x = (area->x1 + area->x2)/2.0;
- double center_y = (area->y1 + area->y2)/2.0;
- double half_dis = sqrt((area->x1-area->x2)*(area->x1-area->x2) + (area->y1-area->y2)*(area->y1 - area->y2))*_cur_map_scale/2.0;
- double dis = 0.0;
- // 分机头-》机尾和机尾-》机头两种情况
- if (1 == it_s->second->bDirection) // 机头-》机尾
- {
- dis = sqrt((card->x-area->x1)*(card->x-area->x1) + (card->y-area->y1)*(card->y - area->y1))*_cur_map_scale ;
- }
- else if(2 == it_s->second->bDirection) // 机尾-》机头
- {
- dis = sqrt((card->x-area->x2)*(card->x-area->x2) + (card->y-area->y2)*(card->y - area->y2))*_cur_map_scale ;
- }
- else
- {
- logn_error(2,"TR-regular_cycle_coalmining error direction2: vehicle_id:%d ",it_s->second->vehicle_id);
- }
- if(half_dis < dis)
- {
- //数据上传
- std::shared_ptr<CoalminingRegularCycleDetail> RegularCycle = std::make_shared<CoalminingRegularCycleDetail>();
- RegularCycle->vehicle_id = card->m_nvehicle_id;
- RegularCycle->dept_id = card->m_ndept_id;
- RegularCycle->end_x =card->x;
- RegularCycle->end_y = card->y;
- RegularCycle->end_time = loctime;
- RegularCycle->start_x = it_s->second->start_x;
- RegularCycle->start_y = it_s->second->start_y;
- RegularCycle->start_time = it_s->second->start_time;
- RegularCycle->coalface_id = it_s->second->coalface_id;
- update_halfknife_coalmining_Regular_cycle(RegularCycle);
- it_s->second->bHalfKnife = true;
- //更新状态改变计算参数
- it_s->second->start_time = RegularCycle->end_time;
- it_s->second->start_x = RegularCycle->end_x;
- it_s->second->start_y = RegularCycle->end_y;
- RegularCycle->start_time = RegularCycle->end_time;
- RegularCycle->start_x = RegularCycle->end_x;
- RegularCycle->start_y = RegularCycle->end_y;
- RegularCycle->move_direction = it_s->second->bDirection;
- store_data_coalmining_Regular_cycle(RegularCycle);
- logn_info(2,"TR-Calc_CoalMining_RegularCycleRate halfknife, vehicle id: %d, center_x: %.4f,center_y:%.4f,dis:%.4f time: %s",
- RegularCycle->vehicle_id, center_x, center_y, half_dis, strrecTime.c_str());
- }
- }
- //判断一刀是否完成
- double end_x=0.0,end_y=0.0;
- time_t endtime = loctime;
- double coalfacedis = sqrt((x1-x2)*(x1-x2) + (y1-y2)*(y1-y2))*_cur_map_scale;
- double dis = sqrt((card->x-x)*(card->x-x) + (card->y-y)*(card->y - y))*_cur_map_scale ;
- if (dis< area->distance)
- {
- logn_info(2,"TR-Calc_CoalMining_RegularCycleRate one knife time:%s has arrived ,distance=%.4f\n",strrecTime.c_str(),dis);
- stateChanged = true;
- end_x = card->x;
- end_y = card->y;
- }
- else if (dis < it_s->second->mindistance )
- {
- it_s->second->mindistance = dis;
- it_s->second->mindis_time = loctime;
- it_s->second->end_x = card->x;
- it_s->second->end_y = card->y ;
- }
- else if (loctime - it_s->second->mindis_time > 1800 && it_s->second->mindistance < 0.2 * coalfacedis)
- {
- logn_info(2,"TR-Calc_CoalMining_RegularCycleRate: %s time is too long, is arrived ,distance=%.4f\n", strrecTime.c_str(),dis);
- //防止有障碍不能到机头或机尾的情况
- stateChanged = true;
- end_x = it_s->second->end_x;
- end_y = it_s->second->end_y;
- endtime = it_s->second->mindis_time;
- }
- if (stateChanged)
- {
- //数据上传
- std::shared_ptr<CoalminingRegularCycleDetail> RegularCycle = std::make_shared<CoalminingRegularCycleDetail>();
- RegularCycle->vehicle_id = card->m_nvehicle_id;
- //RegularCycle->coalface_id = m_coalWorkfaceVehicleMap[card->m_nvehicle_id];
- RegularCycle->dept_id = card->m_ndept_id;
- RegularCycle->end_x =end_x;
- RegularCycle->end_y = end_y;
- RegularCycle->end_time = endtime;
- RegularCycle->start_x = it_s->second->start_x;
- RegularCycle->start_y = it_s->second->start_y;
- RegularCycle->start_time = it_s->second->start_time;
- RegularCycle->coalface_id = it_s->second->coalface_id;
- //RegularCycle->schedule_times = it_s->second->schedule_times;
- Update_data_coalmining_Regular_cycle(RegularCycle);
- //更新状态改变计算参数
- it_s->second->start_time = endtime;
- it_s->second->start_x = end_x;
- it_s->second->start_y = end_y;
- //it_s->second->tgPointNum = tagNum;//到达端点后进行目标点切换
- it_s->second->mindistance = FLT_MAX;
- it_s->second->mindis_time = loctime;
- it_s->second->bHalfKnife = false;
- RegularCycle->start_time = endtime;
- RegularCycle->start_x = end_x;
- RegularCycle->start_y = end_y;
- if(1 == it_s->second->bDirection)
- {
- it_s->second->bDirection = 2;
- RegularCycle->move_direction = 2;
- }
- else if(2 == it_s->second->bDirection)
- {
- it_s->second->bDirection = 1;
- RegularCycle->move_direction = 1;
- }
- else
- {
- logn_info(2,"regular_cycle_coalmining error direction3: vehicle_id:%d ",RegularCycle->vehicle_id);
- }
- store_halfknife_coalmining_Regular_cycle(RegularCycle);
- }
- }
- else
- {
- //采煤机是否在机头或这机尾,并改变状态
- double _head_dist = sqrt((card->x-x1)*(card->x-x1) + (card->y-y1)*(card->y - y1));
- double _tail_dist = sqrt((card->x-x2)*(card->x-x2) + (card->y-y2)*(card->y - y2));
- if (_head_dist * _cur_map_scale < area->distance)
- {
- stateChanged = true;
- it_s->second->IsWorking = true;//改变工作状态
- //tagNum = 2;//开始计算正规循环率
- it_s->second->bDirection = 1; //在机头,下一刀运动方向是机头->机尾
- }
- else if (_tail_dist * _cur_map_scale < area->distance)
- {
- stateChanged = true;
- it_s->second->IsWorking = true;//改变工作状态
- //tagNum = 1;//开始计算正规循环率
- it_s->second->bDirection = 2; //在机尾,下一刀运动方向是机尾->机头
- }
- if (stateChanged)
- {
- //更新状态改变计算参数
- it_s->second->start_time = card->rec_time/1000;
- it_s->second->start_x = card->x;
- it_s->second->start_y = card->y;
- //it_s->second->tgPointNum = tagNum;//到达端点后进行目标点切换
- it_s->second->mindistance = FLT_MAX;
- it_s->second->mindis_time = loctime;
- it_s->second->bHalfKnife = false;
- std::shared_ptr<CoalminingRegularCycleDetail> RegularCycle = std::make_shared<CoalminingRegularCycleDetail>();
- RegularCycle->vehicle_id = card->id;
- RegularCycle->dept_id = card->m_ndept_id;
- RegularCycle->start_time = card->rec_time/1000;
- RegularCycle->start_x = card->x;
- RegularCycle->start_y = card->y;
- RegularCycle->move_direction = it_s->second->bDirection;
- RegularCycle->coalface_id = work_face_id;
- store_halfknife_coalmining_Regular_cycle(RegularCycle);
- }
- }
- }
- }
|