/* how much time from face detected to face left? */ int SQL_Devices::form_response__saw_for_duration( std::string mPerson, time_t& mTime) { time_t sTime,eTime; query_string = "SELECT *,UNIX_TIMESTAMP(timestamp) FROM "; query_string += table_name; query_string += " WHERE "; if (mPerson.length()) { query_string += table_name; query_string += ".people_names LIKE '%"; query_string += mPerson; query_string += "%' AND "; } query_string += "(event_description LIKE '%face detected%' "; query_string += "OR event_description LIKE '%face left%')"; query_string += " ORDER BY timestamp DESC;"; //printf("\n%s\n", query_string.c_str() ); query(true); m_row = mysql_fetch_row( m_result ); m_row_count = get_number_results(); int cols = get_number_columns(); printf("m_row_count=%ld; cols=%d; \n", m_row_count, cols ); sTime = atoi( m_row[cols-1] ); eTime = atoi( m_row[cols-1] ); mTime = difftime(sTime,eTime); printf("m_row[%d]=%s; %ld\n", cols, m_row[cols-1], mTime ); return m_row_count; }
int SQL_Devices::form_response__last_time_i_deactivated( time_t& mTime) { sql_query_event( "", "System De-activated" ); m_row = mysql_fetch_row( m_result ); int rows = get_number_results(); int cols = get_number_columns(); mTime = atoi( m_row[cols-1] ); return rows; }
int SQL_Devices::form_response__last_time_i_saw( std::string mPerson, time_t& mTime ) { sql_query_event( mPerson, "face left" ); m_row = mysql_fetch_row( m_result ); m_row_count = get_number_results(); int cols = get_number_columns(); printf("m_row_count=%ld; cols=%d; \n", m_row_count, cols ); mTime = atoi( m_row[cols-1] ); printf("m_row[%d]=%s; %ld\n", cols, m_row[cols-1], mTime ); return m_row_count; }
int SQL_Devices::form_response__hours_active( std::string mDescription, time_t& mTime, struct tm start_time_bd, struct tm end_time_bd ) { time_t sTime,eTime, sumTotal, deltaTime; sumTotal = 0; deltaTime = 0; sTime = 0; query_string = "SELECT *,UNIX_TIMESTAMP(timestamp) FROM "; query_string += table_name; query_string +=" WHERE "; query_string += "(event_description LIKE '%System Activated%' "; query_string += "OR event_description LIKE '%System De-activated%') AND "; query_string += table_name; query_string += ".timestamp BETWEEN '"; query_string += form_date_time_string(start_time_bd); query_string += "' AND '"; query_string += form_date_time_string( end_time_bd ); query_string += "' "; query_string += " ORDER BY timestamp ASC;"; query(true); m_row = mysql_fetch_row( m_result ); m_row_count = get_number_results(); int cols = get_number_columns(); printf("m_row_count=%ld; cols=%d; \n", m_row_count, cols ); while (m_row) { if (strcmp(m_row[2], "Vision System Activated")==0) sTime = atoi( m_row[9] ); if (strcmp(m_row[2], "Vision System De-activated")==0) { eTime = atoi( m_row[9] ); if (sTime) { deltaTime = difftime(eTime, sTime); sumTotal += deltaTime; } } //printf("%d m_row[%d]=%s; %d <%d..%d>\n", row++, cols-1, m_row[cols-1], deltaTime, sTime, eTime ); m_row = mysql_fetch_row( m_result ); } //printf("Sum Total Active Time = %6.1f hours.\n", sumTotal/3600. ); mTime = sumTotal; return m_row_count; }
// Check location information static int check_datapool_location(FILE *ifp, char **header_line, int *n) { dbf_header_t *dbf; int ii, nCols; char *header = (char *) MALLOC(sizeof(char)*1024); fgets(header, 1024, ifp); strip_end_whitesp(header); int nColumns = get_number_columns(header); // Read configuration file read_header_config("DATAPOOL", &dbf, &nCols); // ensure we have the columns we need int granule_col = find_str(header, "Granule Name"); int near_start_lat_col = find_str(header, "Near Start Lat"); int near_start_lon_col = find_str(header, "Near Start Lon"); int far_start_lat_col = find_str(header, "Far Start Lat"); int far_start_lon_col = find_str(header, "Far Start Lon"); int near_end_lat_col = find_str(header, "Near End Lat"); int near_end_lon_col = find_str(header, "Near End Lon"); int far_end_lat_col = find_str(header, "Far End Lat"); int far_end_lon_col = find_str(header, "Far End Lon"); // Check whether all visible columns are actually available in the file for (ii=0; ii<nCols; ii++) { if (find_str(header, dbf[ii].header) < 0) dbf[ii].visible = FALSE; } int all_ok=TRUE; if (granule_col < 0) { printf("Missing: Granule Name\n"); all_ok=FALSE; } if (near_start_lat_col < 0) { printf("Missing: Near Start Lat\n"); all_ok=FALSE; } if (near_start_lon_col < 0) { printf("Missing: Near Start Lon\n"); all_ok=FALSE; } if (far_start_lat_col < 0) { printf("Missing: Far Start Lat\n"); all_ok=FALSE; } if (far_start_lon_col < 0) { printf("Missing: Far Start Lon\n"); all_ok=FALSE; } if (near_end_lat_col < 0) { printf("Missing: Near End Lat\n"); all_ok=FALSE; } if (near_end_lon_col < 0) { printf("Missing: Near End Lon\n"); all_ok=FALSE; } if (far_end_lat_col < 0) { printf("Missing: Far End Lat\n"); all_ok=FALSE; } if (far_end_lon_col < 0) { printf("Missing: Far End Lon\n"); all_ok=FALSE; } if (!all_ok) { printf("Required data columns missing, cannot process this file.\n"); return 0; } *header_line = header; *n = nColumns; return 1; }