Minor code improvements
Replaced use of postfix operators with prefix operators. Replaced manual declarations with Q_DISABLE_COPY_MOVE macro for FileHandler classes.
This commit is contained in:
parent
97379cfd17
commit
d910069a1b
|
@ -189,7 +189,7 @@ bool CrissCross::checkVictory()
|
||||||
streak = 0;
|
streak = 0;
|
||||||
for ( const auto& index : sequence ) {
|
for ( const auto& index : sequence ) {
|
||||||
if ( this->board[ index ] == this->p_turn ) {
|
if ( this->board[ index ] == this->p_turn ) {
|
||||||
streak ++;
|
++streak;
|
||||||
this->victory_sequence.push_back( index );
|
this->victory_sequence.push_back( index );
|
||||||
} else {
|
} else {
|
||||||
break;
|
break;
|
||||||
|
@ -210,7 +210,7 @@ void CrissCross::victory()
|
||||||
{
|
{
|
||||||
// disable all buttons except the victory sequence ones
|
// disable all buttons except the victory sequence ones
|
||||||
bool disable{ true };
|
bool disable{ true };
|
||||||
for ( unsigned i=0; i<9; i++ ) {
|
for ( unsigned i=0; i<9; ++i ) {
|
||||||
disable |= true;
|
disable |= true;
|
||||||
for ( const auto& j : this->victory_sequence ) {
|
for ( const auto& j : this->victory_sequence ) {
|
||||||
if ( i == j ) {
|
if ( i == j ) {
|
||||||
|
@ -252,7 +252,7 @@ bool CrissCross::gameDraw() const
|
||||||
unsigned empty_tiles{ 9 };
|
unsigned empty_tiles{ 9 };
|
||||||
for ( const auto& tile : this->board ) {
|
for ( const auto& tile : this->board ) {
|
||||||
if ( tile > 0 ) {
|
if ( tile > 0 ) {
|
||||||
empty_tiles --;
|
-- empty_tiles;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
if ( empty_tiles == 0 ) {
|
if ( empty_tiles == 0 ) {
|
||||||
|
@ -290,7 +290,7 @@ void CrissCross::AI_playTurn()
|
||||||
void CrissCross::AI_updateWeights()
|
void CrissCross::AI_updateWeights()
|
||||||
{
|
{
|
||||||
// reset the weights
|
// reset the weights
|
||||||
for ( size_t i{0ul}; i<9ul; i++ ) {
|
for ( size_t i{0ul}; i<9ul; ++i ) {
|
||||||
this->board_weights[ i ] = 0;
|
this->board_weights[ i ] = 0;
|
||||||
}
|
}
|
||||||
// calculate the new weights
|
// calculate the new weights
|
||||||
|
@ -303,9 +303,9 @@ void CrissCross::AI_updateWeights()
|
||||||
// check the tiles in the sequence
|
// check the tiles in the sequence
|
||||||
for ( const auto index : sequence ) {
|
for ( const auto index : sequence ) {
|
||||||
if ( this->board[ index ] == this->p_turn ) {
|
if ( this->board[ index ] == this->p_turn ) {
|
||||||
win_streak ++;
|
++ win_streak;
|
||||||
} else if ( this->board[ index ] > 0 ) {
|
} else if ( this->board[ index ] > 0 ) {
|
||||||
lose_streak ++;
|
++ lose_streak;
|
||||||
} else {
|
} else {
|
||||||
empty_tiles.emplace_back( std::move(index) );
|
empty_tiles.emplace_back( std::move(index) );
|
||||||
}
|
}
|
||||||
|
@ -341,7 +341,7 @@ unsigned CrissCross::AI_makeChoice() const
|
||||||
// lighter weight
|
// lighter weight
|
||||||
;
|
;
|
||||||
}*/
|
}*/
|
||||||
index ++;
|
++ index;
|
||||||
}
|
}
|
||||||
// decide the movement (or better, randomly pick one)
|
// decide the movement (or better, randomly pick one)
|
||||||
unsigned next_move;
|
unsigned next_move;
|
||||||
|
|
|
@ -185,17 +185,17 @@ void SnakeGame::newSnake_()
|
||||||
case Direction::UP:
|
case Direction::UP:
|
||||||
case Direction::DOWN:
|
case Direction::DOWN:
|
||||||
if ( rnd ) {
|
if ( rnd ) {
|
||||||
head_x ++;
|
++ head_x;
|
||||||
} else {
|
} else {
|
||||||
head_x --;
|
-- head_x;
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
case Direction::LEFT:
|
case Direction::LEFT:
|
||||||
case Direction::RIGHT:
|
case Direction::RIGHT:
|
||||||
if ( rnd ) {
|
if ( rnd ) {
|
||||||
head_y ++;
|
++ head_y;
|
||||||
} else {
|
} else {
|
||||||
head_y --;
|
-- head_y;
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
default:
|
default:
|
||||||
|
@ -272,7 +272,7 @@ void SnakeGame::processGameLogic()
|
||||||
this->moving_countdown = this->moving_rate;
|
this->moving_countdown = this->moving_rate;
|
||||||
}
|
}
|
||||||
} else if ( this->game_mode == GameMode::Hunt ) {
|
} else if ( this->game_mode == GameMode::Hunt ) {
|
||||||
this->moving_countdown --;
|
-- this->moving_countdown;
|
||||||
if ( this->moving_countdown == 0u ) {
|
if ( this->moving_countdown == 0u ) {
|
||||||
this->moving_countdown = this->moving_rate;
|
this->moving_countdown = this->moving_rate;
|
||||||
this->food.move( this->snake );
|
this->food.move( this->snake );
|
||||||
|
@ -327,16 +327,16 @@ void SnakeGame::checkCollision( Snake& snake, Snake& adv_snake, const bool is_ad
|
||||||
unsigned x_, y_;
|
unsigned x_, y_;
|
||||||
switch ( snake.direction() ) {
|
switch ( snake.direction() ) {
|
||||||
case Direction::UP:
|
case Direction::UP:
|
||||||
y--;
|
--y;
|
||||||
break;
|
break;
|
||||||
case Direction::DOWN:
|
case Direction::DOWN:
|
||||||
y++;
|
++y;
|
||||||
break;
|
break;
|
||||||
case Direction::LEFT:
|
case Direction::LEFT:
|
||||||
x--;
|
--x;
|
||||||
break;
|
break;
|
||||||
case Direction::RIGHT:
|
case Direction::RIGHT:
|
||||||
x++;
|
++x;
|
||||||
break;
|
break;
|
||||||
default:
|
default:
|
||||||
// should be unreachable
|
// should be unreachable
|
||||||
|
@ -348,16 +348,16 @@ void SnakeGame::checkCollision( Snake& snake, Snake& adv_snake, const bool is_ad
|
||||||
y_ = adv_snake.front().y;
|
y_ = adv_snake.front().y;
|
||||||
switch ( adv_snake.direction() ) {
|
switch ( adv_snake.direction() ) {
|
||||||
case Direction::UP:
|
case Direction::UP:
|
||||||
y_--;
|
--y_;
|
||||||
break;
|
break;
|
||||||
case Direction::DOWN:
|
case Direction::DOWN:
|
||||||
y_++;
|
++y_;
|
||||||
break;
|
break;
|
||||||
case Direction::LEFT:
|
case Direction::LEFT:
|
||||||
x_--;
|
--x_;
|
||||||
break;
|
break;
|
||||||
case Direction::RIGHT:
|
case Direction::RIGHT:
|
||||||
x_++;
|
++x_;
|
||||||
break;
|
break;
|
||||||
default:
|
default:
|
||||||
// should be unreachable
|
// should be unreachable
|
||||||
|
|
|
@ -40,13 +40,13 @@ bool Snake::inTile( const unsigned x, const unsigned y, const bool avoid_tail )
|
||||||
size_t i{ 0 };
|
size_t i{ 0 };
|
||||||
size_t max{ this->size()-1ul };
|
size_t max{ this->size()-1ul };
|
||||||
if ( !avoid_tail ) {
|
if ( !avoid_tail ) {
|
||||||
max ++;
|
++ max;
|
||||||
}
|
}
|
||||||
for ( auto bp{ this->cbegin() }; bp != this->cend(); ++bp ) {
|
for ( auto bp{ this->cbegin() }; bp != this->cend(); ++bp ) {
|
||||||
if ( bp->x == x && bp->y == y ) {
|
if ( bp->x == x && bp->y == y ) {
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
i++;
|
++i;
|
||||||
if ( i >= max ) {
|
if ( i >= max ) {
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
@ -81,16 +81,16 @@ void Snake::grow( const bool is_borning )
|
||||||
// one tile behind
|
// one tile behind
|
||||||
switch ( d ) {
|
switch ( d ) {
|
||||||
case Direction::UP:
|
case Direction::UP:
|
||||||
y ++;
|
++ y;
|
||||||
break;
|
break;
|
||||||
case Direction::DOWN:
|
case Direction::DOWN:
|
||||||
y --;
|
-- y;
|
||||||
break;
|
break;
|
||||||
case Direction::LEFT:
|
case Direction::LEFT:
|
||||||
x ++;
|
++ x;
|
||||||
break;
|
break;
|
||||||
case Direction::RIGHT:
|
case Direction::RIGHT:
|
||||||
x --;
|
-- x;
|
||||||
break;
|
break;
|
||||||
default:
|
default:
|
||||||
// should be unreachable
|
// should be unreachable
|
||||||
|
@ -366,7 +366,7 @@ void Snake::update( QGraphicsScene* field_scene, const bool dry , const bool is_
|
||||||
throw("Unexpected direction: "+std::to_string(bp->direction));
|
throw("Unexpected direction: "+std::to_string(bp->direction));
|
||||||
}
|
}
|
||||||
prev_body_d = bp->direction;
|
prev_body_d = bp->direction;
|
||||||
i++;
|
++i;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -399,7 +399,7 @@ void Snake::move( const Snake& adv_snake, const unsigned food_x, const unsigned
|
||||||
|
|
||||||
this->updateFieldMap( adv_snake, food_x, food_y );
|
this->updateFieldMap( adv_snake, food_x, food_y );
|
||||||
|
|
||||||
for ( size_t i{0}; i<4ul; i++ ) {
|
for ( size_t i{0}; i<4ul; ++i ) {
|
||||||
this->collectData( dataset.at(i), classes.at(i), adv_snake, food_x, food_y );
|
this->collectData( dataset.at(i), classes.at(i), adv_snake, food_x, food_y );
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -415,10 +415,10 @@ Direction Snake::predictDirection( const std::array<std::array<float,7>,4>& data
|
||||||
Direction class_label;
|
Direction class_label;
|
||||||
|
|
||||||
// process data
|
// process data
|
||||||
for ( size_t i{0}; i<4ul; i++ ) {
|
for ( size_t i{0}; i<4ul; ++i ) {
|
||||||
const std::array<float, 7>& d = data.at(i);
|
const std::array<float, 7>& d = data.at(i);
|
||||||
float& r = results[i];
|
float& r = results[i];
|
||||||
for ( size_t j{0}; j<7ul; j++ ) {
|
for ( size_t j{0}; j<7ul; ++j ) {
|
||||||
r += d.at(j) * weights.at(j);
|
r += d.at(j) * weights.at(j);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -434,12 +434,12 @@ Direction Snake::predictDirection( const std::array<std::array<float,7>,4>& data
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
if ( max != min ) {
|
if ( max != min ) {
|
||||||
for ( size_t i{0}; i<4ul; i++ ) {
|
for ( size_t i{0}; i<4ul; ++i ) {
|
||||||
results[i] = (results[i]-min) / (max-min);
|
results[i] = (results[i]-min) / (max-min);
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
keep_current |= true;
|
keep_current |= true;
|
||||||
for ( size_t i{0}; i<4ul; i++ ) {
|
for ( size_t i{0}; i<4ul; ++i ) {
|
||||||
results[i] = 0.f;
|
results[i] = 0.f;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -449,7 +449,7 @@ Direction Snake::predictDirection( const std::array<std::array<float,7>,4>& data
|
||||||
class_label = this->head_direction;
|
class_label = this->head_direction;
|
||||||
} else {
|
} else {
|
||||||
max = 0.f;
|
max = 0.f;
|
||||||
for ( size_t i{0}; i<4ul; i++ ) {
|
for ( size_t i{0}; i<4ul; ++i ) {
|
||||||
if ( results[i] > max ) {
|
if ( results[i] > max ) {
|
||||||
class_label = classes.at(i);
|
class_label = classes.at(i);
|
||||||
max = results[i];
|
max = results[i];
|
||||||
|
@ -731,8 +731,8 @@ void Snake::collectData( std::array<float,7>& data, const Direction& direction,
|
||||||
void Snake::updateFieldMap( const Snake& adv_snake, const unsigned& food_x, const unsigned& food_y )
|
void Snake::updateFieldMap( const Snake& adv_snake, const unsigned& food_x, const unsigned& food_y )
|
||||||
{
|
{
|
||||||
// reset to default state
|
// reset to default state
|
||||||
for ( size_t x{0}; x<16ul; x++ ) {
|
for ( size_t x{0}; x<16ul; ++x ) {
|
||||||
for ( size_t y{0}; y<16ul; y++ ) {
|
for ( size_t y{0}; y<16ul; ++y ) {
|
||||||
Tile& t = this->field_map.at(x).at(y);
|
Tile& t = this->field_map.at(x).at(y);
|
||||||
t.entity = Entity::N;
|
t.entity = Entity::N;
|
||||||
t.s_index = 0u;
|
t.s_index = 0u;
|
||||||
|
@ -746,7 +746,7 @@ void Snake::updateFieldMap( const Snake& adv_snake, const unsigned& food_x, cons
|
||||||
Tile& t = this->field_map.at(bp->x).at(bp->y);
|
Tile& t = this->field_map.at(bp->x).at(bp->y);
|
||||||
t.entity = Entity::S;
|
t.entity = Entity::S;
|
||||||
t.s_index = i;
|
t.s_index = i;
|
||||||
i--;
|
--i;
|
||||||
}
|
}
|
||||||
// update adversary
|
// update adversary
|
||||||
i = static_cast<unsigned>( adv_snake.size() );
|
i = static_cast<unsigned>( adv_snake.size() );
|
||||||
|
@ -754,7 +754,7 @@ void Snake::updateFieldMap( const Snake& adv_snake, const unsigned& food_x, cons
|
||||||
Tile& t = this->field_map.at(bp.x).at(bp.y);
|
Tile& t = this->field_map.at(bp.x).at(bp.y);
|
||||||
t.entity = Entity::A;
|
t.entity = Entity::A;
|
||||||
t.s_index = i;
|
t.s_index = i;
|
||||||
i--;
|
--i;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -836,7 +836,7 @@ std::array<unsigned,8> Snake::checkAround( const Direction& direction, const uns
|
||||||
}
|
}
|
||||||
|
|
||||||
unsigned x_, y_;
|
unsigned x_, y_;
|
||||||
for ( size_t i{0}; i<8ul; i++ ) {
|
for ( size_t i{0}; i<8ul; ++i ) {
|
||||||
x_ = x;
|
x_ = x;
|
||||||
x_ += x_pattern.at(i);
|
x_ += x_pattern.at(i);
|
||||||
y_ = y;
|
y_ = y;
|
||||||
|
@ -1104,7 +1104,7 @@ unsigned Snake::isDeadHole( const unsigned start_x, const unsigned start_y, cons
|
||||||
result = true;
|
result = true;
|
||||||
break;
|
break;
|
||||||
} else {
|
} else {
|
||||||
steps ++;
|
++ steps;
|
||||||
if ( steps >= max_steps ) {
|
if ( steps >= max_steps ) {
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
@ -1121,7 +1121,7 @@ unsigned Snake::isDeadHole( const unsigned start_x, const unsigned start_y, cons
|
||||||
if ( !result ) {
|
if ( !result ) {
|
||||||
steps = 0;
|
steps = 0;
|
||||||
}
|
}
|
||||||
i ++;
|
++ i;
|
||||||
if ( i == 2u ) {
|
if ( i == 2u ) {
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
|
|
@ -382,7 +382,7 @@ void MainWindow::readConfigs()
|
||||||
std::vector<std::string> aux, configs;
|
std::vector<std::string> aux, configs;
|
||||||
try {
|
try {
|
||||||
// reset the lists when a config file is found
|
// reset the lists when a config file is found
|
||||||
for ( unsigned w=APACHE_ID; w<=IIS_ID; w++ ) {
|
for ( unsigned w=APACHE_ID; w<=IIS_ID; ++w ) {
|
||||||
for ( const int& f : {11,12,20,21} ) {
|
for ( const int& f : {11,12,20,21} ) {
|
||||||
this->craplog.setWarnlist( w, f, {} );
|
this->craplog.setWarnlist( w, f, {} );
|
||||||
}
|
}
|
||||||
|
@ -952,7 +952,7 @@ void MainWindow::backupDatabase() const
|
||||||
}
|
}
|
||||||
if ( proceed ) {
|
if ( proceed ) {
|
||||||
// cascade rename
|
// cascade rename
|
||||||
for ( int n=this->db_backups_number-1; n>=0; n-- ) {
|
for ( int n=this->db_backups_number-1; n>=0; --n ) {
|
||||||
path = this->db_data_path+"/backups/collection.db."+std::to_string( n );
|
path = this->db_data_path+"/backups/collection.db."+std::to_string( n );
|
||||||
if ( std::filesystem::exists( path ) ) {
|
if ( std::filesystem::exists( path ) ) {
|
||||||
new_path = this->db_data_path+"/backups/collection.db."+std::to_string( n+1 );
|
new_path = this->db_data_path+"/backups/collection.db."+std::to_string( n+1 );
|
||||||
|
@ -2673,9 +2673,9 @@ void MainWindow::on_listLogFiles_itemChanged(QTreeWidgetItem *item, int column)
|
||||||
QTreeWidgetItemIterator i(this->ui->listLogFiles);
|
QTreeWidgetItemIterator i(this->ui->listLogFiles);
|
||||||
while ( *i ) {
|
while ( *i ) {
|
||||||
if ( (*i)->checkState(0) == Qt::CheckState::Checked ) {
|
if ( (*i)->checkState(0) == Qt::CheckState::Checked ) {
|
||||||
n_checked++;
|
++ n_checked;
|
||||||
}
|
}
|
||||||
++i;
|
++ i;
|
||||||
}
|
}
|
||||||
if ( n_checked == 0ul ) {
|
if ( n_checked == 0ul ) {
|
||||||
this->ui->checkBox_LogFiles_CheckAll->setCheckState(Qt::CheckState::Unchecked);
|
this->ui->checkBox_LogFiles_CheckAll->setCheckState(Qt::CheckState::Unchecked);
|
||||||
|
@ -4362,7 +4362,7 @@ void MainWindow::refreshChartsPreview()
|
||||||
return (rand()%10 > 8) ? rand()%100 : (rand()%10 > 6) ? rand()%50 : rand()%30;
|
return (rand()%10 > 8) ? rand()%100 : (rand()%10 > 6) ? rand()%50 : rand()%30;
|
||||||
};
|
};
|
||||||
int aux, max{0};
|
int aux, max{0};
|
||||||
for ( int i{0}; i<24; i++ ) {
|
for ( int i{0}; i<24; ++i ) {
|
||||||
aux = random_value();
|
aux = random_value();
|
||||||
*bars_1 << aux;
|
*bars_1 << aux;
|
||||||
if ( aux > max ) {
|
if ( aux > max ) {
|
||||||
|
@ -4772,7 +4772,7 @@ void MainWindow::on_list_ConfApache_Warnlist_List_itemSelectionChanged()
|
||||||
this->ui->button_ConfApache_Warnlist_Up->setEnabled( false );
|
this->ui->button_ConfApache_Warnlist_Up->setEnabled( false );
|
||||||
this->ui->button_ConfApache_Warnlist_Down->setEnabled( false );
|
this->ui->button_ConfApache_Warnlist_Down->setEnabled( false );
|
||||||
} else {
|
} else {
|
||||||
for ( int i{0}; i<=max; i++ ) {
|
for ( int i{0}; i<=max; ++i ) {
|
||||||
if ( this->ui->list_ConfApache_Warnlist_List->item(i) == item ) {
|
if ( this->ui->list_ConfApache_Warnlist_List->item(i) == item ) {
|
||||||
if ( i == 0 ) {
|
if ( i == 0 ) {
|
||||||
this->ui->button_ConfApache_Warnlist_Up->setEnabled( false );
|
this->ui->button_ConfApache_Warnlist_Up->setEnabled( false );
|
||||||
|
@ -4919,7 +4919,7 @@ void MainWindow::on_list_ConfApache_Blacklist_List_itemSelectionChanged()
|
||||||
this->ui->button_ConfApache_Blacklist_Up->setEnabled( false );
|
this->ui->button_ConfApache_Blacklist_Up->setEnabled( false );
|
||||||
this->ui->button_ConfApache_Blacklist_Down->setEnabled( false );
|
this->ui->button_ConfApache_Blacklist_Down->setEnabled( false );
|
||||||
} else {
|
} else {
|
||||||
for ( int i{0}; i<=max; i++ ) {
|
for ( int i{0}; i<=max; ++i ) {
|
||||||
if ( this->ui->list_ConfApache_Blacklist_List->item(i) == item ) {
|
if ( this->ui->list_ConfApache_Blacklist_List->item(i) == item ) {
|
||||||
if ( i == 0 ) {
|
if ( i == 0 ) {
|
||||||
this->ui->button_ConfApache_Blacklist_Up->setEnabled( false );
|
this->ui->button_ConfApache_Blacklist_Up->setEnabled( false );
|
||||||
|
@ -5143,7 +5143,7 @@ void MainWindow::on_list_ConfNginx_Warnlist_List_itemSelectionChanged()
|
||||||
this->ui->button_ConfNginx_Warnlist_Up->setEnabled( false );
|
this->ui->button_ConfNginx_Warnlist_Up->setEnabled( false );
|
||||||
this->ui->button_ConfNginx_Warnlist_Down->setEnabled( false );
|
this->ui->button_ConfNginx_Warnlist_Down->setEnabled( false );
|
||||||
} else {
|
} else {
|
||||||
for ( int i{0}; i<=max; i++ ) {
|
for ( int i{0}; i<=max; ++i ) {
|
||||||
if ( this->ui->list_ConfNginx_Warnlist_List->item(i) == item ) {
|
if ( this->ui->list_ConfNginx_Warnlist_List->item(i) == item ) {
|
||||||
if ( i == 0 ) {
|
if ( i == 0 ) {
|
||||||
this->ui->button_ConfNginx_Warnlist_Up->setEnabled( false );
|
this->ui->button_ConfNginx_Warnlist_Up->setEnabled( false );
|
||||||
|
@ -5290,7 +5290,7 @@ void MainWindow::on_list_ConfNginx_Blacklist_List_itemSelectionChanged()
|
||||||
this->ui->button_ConfNginx_Blacklist_Up->setEnabled( false );
|
this->ui->button_ConfNginx_Blacklist_Up->setEnabled( false );
|
||||||
this->ui->button_ConfNginx_Blacklist_Down->setEnabled( false );
|
this->ui->button_ConfNginx_Blacklist_Down->setEnabled( false );
|
||||||
} else {
|
} else {
|
||||||
for ( int i{0}; i<=max; i++ ) {
|
for ( int i{0}; i<=max; ++i ) {
|
||||||
if ( this->ui->list_ConfNginx_Blacklist_List->item(i) == item ) {
|
if ( this->ui->list_ConfNginx_Blacklist_List->item(i) == item ) {
|
||||||
if ( i == 0 ) {
|
if ( i == 0 ) {
|
||||||
this->ui->button_ConfNginx_Blacklist_Up->setEnabled( false );
|
this->ui->button_ConfNginx_Blacklist_Up->setEnabled( false );
|
||||||
|
@ -5577,7 +5577,7 @@ void MainWindow::on_list_ConfIis_Warnlist_List_itemSelectionChanged()
|
||||||
this->ui->button_ConfIis_Warnlist_Up->setEnabled( false );
|
this->ui->button_ConfIis_Warnlist_Up->setEnabled( false );
|
||||||
this->ui->button_ConfIis_Warnlist_Down->setEnabled( false );
|
this->ui->button_ConfIis_Warnlist_Down->setEnabled( false );
|
||||||
} else {
|
} else {
|
||||||
for ( int i{0}; i<=max; i++ ) {
|
for ( int i{0}; i<=max; ++i ) {
|
||||||
if ( this->ui->list_ConfIis_Warnlist_List->item(i) == item ) {
|
if ( this->ui->list_ConfIis_Warnlist_List->item(i) == item ) {
|
||||||
if ( i == 0 ) {
|
if ( i == 0 ) {
|
||||||
this->ui->button_ConfIis_Warnlist_Up->setEnabled( false );
|
this->ui->button_ConfIis_Warnlist_Up->setEnabled( false );
|
||||||
|
@ -5724,7 +5724,7 @@ void MainWindow::on_list_ConfIis_Blacklist_List_itemSelectionChanged()
|
||||||
this->ui->button_ConfIis_Blacklist_Up->setEnabled( false );
|
this->ui->button_ConfIis_Blacklist_Up->setEnabled( false );
|
||||||
this->ui->button_ConfIis_Blacklist_Down->setEnabled( false );
|
this->ui->button_ConfIis_Blacklist_Down->setEnabled( false );
|
||||||
} else {
|
} else {
|
||||||
for ( int i{0}; i<=max; i++ ) {
|
for ( int i{0}; i<=max; ++i ) {
|
||||||
if ( this->ui->list_ConfIis_Blacklist_List->item(i) == item ) {
|
if ( this->ui->list_ConfIis_Blacklist_List->item(i) == item ) {
|
||||||
if ( i == 0 ) {
|
if ( i == 0 ) {
|
||||||
this->ui->button_ConfIis_Blacklist_Up->setEnabled( false );
|
this->ui->button_ConfIis_Blacklist_Up->setEnabled( false );
|
||||||
|
|
|
@ -33,7 +33,7 @@ Craplog::Craplog()
|
||||||
//// INITIALIZATION ////
|
//// INITIALIZATION ////
|
||||||
////////////////////////
|
////////////////////////
|
||||||
// blacklists / whitelists
|
// blacklists / whitelists
|
||||||
for ( unsigned i{APACHE_ID}; i<=IIS_ID; i++ ) {
|
for ( unsigned i{APACHE_ID}; i<=IIS_ID; ++i ) {
|
||||||
this->warnlists.emplace( i, std::unordered_map<int, BWlist>(4) );
|
this->warnlists.emplace( i, std::unordered_map<int, BWlist>(4) );
|
||||||
this->blacklists.emplace( i, std::unordered_map<int, BWlist>(1) );
|
this->blacklists.emplace( i, std::unordered_map<int, BWlist>(1) );
|
||||||
// default data
|
// default data
|
||||||
|
@ -185,7 +185,7 @@ void Craplog::blacklistRemove( const unsigned& web_server_id, const int& log_fie
|
||||||
auto& list = this->blacklists.at( web_server_id ).at( log_field_id ).list;
|
auto& list = this->blacklists.at( web_server_id ).at( log_field_id ).list;
|
||||||
// move the item to the end, then pop it
|
// move the item to the end, then pop it
|
||||||
const size_t max{ list.size()-1ul };
|
const size_t max{ list.size()-1ul };
|
||||||
for ( size_t i{0}; i<max; i++ ) {
|
for ( size_t i{0}; i<max; ++i ) {
|
||||||
if ( list.at( i ) == item ) {
|
if ( list.at( i ) == item ) {
|
||||||
list.at( i ) = list.at( i+1ul );
|
list.at( i ) = list.at( i+1ul );
|
||||||
list.at( i+1ul ) = item;
|
list.at( i+1ul ) = item;
|
||||||
|
@ -198,7 +198,7 @@ void Craplog::warnlistRemove( const unsigned& web_server_id, const int& log_fiel
|
||||||
auto& list = this->warnlists.at( web_server_id ).at( log_field_id ).list;
|
auto& list = this->warnlists.at( web_server_id ).at( log_field_id ).list;
|
||||||
// move the item to the end, then pop it
|
// move the item to the end, then pop it
|
||||||
const size_t max{ list.size()-1ul };
|
const size_t max{ list.size()-1ul };
|
||||||
for ( size_t i{0}; i<max; i++ ) {
|
for ( size_t i{0}; i<max; ++i ) {
|
||||||
if ( list.at( i ) == item ) {
|
if ( list.at( i ) == item ) {
|
||||||
list.at( i ) = list.at( i+1ul );
|
list.at( i ) = list.at( i+1ul );
|
||||||
list.at( i+1ul ) = item;
|
list.at( i+1ul ) = item;
|
||||||
|
@ -212,11 +212,11 @@ int Craplog::blacklistMoveUp( const unsigned& web_server_id, const int& log_fiel
|
||||||
auto& list = this->blacklists.at( web_server_id ).at( log_field_id ).list;
|
auto& list = this->blacklists.at( web_server_id ).at( log_field_id ).list;
|
||||||
size_t i{ 1 };
|
size_t i{ 1 };
|
||||||
const size_t max{ list.size() };
|
const size_t max{ list.size() };
|
||||||
for ( ; i<max; i++ ) {
|
for ( ; i<max; ++i ) {
|
||||||
if ( list.at( i ) == item ) {
|
if ( list.at( i ) == item ) {
|
||||||
list.at( i ) = list.at( i-1ul );
|
list.at( i ) = list.at( i-1ul );
|
||||||
list.at( i-1ul ) = item;
|
list.at( i-1ul ) = item;
|
||||||
i--;
|
--i;
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -227,11 +227,11 @@ int Craplog::warnlistMoveUp( const unsigned& web_server_id, const int& log_field
|
||||||
auto& list = this->warnlists.at( web_server_id ).at( log_field_id ).list;
|
auto& list = this->warnlists.at( web_server_id ).at( log_field_id ).list;
|
||||||
size_t i{ 1 };
|
size_t i{ 1 };
|
||||||
const size_t max{ list.size() };
|
const size_t max{ list.size() };
|
||||||
for ( ; i<max; i++ ) {
|
for ( ; i<max; ++i ) {
|
||||||
if ( list.at( i ) == item ) {
|
if ( list.at( i ) == item ) {
|
||||||
list.at( i ) = list.at( i-1ul );
|
list.at( i ) = list.at( i-1ul );
|
||||||
list.at( i-1ul ) = item;
|
list.at( i-1ul ) = item;
|
||||||
i--;
|
--i;
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -243,11 +243,11 @@ int Craplog::blacklistMoveDown( const unsigned& web_server_id, const int& log_fi
|
||||||
auto& list = this->blacklists.at( web_server_id ).at( log_field_id ).list;
|
auto& list = this->blacklists.at( web_server_id ).at( log_field_id ).list;
|
||||||
size_t i{ 0 };
|
size_t i{ 0 };
|
||||||
const size_t max{ list.size()-1ul };
|
const size_t max{ list.size()-1ul };
|
||||||
for ( ; i<max; i++ ) {
|
for ( ; i<max; ++i ) {
|
||||||
if ( list.at( i ) == item ) {
|
if ( list.at( i ) == item ) {
|
||||||
list.at( i ) = list.at( i+1ul );
|
list.at( i ) = list.at( i+1ul );
|
||||||
list.at( i+1ul ) = item;
|
list.at( i+1ul ) = item;
|
||||||
i++;
|
++i;
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -258,11 +258,11 @@ int Craplog::warnlistMoveDown( const unsigned& web_server_id, const int& log_fie
|
||||||
auto& list = this->warnlists.at( web_server_id ).at( log_field_id ).list;
|
auto& list = this->warnlists.at( web_server_id ).at( log_field_id ).list;
|
||||||
size_t i{ 0 };
|
size_t i{ 0 };
|
||||||
const size_t max{ list.size()-1ul };
|
const size_t max{ list.size()-1ul };
|
||||||
for ( ; i<max; i++ ) {
|
for ( ; i<max; ++i ) {
|
||||||
if ( list.at( i ) == item ) {
|
if ( list.at( i ) == item ) {
|
||||||
list.at( i ) = list.at( i+1ul );
|
list.at( i ) = list.at( i+1ul );
|
||||||
list.at( i+1ul ) = item;
|
list.at( i+1ul ) = item;
|
||||||
i++;
|
++i;
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -602,7 +602,7 @@ bool Craplog::isFileNameValid( const std::string& name ) const
|
||||||
stop -= 3ul;
|
stop -= 3ul;
|
||||||
}
|
}
|
||||||
// serach for incremental numbers
|
// serach for incremental numbers
|
||||||
for ( size_t i{start}; i<=stop; i++ ) {
|
for ( size_t i{start}; i<=stop; ++i ) {
|
||||||
if ( ! CharOps::isNumeric( name.at( i ) ) ) {
|
if ( ! CharOps::isNumeric( name.at( i ) ) ) {
|
||||||
valid &= false;
|
valid &= false;
|
||||||
break;
|
break;
|
||||||
|
@ -623,7 +623,7 @@ bool Craplog::isFileNameValid( const std::string& name ) const
|
||||||
}
|
}
|
||||||
// search for date
|
// search for date
|
||||||
std::string date;
|
std::string date;
|
||||||
for ( size_t i{start}; i<=stop; i++ ) {
|
for ( size_t i{start}; i<=stop; ++i ) {
|
||||||
if ( ! CharOps::isNumeric( name.at( i ) ) ) {
|
if ( ! CharOps::isNumeric( name.at( i ) ) ) {
|
||||||
valid &= false;
|
valid &= false;
|
||||||
break;
|
break;
|
||||||
|
@ -639,7 +639,7 @@ bool Craplog::isFileNameValid( const std::string& name ) const
|
||||||
// using strftime to display time
|
// using strftime to display time
|
||||||
strftime( aux_date, 7, "%y%m%d", tmp );
|
strftime( aux_date, 7, "%y%m%d", tmp );
|
||||||
valid &= false;
|
valid &= false;
|
||||||
for ( size_t i{0}; i<6ul; i++ ) {
|
for ( size_t i{0}; i<6ul; ++i ) {
|
||||||
if ( date.at(i) != aux_date[i] ) {
|
if ( date.at(i) != aux_date[i] ) {
|
||||||
// different date, valid
|
// different date, valid
|
||||||
valid |= true;
|
valid |= true;
|
||||||
|
|
|
@ -66,14 +66,14 @@ std::string parseApacheEscapes( std::string_view string , const bool strftime=fa
|
||||||
cc = string.at( i+1ul );
|
cc = string.at( i+1ul );
|
||||||
if ( c == '\\' && (cc == '\\' || cc == '"') ) {
|
if ( c == '\\' && (cc == '\\' || cc == '"') ) {
|
||||||
str1.push_back( cc );
|
str1.push_back( cc );
|
||||||
i++;
|
++i;
|
||||||
} else if ( c == '%' && cc == '%' ) {
|
} else if ( c == '%' && cc == '%' ) {
|
||||||
str1.push_back( c );
|
str1.push_back( c );
|
||||||
i++;
|
++i;
|
||||||
} else {
|
} else {
|
||||||
str1.push_back( c );
|
str1.push_back( c );
|
||||||
}
|
}
|
||||||
i++;
|
++i;
|
||||||
}
|
}
|
||||||
i = 0ul;
|
i = 0ul;
|
||||||
max = str1.size()-1ul;
|
max = str1.size()-1ul;
|
||||||
|
@ -92,29 +92,29 @@ std::string parseApacheEscapes( std::string_view string , const bool strftime=fa
|
||||||
// just the ones supported
|
// just the ones supported
|
||||||
if ( cc == '\\' || cc == '"' ) {
|
if ( cc == '\\' || cc == '"' ) {
|
||||||
str2.push_back( cc );
|
str2.push_back( cc );
|
||||||
i++;
|
++i;
|
||||||
} else {
|
} else {
|
||||||
if ( strftime ) {
|
if ( strftime ) {
|
||||||
// when parsing for strftime, any other backslashed characters result in a backslash+character
|
// when parsing for strftime, any other backslashed characters result in a backslash+character
|
||||||
str2.push_back( c );
|
str2.push_back( c );
|
||||||
str2.push_back( cc );
|
str2.push_back( cc );
|
||||||
i++;
|
++i;
|
||||||
|
|
||||||
} else {
|
} else {
|
||||||
if ( cc == 'n' ) {
|
if ( cc == 'n' ) {
|
||||||
str2.push_back( '\n' );
|
str2.push_back( '\n' );
|
||||||
i++;
|
++i;
|
||||||
} else if ( cc == 'r' ) {
|
} else if ( cc == 'r' ) {
|
||||||
// not supported
|
// not supported
|
||||||
throw LogFormatException( "LogDoctor doesn't support the usage of the Carriage Return: '\\r'" );
|
throw LogFormatException( "LogDoctor doesn't support the usage of the Carriage Return: '\\r'" );
|
||||||
} else if ( cc == 't' ) {
|
} else if ( cc == 't' ) {
|
||||||
str2.push_back( '\t' );
|
str2.push_back( '\t' );
|
||||||
i++;
|
++i;
|
||||||
} else {
|
} else {
|
||||||
// any other backslashed characters result in a backslash+character
|
// any other backslashed characters result in a backslash+character
|
||||||
str2.push_back( c );
|
str2.push_back( c );
|
||||||
str2.push_back( cc );
|
str2.push_back( cc );
|
||||||
i++;
|
++i;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -122,21 +122,21 @@ std::string parseApacheEscapes( std::string_view string , const bool strftime=fa
|
||||||
// strftime control-characters
|
// strftime control-characters
|
||||||
if ( cc == 'n' ) {
|
if ( cc == 'n' ) {
|
||||||
str2.push_back( '\n' );
|
str2.push_back( '\n' );
|
||||||
i++;
|
++i;
|
||||||
} else if ( cc == 't' ) {
|
} else if ( cc == 't' ) {
|
||||||
str2.push_back( '\t' );
|
str2.push_back( '\t' );
|
||||||
i++;
|
++i;
|
||||||
} else {
|
} else {
|
||||||
// any other characters result in a percent+character
|
// any other characters result in a percent+character
|
||||||
str2.push_back( c );
|
str2.push_back( c );
|
||||||
str2.push_back( cc );
|
str2.push_back( cc );
|
||||||
i++;
|
++i;
|
||||||
}
|
}
|
||||||
|
|
||||||
} else {
|
} else {
|
||||||
str2.push_back( c );
|
str2.push_back( c );
|
||||||
}
|
}
|
||||||
i++;
|
++i;
|
||||||
}
|
}
|
||||||
|
|
||||||
str2.shrink_to_fit();
|
str2.shrink_to_fit();
|
||||||
|
@ -177,26 +177,26 @@ std::string parseNginxEscapes( std::string_view string )
|
||||||
// just the ones supported by nginx
|
// just the ones supported by nginx
|
||||||
if ( cc == '\\' || cc == '\'' || cc == '"' ) {
|
if ( cc == '\\' || cc == '\'' || cc == '"' ) {
|
||||||
str.push_back( cc );
|
str.push_back( cc );
|
||||||
i++;
|
++i;
|
||||||
} else if ( cc == 'n' ) {
|
} else if ( cc == 'n' ) {
|
||||||
str.push_back( '\n' );
|
str.push_back( '\n' );
|
||||||
i++;
|
++i;
|
||||||
} else if ( cc == 'r' ) {
|
} else if ( cc == 'r' ) {
|
||||||
// not supported
|
// not supported
|
||||||
throw LogFormatException( "LogDoctor doesn't support the usage of the Carriage Return: '\\r'" );
|
throw LogFormatException( "LogDoctor doesn't support the usage of the Carriage Return: '\\r'" );
|
||||||
} else if ( cc == 't' ) {
|
} else if ( cc == 't' ) {
|
||||||
str.push_back( '\t' );
|
str.push_back( '\t' );
|
||||||
i++;
|
++i;
|
||||||
} else {
|
} else {
|
||||||
// not a control-character, resulting in a backslash+character
|
// not a control-character, resulting in a backslash+character
|
||||||
str.push_back( c );
|
str.push_back( c );
|
||||||
str.push_back( cc );
|
str.push_back( cc );
|
||||||
i++;
|
++i;
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
str.push_back( c );
|
str.push_back( c );
|
||||||
}
|
}
|
||||||
i++;
|
++i;
|
||||||
}
|
}
|
||||||
|
|
||||||
str.shrink_to_fit();
|
str.shrink_to_fit();
|
||||||
|
@ -330,7 +330,7 @@ LogsFormat FormatOps::processApacheFormatString( const std::string& f_str ) cons
|
||||||
|
|
||||||
// append the current separator
|
// append the current separator
|
||||||
cur_sep += f_str.substr( start, aux-start );
|
cur_sep += f_str.substr( start, aux-start );
|
||||||
aux ++;
|
++ aux;
|
||||||
|
|
||||||
char c = f_str.at( aux );
|
char c = f_str.at( aux );
|
||||||
// remove the per-status directives (if any)
|
// remove the per-status directives (if any)
|
||||||
|
@ -344,7 +344,7 @@ LogsFormat FormatOps::processApacheFormatString( const std::string& f_str ) cons
|
||||||
c = f_str.at( aux_aux );
|
c = f_str.at( aux_aux );
|
||||||
if ( CharOps::isNumeric( c ) || c == '!' || c == ',' ) {
|
if ( CharOps::isNumeric( c ) || c == '!' || c == ',' ) {
|
||||||
// skip these chars
|
// skip these chars
|
||||||
aux_aux ++;
|
++ aux_aux;
|
||||||
continue;
|
continue;
|
||||||
} else {
|
} else {
|
||||||
// stop
|
// stop
|
||||||
|
@ -493,7 +493,7 @@ LogsFormat FormatOps::processApacheFormatString( const std::string& f_str ) cons
|
||||||
cur_sep.clear();
|
cur_sep.clear();
|
||||||
// append the field
|
// append the field
|
||||||
fields.push_back( cur_fld );
|
fields.push_back( cur_fld );
|
||||||
n_fld ++;
|
++ n_fld;
|
||||||
|
|
||||||
} else {
|
} else {
|
||||||
// invalid, append as separator and keep hunting
|
// invalid, append as separator and keep hunting
|
||||||
|
@ -514,7 +514,7 @@ LogsFormat FormatOps::processApacheFormatString( const std::string& f_str ) cons
|
||||||
aux_stop = aux+1ul;
|
aux_stop = aux+1ul;
|
||||||
if ( aux_fld == ">" || aux_fld == "<" ) {
|
if ( aux_fld == ">" || aux_fld == "<" ) {
|
||||||
aux_fld += f_str.at( aux+1 );
|
aux_fld += f_str.at( aux+1 );
|
||||||
aux_stop ++;
|
++ aux_stop;
|
||||||
}
|
}
|
||||||
// check if the module is valid
|
// check if the module is valid
|
||||||
if ( f_map.find( aux_fld ) != f_map.end() ) {
|
if ( f_map.find( aux_fld ) != f_map.end() ) {
|
||||||
|
@ -566,7 +566,7 @@ LogsFormat FormatOps::processApacheFormatString( const std::string& f_str ) cons
|
||||||
|
|
||||||
// append the field
|
// append the field
|
||||||
fields.push_back( cur_fld );
|
fields.push_back( cur_fld );
|
||||||
n_fld++;
|
++ n_fld;
|
||||||
}
|
}
|
||||||
|
|
||||||
return LogsFormat(
|
return LogsFormat(
|
||||||
|
@ -582,7 +582,7 @@ QString FormatOps::getApacheLogSample( const LogsFormat& log_format ) const
|
||||||
|
|
||||||
// append the initial characters
|
// append the initial characters
|
||||||
sample += QString::fromStdString( log_format.initial );
|
sample += QString::fromStdString( log_format.initial );
|
||||||
for ( size_t i{0ul}; i<log_format.separators.size(); i++ ) {
|
for ( size_t i{0ul}; i<log_format.separators.size(); ++i ) {
|
||||||
// append fields and separators
|
// append fields and separators
|
||||||
sample += map.at( log_format.fields.at( i ) );
|
sample += map.at( log_format.fields.at( i ) );
|
||||||
sample += QString::fromStdString( log_format.separators.at( i ) );
|
sample += QString::fromStdString( log_format.separators.at( i ) );
|
||||||
|
@ -624,14 +624,14 @@ LogsFormat FormatOps::processNginxFormatString( const std::string& f_str ) const
|
||||||
final = parseNginxEscapes( f_str.substr( start ) );
|
final = parseNginxEscapes( f_str.substr( start ) );
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
aux ++;
|
++ aux;
|
||||||
// find the end of the current field
|
// find the end of the current field
|
||||||
stop = findNginxFieldEnd( f_str, aux );
|
stop = findNginxFieldEnd( f_str, aux );
|
||||||
if ( stop == max ) {
|
if ( stop == max ) {
|
||||||
// this is the last field, and ther's no final separator
|
// this is the last field, and ther's no final separator
|
||||||
finished |= true;
|
finished |= true;
|
||||||
}
|
}
|
||||||
stop ++;
|
++ stop;
|
||||||
|
|
||||||
cur_sep = f_str.substr( start, aux-start-1ul );
|
cur_sep = f_str.substr( start, aux-start-1ul );
|
||||||
cur_fld = f_str.substr( aux, stop-aux );
|
cur_fld = f_str.substr( aux, stop-aux );
|
||||||
|
@ -683,7 +683,7 @@ QString FormatOps::getNginxLogSample( const LogsFormat& log_format ) const
|
||||||
|
|
||||||
// append the initial characters
|
// append the initial characters
|
||||||
sample += QString::fromStdString( log_format.initial );
|
sample += QString::fromStdString( log_format.initial );
|
||||||
for ( size_t i{0}; i<log_format.separators.size(); i++ ) {
|
for ( size_t i{0}; i<log_format.separators.size(); ++i ) {
|
||||||
// append fields and separators
|
// append fields and separators
|
||||||
sample += map.at( log_format.fields.at( i ) );
|
sample += map.at( log_format.fields.at( i ) );
|
||||||
sample += QString::fromStdString( log_format.separators.at( i ) );
|
sample += QString::fromStdString( log_format.separators.at( i ) );
|
||||||
|
@ -740,7 +740,7 @@ LogsFormat FormatOps::processIisFormatString( const std::string& f_str, const in
|
||||||
// set the current field
|
// set the current field
|
||||||
cur_fld = f_str.substr( start, stop-start );
|
cur_fld = f_str.substr( start, stop-start );
|
||||||
// step over the separator
|
// step over the separator
|
||||||
stop++;
|
++ stop;
|
||||||
|
|
||||||
// check if the module is valid
|
// check if the module is valid
|
||||||
if ( f_map.find( cur_fld ) != f_map.end() ) {
|
if ( f_map.find( cur_fld ) != f_map.end() ) {
|
||||||
|
@ -777,7 +777,7 @@ QString FormatOps::getIisLogSample( const LogsFormat& log_format ) const
|
||||||
|
|
||||||
// append the initial characters
|
// append the initial characters
|
||||||
sample += QString::fromStdString( log_format.initial );
|
sample += QString::fromStdString( log_format.initial );
|
||||||
for ( size_t i{0}; i<log_format.separators.size(); i++ ) {
|
for ( size_t i{0}; i<log_format.separators.size(); ++i ) {
|
||||||
// append fields and separators
|
// append fields and separators
|
||||||
sample += map.at( log_format.fields.at( i ) );
|
sample += map.at( log_format.fields.at( i ) );
|
||||||
sample += QString::fromStdString( log_format.separators.at( i ) );
|
sample += QString::fromStdString( log_format.separators.at( i ) );
|
||||||
|
|
|
@ -29,18 +29,18 @@ bool deepTypeCheck( const std::string& line, const LogsFormat& format )
|
||||||
// check the initial part
|
// check the initial part
|
||||||
if ( ! format.initial.empty() ) {
|
if ( ! format.initial.empty() ) {
|
||||||
if ( StringOps::startsWith( line, format.initial ) ) {
|
if ( StringOps::startsWith( line, format.initial ) ) {
|
||||||
n_sep_found ++;
|
++ n_sep_found;
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
n_sep_found ++;
|
++ n_sep_found;
|
||||||
n_blank_sep ++;
|
++ n_blank_sep;
|
||||||
}
|
}
|
||||||
// check the middle part
|
// check the middle part
|
||||||
for ( size_t i{0}; i<n_sep; i++ ) {
|
for ( size_t i{0}; i<n_sep; ++i ) {
|
||||||
sep = format.separators.at( i );
|
sep = format.separators.at( i );
|
||||||
if ( sep.empty() ) {
|
if ( sep.empty() ) {
|
||||||
n_sep_found ++;
|
++ n_sep_found;
|
||||||
n_blank_sep ++;
|
++ n_blank_sep;
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
aux_found_at2 = aux_found_at1;
|
aux_found_at2 = aux_found_at1;
|
||||||
|
@ -58,7 +58,7 @@ bool deepTypeCheck( const std::string& line, const LogsFormat& format )
|
||||||
aux_sep1 = StringOps::lstripUntil( aux_sep1, ' ' );
|
aux_sep1 = StringOps::lstripUntil( aux_sep1, ' ' );
|
||||||
}
|
}
|
||||||
// iterate over following separators
|
// iterate over following separators
|
||||||
for ( size_t j{i+1ul}; j<n_sep; j++ ) {
|
for ( size_t j{i+1ul}; j<n_sep; ++j ) {
|
||||||
aux_sep2 = format.separators.at( j );
|
aux_sep2 = format.separators.at( j );
|
||||||
aux_found_at2 = aux_sep2.find(' ');
|
aux_found_at2 = aux_sep2.find(' ');
|
||||||
if ( aux_found_at2 == std::string::npos ) {
|
if ( aux_found_at2 == std::string::npos ) {
|
||||||
|
@ -81,18 +81,18 @@ bool deepTypeCheck( const std::string& line, const LogsFormat& format )
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
aux_found_at1 = found_at + sep.size();
|
aux_found_at1 = found_at + sep.size();
|
||||||
n_sep_found ++;
|
++ n_sep_found;
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// check the final part
|
// check the final part
|
||||||
if ( ! format.final.empty() ) {
|
if ( ! format.final.empty() ) {
|
||||||
if ( StringOps::endsWith( line, format.final ) ) {
|
if ( StringOps::endsWith( line, format.final ) ) {
|
||||||
n_sep_found ++;
|
++ n_sep_found;
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
n_sep_found ++;
|
++ n_sep_found;
|
||||||
n_blank_sep ++;
|
++ n_blank_sep;
|
||||||
}
|
}
|
||||||
|
|
||||||
// add the initial and final seps now
|
// add the initial and final seps now
|
||||||
|
@ -124,9 +124,9 @@ LogType defineFileType( const std::vector<std::string>& lines, const LogsFormat&
|
||||||
for ( const std::string& line : lines ) {
|
for ( const std::string& line : lines ) {
|
||||||
// scan the given lines
|
// scan the given lines
|
||||||
if ( deepTypeCheck( line, format ) ) {
|
if ( deepTypeCheck( line, format ) ) {
|
||||||
n_access++;
|
++ n_access;
|
||||||
} else {
|
} else {
|
||||||
n_other++;
|
++ n_other;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -256,7 +256,7 @@ LogLineData::LogLineData(const std::string& line, const LogsFormat& logs_format)
|
||||||
|
|
||||||
// update the stop for the next start
|
// update the stop for the next start
|
||||||
stop += sep_size;
|
stop += sep_size;
|
||||||
sep_i++;
|
++sep_i;
|
||||||
if ( stop > line_size ) {
|
if ( stop > line_size ) {
|
||||||
// this was the final separator
|
// this was the final separator
|
||||||
break;
|
break;
|
||||||
|
|
|
@ -193,7 +193,7 @@ void CraplogParser::parseLogLines()
|
||||||
const auto parseLine = [this]( const std::string& line, const LogsFormat& logs_format ) {
|
const auto parseLine = [this]( const std::string& line, const LogsFormat& logs_format ) {
|
||||||
this->data_collection.emplace_back( LogLineData(line, logs_format) );
|
this->data_collection.emplace_back( LogLineData(line, logs_format) );
|
||||||
this->parsed_size += line.size();
|
this->parsed_size += line.size();
|
||||||
this->parsed_lines ++;
|
++ this->parsed_lines;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
||||||
|
@ -219,10 +219,10 @@ void CraplogParser::parseLogLines()
|
||||||
const size_t send_gap{ real_lines>1000ul ? real_lines/100 : real_lines>100ul ? real_lines/10 : 10 };
|
const size_t send_gap{ real_lines>1000ul ? real_lines/100 : real_lines>100ul ? real_lines/10 : 10 };
|
||||||
const LogsFormat& lf {this->logs_format};
|
const LogsFormat& lf {this->logs_format};
|
||||||
this->data_collection.reserve( real_lines );
|
this->data_collection.reserve( real_lines );
|
||||||
for ( size_t i{0ul}; i<n_lines; i++ ) {
|
for ( size_t i{0ul}; i<n_lines; ++i ) {
|
||||||
std::string line = this->logs_lines.at( i );
|
std::string line = this->logs_lines.at( i );
|
||||||
for ( size_t n{0ul}; n<nl; n++ ) {
|
for ( size_t n{0ul}; n<nl; ++n ) {
|
||||||
i++;
|
++i;
|
||||||
line += "\n" + this->logs_lines.at( i );
|
line += "\n" + this->logs_lines.at( i );
|
||||||
}
|
}
|
||||||
parseLine( line, lf );
|
parseLine( line, lf );
|
||||||
|
|
|
@ -153,7 +153,7 @@ void Crapview::sliceClicked( QPieSlice* slice )
|
||||||
void Crapview::updateWarn( QTableWidget* table , const QString& web_server ) const
|
void Crapview::updateWarn( QTableWidget* table , const QString& web_server ) const
|
||||||
{
|
{
|
||||||
std::vector<std::tuple<int, int>> updates; // { (rowid, warn) }
|
std::vector<std::tuple<int, int>> updates; // { (rowid, warn) }
|
||||||
for ( int i{0}; i<table->rowCount(); i++ ) {
|
for ( int i{0}; i<table->rowCount(); ++i ) {
|
||||||
QTableWidgetItem* item = table->item( i, 0 );
|
QTableWidgetItem* item = table->item( i, 0 );
|
||||||
if ( item->checkState() == Qt::CheckState::Checked && item->text() == TR::tr( BOOLS__FALSE.c_str() ) ) {
|
if ( item->checkState() == Qt::CheckState::Checked && item->text() == TR::tr( BOOLS__FALSE.c_str() ) ) {
|
||||||
// remove warning
|
// remove warning
|
||||||
|
@ -188,13 +188,13 @@ void Crapview::drawWarn( QTableWidget* table, QChartView* chart, const QChart::C
|
||||||
int norm_count, warn_count, sum_count, max_count=0, n_rows=0;
|
int norm_count, warn_count, sum_count, max_count=0, n_rows=0;
|
||||||
if ( hour.isEmpty() ) {
|
if ( hour.isEmpty() ) {
|
||||||
// entire day
|
// entire day
|
||||||
for ( int i{0}; i<6; i++ ) {
|
for ( int i{0}; i<6; ++i ) {
|
||||||
sets.push_back( std::vector<QBarSet*>() );
|
sets.push_back( std::vector<QBarSet*>() );
|
||||||
sets.back().push_back( new QBarSet("") );
|
sets.back().push_back( new QBarSet("") );
|
||||||
sets.back().push_back( new QBarSet("") );
|
sets.back().push_back( new QBarSet("") );
|
||||||
}
|
}
|
||||||
for ( size_t h{0}; h<24ul; h++ ) {
|
for ( size_t h{0}; h<24ul; ++h ) {
|
||||||
for ( size_t m{0}; m<6ul; m++ ) {
|
for ( size_t m{0}; m<6ul; ++m ) {
|
||||||
const auto& data{ items.at( h ).at( m ) };
|
const auto& data{ items.at( h ).at( m ) };
|
||||||
norm_count = warn_count = 0;
|
norm_count = warn_count = 0;
|
||||||
for ( const std::vector<QString>& line : data ) {
|
for ( const std::vector<QString>& line : data ) {
|
||||||
|
@ -210,7 +210,7 @@ void Crapview::drawWarn( QTableWidget* table, QChartView* chart, const QChart::C
|
||||||
table->setItem( n_rows, 2, new QTableWidgetItem( PrintSec::printableTime( line.at( 4 ).toInt(), line.at( 5 ).toInt(), line.at( 6 ).toInt() )));
|
table->setItem( n_rows, 2, new QTableWidgetItem( PrintSec::printableTime( line.at( 4 ).toInt(), line.at( 5 ).toInt(), line.at( 6 ).toInt() )));
|
||||||
int col{ 3 };
|
int col{ 3 };
|
||||||
const size_t max{ line.size() };
|
const size_t max{ line.size() };
|
||||||
for ( size_t i{7ul}; i<max; i++ ) {
|
for ( size_t i{7ul}; i<max; ++i ) {
|
||||||
QTableWidgetItem* itm;
|
QTableWidgetItem* itm;
|
||||||
if ( (col == 7 || col >= 12) && !line.at(i).isEmpty() ) {
|
if ( (col == 7 || col >= 12) && !line.at(i).isEmpty() ) {
|
||||||
itm = new QTableWidgetItem();
|
itm = new QTableWidgetItem();
|
||||||
|
@ -219,14 +219,14 @@ void Crapview::drawWarn( QTableWidget* table, QChartView* chart, const QChart::C
|
||||||
itm = new QTableWidgetItem( line.at( i ) );
|
itm = new QTableWidgetItem( line.at( i ) );
|
||||||
}
|
}
|
||||||
table->setItem( n_rows, col, itm );
|
table->setItem( n_rows, col, itm );
|
||||||
col ++;
|
++ col;
|
||||||
}
|
}
|
||||||
if ( line.at( 0ul ) == "0" ) {
|
if ( line.at( 0ul ) == "0" ) {
|
||||||
norm_count ++;
|
++ norm_count;
|
||||||
} else {
|
} else {
|
||||||
warn_count ++;
|
++ warn_count;
|
||||||
}
|
}
|
||||||
n_rows ++;
|
++ n_rows;
|
||||||
}
|
}
|
||||||
sets.at( m ).at( 0ul )->append( norm_count );
|
sets.at( m ).at( 0ul )->append( norm_count );
|
||||||
sets.at( m ).at( 1ul )->append( warn_count );
|
sets.at( m ).at( 1ul )->append( warn_count );
|
||||||
|
@ -239,13 +239,13 @@ void Crapview::drawWarn( QTableWidget* table, QChartView* chart, const QChart::C
|
||||||
date = PrintSec::printableDate( year, this->getMonthNumber( month ), day );
|
date = PrintSec::printableDate( year, this->getMonthNumber( month ), day );
|
||||||
} else {
|
} else {
|
||||||
// 1 hour
|
// 1 hour
|
||||||
for ( int i{0}; i<10; i++ ) {
|
for ( int i{0}; i<10; ++i ) {
|
||||||
sets.push_back( std::vector<QBarSet*>() );
|
sets.push_back( std::vector<QBarSet*>() );
|
||||||
sets.back().push_back( new QBarSet("") );
|
sets.back().push_back( new QBarSet("") );
|
||||||
sets.back().push_back( new QBarSet("") );
|
sets.back().push_back( new QBarSet("") );
|
||||||
}
|
}
|
||||||
for ( size_t g{0ul}; g<6ul; g++ ) {
|
for ( size_t g{0ul}; g<6ul; ++g ) {
|
||||||
for ( size_t m{0ul}; m<10ul; m++ ) {
|
for ( size_t m{0ul}; m<10ul; ++m ) {
|
||||||
const auto& data{ items.at( g ).at( m ) };
|
const auto& data{ items.at( g ).at( m ) };
|
||||||
norm_count = warn_count = 0;
|
norm_count = warn_count = 0;
|
||||||
for ( const std::vector<QString>& line : data ) {
|
for ( const std::vector<QString>& line : data ) {
|
||||||
|
@ -260,13 +260,13 @@ void Crapview::drawWarn( QTableWidget* table, QChartView* chart, const QChart::C
|
||||||
}
|
}
|
||||||
table->setItem( n_rows, 1, new QTableWidgetItem( PrintSec::printableDate( line.at( 1 ).toInt(), line.at( 2 ).toInt(), line.at( 3 ).toInt() )));
|
table->setItem( n_rows, 1, new QTableWidgetItem( PrintSec::printableDate( line.at( 1 ).toInt(), line.at( 2 ).toInt(), line.at( 3 ).toInt() )));
|
||||||
table->setItem( n_rows, 2, new QTableWidgetItem( PrintSec::printableTime( line.at( 4 ).toInt(), line.at( 5 ).toInt(), line.at( 6 ).toInt() )));
|
table->setItem( n_rows, 2, new QTableWidgetItem( PrintSec::printableTime( line.at( 4 ).toInt(), line.at( 5 ).toInt(), line.at( 6 ).toInt() )));
|
||||||
for ( size_t i{7ul}; i<line.size(); i++ ) {
|
for ( size_t i{7ul}; i<line.size(); ++i ) {
|
||||||
table->setItem( n_rows, i-4, new QTableWidgetItem( line.at( i ) ));
|
table->setItem( n_rows, i-4, new QTableWidgetItem( line.at( i ) ));
|
||||||
}
|
}
|
||||||
if ( line.at( 0ul ) == "0" ) {
|
if ( line.at( 0ul ) == "0" ) {
|
||||||
norm_count ++;
|
++ norm_count;
|
||||||
} else {
|
} else {
|
||||||
warn_count ++;
|
++ warn_count;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
sets.at( m ).at( 0ul )->append( norm_count );
|
sets.at( m ).at( 0ul )->append( norm_count );
|
||||||
|
@ -286,10 +286,10 @@ void Crapview::drawWarn( QTableWidget* table, QChartView* chart, const QChart::C
|
||||||
//QColor cols[] = {QColor(18,175,194), QColor(237,80,61)};
|
//QColor cols[] = {QColor(18,175,194), QColor(237,80,61)};
|
||||||
std::vector<QStackedBarSeries*> b_series;
|
std::vector<QStackedBarSeries*> b_series;
|
||||||
const size_t max{ sets.size() };
|
const size_t max{ sets.size() };
|
||||||
for ( size_t i{0}; i<max; i++ ) {
|
for ( size_t i{0}; i<max; ++i ) {
|
||||||
const auto& set{ sets.at( i ) };
|
const auto& set{ sets.at( i ) };
|
||||||
b_series.push_back( new QStackedBarSeries() );
|
b_series.push_back( new QStackedBarSeries() );
|
||||||
for ( size_t w{0}; w<2ul; w++ ) {
|
for ( size_t w{0}; w<2ul; ++w ) {
|
||||||
QBarSet* b = set.at( w );
|
QBarSet* b = set.at( w );
|
||||||
b->setColor( cols[ w ] );
|
b->setColor( cols[ w ] );
|
||||||
b_series.at( i )->append( b );
|
b_series.at( i )->append( b );
|
||||||
|
@ -374,7 +374,7 @@ void Crapview::drawSpeed( QTableWidget* table, QChartView* chart, const QChart::
|
||||||
QDateTime dt;
|
QDateTime dt;
|
||||||
std::vector<QString> data;
|
std::vector<QString> data;
|
||||||
for ( const auto& item : items ) {
|
for ( const auto& item : items ) {
|
||||||
i++;
|
++i;
|
||||||
// append a value to the chart
|
// append a value to the chart
|
||||||
aux_time = std::get<0>(item);
|
aux_time = std::get<0>(item);
|
||||||
data = std::get<1>(item);
|
data = std::get<1>(item);
|
||||||
|
@ -401,7 +401,7 @@ void Crapview::drawSpeed( QTableWidget* table, QChartView* chart, const QChart::
|
||||||
if ( first_count ) {
|
if ( first_count ) {
|
||||||
first_count &= false;
|
first_count &= false;
|
||||||
} else {
|
} else {
|
||||||
count ++;
|
++ count;
|
||||||
}
|
}
|
||||||
value += aux_value;
|
value += aux_value;
|
||||||
if ( i == max_i ) {
|
if ( i == max_i ) {
|
||||||
|
@ -426,7 +426,7 @@ void Crapview::drawSpeed( QTableWidget* table, QChartView* chart, const QChart::
|
||||||
table->setItem( n_rows, 5, new QTableWidgetItem( data.at(5ul) ));
|
table->setItem( n_rows, 5, new QTableWidgetItem( data.at(5ul) ));
|
||||||
dt = QDateTime::fromMSecsSinceEpoch( aux_time );
|
dt = QDateTime::fromMSecsSinceEpoch( aux_time );
|
||||||
table->setItem( n_rows, 6, new QTableWidgetItem( dt.time().toString("hh:mm:ss") ));
|
table->setItem( n_rows, 6, new QTableWidgetItem( dt.time().toString("hh:mm:ss") ));
|
||||||
n_rows ++;
|
++ n_rows;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
table->verticalHeader()->setVisible( false );
|
table->verticalHeader()->setVisible( false );
|
||||||
|
@ -527,7 +527,7 @@ void Crapview::drawCount( QTableWidget* table, QChartView* chart, const QChart::
|
||||||
ic->setData( Qt::DisplayRole, count );
|
ic->setData( Qt::DisplayRole, count );
|
||||||
table->setItem( n_rows, 0, ic );
|
table->setItem( n_rows, 0, ic );
|
||||||
table->setItem( n_rows, 1, new QTableWidgetItem( item ));
|
table->setItem( n_rows, 1, new QTableWidgetItem( item ));
|
||||||
n_rows ++;
|
++ n_rows;
|
||||||
}
|
}
|
||||||
table->verticalHeader()->setVisible( false );
|
table->verticalHeader()->setVisible( false );
|
||||||
|
|
||||||
|
@ -594,7 +594,7 @@ void Crapview::drawDay( QChartView* chart, const QChart::ChartTheme& theme, cons
|
||||||
|
|
||||||
// build the bars upon data
|
// build the bars upon data
|
||||||
int count, max_count{0};
|
int count, max_count{0};
|
||||||
for ( size_t h{0ul}; h<24ul; h++ ) {
|
for ( size_t h{0ul}; h<24ul; ++h ) {
|
||||||
auto& data = items.at( h );
|
auto& data = items.at( h );
|
||||||
count = data.at( 0ul );
|
count = data.at( 0ul );
|
||||||
*b_10 << count;
|
*b_10 << count;
|
||||||
|
@ -823,7 +823,7 @@ bool Crapview::calcGlobals( std::vector<std::tuple<QString,QString>>& recur_list
|
||||||
// compose the results
|
// compose the results
|
||||||
|
|
||||||
// max request elements
|
// max request elements
|
||||||
for ( size_t i{0}; i<4ul; i++ ) {
|
for ( size_t i{0}; i<4ul; ++i ) {
|
||||||
unsigned max{ 0 };
|
unsigned max{ 0 };
|
||||||
QString max_str{ "-" };
|
QString max_str{ "-" };
|
||||||
const auto& aux{ recurs.at( i ) };
|
const auto& aux{ recurs.at( i ) };
|
||||||
|
|
|
@ -115,18 +115,18 @@ std::optional<QString> parseNumericFilter( const QString& filter_str )
|
||||||
size_t i{ 0ul };
|
size_t i{ 0ul };
|
||||||
const size_t max{ str.size() };
|
const size_t max{ str.size() };
|
||||||
if ( char c=str.at(i); c == '=' || c == '!' || c == '<' || c == '>' ) {
|
if ( char c=str.at(i); c == '=' || c == '!' || c == '<' || c == '>' ) {
|
||||||
i ++;
|
++i;
|
||||||
if ( i >= max ) {
|
if ( i >= max ) {
|
||||||
return result;
|
return result;
|
||||||
}
|
}
|
||||||
if ( str.at(i) == '=' ) {
|
if ( str.at(i) == '=' ) {
|
||||||
i ++;
|
++i;
|
||||||
if ( i >= max ) {
|
if ( i >= max ) {
|
||||||
return result;
|
return result;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
if ( str.at(i) == ' ' ) {
|
if ( str.at(i) == ' ' ) {
|
||||||
i ++;
|
++i;
|
||||||
if ( i >= max ) {
|
if ( i >= max ) {
|
||||||
return result;
|
return result;
|
||||||
}
|
}
|
||||||
|
|
|
@ -43,7 +43,7 @@ int DbQuery::getMinuteGap( const int minute, const int gap )
|
||||||
m = gap * n;
|
m = gap * n;
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
n++;
|
++n;
|
||||||
}
|
}
|
||||||
return m;
|
return m;
|
||||||
}
|
}
|
||||||
|
@ -95,7 +95,7 @@ int DbQuery::countDays( const int from_year, const int from_month, const int fro
|
||||||
n_days += to_day - from_day + 1;
|
n_days += to_day - from_day + 1;
|
||||||
} else {
|
} else {
|
||||||
n_days += getMonthDays( from_year, from_month ) - from_day; // first month's days
|
n_days += getMonthDays( from_year, from_month ) - from_day; // first month's days
|
||||||
for ( int month=from_month+1; month<to_month; month++ ) {
|
for ( int month=from_month+1; month<to_month; ++month ) {
|
||||||
n_days += getMonthDays( from_year, month );
|
n_days += getMonthDays( from_year, month );
|
||||||
}
|
}
|
||||||
n_days += to_day; // last month's days
|
n_days += to_day; // last month's days
|
||||||
|
@ -103,17 +103,17 @@ int DbQuery::countDays( const int from_year, const int from_month, const int fro
|
||||||
} else {
|
} else {
|
||||||
n_days += getMonthDays( from_year, from_month ) - from_day;
|
n_days += getMonthDays( from_year, from_month ) - from_day;
|
||||||
if ( from_month < 12 ) {
|
if ( from_month < 12 ) {
|
||||||
for ( int month{from_month+1}; month<=12; month++ ) {
|
for ( int month{from_month+1}; month<=12; ++month ) {
|
||||||
n_days += getMonthDays( from_year, month );
|
n_days += getMonthDays( from_year, month );
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
for ( int year{from_year+1}; year<=to_year; year++ ) {
|
for ( int year{from_year+1}; year<=to_year; ++year ) {
|
||||||
int last_month{ 12 };
|
int last_month{ 12 };
|
||||||
if ( year == to_year ) {
|
if ( year == to_year ) {
|
||||||
last_month = to_month-1;
|
last_month = to_month-1;
|
||||||
n_days += to_day; // last month's days, added in advance
|
n_days += to_day; // last month's days, added in advance
|
||||||
}
|
}
|
||||||
for ( int month{1}; month<=last_month; month++ ) {
|
for ( int month{1}; month<=last_month; ++month ) {
|
||||||
n_days += getMonthDays( year, month );
|
n_days += getMonthDays( year, month );
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -451,7 +451,7 @@ void DbQuery::getWarnCounts( std::optional<stats_warn_items_t>& result, const QS
|
||||||
if ( hour_.isEmpty() ) {
|
if ( hour_.isEmpty() ) {
|
||||||
// entire day
|
// entire day
|
||||||
items.reserve( 24 );
|
items.reserve( 24 );
|
||||||
for ( size_t h{0}; h<24ul; h++ ) {
|
for ( size_t h{0}; h<24ul; ++h ) {
|
||||||
items.push_back( std::vector<std::vector<std::vector<QString>>>() );
|
items.push_back( std::vector<std::vector<std::vector<QString>>>() );
|
||||||
auto& aux{ items.at( h ) };
|
auto& aux{ items.at( h ) };
|
||||||
aux.reserve( 6 );
|
aux.reserve( 6 );
|
||||||
|
@ -472,10 +472,10 @@ void DbQuery::getWarnCounts( std::optional<stats_warn_items_t>& result, const QS
|
||||||
while ( query.next() ) {
|
while ( query.next() ) {
|
||||||
std::vector<QString> aux;
|
std::vector<QString> aux;
|
||||||
aux.reserve( 20 );
|
aux.reserve( 20 );
|
||||||
for ( int i{1}; i<13; i++ ) {
|
for ( int i{1}; i<13; ++i ) {
|
||||||
aux.push_back( query.value( i ).toString() );
|
aux.push_back( query.value( i ).toString() );
|
||||||
}
|
}
|
||||||
for ( int i{19}; i>12; i-- ) {
|
for ( int i{19}; i>12; --i ) {
|
||||||
aux.push_back( query.value( i ).toString() );
|
aux.push_back( query.value( i ).toString() );
|
||||||
}
|
}
|
||||||
aux.push_back( query.value( 0 ).toString() );
|
aux.push_back( query.value( 0 ).toString() );
|
||||||
|
@ -494,11 +494,11 @@ void DbQuery::getWarnCounts( std::optional<stats_warn_items_t>& result, const QS
|
||||||
} else {
|
} else {
|
||||||
// 1 hour
|
// 1 hour
|
||||||
items.reserve( 6 );
|
items.reserve( 6 );
|
||||||
for ( size_t g{0}; g<6ul; g++ ) {
|
for ( size_t g{0}; g<6ul; ++g ) {
|
||||||
items.push_back( std::vector<std::vector<std::vector<QString>>>() );
|
items.push_back( std::vector<std::vector<std::vector<QString>>>() );
|
||||||
auto& aux{ items.at( g ) };
|
auto& aux{ items.at( g ) };
|
||||||
aux.reserve( 10ul );
|
aux.reserve( 10ul );
|
||||||
for ( int m{0}; m<10; m++ ) {
|
for ( int m{0}; m<10; ++m ) {
|
||||||
aux.push_back( std::vector<std::vector<QString>>() );
|
aux.push_back( std::vector<std::vector<QString>>() );
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -515,10 +515,10 @@ void DbQuery::getWarnCounts( std::optional<stats_warn_items_t>& result, const QS
|
||||||
while ( query.next() ) {
|
while ( query.next() ) {
|
||||||
std::vector<QString> aux;
|
std::vector<QString> aux;
|
||||||
aux.reserve( 20 );
|
aux.reserve( 20 );
|
||||||
for ( int i{1}; i<13; i++ ) {
|
for ( int i{1}; i<13; ++i ) {
|
||||||
aux.push_back( query.value( i ).toString() );
|
aux.push_back( query.value( i ).toString() );
|
||||||
}
|
}
|
||||||
for ( int i{19}; i>12; i-- ) {
|
for ( int i{19}; i>12; --i ) {
|
||||||
aux.push_back( query.value( i ).toString() );
|
aux.push_back( query.value( i ).toString() );
|
||||||
}
|
}
|
||||||
aux.push_back( query.value( 0 ).toString() );
|
aux.push_back( query.value( 0 ).toString() );
|
||||||
|
@ -714,9 +714,9 @@ void DbQuery::getSpeedData( std::optional<stats_speed_items_t>& result, const QS
|
||||||
if ( aux_hour == hour ) {
|
if ( aux_hour == hour ) {
|
||||||
h=hour; m=minute; s=second-1;
|
h=hour; m=minute; s=second-1;
|
||||||
if ( s < 0 ) {
|
if ( s < 0 ) {
|
||||||
s=59; m--;
|
s=59; --m;
|
||||||
if ( m < 0 ) {
|
if ( m < 0 ) {
|
||||||
m=59; h--;
|
m=59; --h;
|
||||||
if ( h < 0 ) {
|
if ( h < 0 ) {
|
||||||
h=m=s=0;
|
h=m=s=0;
|
||||||
}
|
}
|
||||||
|
@ -737,9 +737,9 @@ void DbQuery::getSpeedData( std::optional<stats_speed_items_t>& result, const QS
|
||||||
// append the second after the last one found, if it is not equal to the next
|
// append the second after the last one found, if it is not equal to the next
|
||||||
h=hour; m=minute; s=second+1;
|
h=hour; m=minute; s=second+1;
|
||||||
if ( s > 59 ) {
|
if ( s > 59 ) {
|
||||||
s=0; m++;
|
s=0; ++m;
|
||||||
if ( m > 59 ) {
|
if ( m > 59 ) {
|
||||||
m=0; h++;
|
m=0; ++h;
|
||||||
if ( h > 23 ) {
|
if ( h > 23 ) {
|
||||||
h=23;m=59;s=59;
|
h=23;m=59;s=59;
|
||||||
}
|
}
|
||||||
|
@ -759,9 +759,9 @@ void DbQuery::getSpeedData( std::optional<stats_speed_items_t>& result, const QS
|
||||||
// append the prev as zero
|
// append the prev as zero
|
||||||
h=hour; m=minute; s=second-1;
|
h=hour; m=minute; s=second-1;
|
||||||
if ( s < 0 ) {
|
if ( s < 0 ) {
|
||||||
s=59; m--;
|
s=59; --m;
|
||||||
if ( m < 0 ) {
|
if ( m < 0 ) {
|
||||||
m=59; h--;
|
m=59; --h;
|
||||||
if ( h < 0 ) {
|
if ( h < 0 ) {
|
||||||
h=m=s=0;
|
h=m=s=0;
|
||||||
}
|
}
|
||||||
|
@ -781,9 +781,9 @@ void DbQuery::getSpeedData( std::optional<stats_speed_items_t>& result, const QS
|
||||||
// append the next as zero
|
// append the next as zero
|
||||||
h=hour; m=minute; s=second+1;
|
h=hour; m=minute; s=second+1;
|
||||||
if ( s > 59 ) {
|
if ( s > 59 ) {
|
||||||
s=0; m++;
|
s=0; ++m;
|
||||||
if ( m > 59 ) {
|
if ( m > 59 ) {
|
||||||
m=0; h++;
|
m=0; ++h;
|
||||||
if ( h > 23 ) {
|
if ( h > 23 ) {
|
||||||
h=23;m=59;s=59;
|
h=23;m=59;s=59;
|
||||||
}
|
}
|
||||||
|
@ -805,9 +805,9 @@ void DbQuery::getSpeedData( std::optional<stats_speed_items_t>& result, const QS
|
||||||
// append the second before the first found
|
// append the second before the first found
|
||||||
h=aux_hour; m=aux_minute; s=aux_second-1;
|
h=aux_hour; m=aux_minute; s=aux_second-1;
|
||||||
if ( s < 0 ) {
|
if ( s < 0 ) {
|
||||||
s=59; m--;
|
s=59; --m;
|
||||||
if ( m < 0 ) {
|
if ( m < 0 ) {
|
||||||
m=59; h--;
|
m=59; --h;
|
||||||
if ( h < 0 ) {
|
if ( h < 0 ) {
|
||||||
// abort
|
// abort
|
||||||
h=m=s=0;
|
h=m=s=0;
|
||||||
|
@ -840,9 +840,9 @@ void DbQuery::getSpeedData( std::optional<stats_speed_items_t>& result, const QS
|
||||||
// last one, append the prev
|
// last one, append the prev
|
||||||
h=hour; m=minute; s=second-1;
|
h=hour; m=minute; s=second-1;
|
||||||
if ( s < 0 ) {
|
if ( s < 0 ) {
|
||||||
s=59; m--;
|
s=59; --m;
|
||||||
if ( m < 0 ) {
|
if ( m < 0 ) {
|
||||||
m=59; h--;
|
m=59; --h;
|
||||||
if ( h < 0 ) {
|
if ( h < 0 ) {
|
||||||
h=m=s=0;
|
h=m=s=0;
|
||||||
}
|
}
|
||||||
|
@ -862,9 +862,9 @@ void DbQuery::getSpeedData( std::optional<stats_speed_items_t>& result, const QS
|
||||||
// append 1 second after the last
|
// append 1 second after the last
|
||||||
h=hour; m=minute; s=second+1;
|
h=hour; m=minute; s=second+1;
|
||||||
if ( s > 59 ) {
|
if ( s > 59 ) {
|
||||||
s=0; m++;
|
s=0; ++m;
|
||||||
if ( m > 59 ) {
|
if ( m > 59 ) {
|
||||||
m=0; h++;
|
m=0; ++h;
|
||||||
if ( h > 23 ) {
|
if ( h > 23 ) {
|
||||||
h=23;m=59;s=59;
|
h=23;m=59;s=59;
|
||||||
}
|
}
|
||||||
|
@ -878,13 +878,13 @@ void DbQuery::getSpeedData( std::optional<stats_speed_items_t>& result, const QS
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
// append the last fictitious count
|
// append the last fictitious count
|
||||||
day ++;
|
++ day;
|
||||||
if ( day > getMonthDays( year, month ) ) {
|
if ( day > getMonthDays( year, month ) ) {
|
||||||
day = 1;
|
day = 1;
|
||||||
month ++;
|
++ month;
|
||||||
if ( month > 12 ) {
|
if ( month > 12 ) {
|
||||||
month = 1;
|
month = 1;
|
||||||
year ++;
|
++ year;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
time.setDate( QDate( year, month , day ) );
|
time.setDate( QDate( year, month , day ) );
|
||||||
|
@ -974,7 +974,7 @@ void DbQuery::getItemsCount( std::optional<stats_count_items_t>& result, const Q
|
||||||
while ( query.next() ) {
|
while ( query.next() ) {
|
||||||
item = query.value(0).toString();
|
item = query.value(0).toString();
|
||||||
if ( ! item.isEmpty() ) {
|
if ( ! item.isEmpty() ) {
|
||||||
aux_items[ item ] ++;
|
++ aux_items[ item ];
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
} catch (...) {
|
} catch (...) {
|
||||||
|
@ -1138,9 +1138,9 @@ void DbQuery::getDaytimeCounts( std::optional<stats_day_items_t>& result, const
|
||||||
hour = query.value(1).toInt();
|
hour = query.value(1).toInt();
|
||||||
minute = query.value(2).toInt();
|
minute = query.value(2).toInt();
|
||||||
// increase the count
|
// increase the count
|
||||||
data.at( hour ).at( getMinuteGap( minute ) ) ++;
|
++ data.at( hour ).at( getMinuteGap( minute ) );
|
||||||
// append the day as newly found if not found yet
|
// append the day as newly found if not found yet
|
||||||
days_l[ day ] ++;
|
++ days_l[ day ];
|
||||||
}
|
}
|
||||||
n_days += static_cast<int>(days_l.size());
|
n_days += static_cast<int>(days_l.size());
|
||||||
} catch (...) {
|
} catch (...) {
|
||||||
|
@ -1152,7 +1152,7 @@ void DbQuery::getDaytimeCounts( std::optional<stats_day_items_t>& result, const
|
||||||
|
|
||||||
|
|
||||||
} else {
|
} else {
|
||||||
for ( int m=1; m<=n_months; m++ ) {
|
for ( int m=1; m<=n_months; ++m ) {
|
||||||
stmt = QString("SELECT \"day\", \"hour\", \"minute\" FROM \"%1\" WHERE \"year\"=%2 AND \"month\"=%3")
|
stmt = QString("SELECT \"day\", \"hour\", \"minute\" FROM \"%1\" WHERE \"year\"=%2 AND \"month\"=%3")
|
||||||
.arg( web_server )
|
.arg( web_server )
|
||||||
.arg( year ).arg( month );
|
.arg( year ).arg( month );
|
||||||
|
@ -1217,15 +1217,15 @@ void DbQuery::getDaytimeCounts( std::optional<stats_day_items_t>& result, const
|
||||||
hour = query.value(1).toInt();
|
hour = query.value(1).toInt();
|
||||||
minute = query.value(2).toInt();
|
minute = query.value(2).toInt();
|
||||||
// increase the count
|
// increase the count
|
||||||
data.at( hour ).at( getMinuteGap( minute ) ) ++;
|
++ data.at( hour ).at( getMinuteGap( minute ) );
|
||||||
// append the day as newly found if not found yet
|
// append the day as newly found if not found yet
|
||||||
days_l[ day ] ++;
|
++ days_l[ day ];
|
||||||
}
|
}
|
||||||
n_days += static_cast<int>(days_l.size());
|
n_days += static_cast<int>(days_l.size());
|
||||||
month ++;
|
++ month;
|
||||||
if ( month > 12 ) {
|
if ( month > 12 ) {
|
||||||
month = 1;
|
month = 1;
|
||||||
year ++;
|
++ year;
|
||||||
}
|
}
|
||||||
} catch (...) {
|
} catch (...) {
|
||||||
// something failed
|
// something failed
|
||||||
|
@ -1245,7 +1245,7 @@ void DbQuery::getDaytimeCounts( std::optional<stats_day_items_t>& result, const
|
||||||
if ( count > 0 ) {
|
if ( count > 0 ) {
|
||||||
count /= n_days;
|
count /= n_days;
|
||||||
if ( count == 0 ) {
|
if ( count == 0 ) {
|
||||||
count++;
|
++ count;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -1404,7 +1404,7 @@ void DbQuery::getRelationalCountsDay( std::optional<stats_relat_items_t>& result
|
||||||
|
|
||||||
} else if ( ! query.last() ) {
|
} else if ( ! query.last() ) {
|
||||||
// no result found, fill with 0 values
|
// no result found, fill with 0 values
|
||||||
for ( int h{0}; h<24; h++ ) {
|
for ( int h{0}; h<24; ++h ) {
|
||||||
for ( int m{0}; m<60; m+=gap ) {
|
for ( int m{0}; m<60; m+=gap ) {
|
||||||
time.setTime( QTime( h, m ) );
|
time.setTime( QTime( h, m ) );
|
||||||
data.push_back( std::make_tuple( time.toMSecsSinceEpoch(), 0 ) );
|
data.push_back( std::make_tuple( time.toMSecsSinceEpoch(), 0 ) );
|
||||||
|
@ -1425,7 +1425,7 @@ void DbQuery::getRelationalCountsDay( std::optional<stats_relat_items_t>& result
|
||||||
aux_hour = query.value(0).toInt();
|
aux_hour = query.value(0).toInt();
|
||||||
aux_minute = getMinuteGap( query.value(1).toInt(), gap );
|
aux_minute = getMinuteGap( query.value(1).toInt(), gap );
|
||||||
if ( aux_hour == hour && aux_minute == minute ) {
|
if ( aux_hour == hour && aux_minute == minute ) {
|
||||||
count ++;
|
++ count;
|
||||||
} else {
|
} else {
|
||||||
if ( aux_hour == hour ) {
|
if ( aux_hour == hour ) {
|
||||||
// same hour new minute gap, append the last count
|
// same hour new minute gap, append the last count
|
||||||
|
@ -1447,13 +1447,13 @@ void DbQuery::getRelationalCountsDay( std::optional<stats_relat_items_t>& result
|
||||||
time.setTime( QTime( hour, m ) );
|
time.setTime( QTime( hour, m ) );
|
||||||
data.push_back( std::make_tuple( time.toMSecsSinceEpoch(), 0 ) );
|
data.push_back( std::make_tuple( time.toMSecsSinceEpoch(), 0 ) );
|
||||||
}
|
}
|
||||||
hour ++;
|
++ hour;
|
||||||
} else {
|
} else {
|
||||||
// prepare to add missing gaps from 00:00 (+gap will be added to the minute)
|
// prepare to add missing gaps from 00:00 (+gap will be added to the minute)
|
||||||
hour = 0;
|
hour = 0;
|
||||||
}
|
}
|
||||||
// append any missing gap in every hour between the current and the next found (aux)
|
// append any missing gap in every hour between the current and the next found (aux)
|
||||||
for ( int h{hour}; h<aux_hour; h++ ) {
|
for ( int h{hour}; h<aux_hour; ++h ) {
|
||||||
for ( int m{0}; m<60; m+=gap ) {
|
for ( int m{0}; m<60; m+=gap ) {
|
||||||
time.setTime( QTime( h, m ) );
|
time.setTime( QTime( h, m ) );
|
||||||
data.push_back( std::make_tuple( time.toMSecsSinceEpoch(), 0 ) );
|
data.push_back( std::make_tuple( time.toMSecsSinceEpoch(), 0 ) );
|
||||||
|
@ -1478,20 +1478,20 @@ void DbQuery::getRelationalCountsDay( std::optional<stats_relat_items_t>& result
|
||||||
time.setTime( QTime( hour, m ) );
|
time.setTime( QTime( hour, m ) );
|
||||||
data.push_back( std::make_tuple( time.toMSecsSinceEpoch(), 0 ) );
|
data.push_back( std::make_tuple( time.toMSecsSinceEpoch(), 0 ) );
|
||||||
}
|
}
|
||||||
for ( int h{hour+1}; h<24; h++ ) {
|
for ( int h{hour+1}; h<24; ++h ) {
|
||||||
for ( int m{0}; m<60; m+=gap ) {
|
for ( int m{0}; m<60; m+=gap ) {
|
||||||
time.setTime( QTime( h, m ) );
|
time.setTime( QTime( h, m ) );
|
||||||
data.push_back( std::make_tuple( time.toMSecsSinceEpoch(), 0 ) );
|
data.push_back( std::make_tuple( time.toMSecsSinceEpoch(), 0 ) );
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
// append the real last fictitious count
|
// append the real last fictitious count
|
||||||
day ++;
|
++ day;
|
||||||
if ( day > getMonthDays( year, month ) ) {
|
if ( day > getMonthDays( year, month ) ) {
|
||||||
day = 1;
|
day = 1;
|
||||||
month ++;
|
++ month;
|
||||||
if ( month > 12 ) {
|
if ( month > 12 ) {
|
||||||
month = 1;
|
month = 1;
|
||||||
year ++;
|
++ year;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
time.setDate( QDate( year, month , day ) );
|
time.setDate( QDate( year, month , day ) );
|
||||||
|
@ -1647,7 +1647,7 @@ void DbQuery::getRelationalCountsPeriod( std::optional<stats_relat_items_t>& res
|
||||||
|
|
||||||
} else if ( ! query.last() ) {
|
} else if ( ! query.last() ) {
|
||||||
// no days found, append missing days with 0 value
|
// no days found, append missing days with 0 value
|
||||||
for ( int d{from_day}; d<=to_day; d++ ) {
|
for ( int d{from_day}; d<=to_day; ++d ) {
|
||||||
time.setDate( QDate( year, month , d ) );
|
time.setDate( QDate( year, month , d ) );
|
||||||
data.push_back( std::make_tuple( time.toMSecsSinceEpoch(), 0 ) );
|
data.push_back( std::make_tuple( time.toMSecsSinceEpoch(), 0 ) );
|
||||||
}
|
}
|
||||||
|
@ -1663,13 +1663,13 @@ void DbQuery::getRelationalCountsPeriod( std::optional<stats_relat_items_t>& res
|
||||||
while ( query.next() ) {
|
while ( query.next() ) {
|
||||||
aux_day = query.value(0).toInt();
|
aux_day = query.value(0).toInt();
|
||||||
if ( aux_day == day ) {
|
if ( aux_day == day ) {
|
||||||
count ++;
|
++ count;
|
||||||
} else {
|
} else {
|
||||||
if ( day > 0 ) {
|
if ( day > 0 ) {
|
||||||
// any loop-round except the first
|
// any loop-round except the first
|
||||||
time.setDate( QDate( year, month , day ) );
|
time.setDate( QDate( year, month , day ) );
|
||||||
data.push_back( std::make_tuple( time.toMSecsSinceEpoch(), count ) );
|
data.push_back( std::make_tuple( time.toMSecsSinceEpoch(), count ) );
|
||||||
for ( int d{day+1}; d<aux_day; d++ ) {
|
for ( int d{day+1}; d<aux_day; ++d ) {
|
||||||
// append any missing day with a zero value
|
// append any missing day with a zero value
|
||||||
time.setDate( QDate( year, month , d ) );
|
time.setDate( QDate( year, month , d ) );
|
||||||
data.push_back( std::make_tuple( time.toMSecsSinceEpoch(), 0 ) );
|
data.push_back( std::make_tuple( time.toMSecsSinceEpoch(), 0 ) );
|
||||||
|
@ -1680,20 +1680,20 @@ void DbQuery::getRelationalCountsPeriod( std::optional<stats_relat_items_t>& res
|
||||||
m = month,
|
m = month,
|
||||||
y = year;
|
y = year;
|
||||||
if ( d < 1 ) {
|
if ( d < 1 ) {
|
||||||
m --;
|
-- m;
|
||||||
if ( m < 1 ) {
|
if ( m < 1 ) {
|
||||||
m = 12;
|
m = 12;
|
||||||
y --;
|
-- y;
|
||||||
}
|
}
|
||||||
d = getMonthDays( y, m );
|
d = getMonthDays( y, m );
|
||||||
}
|
}
|
||||||
for ( ; d!=aux_day; d++ ) {
|
for ( ; d!=aux_day; ++d ) {
|
||||||
if ( d > getMonthDays( y, m ) ) {
|
if ( d > getMonthDays( y, m ) ) {
|
||||||
d = 1;
|
d = 1;
|
||||||
m ++;
|
++ m;
|
||||||
if ( m > 12 ) {
|
if ( m > 12 ) {
|
||||||
m = 1;
|
m = 1;
|
||||||
y ++;
|
++ y;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
time.setDate( QDate( y, m , d ) );
|
time.setDate( QDate( y, m , d ) );
|
||||||
|
@ -1708,12 +1708,12 @@ void DbQuery::getRelationalCountsPeriod( std::optional<stats_relat_items_t>& res
|
||||||
time.setDate( QDate( year, month , day ) );
|
time.setDate( QDate( year, month , day ) );
|
||||||
data.push_back( std::make_tuple( time.toMSecsSinceEpoch(), count ) );
|
data.push_back( std::make_tuple( time.toMSecsSinceEpoch(), count ) );
|
||||||
// append any missing day from the last found until 1 day before the last one
|
// append any missing day from the last found until 1 day before the last one
|
||||||
day++;
|
++ day;
|
||||||
if ( day > getMonthDays( year, month ) ) {
|
if ( day > getMonthDays( year, month ) ) {
|
||||||
month ++;
|
++ month;
|
||||||
if ( month > 12 ) {
|
if ( month > 12 ) {
|
||||||
month = 1;
|
month = 1;
|
||||||
year ++;
|
++ year;
|
||||||
}
|
}
|
||||||
day = getMonthDays( year, month );
|
day = getMonthDays( year, month );
|
||||||
}
|
}
|
||||||
|
@ -1723,17 +1723,17 @@ void DbQuery::getRelationalCountsPeriod( std::optional<stats_relat_items_t>& res
|
||||||
y{ year };
|
y{ year };
|
||||||
if ( m > 12 ) {
|
if ( m > 12 ) {
|
||||||
m = 1;
|
m = 1;
|
||||||
y ++;
|
++ y;
|
||||||
}
|
}
|
||||||
to_day = getMonthDays( y, m );
|
to_day = getMonthDays( y, m );
|
||||||
}
|
}
|
||||||
for ( ; day!=to_day; day++ ) {
|
for ( ; day!=to_day; ++day ) {
|
||||||
if ( day > getMonthDays( year, month ) ) {
|
if ( day > getMonthDays( year, month ) ) {
|
||||||
day = 1;
|
day = 1;
|
||||||
month ++;
|
++ month;
|
||||||
if ( month > 12 ) {
|
if ( month > 12 ) {
|
||||||
month = 1;
|
month = 1;
|
||||||
year ++;
|
++ year;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
time.setDate( QDate( year, month , day ) );
|
time.setDate( QDate( year, month , day ) );
|
||||||
|
@ -1749,7 +1749,7 @@ void DbQuery::getRelationalCountsPeriod( std::optional<stats_relat_items_t>& res
|
||||||
|
|
||||||
} else {
|
} else {
|
||||||
data.reserve( countDays( from_year, from_month, from_day, to_year, to_month, to_day ) );
|
data.reserve( countDays( from_year, from_month, from_day, to_year, to_month, to_day ) );
|
||||||
for ( int m{1}; m<=n_months; m++ ) {
|
for ( int m{1}; m<=n_months; ++m ) {
|
||||||
stmt = QString("SELECT \"day\" FROM \"%1\" WHERE \"year\"=%2 AND \"month\"=%3")
|
stmt = QString("SELECT \"day\" FROM \"%1\" WHERE \"year\"=%2 AND \"month\"=%3")
|
||||||
.arg( web_server )
|
.arg( web_server )
|
||||||
.arg( year ).arg( month );
|
.arg( year ).arg( month );
|
||||||
|
@ -1835,7 +1835,7 @@ void DbQuery::getRelationalCountsPeriod( std::optional<stats_relat_items_t>& res
|
||||||
// last month, only get the days until the ending day
|
// last month, only get the days until the ending day
|
||||||
t_d = to_day;
|
t_d = to_day;
|
||||||
}
|
}
|
||||||
for ( ; f_d<=t_d; f_d++ ) {
|
for ( ; f_d<=t_d; ++f_d ) {
|
||||||
time.setDate( QDate( year, month , f_d ) );
|
time.setDate( QDate( year, month , f_d ) );
|
||||||
data.push_back( std::make_tuple( time.toMSecsSinceEpoch(), 0 ) );
|
data.push_back( std::make_tuple( time.toMSecsSinceEpoch(), 0 ) );
|
||||||
}
|
}
|
||||||
|
@ -1848,13 +1848,13 @@ void DbQuery::getRelationalCountsPeriod( std::optional<stats_relat_items_t>& res
|
||||||
while ( query.next() ) {
|
while ( query.next() ) {
|
||||||
aux_day = query.value(0).toInt();
|
aux_day = query.value(0).toInt();
|
||||||
if ( aux_day == day ) {
|
if ( aux_day == day ) {
|
||||||
count ++;
|
++ count;
|
||||||
} else {
|
} else {
|
||||||
if ( day > 0 ) {
|
if ( day > 0 ) {
|
||||||
// any loop-round except the first
|
// any loop-round except the first
|
||||||
time.setDate( QDate( year, month , day ) );
|
time.setDate( QDate( year, month , day ) );
|
||||||
data.push_back( std::make_tuple( time.toMSecsSinceEpoch(), count ) );
|
data.push_back( std::make_tuple( time.toMSecsSinceEpoch(), count ) );
|
||||||
for ( int d{day+1}; d<aux_day; d++ ) {
|
for ( int d{day+1}; d<aux_day; ++d ) {
|
||||||
// append any missing day with a zero value
|
// append any missing day with a zero value
|
||||||
time.setDate( QDate( year, month , d ) );
|
time.setDate( QDate( year, month , d ) );
|
||||||
data.push_back( std::make_tuple( time.toMSecsSinceEpoch(), 0 ) );
|
data.push_back( std::make_tuple( time.toMSecsSinceEpoch(), 0 ) );
|
||||||
|
@ -1862,7 +1862,7 @@ void DbQuery::getRelationalCountsPeriod( std::optional<stats_relat_items_t>& res
|
||||||
} else {
|
} else {
|
||||||
// append any missing day until the next found day
|
// append any missing day until the next found day
|
||||||
day = 1;
|
day = 1;
|
||||||
for ( int d{day}; d<aux_day; d++ ) {
|
for ( int d{day}; d<aux_day; ++d ) {
|
||||||
time.setDate( QDate( year, month , d ) );
|
time.setDate( QDate( year, month , d ) );
|
||||||
data.push_back( std::make_tuple( time.toMSecsSinceEpoch(), 0 ) );
|
data.push_back( std::make_tuple( time.toMSecsSinceEpoch(), 0 ) );
|
||||||
}
|
}
|
||||||
|
@ -1877,16 +1877,16 @@ void DbQuery::getRelationalCountsPeriod( std::optional<stats_relat_items_t>& res
|
||||||
data.push_back( std::make_tuple( time.toMSecsSinceEpoch(), count ) );
|
data.push_back( std::make_tuple( time.toMSecsSinceEpoch(), count ) );
|
||||||
}
|
}
|
||||||
// append any missing day to the end of the month with a zero value
|
// append any missing day to the end of the month with a zero value
|
||||||
for ( int d{day+1}; d<=getMonthDays(year,month); d++ ) {
|
for ( int d{day+1}; d<=getMonthDays(year,month); ++d ) {
|
||||||
time.setDate( QDate( year, month , d ) );
|
time.setDate( QDate( year, month , d ) );
|
||||||
data.push_back( std::make_tuple( time.toMSecsSinceEpoch(), 0 ) );
|
data.push_back( std::make_tuple( time.toMSecsSinceEpoch(), 0 ) );
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
// increase the month
|
// increase the month
|
||||||
month ++;
|
++ month;
|
||||||
if ( month > 12 ) {
|
if ( month > 12 ) {
|
||||||
month = 1;
|
month = 1;
|
||||||
year ++;
|
++ year;
|
||||||
}
|
}
|
||||||
} catch (...) {
|
} catch (...) {
|
||||||
// something failed
|
// something failed
|
||||||
|
@ -1902,7 +1902,7 @@ void DbQuery::getRelationalCountsPeriod( std::optional<stats_relat_items_t>& res
|
||||||
month = to_month +1;
|
month = to_month +1;
|
||||||
if ( month > 12 ) {
|
if ( month > 12 ) {
|
||||||
month = 1;
|
month = 1;
|
||||||
year ++;
|
++ year;
|
||||||
}
|
}
|
||||||
time.setDate( QDate( year, month , day ) );
|
time.setDate( QDate( year, month , day ) );
|
||||||
data.push_back( std::make_tuple( time.toMSecsSinceEpoch(), 0 ) );
|
data.push_back( std::make_tuple( time.toMSecsSinceEpoch(), 0 ) );
|
||||||
|
@ -2060,15 +2060,15 @@ bool DbQuery::getGlobalCounts( const QString& web_server, const std::map<int, st
|
||||||
day = d;
|
day = d;
|
||||||
}
|
}
|
||||||
if ( d == day ) {
|
if ( d == day ) {
|
||||||
day_count ++;
|
++ day_count;
|
||||||
} else {
|
} else {
|
||||||
n_days ++;
|
++ n_days;
|
||||||
// sum the day count to the total count
|
// sum the day count to the total count
|
||||||
req_count += day_count;
|
req_count += day_count;
|
||||||
// sum the day count to the relative day of the week count
|
// sum the day count to the relative day of the week count
|
||||||
week_day = QDate(year,month,day).dayOfWeek();
|
week_day = QDate(year,month,day).dayOfWeek();
|
||||||
traf_day.at( week_day ) += day_count;
|
traf_day.at( week_day ) += day_count;
|
||||||
num_day_count.at( week_day ) ++;
|
++ num_day_count.at( week_day );
|
||||||
// check the max date count
|
// check the max date count
|
||||||
const QString m_str{ (month<10) ? QString("0%1").arg(month) : QString("%1").arg(month) };
|
const QString m_str{ (month<10) ? QString("0%1").arg(month) : QString("%1").arg(month) };
|
||||||
const QString d_str{ (day<10) ? QString("0%1").arg(day) : QString("%1").arg(day) };
|
const QString d_str{ (day<10) ? QString("0%1").arg(day) : QString("%1").arg(day) };
|
||||||
|
@ -2087,7 +2087,7 @@ bool DbQuery::getGlobalCounts( const QString& web_server, const std::map<int, st
|
||||||
hour = h;
|
hour = h;
|
||||||
}
|
}
|
||||||
if ( h == hour ) {
|
if ( h == hour ) {
|
||||||
hour_count ++;
|
++ hour_count;
|
||||||
} else {
|
} else {
|
||||||
traf_hour.at( hour ) += hour_count;
|
traf_hour.at( hour ) += hour_count;
|
||||||
hour_count = 1;
|
hour_count = 1;
|
||||||
|
@ -2101,7 +2101,7 @@ bool DbQuery::getGlobalCounts( const QString& web_server, const std::map<int, st
|
||||||
max_tt = tt;
|
max_tt = tt;
|
||||||
}
|
}
|
||||||
tot_tt += tt;
|
tot_tt += tt;
|
||||||
num_tt ++;
|
++ num_tt;
|
||||||
}
|
}
|
||||||
|
|
||||||
// sum the bytes sent
|
// sum the bytes sent
|
||||||
|
@ -2110,7 +2110,7 @@ bool DbQuery::getGlobalCounts( const QString& web_server, const std::map<int, st
|
||||||
max_bs = bs;
|
max_bs = bs;
|
||||||
}
|
}
|
||||||
tot_bs += bs;
|
tot_bs += bs;
|
||||||
num_bs ++;
|
++ num_bs;
|
||||||
}
|
}
|
||||||
|
|
||||||
// sum the bytes received
|
// sum the bytes received
|
||||||
|
@ -2119,27 +2119,27 @@ bool DbQuery::getGlobalCounts( const QString& web_server, const std::map<int, st
|
||||||
max_br = br;
|
max_br = br;
|
||||||
}
|
}
|
||||||
tot_br += br;
|
tot_br += br;
|
||||||
num_br ++;
|
++ num_br;
|
||||||
}
|
}
|
||||||
|
|
||||||
// process the protocol
|
// process the protocol
|
||||||
if ( ! protocol.isEmpty() ) {
|
if ( ! protocol.isEmpty() ) {
|
||||||
recurs.at( 0 )[ protocol ] ++;
|
++ recurs.at( 0 )[ protocol ];
|
||||||
}
|
}
|
||||||
|
|
||||||
// process the method
|
// process the method
|
||||||
if ( ! method.isEmpty() ) {
|
if ( ! method.isEmpty() ) {
|
||||||
recurs.at( 1 )[ method ] ++;
|
++ recurs.at( 1 )[ method ];
|
||||||
}
|
}
|
||||||
|
|
||||||
// process the uri
|
// process the uri
|
||||||
if ( ! uri.isEmpty() ) {
|
if ( ! uri.isEmpty() ) {
|
||||||
recurs.at( 2 )[ uri ] ++;
|
++ recurs.at( 2 )[ uri ];
|
||||||
}
|
}
|
||||||
|
|
||||||
// process the user-agent
|
// process the user-agent
|
||||||
if ( ! user_agent.isEmpty() ) {
|
if ( ! user_agent.isEmpty() ) {
|
||||||
recurs.at( 3 )[ user_agent ] ++;
|
++ recurs.at( 3 )[ user_agent ];
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -2156,7 +2156,7 @@ bool DbQuery::getGlobalCounts( const QString& web_server, const std::map<int, st
|
||||||
// sum the day count to the relative day of the week count
|
// sum the day count to the relative day of the week count
|
||||||
week_day = QDate(year,month,day).dayOfWeek();
|
week_day = QDate(year,month,day).dayOfWeek();
|
||||||
traf_day.at( week_day ) += day_count;
|
traf_day.at( week_day ) += day_count;
|
||||||
num_day_count.at( week_day ) ++;
|
++ num_day_count.at( week_day );
|
||||||
|
|
||||||
// check the max date count
|
// check the max date count
|
||||||
const QString m_str{ (month<10) ? QString("0%1").arg(month) : QString("%1").arg(month) };
|
const QString m_str{ (month<10) ? QString("0%1").arg(month) : QString("%1").arg(month) };
|
||||||
|
@ -2177,14 +2177,14 @@ bool DbQuery::getGlobalCounts( const QString& web_server, const std::map<int, st
|
||||||
if ( successful ) {
|
if ( successful ) {
|
||||||
|
|
||||||
// process the hours of the day
|
// process the hours of the day
|
||||||
for ( int i{0}; i<24; i++ ) {
|
for ( int i{0}; i<24; ++i ) {
|
||||||
if ( n_days > 0 ) {
|
if ( n_days > 0 ) {
|
||||||
traf_hour.at( i ) /= n_days;
|
traf_hour.at( i ) /= n_days;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// process the day of the week
|
// process the day of the week
|
||||||
for ( int i{1}; i<8; i++ ) {
|
for ( int i{1}; i<8; ++i ) {
|
||||||
const int& x{ num_day_count.at( i ) };
|
const int& x{ num_day_count.at( i ) };
|
||||||
if ( x > 0 ) {
|
if ( x > 0 ) {
|
||||||
traf_day.at( i ) /= x;
|
traf_day.at( i ) /= x;
|
||||||
|
|
|
@ -76,7 +76,7 @@ void TextBrowser::makePreview( QString& content ) const
|
||||||
/*if ( this->wide_lines ) {
|
/*if ( this->wide_lines ) {
|
||||||
content += "<br/>";
|
content += "<br/>";
|
||||||
}*/
|
}*/
|
||||||
for ( int i{0}; i<32; i++ ) {
|
for ( int i{0}; i<32; ++i ) {
|
||||||
content += "<p>";
|
content += "<p>";
|
||||||
|
|
||||||
content += "<b>";
|
content += "<b>";
|
||||||
|
|
|
@ -71,7 +71,7 @@ void testUtilities()
|
||||||
{
|
{
|
||||||
const auto every_other_char_but = [](const std::vector<char>& in)->std::vector<char>{
|
const auto every_other_char_but = [](const std::vector<char>& in)->std::vector<char>{
|
||||||
std::vector<char> out( 128-in.size() );
|
std::vector<char> out( 128-in.size() );
|
||||||
for (char c{0}; c<127; c++) {
|
for (char c{0}; c<127; ++c) {
|
||||||
if (const auto it = std::find(in.cbegin(),in.cend(),c); it == in.cend()) {
|
if (const auto it = std::find(in.cbegin(),in.cend(),c); it == in.cend()) {
|
||||||
out.push_back( c );
|
out.push_back( c );
|
||||||
}
|
}
|
||||||
|
|
|
@ -47,10 +47,7 @@ public:
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
FileHandler(const FileHandler&) = delete;
|
Q_DISABLE_COPY_MOVE(FileHandler)
|
||||||
FileHandler(FileHandler&&) = delete;
|
|
||||||
FileHandler& operator=(const FileHandler&) = delete;
|
|
||||||
FileHandler& operator=(FileHandler&&) = delete;
|
|
||||||
|
|
||||||
inline operator FILE*()
|
inline operator FILE*()
|
||||||
{
|
{
|
||||||
|
@ -144,7 +141,7 @@ void readFile( const std::string& path, std::string& content )
|
||||||
successful = false;
|
successful = false;
|
||||||
break;
|
break;
|
||||||
}*/
|
}*/
|
||||||
for ( unsigned i{0u}; i<have; i++ ) {
|
for ( unsigned i{0u}; i<have; ++i ) {
|
||||||
content.push_back( out[i] );
|
content.push_back( out[i] );
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -35,10 +35,7 @@ public:
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
FileHandler(const FileHandler&) = delete;
|
Q_DISABLE_COPY_MOVE(FileHandler)
|
||||||
FileHandler(FileHandler&&) = delete;
|
|
||||||
FileHandler& operator=(const FileHandler&) = delete;
|
|
||||||
FileHandler& operator=(FileHandler&&) = delete;
|
|
||||||
|
|
||||||
inline Stream& operator*()
|
inline Stream& operator*()
|
||||||
{
|
{
|
||||||
|
@ -196,7 +193,7 @@ void randomLines( const std::string& path, std::vector<std::string>& lines, cons
|
||||||
srand( (unsigned)time(&nTime) );
|
srand( (unsigned)time(&nTime) );
|
||||||
size_t index;
|
size_t index;
|
||||||
std::vector<size_t> picked_indexes;
|
std::vector<size_t> picked_indexes;
|
||||||
for( size_t i=0ul; i<n_lines ; i++ ) {
|
for( size_t i=0ul; i<n_lines ; ++i ) {
|
||||||
while (true) {
|
while (true) {
|
||||||
index = static_cast<size_t>(rand()) % max;
|
index = static_cast<size_t>(rand()) % max;
|
||||||
if ( VecOps::contains<size_t>( picked_indexes, index ) ) {
|
if ( VecOps::contains<size_t>( picked_indexes, index ) ) {
|
||||||
|
@ -206,7 +203,7 @@ void randomLines( const std::string& path, std::vector<std::string>& lines, cons
|
||||||
}
|
}
|
||||||
const std::string& line{ aux_lines.at( index ) };
|
const std::string& line{ aux_lines.at( index ) };
|
||||||
if ( StringOps::startsWith( line, '#' ) ) { // leave the "#" check for IIS logs
|
if ( StringOps::startsWith( line, '#' ) ) { // leave the "#" check for IIS logs
|
||||||
i--;
|
-- i;
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
lines.push_back( line );
|
lines.push_back( line );
|
||||||
|
|
|
@ -29,12 +29,12 @@ QString printableSize( const size_t bytes )
|
||||||
}
|
}
|
||||||
size_t n_decimals{ 3ul };
|
size_t n_decimals{ 3ul };
|
||||||
if ( size >= 100.0 ) {
|
if ( size >= 100.0 ) {
|
||||||
n_decimals --;
|
-- n_decimals;
|
||||||
if ( size >= 1000.0 ) {
|
if ( size >= 1000.0 ) {
|
||||||
n_decimals --;
|
-- n_decimals;
|
||||||
if ( size >= 10000.0 ) {
|
if ( size >= 10000.0 ) {
|
||||||
n_decimals --;
|
-- n_decimals;
|
||||||
cut_index --; // no decimals, no "dot"
|
-- cut_index; // no decimals, no "dot"
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -69,12 +69,12 @@ QString printableSpeed( const double bytes, const double secs_ )
|
||||||
}
|
}
|
||||||
size_t n_decimals{ 3ul };
|
size_t n_decimals{ 3ul };
|
||||||
if ( speed >= 100.0 ) {
|
if ( speed >= 100.0 ) {
|
||||||
n_decimals --;
|
-- n_decimals;
|
||||||
if ( speed >= 1000.0 ) {
|
if ( speed >= 1000.0 ) {
|
||||||
n_decimals --;
|
-- n_decimals;
|
||||||
if ( speed >= 10000.0 ) {
|
if ( speed >= 10000.0 ) {
|
||||||
n_decimals --;
|
-- n_decimals;
|
||||||
cut_index --; // no decimals, no "dot"
|
-- cut_index; // no decimals, no "dot"
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -35,7 +35,7 @@ void RichText::enrichLogs( QString& rich_content, const std::string& content, co
|
||||||
StringOps::splitrip( lines, content );
|
StringOps::splitrip( lines, content );
|
||||||
size_t lines_left{ lines.size() };
|
size_t lines_left{ lines.size() };
|
||||||
for ( const std::string& line : lines ) {
|
for ( const std::string& line : lines ) {
|
||||||
lines_left --;
|
-- lines_left;
|
||||||
// check if the line is commented, usually from IIS logs
|
// check if the line is commented, usually from IIS logs
|
||||||
if ( StringOps::startsWith( line, '#' ) && !StringOps::startsWith( logs_format.initial, '#' ) ) {
|
if ( StringOps::startsWith( line, '#' ) && !StringOps::startsWith( logs_format.initial, '#' ) ) {
|
||||||
rich_line = QString("<p>%1</p>").arg( QString::fromStdString( line ) );
|
rich_line = QString("<p>%1</p>").arg( QString::fromStdString( line ) );
|
||||||
|
@ -74,7 +74,7 @@ void RichText::enrichLogs( QString& rich_content, const std::string& content, co
|
||||||
}
|
}
|
||||||
if ( stop == std::string::npos ) {
|
if ( stop == std::string::npos ) {
|
||||||
// separator not found, skip to the next one
|
// separator not found, skip to the next one
|
||||||
i++;
|
++i;
|
||||||
stop = start;
|
stop = start;
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
|
@ -112,7 +112,7 @@ void RichText::enrichLogs( QString& rich_content, const std::string& content, co
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
aux_start = aux_stop + 1;
|
aux_start = aux_stop + 1;
|
||||||
c++;
|
++c;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -186,7 +186,7 @@ void RichText::enrichLogs( QString& rich_content, const std::string& content, co
|
||||||
stop = aux_stop;
|
stop = aux_stop;
|
||||||
} else {
|
} else {
|
||||||
stop += sep_size;
|
stop += sep_size;
|
||||||
i++;
|
++i;
|
||||||
}
|
}
|
||||||
if ( stop > line_size ) {
|
if ( stop > line_size ) {
|
||||||
// this was the final separator
|
// this was the final separator
|
||||||
|
|
|
@ -10,7 +10,7 @@ size_t count( std::string_view str, std::string_view flag )
|
||||||
{
|
{
|
||||||
const size_t flg_size{ flag.size() };
|
const size_t flg_size{ flag.size() };
|
||||||
size_t count{ 0ul };
|
size_t count{ 0ul };
|
||||||
for ( size_t start{0ul}; (start=str.find(flag, start)) != std::string::npos; count++ ) {
|
for ( size_t start{0ul}; (start=str.find(flag, start)) != std::string::npos; ++count ) {
|
||||||
start += flg_size;
|
start += flg_size;
|
||||||
}
|
}
|
||||||
return count;
|
return count;
|
||||||
|
@ -74,7 +74,7 @@ std::string lstripUntil( const std::string& str, const char delim, const bool in
|
||||||
{
|
{
|
||||||
if (size_t start{ str.find( delim ) }; start != std::string::npos ) {
|
if (size_t start{ str.find( delim ) }; start != std::string::npos ) {
|
||||||
if ( inclusive ) {
|
if ( inclusive ) {
|
||||||
start ++;
|
++ start;
|
||||||
if ( consecutives ) {
|
if ( consecutives ) {
|
||||||
if (str[start] == delim) {
|
if (str[start] == delim) {
|
||||||
start = str.find_first_not_of( delim, start );
|
start = str.find_first_not_of( delim, start );
|
||||||
|
|
Loading…
Reference in a new issue