123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548 |
- #include "operating_rate.h"
- #include "db_api/CDBSingletonDefine.h"
- #include "log.h"
- #include "three_rates_impl.h"
- #include <numeric>
- #include "common_data.h"
- /*
- * Functon: Constructor
- */
- operating_rate::operating_rate():m_bzero(false),m_brestart(true)
- {
- init_coaldrivingface_vehicle();
- }
- /*
- * Functon: Destructor
- */
- operating_rate::~operating_rate()
- {
- }
- /*
- * Functon: Init drivingface and coalface vehicle
- * Parameters: void
- * Returns: int, returns 0 normally, otherwise it returns 1
- * Throws: void
- */
- int operating_rate::init_coaldrivingface_vehicle()
- {
- int ret = 0;
- m_coaldrivingface_map.clear();
- // init coaldrivingface card
- const char * sql_drivingface = "select a.drivingface_id,c.vehicle_type_id, b.vehicle_id, b.card_id,b.dept_id from dat_drivingface_vehicle a, dat_vehicle_extend b ,dat_vehicle as c where a.vehicle_id = b.vehicle_id and a.vehicle_id = c.vehicle_id;";
- const char * sql_coalface = "select a.coalface_id, c.vehicle_type_id, b.vehicle_id, b.card_id,b.dept_id from dat_coalface_vehicle a, dat_vehicle_extend b ,dat_vehicle as c where a.vehicle_id = b.vehicle_id and a.vehicle_id = c.vehicle_id;";
- std::string Error;
- YADB::CDBResultSet DBRes;
- if (0 == sDBConnPool.Query(sql_drivingface,DBRes,Error))
- {
- logn_error(2,"TR-init_coaldrivingface_vehicle drivingface 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 vehicle_id = 0;
- int ndept_id = 0;
- std::string card_id;
- int vehicle_type_id = 0;
- int db_work_face_id = 0;
- bRet = DBRes.GetField( "vehicle_id",vehicle_id, Error );
- bRet = DBRes.GetField( "card_id",card_id, Error );
- bRet = DBRes.GetField( "dept_id",ndept_id, Error );
- DBRes.GetField( "vehicle_type_id",vehicle_type_id, Error );
- DBRes.GetField( "drivingface_id",db_work_face_id, Error );
- if(!bRet)
- {
- logn_error(2,"TR-init_coaldrivingface_vehicle drivingface GetField exist error, error: %s", Error.c_str());
- }
- printf("coaldrivingface_card cardid=%s,vehicleid=%d \n",card_id.c_str(),vehicle_id);
- std::shared_ptr<coaldrivingface_card> dr_card = std::make_shared<coaldrivingface_card>();
- dr_card->m_scard_id = card_id;
- dr_card->m_nvehicle_id = vehicle_id;
- dr_card->m_ndept_id = ndept_id;
- dr_card->m_vehicle_type = vehicle_type_id;
- dr_card->m_work_face_id = db_work_face_id;
- dr_card->m_ncard_type = THREE_RATES_CARD_TYPE::CT_TUNNELBORING_MACHINE;
- get_vibratethrethold(dr_card,dr_card->m_nshake_threshold);
- m_coaldrivingface_map.insert(make_pair(vehicle_id,dr_card));
- }
- }
- else
- {
- ret = 1;
- // there is no drivingface vehicle in db
- logn_warn(2,"TR-there is no drivingface vehicle in db");
- }
- if (0 == sDBConnPool.Query(sql_coalface,DBRes,Error))
- {
- logn_error(2,"TR-init_coaldrivingface_vehicle coalface Query exist error, error: %s", Error.c_str());
- return 1;
- }
- nCount = DBRes.GetRecordCount( Error );
- if (nCount > 0)
- {
- while ( DBRes.GetNextRecod(Error) )
- {
- bool bRet = true;
- int vehicle_id = 0;
- std::string card_id = "";
- int ndept_id = 0;
- int vehicle_type_id = 0;
- int db_work_face_id = 0;
- bRet = DBRes.GetField( "vehicle_id",vehicle_id, Error );
- bRet = DBRes.GetField( "card_id",card_id, Error );
- bRet = DBRes.GetField( "dept_id",ndept_id, Error );
- DBRes.GetField( "vehicle_type_id", vehicle_type_id, Error );
- DBRes.GetField( "coalface_id",db_work_face_id, Error );
- if(!bRet)
- {
- logn_error(2,"TR-init_coaldrivingface_vehicle coalface GetField exist error, error: %s", Error.c_str());
- }
- std_info("coaldrivingface_card cardid=%s,vehicleid=%d \n",card_id.c_str(),vehicle_id);
- std::shared_ptr<coaldrivingface_card> co_card = std::make_shared<coaldrivingface_card>();
- co_card->m_scard_id = card_id;
- co_card->m_nvehicle_id = vehicle_id;
- co_card->m_ndept_id = ndept_id;
- co_card->m_vehicle_type = vehicle_type_id;
- co_card->m_work_face_id = db_work_face_id;
- co_card->m_ncard_type = THREE_RATES_CARD_TYPE::CT_COALMINING_MACHINE;
- get_vibratethrethold(co_card,co_card->m_nshake_threshold);
- m_coaldrivingface_map.insert(make_pair(vehicle_id,co_card));
- }
- }
- else
- {
- ret = 1;
- // there is no coalface vehicle in db
- logn_warn(2,"TR-there is no coalface vehicle in db");
- }
- return ret;
- }
- /*
- * Functon: Update the unprocessed record across days 零点时关机再开机动作
- * Parameters: void
- * Returns: int, returns 0 normally, otherwise it returns 1
- * Throws: void
- */
- int operating_rate::zero_update_unprocess_record(time_t tCurTime)
- {
- char strsql[tr_helper::SQL_LENGTH] = {0};
- /*const char * sql = "select a.vehicle_id,a.start_up_time,a.schedule_work_time,a.dept_id,b.card_id \
- from his_startup_detail a, dat_vehicle_extend b \
- where a.proc_tag = 0 and a.vehicle_id = b.vehicle_id;";
- */
- sprintf(strsql,"(SELECT a.work_face_id,a.start_up_time,a.schedule_work_time,a.dept_id,f.card_id, a.proc_tag "
- "FROM his_startup_detail a, (select e.card_id, b.coalface_id "
- "from dat_vehicle_extend e, dat_coalface_vehicle b "
- "where b.vehicle_id = e.vehicle_id) f "
- "WHERE a.proc_tag = 0 and f.coalface_id = a.work_face_id)"
- "union"
- "(SELECT a.work_face_id,a.start_up_time,a.schedule_work_time,a.dept_id,f.card_id, a.proc_tag "
- "FROM his_startup_detail a, (select e.card_id, b.drivingface_id "
- "from dat_vehicle_extend e, dat_drivingface_vehicle b "
- "where b.vehicle_id = e.vehicle_id) f "
- "WHERE a.proc_tag = 0 and f.drivingface_id = a.work_face_id);");
- // 零点分割,开机时间更新到“xxxx-xx-xx 00:00:00”
- time_t tTime = tCurTime + 1;
- std::string Error;
- YADB::CDBResultSet DBRes;
- if (0 == sDBConnPool.Query(strsql,DBRes,Error))
- {
- logn_error(2,"TR-zero_update_unprocess_record Query exist error, error: %s", Error.c_str());
- return 1;
- }
- int nCount = DBRes.GetRecordCount( Error );
- if (nCount <= 0)
- {
- logn_errno(2,"zero_update_unprocess_record select no record!");
- return 1;
- }
- while ( DBRes.GetNextRecod(Error) )
- {
- bool bRet = true;
- // 局部变量初始化
- int nWorkfaceId = 0;
- std::string strStartTime = "";
- double fScheduleWorkTime = 0.0;
- int nDeptId = -1;
- std::string sCardId ="";
- // 取数据表记录
- bRet = DBRes.GetField( "work_face_id",nWorkfaceId, Error );
- bRet = DBRes.GetField( "start_up_time",strStartTime, Error );
- bRet = DBRes.GetField( "schedule_work_time",fScheduleWorkTime, Error );
- bRet = DBRes.GetField( "dept_id",nDeptId, Error );
- bRet = DBRes.GetField( "card_id",sCardId, Error );
- if(!bRet)
- {
- logn_error(2,"TR-zero_update_unprocess_record GetField exist error, error: %s", Error.c_str());
- }
- // 时间处理
- std::string strCurTime = tr_helper::time_t_switch_string(tCurTime);
- time_t tStartTime = tr_helper::string_switch_time_t(strStartTime);
- double timeInterval = 0;
- if (tCurTime > tStartTime)
- {
- timeInterval = (double)(tCurTime - tStartTime)/(double)SEC_TO_HOUR;
- }
- // 处理未关机的记录
- snprintf(strsql, sizeof(strsql), "Update his_startup_detail set shut_down_time ='%s',real_startup_time=%.3f, proc_tag = 1 where start_up_time='%s' and work_face_id=%d;",
- strCurTime.c_str(),timeInterval, strStartTime.c_str(),nWorkfaceId);
- std::string Error;
- if ( sDBConnPool.ExecuteSql( strsql, Error ) < 0 )
- {
- logn_error(2,"TR-Update_unprocess_record Failed to Execute -update- SQL sql=%s, error: %s", strsql, Error.c_str());
- }
- logn_info(2,"TR-Update_unprocess_record zero time:%s -update- SQL sql=%s", strStartTime.c_str(),strsql);
- // 关机后重开
- strStartTime = tr_helper::time_t_switch_string(tTime);
- // 零点插入时重新获取计划开机时间
- double zeroScheduleStartupTime = 0.0;
- std::string strDate = strStartTime.substr(0,10); // 截取日期字符串前10位
- zeroScheduleStartupTime = get_schedulestartuptime(nWorkfaceId, strDate);
- // 写库
- snprintf(strsql, sizeof(strsql),
- "INSERT IGNORE INTO his_startup_detail(work_face_id, start_up_time,schedule_work_time,dept_id) VALUES(%d, '%s',%.3f,%d);",
- nWorkfaceId,strStartTime.c_str(),zeroScheduleStartupTime,nDeptId);
- if ( sDBConnPool.ExecuteSql( strsql, Error ) < 0 )
- {
- logn_error(2,"TR-Update_unprocess_record Failed to Execute -insert- SQL sql=%s, error: %s", strsql, Error.c_str());
- }
- logn_info(2,"TR-zero reinsert time:%s -insert- SQL sql=%s", strStartTime.c_str(),strsql);
- }
- return 0;
- }
- /*
- * Functon: Update the unprocessed record when restarting
- * Parameters: void
- * Returns: int, returns 0 normally, otherwise it returns 1
- * Throws: void
- */
- int operating_rate::restart_update_unprocess_record()
- {
- char strsql[tr_helper::SQL_LENGTH] = {0};
- const char * sql = "select work_face_id, start_up_time from his_startup_detail where proc_tag=0;";
- std::string Error;
- YADB::CDBResultSet DBRes;
- if (0 == sDBConnPool.Query(sql,DBRes,Error))
- {
- logn_error(2,"TR-restart_update_unprocess_record 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 workface_id = 0;
- std::string start_time;
- bRet = DBRes.GetField( "work_face_id",workface_id, Error );
- bRet = DBRes.GetField( "start_up_time",start_time, Error );
- if(!bRet)
- {
- logn_error(2,"TR-restart_update_unprocess_record GetField exist error, error: %s", Error.c_str());
- }
- time_t tcur_time = time(NULL);
- std::string cur_time = tr_helper::time_t_switch_string(tcur_time);
- time_t tstart_time = tr_helper::string_switch_time_t(start_time);
- double time_interval = 0;
- if (tcur_time > tstart_time)
- {
- time_interval = (double )(tcur_time - tstart_time)/(double )operating_rate::SEC_TO_HOUR;
- }
- snprintf(strsql, sizeof(strsql),
- "Update his_startup_detail set shut_down_time ='%s',real_startup_time=%.3f, proc_tag = 1 where start_up_time='%s' and work_face_id=%d;",
- cur_time.c_str(),time_interval, start_time.c_str(),workface_id);
- if ( sDBConnPool.ExecuteSql( strsql, Error ) < 0 )
- {
- logn_error(2,"TR-restart_update_unprocess_record Failed to Execute -update- SQL sql=%s, error: %s", strsql, Error.c_str());
- }
- logn_info(2,"TR-restart_update_unprocess_record time:%s -update- sql=%s", start_time.c_str(),strsql);
- }
- }
- return 0;
- }
- /*
- * Functon: Get the schedule startup time of vihicle
- * Parameters: void
- * Returns: void
- * Throws: void
- */
- void operating_rate::get_schedulestartuptime(int cardType, std::string strCard, double &scheduleStartupTime,std::string strDate)
- {
- char strsql[tr_helper::SQL_LENGTH] = {0};
- // 查计划开机时间
- if(THREE_RATES_CARD_TYPE::CT_COALMINING_MACHINE == cardType)
- {
- sprintf(strsql,"SELECT schedule_startup_time FROM dat_workface_scheduling "
- "WHERE schedule_date='%s' "
- "and workface_id = (select coalface_id from dat_coalface_vehicle "
- "where vehicle_id = (select vehicle_id from dat_vehicle_extend "
- "where card_id = %s));",strDate.c_str(),strCard.c_str());
- scheduleStartupTime = 0.0; // 采煤机计划开机时间数据库未配置,默认取0
- }
- else if(THREE_RATES_CARD_TYPE::CT_TUNNELBORING_MACHINE == cardType)
- {
- sprintf(strsql, "SELECT schedule_startup_time FROM dat_workface_scheduling "
- "WHERE schedule_date='%s' "
- "and workface_id = (select drivingface_id from dat_drivingface_vehicle "
- "where vehicle_id = (select vehicle_id from dat_vehicle_extend "
- "where card_id = %s));",strDate.c_str(),strCard.c_str());
- scheduleStartupTime = 0.0; // 掘进机计划开机时间数据库未配置,默认取0
- }
- std::string Error;
- YADB::CDBResultSet DBRes;
- if (0 == sDBConnPool.Query(strsql,DBRes,Error))
- {
- logn_error(2,"TR-get_schedulestartuptime Query exist error, error: %s", Error.c_str());
- return ;
- }
- int nCount = DBRes.GetRecordCount( Error );
- if (nCount > 0)
- {
- while ( DBRes.GetNextRecod(Error) )
- {
- bool bRet = true;
- bRet = DBRes.GetField( "schedule_startup_time",scheduleStartupTime, Error );
- if(!bRet)
- {
- logn_error(2,"TR-get_schedulestartuptime GetField exist error, error: %s", Error.c_str());
- }
- break;
- }
- }
- return ;
- }
- double operating_rate::get_schedulestartuptime(int work_face_id,const std::string &strDate)
- {
- char strsql[tr_helper::SQL_LENGTH] = {0};
- // 查计划开机时间
- sprintf(strsql, "SELECT schedule_startup_time FROM dat_workface_scheduling "
- "WHERE schedule_date='%s' and workface_id = %d;",strDate.c_str(),work_face_id);
- std::string Error;
- YADB::CDBResultSet DBRes;
- if (0 == sDBConnPool.Query(strsql,DBRes,Error))
- {
- logn_error(2,"TR-get_schedulestartuptime Query exist error, error: %s", Error.c_str());
- return 0.0;
- }
- double scheduleStartupTime = 0.0;
- int nCount = DBRes.GetRecordCount( Error );
- if (nCount > 0)
- {
- while ( DBRes.GetNextRecod(Error) )
- {
- bool bRet = true;
- bRet = DBRes.GetField( "schedule_startup_time",scheduleStartupTime, Error );
- if(!bRet)
- {
- logn_error(2,"TR-get_schedulestartuptime GetField exist error, error: %s", Error.c_str());
- }
- break;
- }
- }
- return scheduleStartupTime;
- }
- /*
- * Functon: Get vibrate threthold of vihicle
- * Parameters: void
- * Returns: void
- * Throws: void
- */
- void operating_rate::get_vibratethrethold(std::shared_ptr<coaldrivingface_card> card, int& threshold)
- {
- // 查卡号对应的震动阈值
- char strsql[tr_helper::SQL_LENGTH] = {0};
- if(tr_helper::is_coalminingface(card))
- {
- snprintf(strsql,sizeof(strsql),"SELECT a.shake_threshold FROM dat_coalface_vehicle a, dat_vehicle_extend b WHERE a.vehicle_id = b.vehicle_id AND b.card_id = %s;",card->m_scard_id.c_str());
- }
- else if(tr_helper::is_drivingface(card))
- {
- snprintf(strsql,sizeof(strsql), "SELECT a.shake_threshold FROM dat_drivingface_vehicle a, dat_vehicle_extend b WHERE a.vehicle_id = b.vehicle_id AND b.card_id = %s;",card->m_scard_id.c_str());
- }
- std::string Error;
- YADB::CDBResultSet DBRes;
- if (0 == sDBConnPool.Query(strsql,DBRes,Error))
- {
- logn_error(2,"TR-get_vibratethrethold Query exist error, error: %s", Error.c_str());
- return ;
- }
- int nCount = DBRes.GetRecordCount( Error );
- if (nCount > 0)
- {
- while ( DBRes.GetNextRecod(Error) )
- {
- bool bRet = true;
- bRet = DBRes.GetField( "shake_threshold",threshold, Error );
- if(!bRet)
- {
- logn_error(2,"TR-get_vibratethrethold GetField exist error, error: %s", Error.c_str());
- }
- break;
- }
- }
- return ;
- }
- /*
- * Functon: Open machine
- * Parameters: card, coalface or drivingface card
- * Returns: int, returns 0 normally, otherwise it returns 1
- * Throws: void
- */
- int operating_rate::open_machine(std::shared_ptr<coaldrivingface_card> card)
- {
- card->m_bopen = true;
- time_t tCurTime = time(NULL);
- card->m_tstartup_time = tCurTime;
- std::string strStartTime = tr_helper::time_t_switch_string(card->m_tstartup_time);
- // 从工作面排班表中获取计划开机时间
- double scheduleStartupTime = 0.0;
- int deptId = card->m_ndept_id;
- int nWorkfaceID = G_CommonData->get_workface_id(card->m_scard_id);
- if (nWorkfaceID == -1)
- {
- logn_errno(2,"TR-open_machine: WorkFaceId Not Find By Card=%s ", card->m_scard_id.c_str());
- }
- std::string strDate = strStartTime.substr(0,10); // 截取日期字符串前10位
- scheduleStartupTime = get_schedulestartuptime(nWorkfaceID, strDate);
- logn_info(2,"TR-open_machine get_schedulestartuptime card=%s,scheduleStartupTime-%.4f", card->m_scard_id.c_str(),scheduleStartupTime);
- char sql[tr_helper::SQL_LENGTH] = { 0 };
- snprintf(sql, sizeof(sql),
- "INSERT IGNORE INTO his_startup_detail(work_face_id, start_up_time,schedule_work_time,dept_id) VALUES(%d, '%s',%.3f,%d);",
- nWorkfaceID,strStartTime.c_str(),scheduleStartupTime,deptId);
- std::string Error;
- if ( sDBConnPool.ExecuteSql( sql, Error ) < 0 )
- {
- logn_error(2,"TR-open_machine Failed to Execute -insert- SQL sql=%s,error: %s", sql, Error.c_str());
- return -1;
- }
- logn_info(2,"TR-open_machine -insert- sql=%s", sql);
- logn_info(2,"open_machine time: %s,card: %s,open state: %d,scheduleTime: %.3f,deptId: %d,Update: %s",
- strStartTime.c_str(),card->m_scard_id.c_str(), card->m_bopen,scheduleStartupTime,deptId,sql);
- return 0;
- }
- /*
- * Functon: Close machine
- * Parameters: card, coalface or drivingface card
- * Parameters: bTimeOut 是否超时
- * Returns: int, returns 0 normally, otherwise it returns 1
- * Throws: void
- */
- int operating_rate::close_machine(std::shared_ptr<coaldrivingface_card> card, bool bTimeOut /*= true*/)
- {
- card->m_bopen = false;
- char sql[tr_helper::SQL_LENGTH] = { 0 };
- time_t tCurTime = time(NULL);
- if(bTimeOut) // 超时关机,因为延时值不是有效开机时间,需减去延时值
- {
- tCurTime -= three_rates_impl::_instance()->m_shutdown_timeout_threshold;
- }
- std::string strCurTime = tr_helper::time_t_switch_string(tCurTime);
- std::string strStartTime = tr_helper::time_t_switch_string(card->m_tstartup_time);
- int nWorkfaceID = G_CommonData->get_workface_id(card->m_scard_id);
- if (nWorkfaceID == -1)
- {
- logn_errno(2,"TR-open_machine: WorkFaceId Not Find By Card=%s ", card->m_scard_id.c_str());
- }
- double timeInterval = 0;
- if (tCurTime > card->m_tstartup_time)
- {
- timeInterval = (double )(tCurTime - card->m_tstartup_time)/(double )operating_rate::SEC_TO_HOUR;
- }
- snprintf(sql, sizeof(sql), "Update his_startup_detail set shut_down_time ='%s',real_startup_time=%.3f, proc_tag = 1 where start_up_time='%s' and work_face_id=%d;",
- strCurTime.c_str(),timeInterval, strStartTime.c_str(),nWorkfaceID);
- std::string Error;
- if ( sDBConnPool.ExecuteSql( sql, Error ) < 0 )
- {
- logn_error(2,"TR-close_machine Failed to Execute -update- SQL sql=%s,error: %s", sql, Error.c_str());
- }
- logn_info(2,"close_machine card:%s time: %s, open state: %d, Update: %s",card->m_scard_id.c_str(), strCurTime.c_str(), card->m_bopen,sql);
- // 循环队列置位
- for (unsigned int index = 0; index < card->m_cb_state.size(); ++index)
- {
- card->m_cb_state[index] = 0;
- }
- return 0;
- }
- /*
- * Functon: Store machine state /存储采煤机/掘进机开关机时间段到数据库
- * Parameters: card, coalface or drivingface card
- * Returns: int, returns 0 normally, otherwise it returns 1
- * Throws: void
- */
- int operating_rate::store_machine_state(std::shared_ptr<coaldrivingface_card> card)
- {
- // 分割跨日的开机记录
- this->zeroes_update();
- if(m_brestart) // 采集重启,更新his_startup_detail表中未处理的记录
- {
- m_brestart = false;
- restart_update_unprocess_record();
- }
- if(tr_helper::is_drivingface(card) || tr_helper::is_coalminingface(card))
- {
- int sum = std::accumulate(card->m_cb_state.begin(), card->m_cb_state.end(), 0);
- //日志
- logn_info(2,"TR-three_rates_impl::run, coaldrivingface card:%s, "
- "card->m_cb_state[0]:%d, card->m_cb_state[1]:%d,card->m_cb_state[2]:%d,card->m_cb_state[3] :%d, "
- "card->m_cb_state[4]:%d,card->m_cb_state[5]:%d,card->m_cb_state[6]:%d, card->m_cb_state[7]:%d,"
- "card->m_cb_state[8]:%d,card->m_cb_state[9]",
- card->m_scard_id.c_str(),card->m_cb_state[0],card->m_cb_state[1],card->m_cb_state[2],card->m_cb_state[3]
- ,card->m_cb_state[4],card->m_cb_state[5],card->m_cb_state[6],card->m_cb_state[7],
- card->m_cb_state[8],card->m_cb_state[9]);
- // 判断采煤机/掘进机惯导开关标
- int threshold = card->m_nshake_threshold;
- int openThreshold = STARTUP_STATE_COUNT * threshold;
- if(sum >= openThreshold && !card->m_bopen) // 设置为开机,开机的时候insert card_id,start_up_time,schedule_startup_time,dept_id字段
- {
- open_machine(card);
- }
- int closeThreshold = SHUTDOWN_STATE_COUNT * threshold;
- bool bCloseCondition = sum <= closeThreshold && card->m_tstartup_time != 0 && card->m_bopen;
- if(bCloseCondition) // 设置为关机,关机的时候update关机时间shut_down_time,real_startup_time字段
- {
- close_machine(card,false);
- }
- logn_info(2,"TR-three_rates_impl::run, coaldrivingface card:%s, threshold:%d, openThreshold:%d,closThreshold:%d,bCloseCondition :%d, bopen:%d,sum:%d",
- card->m_scard_id.c_str(),threshold,openThreshold,closeThreshold,bCloseCondition,card->m_bopen,sum);
- return 0;
- }
- else
- {
- return 1;
- }
- }
- //判断是否零点 再更新
- void operating_rate::zeroes_update()
- {
- // 分割跨日的开机记录
- time_t tCurTime = time(NULL);
- std::string strCurTime = tr_helper::time_t_switch_string(tCurTime);
- std::string substrCurTime = strCurTime.substr(11,8); // 截取日期字符串后八位
- if("23:59:59" == substrCurTime && !m_bzero)
- {
- m_bzero = true;
- zero_update_unprocess_record(tCurTime);
- logn_info(2,"zeroes_update zero flow. zero time: %s", strCurTime.c_str());
- }
- if("00:00:02" == substrCurTime)
- {
- m_bzero = false; // 后续零点初始化
- }
- }
|