Browse Source

Fix Reports to go new day for Session Start instead of Session End

AGP
Evgeny Gagua 2 years ago
parent
commit
505cba9f61
  1. 37
      lib/App/common/SQLite_dataBinder.cpp
  2. 1244
      lib/App/common/kernelModuleOnvifObserver.cpp
  3. 36
      lib/App/common/serverMySQL_dataBinder.cpp
  4. 3
      lib/App/serva/servaKernel.cpp
  5. 49
      lib/App/serva/servaSessionManager.cpp

37
lib/App/common/SQLite_dataBinder.cpp

@ -689,7 +689,7 @@ bool sqliteDBC::addDeviceDraw( uint32_t DBID, uint8_t type, uint8_t lrf, void *t
};
void sqliteDBC::updateStats( bool evt, bool video, uint8_t ses_status ){
if (m_bStaIsConnected ) {
if ( m_bStaIsConnected ) {
char tQBuf[1024];
switch ( ses_status ) {
case SESSION_CONTINUE:{
@ -707,21 +707,7 @@ void sqliteDBC::updateStats( bool evt, bool video, uint8_t ses_status ){
break;
};
case SESSION_START:{
sprintf( tQBuf, "INSERT INTO `days`(`year`,`month`,`day`,`session_count`,`session_closed`) VALUES(%s,%s,%s,1,0) ON CONFLICT(`year`,`month`,`day`) DO UPDATE SET `session_count`=`session_count`+1, `session_closed`=0",
m_sCRepInfo.YEAR, m_sCRepInfo.MONTH, m_sCRepInfo.DAY );
#ifdef DEBUG_ALL
LOG( tQBuf );
#endif
m_pDataStatistics->SilentQuery( tQBuf );
break;
};
case SESSION_END:{
sprintf( tQBuf, "INSERT INTO `days`(`year`,`month`,`day`,`session_count`,`session_closed`) VALUES(%s,%s,%s,0,1) ON CONFLICT(`year`,`month`,`day`) DO UPDATE SET `session_closed`=1",
m_sCRepInfo.YEAR, m_sCRepInfo.MONTH, m_sCRepInfo.DAY );
#ifdef DEBUG_ALL
LOG( tQBuf );
#endif
m_pDataStatistics->SilentQuery( tQBuf );
//Check New Day Reports
REPORT_DIRINFO tRR = {0};
fillRDF( time( NULL ), tRR );
if( tRR.ts > m_sCRepInfo.ts ) {
@ -748,13 +734,30 @@ void sqliteDBC::updateStats( bool evt, bool video, uint8_t ses_status ){
m_bRepIsConnected = true;
LOG("Report Connected!");
// Create New Day Record
sprintf(tQBuf, "INSERT INTO `days`(`year`,`month`,`day`,`session_count`,`session_closed`) VALUES(%s,%s,%s,0,1) ON CONFLICT(`year`,`month`,`day`) DO UPDATE SET `session_count`=`session_count`+1, `session_closed`=1",
sprintf(tQBuf, "INSERT INTO `days`(`year`,`month`,`day`,`session_count`,`session_closed`) VALUES(%s,%s,%s,0,0) ON CONFLICT(`year`,`month`,`day`) DO UPDATE SET `session_count`=`session_count`+1, `session_closed`=0",
m_sCRepInfo.YEAR, m_sCRepInfo.MONTH, m_sCRepInfo.DAY );
LOG( tQBuf );
m_pDataStatistics->SilentQuery( tQBuf );
};
};
};
// Create New record
sprintf( tQBuf, "INSERT INTO `days`(`year`,`month`,`day`,`session_count`,`session_closed`) VALUES(%s,%s,%s,1,0) ON CONFLICT(`year`,`month`,`day`) DO UPDATE SET `session_count`=`session_count`+1, `session_closed`=0",
m_sCRepInfo.YEAR, m_sCRepInfo.MONTH, m_sCRepInfo.DAY );
#ifdef DEBUG_ALL
LOG( tQBuf );
#endif
m_pDataStatistics->SilentQuery( tQBuf );
break;
};
case SESSION_END:{
sprintf( tQBuf, "INSERT INTO `days`(`year`,`month`,`day`,`session_count`,`session_closed`) VALUES(%s,%s,%s,0,1) ON CONFLICT(`year`,`month`,`day`) DO UPDATE SET `session_closed`=1",
m_sCRepInfo.YEAR, m_sCRepInfo.MONTH, m_sCRepInfo.DAY );
#ifdef DEBUG_ALL
LOG( tQBuf );
#endif
m_pDataStatistics->SilentQuery( tQBuf );
break;
};
};

1244
lib/App/common/kernelModuleOnvifObserver.cpp
File diff suppressed because it is too large
View File

36
lib/App/common/serverMySQL_dataBinder.cpp

@ -49,7 +49,7 @@ uint64_t servaMySQLDBC::addMediaQueueRecord( CSTR uuid, uint64_t module_id, uint
sprintf( tQBuf, "INSERT INTO `media_queue` SET `module_id`=%" PRIu64 ", `session_id`=%" PRIu64 ", `ts`=%d, `tsms`=%d, `uuid`='%s', `width`=%d, `height`=%d, `fps`=%d, `fmt`='%s', `status`=0, `process`=0",
module_id, session_id, ts, tsms, uuid, width, height, fps, fmt
);
#ifdef DEBUG
#ifdef DEBUG_ALL
LOG(tQBuf);
#endif
RetVal = m_pDatabase->QueryID( tQBuf );
@ -201,6 +201,9 @@ uint64_t servaMySQLDBC::getBottomLRF( uint64_t id ){
char tQBuf[MAX_PATH_LEN];
AAssoc *result;
sprintf( tQBuf, "SELECT `id` FROM `lrf_sensors` WHERE `role`='B' AND `mojo_id`=%d", id );
#ifdef DEBUG_ALL
LOG(tQBuf);
#endif
result = m_pDatabase->Query( tQBuf );
if( result!= NULL ) {
if( result->size() > 0 ) {
@ -224,7 +227,9 @@ uint32_t servaMySQLDBC::getCloudLTS( uint8_t Obj, uint64_t id ){
char tQBuf[MAX_PATH_LEN];
AAssoc *result;
sprintf( tQBuf, "SELECT `ts` FROM `mem_online_cloud` WHERE `object_id`=%" PRIu64 " AND `object_type`=%d", id, Obj );
LOG( tQBuf );
#ifdef DEBUG_ALL
LOG(tQBuf);
#endif
result = m_pDatabase->Query( tQBuf );
if( result!= NULL ) {
if( result->size() > 0 ) {
@ -248,6 +253,9 @@ uint8_t servaMySQLDBC::getCloudStatus( uint8_t Obj, uint64_t id ){
char tQBuf[MAX_PATH_LEN];
AAssoc *result;
sprintf( tQBuf, "SELECT `status` FROM `mem_online_cloud` WHERE `object_id`=%" PRIu64 " AND `object_type`=%d", id, Obj );
#ifdef DEBUG_ALL
LOG(tQBuf);
#endif
result = m_pDatabase->Query( tQBuf );
if( result!= NULL ) {
if( result->size() > 0 ) {
@ -271,6 +279,9 @@ uint64_t servaMySQLDBC::getRecentMediaId(){
char tQBuf[MAX_PATH_LEN];
AAssoc *result;
sprintf( tQBuf, "SELECT `id` FROM `media_queue` WHERE `status`=1 LIMIT 1" );
#ifdef DEBUG_ALL
LOG(tQBuf);
#endif
result = m_pDatabase->Query( tQBuf );
if( result!= NULL ) {
if( result->size() > 0 ) {
@ -294,6 +305,9 @@ DBC_RPC_MEDIA_INFO *servaMySQLDBC::getRemoteMediaInfo( uint64_t id ){
char tQBuf[MAX_PATH_LEN];
AAssoc *result;
sprintf( tQBuf, "SELECT * FROM `media_queue` WHERE `id`=%" PRIu64, id );
#ifdef DEBUG_ALL
LOG(tQBuf);
#endif
result = m_pDatabase->Query( tQBuf );
if( result!= NULL ) {
if (result->size() > 0) {
@ -346,6 +360,9 @@ DBC_RPC_MEDIA_INFO_EX *servaMySQLDBC::getRemoteMediaInfoEx( uint64_t id ){
char tQBuf[MAX_PATH_LEN];
AAssoc *result;
sprintf( tQBuf, "SELECT * FROM `media_queue` WHERE `id`=%" PRIu64, id );
#ifdef DEBUG_ALL
LOG(tQBuf);
#endif
result = m_pDatabase->Query( tQBuf );
if( result!= NULL ) {
if (result->size() > 0) {
@ -406,6 +423,9 @@ uint64_t servaMySQLDBC::getTrackIdByMojo( uint64_t id ){
char tQBuf[MAX_PATH_LEN];
AAssoc *result;
sprintf( tQBuf, "SELECT `track_id` FROM `metro_modules` WHERE `id`=%" PRIu64, id );
#ifdef DEBUG_ALL
LOG(tQBuf);
#endif
result = m_pDatabase->Query( tQBuf );
if( result!= NULL ) {
if( result->size() > 0 ) {
@ -429,6 +449,9 @@ uint64_t servaMySQLDBC::getUpperLRF( uint64_t id ){
char tQBuf[MAX_PATH_LEN];
AAssoc *result;
sprintf( tQBuf, "SELECT `id` FROM `lrf_sensors` WHERE `role`='U' AND `mojo_id`=%d", id );
#ifdef DEBUG_ALL
LOG(tQBuf);
#endif
result = m_pDatabase->Query( tQBuf );
if( result!= NULL ) {
if( result->size() > 0 ) {
@ -450,6 +473,9 @@ bool servaMySQLDBC::putIntoLog( CSTR A, CSTR B, CSTR C ){
if( m_bIsConnected ){
char tQBuf[MAX_PATH_LEN];
sprintf( tQBuf, "INSERT INTO `server_log_messages` SET lvl = '%s', `ts`='%s', `msg`='%s'", A, B, C );
#ifdef DEBUG_ALL
LOG(tQBuf);
#endif
m_pDatabase->SilentQuery( tQBuf );
} else LOG("Not Connected!");
};
@ -460,6 +486,9 @@ uint64_t servaMySQLDBC::registerMojo( CSTR A, CSTR B ){
if( m_bIsConnected ){
AAssoc *result;
sprintf( tQBuf, "SELECT `id` FROM `metro_modules` WHERE `IP4`='%s' AND `identity`='%s'", A, B );
#ifdef DEBUG_ALL
LOG(tQBuf);
#endif
result = m_pDatabase->Query( tQBuf );
if( result!= NULL ) {
if( result->size() > 0 ) {
@ -542,6 +571,9 @@ uint32_t servaMySQLDBC::registerVideoTransfer( uint32_t srcNode, CSTR uuid, uint
char tQBuf[MAX_PATH_LEN];
sprintf( tQBuf, "INSERT INTO `media_queue` SET `src`=%d, `uuid`='%s', `size`=%d, `fmt`='%s', `ts`=%d",
srcNode, uuid, dataSize, fmt, ts );
#ifdef DEBUG_ALL
LOG(tQBuf);
#endif
return ( uint32_t ) m_pDatabase->QueryID( tQBuf );
};
return 0;

3
lib/App/serva/servaKernel.cpp

@ -227,6 +227,9 @@ void servaKernel::m_fThreadProc( void ){
if ( uint64_t new_id = m_pDBC->getRecentMediaId() ) {
if ( processVideoFile( new_id ) ) updateEncodeStatus( new_id, MEDIA_ENCODE_PROGRESS, 0 );
};
if ( m_pSM ) m_pSM->validate();
//m_pHardwareManager->updateSysInfo( &m_sSysInfo );
DBC_RPC_WEB_CMD * tCMD = m_pDBC->fetchWebCmd( 0 ); //Kernel
if( tCMD != NULL ) {

49
lib/App/serva/servaSessionManager.cpp

@ -199,7 +199,7 @@ bool servaSessionManager::addEvent( SESSION_DATA *sp, ARGUS_DATA_EVENT *ptr ){
case EVT_TARGET_2D_BLACK:{
updateSessionStat( sp->db_id );
sprintf( tQBuf, "INSERT INTO `events`(`module_id`,`ts`,`ts_ms`,`evt_type`,`azimuth`,`range`,`area`)" \
" VALUES(%d,%d,%d,%d,%0.2f,%0.2f,%0.2f,%0.2f)",
" VALUES(%d,%d,%d,%d,%0.2f,%0.2f,%0.2f)",
ptr->MODULE_ID,
ptr->TS,
ptr->MS,
@ -357,25 +357,46 @@ SESSION_DATA *servaSessionManager::updateSession( uint32_t tack_id, uint32_t mod
};
bool servaSessionManager::updateSessionStat( uint64_t session_id, bool evt ){
if ( evt ) {
m_pDBC->sessionStatAddEvt( session_id );
} else {
m_pDBC->sessionStatAddVid( session_id );
if( SESSION_DATA *tD = validateSession( session_id ) ){
tD->lts = time( NULL );
if ( evt ) {
m_pDBC->sessionStatAddEvt( session_id );
} else {
m_pDBC->sessionStatAddVid( session_id );
};
return true;
};
return true;
return false;
};
bool servaSessionManager::validate(){
uint32_t cts = time(NULL);
uint32_t cts = time( NULL );
M_SESSIONS::iterator dE;
bool bMustDelete = false;
for( M_SESSIONS::iterator idx = m_mSessions.begin(); idx != m_mSessions.end(); idx++ ){
if( cts - (*idx).second->lts > m_nSessionTO ){
// Close Session
m_pDBC->updateSessionStatus( (*idx).second->db_id, 1 );
// remove session
};
if ( (*idx).second ) {
#ifdef DEBUG_EXTRA
char tB[128];
sprintf( tB, "Validation %d %d %d", cts, (*idx).second->lts, m_nSessionTO );
LOG( tB );
#endif
if( cts - (*idx).second->lts > m_nSessionTO ){
// Expire Session
m_pDBC->updateSessionStatus( (*idx).second->db_id, 1 );
// Set Session to remove
dE = idx;
bMustDelete = true;
};
};
};
return true;
if ( bMustDelete ) {
// Remove Session
delete( (*dE).second->m_pDataReport );
free( (*dE).second );
(*dE).second = NULL;
m_mSessions.erase( dE );
};
return true;
};
SESSION_DATA *servaSessionManager::validateSession( uint64_t sid ){

Loading…
Cancel
Save