DB: Rename "unix_time" to "traf_time".

This commit is contained in:
Nodir Temirkhodjaev 2017-12-06 14:45:31 +05:00
parent 8fcf4854d6
commit d42f4941dd
4 changed files with 64 additions and 64 deletions

View File

@ -79,27 +79,27 @@ void Test::debugProcNew(SqliteDb *sqliteDb)
void Test::debugStatTraf(SqliteDb *sqliteDb) void Test::debugStatTraf(SqliteDb *sqliteDb)
{ {
debugStatTrafStep(sqliteDb, "traffic_app_hour", debugStatTrafStep(sqliteDb, "traffic_app_hour",
"SELECT app_id, unix_time, in_bytes, out_bytes" "SELECT app_id, traf_time, in_bytes, out_bytes"
" FROM traffic_app_hour;"); " FROM traffic_app_hour;");
debugStatTrafStep(sqliteDb, "traffic_app_day", debugStatTrafStep(sqliteDb, "traffic_app_day",
"SELECT app_id, unix_time, in_bytes, out_bytes" "SELECT app_id, traf_time, in_bytes, out_bytes"
" FROM traffic_app_day;"); " FROM traffic_app_day;");
debugStatTrafStep(sqliteDb, "traffic_app_month", debugStatTrafStep(sqliteDb, "traffic_app_month",
"SELECT app_id, unix_time, in_bytes, out_bytes" "SELECT app_id, traf_time, in_bytes, out_bytes"
" FROM traffic_app_month;"); " FROM traffic_app_month;");
debugStatTrafStep(sqliteDb, "traffic_hour", debugStatTrafStep(sqliteDb, "traffic_hour",
"SELECT 0, unix_time, in_bytes, out_bytes" "SELECT 0, traf_time, in_bytes, out_bytes"
" FROM traffic_hour;"); " FROM traffic_hour;");
debugStatTrafStep(sqliteDb, "traffic_day", debugStatTrafStep(sqliteDb, "traffic_day",
"SELECT 0, unix_time, in_bytes, out_bytes" "SELECT 0, traf_time, in_bytes, out_bytes"
" FROM traffic_day;"); " FROM traffic_day;");
debugStatTrafStep(sqliteDb, "traffic_month", debugStatTrafStep(sqliteDb, "traffic_month",
"SELECT 0, unix_time, in_bytes, out_bytes" "SELECT 0, traf_time, in_bytes, out_bytes"
" FROM traffic_month;"); " FROM traffic_month;");
debugStatTrafStep(sqliteDb, "traffic_app_total", debugStatTrafStep(sqliteDb, "traffic_app_total",
"SELECT id, unix_time, in_bytes, out_bytes" "SELECT id, traf_time, in_bytes, out_bytes"
" FROM app;", 1); " FROM app;", 1);
} }
@ -112,11 +112,11 @@ void Test::debugStatTrafStep(SqliteDb *sqliteDb, const char *name,
qDebug() << '>' << name << '<'; qDebug() << '>' << name << '<';
while (stmt.step() == SqliteStmt::StepRow) { while (stmt.step() == SqliteStmt::StepRow) {
const qint64 unixTime = stmt.columnInt64(1) * timeMult; const qint64 trafTime = stmt.columnInt64(1) * timeMult;
qDebug() << '>' qDebug() << '>'
<< stmt.columnInt64(0) << stmt.columnInt64(0)
<< QDateTime::fromSecsSinceEpoch(unixTime).toString() << QDateTime::fromSecsSinceEpoch(trafTime).toString()
<< stmt.columnInt64(2) << stmt.columnInt64(2)
<< stmt.columnInt64(3); << stmt.columnInt64(3);
} }

View File

@ -11,9 +11,9 @@
DatabaseManager::DatabaseManager(const QString &filePath, DatabaseManager::DatabaseManager(const QString &filePath,
QObject *parent) : QObject *parent) :
QObject(parent), QObject(parent),
m_lastUnixHour(0), m_lastTrafHour(0),
m_lastUnixDay(0), m_lastTrafDay(0),
m_lastUnixMonth(0), m_lastTrafMonth(0),
m_filePath(filePath), m_filePath(filePath),
m_sqliteDb(new SqliteDb()) m_sqliteDb(new SqliteDb())
{ {
@ -53,18 +53,18 @@ void DatabaseManager::addTraffic(quint16 procCount, const quint8 *procBits,
{ {
QVector<quint16> delProcIndexes; QVector<quint16> delProcIndexes;
const qint64 unixTime = QDateTime::currentSecsSinceEpoch(); const qint64 trafTime = QDateTime::currentSecsSinceEpoch();
const qint32 unixHour = qint32(unixTime / 3600); const qint32 trafHour = qint32(trafTime / 3600);
const bool isNewHour = (unixHour != m_lastUnixHour); const bool isNewHour = (trafHour != m_lastTrafHour);
const qint32 unixDay = isNewHour ? getUnixDay(unixTime) const qint32 trafDay = isNewHour ? getUnixDay(trafTime)
: m_lastUnixDay; : m_lastTrafDay;
const bool isNewDay = (unixDay != m_lastUnixDay); const bool isNewDay = (trafDay != m_lastTrafDay);
const qint32 unixMonth = isNewDay ? getUnixMonth(unixTime) const qint32 trafMonth = isNewDay ? getUnixMonth(trafTime)
: m_lastUnixMonth; : m_lastTrafMonth;
const bool isNewMonth = (unixMonth != m_lastUnixMonth); const bool isNewMonth = (trafMonth != m_lastTrafMonth);
SqliteStmt *stmtInsertAppHour = nullptr; SqliteStmt *stmtInsertAppHour = nullptr;
SqliteStmt *stmtInsertAppDay = nullptr; SqliteStmt *stmtInsertAppDay = nullptr;
@ -75,31 +75,31 @@ void DatabaseManager::addTraffic(quint16 procCount, const quint8 *procBits,
SqliteStmt *stmtInsertMonth = nullptr; SqliteStmt *stmtInsertMonth = nullptr;
if (isNewHour) { if (isNewHour) {
m_lastUnixHour = unixHour; m_lastTrafHour = trafHour;
stmtInsertAppHour = getSqliteStmt(DatabaseSql::sqlInsertTrafficAppHour); stmtInsertAppHour = getSqliteStmt(DatabaseSql::sqlInsertTrafficAppHour);
stmtInsertHour = getSqliteStmt(DatabaseSql::sqlInsertTrafficHour); stmtInsertHour = getSqliteStmt(DatabaseSql::sqlInsertTrafficHour);
stmtInsertAppHour->bindInt(1, unixHour); stmtInsertAppHour->bindInt(1, trafHour);
stmtInsertHour->bindInt(1, unixHour); stmtInsertHour->bindInt(1, trafHour);
if (isNewDay) { if (isNewDay) {
m_lastUnixDay = unixDay; m_lastTrafDay = trafDay;
stmtInsertAppDay = getSqliteStmt(DatabaseSql::sqlInsertTrafficAppDay); stmtInsertAppDay = getSqliteStmt(DatabaseSql::sqlInsertTrafficAppDay);
stmtInsertDay = getSqliteStmt(DatabaseSql::sqlInsertTrafficDay); stmtInsertDay = getSqliteStmt(DatabaseSql::sqlInsertTrafficDay);
stmtInsertAppDay->bindInt(1, unixDay); stmtInsertAppDay->bindInt(1, trafDay);
stmtInsertDay->bindInt(1, unixDay); stmtInsertDay->bindInt(1, trafDay);
if (isNewMonth) { if (isNewMonth) {
m_lastUnixMonth = unixMonth; m_lastTrafMonth = trafMonth;
stmtInsertAppMonth = getSqliteStmt(DatabaseSql::sqlInsertTrafficAppMonth); stmtInsertAppMonth = getSqliteStmt(DatabaseSql::sqlInsertTrafficAppMonth);
stmtInsertMonth = getSqliteStmt(DatabaseSql::sqlInsertTrafficMonth); stmtInsertMonth = getSqliteStmt(DatabaseSql::sqlInsertTrafficMonth);
stmtInsertAppMonth->bindInt(1, unixMonth); stmtInsertAppMonth->bindInt(1, trafMonth);
stmtInsertMonth->bindInt(1, unixMonth); stmtInsertMonth->bindInt(1, trafMonth);
} }
} }
} }
@ -114,13 +114,13 @@ void DatabaseManager::addTraffic(quint16 procCount, const quint8 *procBits,
SqliteStmt *stmtUpdateAppTotal = getSqliteStmt(DatabaseSql::sqlUpdateTrafficAppTotal); SqliteStmt *stmtUpdateAppTotal = getSqliteStmt(DatabaseSql::sqlUpdateTrafficAppTotal);
stmtUpdateAppHour->bindInt(1, unixHour); stmtUpdateAppHour->bindInt(1, trafHour);
stmtUpdateAppDay->bindInt(1, unixDay); stmtUpdateAppDay->bindInt(1, trafDay);
stmtUpdateAppMonth->bindInt(1, unixMonth); stmtUpdateAppMonth->bindInt(1, trafMonth);
stmtUpdateHour->bindInt(1, unixHour); stmtUpdateHour->bindInt(1, trafHour);
stmtUpdateDay->bindInt(1, unixDay); stmtUpdateDay->bindInt(1, trafDay);
stmtUpdateMonth->bindInt(1, unixMonth); stmtUpdateMonth->bindInt(1, trafMonth);
m_sqliteDb->beginTransaction(); m_sqliteDb->beginTransaction();

View File

@ -47,9 +47,9 @@ private:
static qint32 getUnixMonth(qint64 unixTime); static qint32 getUnixMonth(qint64 unixTime);
private: private:
qint32 m_lastUnixHour; qint32 m_lastTrafHour;
qint32 m_lastUnixDay; qint32 m_lastTrafDay;
qint32 m_lastUnixMonth; qint32 m_lastTrafMonth;
QString m_filePath; QString m_filePath;

View File

@ -11,49 +11,49 @@ const char * const DatabaseSql::sqlCreateTables =
" id INTEGER PRIMARY KEY," " id INTEGER PRIMARY KEY,"
" path TEXT UNIQUE NOT NULL," " path TEXT UNIQUE NOT NULL,"
" creat_time INTEGER NOT NULL," " creat_time INTEGER NOT NULL,"
" unix_time INTEGER NOT NULL," " traf_time INTEGER NOT NULL,"
" in_bytes INTEGER NOT NULL," " in_bytes INTEGER NOT NULL,"
" out_bytes INTEGER NOT NULL" " out_bytes INTEGER NOT NULL"
");" ");"
"CREATE TABLE traffic_app_hour(" "CREATE TABLE traffic_app_hour("
" app_id INTEGER NOT NULL," " app_id INTEGER NOT NULL,"
" unix_time INTEGER NOT NULL," " traf_time INTEGER NOT NULL,"
" in_bytes INTEGER NOT NULL," " in_bytes INTEGER NOT NULL,"
" out_bytes INTEGER NOT NULL," " out_bytes INTEGER NOT NULL,"
" PRIMARY KEY (app_id, unix_time)" " PRIMARY KEY (app_id, traf_time)"
") WITHOUT ROWID;" ") WITHOUT ROWID;"
"CREATE TABLE traffic_app_day(" "CREATE TABLE traffic_app_day("
" app_id INTEGER NOT NULL," " app_id INTEGER NOT NULL,"
" unix_time INTEGER NOT NULL," " traf_time INTEGER NOT NULL,"
" in_bytes INTEGER NOT NULL," " in_bytes INTEGER NOT NULL,"
" out_bytes INTEGER NOT NULL," " out_bytes INTEGER NOT NULL,"
" PRIMARY KEY (app_id, unix_time)" " PRIMARY KEY (app_id, traf_time)"
") WITHOUT ROWID;" ") WITHOUT ROWID;"
"CREATE TABLE traffic_app_month(" "CREATE TABLE traffic_app_month("
" app_id INTEGER NOT NULL," " app_id INTEGER NOT NULL,"
" unix_time INTEGER NOT NULL," " traf_time INTEGER NOT NULL,"
" in_bytes INTEGER NOT NULL," " in_bytes INTEGER NOT NULL,"
" out_bytes INTEGER NOT NULL," " out_bytes INTEGER NOT NULL,"
" PRIMARY KEY (app_id, unix_time)" " PRIMARY KEY (app_id, traf_time)"
") WITHOUT ROWID;" ") WITHOUT ROWID;"
"CREATE TABLE traffic_hour(" "CREATE TABLE traffic_hour("
" unix_time INTEGER PRIMARY KEY," " traf_time INTEGER PRIMARY KEY,"
" in_bytes INTEGER NOT NULL," " in_bytes INTEGER NOT NULL,"
" out_bytes INTEGER NOT NULL" " out_bytes INTEGER NOT NULL"
") WITHOUT ROWID;" ") WITHOUT ROWID;"
"CREATE TABLE traffic_day(" "CREATE TABLE traffic_day("
" unix_time INTEGER PRIMARY KEY," " traf_time INTEGER PRIMARY KEY,"
" in_bytes INTEGER NOT NULL," " in_bytes INTEGER NOT NULL,"
" out_bytes INTEGER NOT NULL" " out_bytes INTEGER NOT NULL"
") WITHOUT ROWID;" ") WITHOUT ROWID;"
"CREATE TABLE traffic_month(" "CREATE TABLE traffic_month("
" unix_time INTEGER PRIMARY KEY," " traf_time INTEGER PRIMARY KEY,"
" in_bytes INTEGER NOT NULL," " in_bytes INTEGER NOT NULL,"
" out_bytes INTEGER NOT NULL" " out_bytes INTEGER NOT NULL"
") WITHOUT ROWID;" ") WITHOUT ROWID;"
@ -64,7 +64,7 @@ const char * const DatabaseSql::sqlSelectAppId =
; ;
const char * const DatabaseSql::sqlInsertAppId = const char * const DatabaseSql::sqlInsertAppId =
"INSERT INTO app(path, creat_time, unix_time, in_bytes, out_bytes)" "INSERT INTO app(path, creat_time, traf_time, in_bytes, out_bytes)"
" VALUES(?1, ?2, ?3, 0, 0);" " VALUES(?1, ?2, ?3, 0, 0);"
; ;
@ -73,32 +73,32 @@ const char * const DatabaseSql::sqlSelectAppPaths =
; ;
const char * const DatabaseSql::sqlInsertTrafficAppHour = const char * const DatabaseSql::sqlInsertTrafficAppHour =
"INSERT INTO traffic_app_hour(app_id, unix_time, in_bytes, out_bytes)" "INSERT INTO traffic_app_hour(app_id, traf_time, in_bytes, out_bytes)"
" VALUES(?2, ?1, 0, 0);" " VALUES(?2, ?1, 0, 0);"
; ;
const char * const DatabaseSql::sqlInsertTrafficAppDay = const char * const DatabaseSql::sqlInsertTrafficAppDay =
"INSERT INTO traffic_app_day(app_id, unix_time, in_bytes, out_bytes)" "INSERT INTO traffic_app_day(app_id, traf_time, in_bytes, out_bytes)"
" VALUES(?2, ?1, 0, 0);" " VALUES(?2, ?1, 0, 0);"
; ;
const char * const DatabaseSql::sqlInsertTrafficAppMonth = const char * const DatabaseSql::sqlInsertTrafficAppMonth =
"INSERT INTO traffic_app_month(app_id, unix_time, in_bytes, out_bytes)" "INSERT INTO traffic_app_month(app_id, traf_time, in_bytes, out_bytes)"
" VALUES(?2, ?1, 0, 0);" " VALUES(?2, ?1, 0, 0);"
; ;
const char * const DatabaseSql::sqlInsertTrafficHour = const char * const DatabaseSql::sqlInsertTrafficHour =
"INSERT INTO traffic_hour(unix_time, in_bytes, out_bytes)" "INSERT INTO traffic_hour(traf_time, in_bytes, out_bytes)"
" VALUES(?1, 0, 0);" " VALUES(?1, 0, 0);"
; ;
const char * const DatabaseSql::sqlInsertTrafficDay = const char * const DatabaseSql::sqlInsertTrafficDay =
"INSERT INTO traffic_day(unix_time, in_bytes, out_bytes)" "INSERT INTO traffic_day(traf_time, in_bytes, out_bytes)"
" VALUES(?1, 0, 0);" " VALUES(?1, 0, 0);"
; ;
const char * const DatabaseSql::sqlInsertTrafficMonth = const char * const DatabaseSql::sqlInsertTrafficMonth =
"INSERT INTO traffic_month(unix_time, in_bytes, out_bytes)" "INSERT INTO traffic_month(traf_time, in_bytes, out_bytes)"
" VALUES(?1, 0, 0);" " VALUES(?1, 0, 0);"
; ;
@ -106,42 +106,42 @@ const char * const DatabaseSql::sqlUpdateTrafficAppHour =
"UPDATE traffic_app_hour" "UPDATE traffic_app_hour"
" SET in_bytes = in_bytes + ?2," " SET in_bytes = in_bytes + ?2,"
" out_bytes = out_bytes + ?3" " out_bytes = out_bytes + ?3"
" WHERE app_id = ?4 and unix_time = ?1;" " WHERE app_id = ?4 and traf_time = ?1;"
; ;
const char * const DatabaseSql::sqlUpdateTrafficAppDay = const char * const DatabaseSql::sqlUpdateTrafficAppDay =
"UPDATE traffic_app_day" "UPDATE traffic_app_day"
" SET in_bytes = in_bytes + ?2," " SET in_bytes = in_bytes + ?2,"
" out_bytes = out_bytes + ?3" " out_bytes = out_bytes + ?3"
" WHERE app_id = ?4 and unix_time = ?1;" " WHERE app_id = ?4 and traf_time = ?1;"
; ;
const char * const DatabaseSql::sqlUpdateTrafficAppMonth = const char * const DatabaseSql::sqlUpdateTrafficAppMonth =
"UPDATE traffic_app_month" "UPDATE traffic_app_month"
" SET in_bytes = in_bytes + ?2," " SET in_bytes = in_bytes + ?2,"
" out_bytes = out_bytes + ?3" " out_bytes = out_bytes + ?3"
" WHERE app_id = ?4 and unix_time = ?1;" " WHERE app_id = ?4 and traf_time = ?1;"
; ;
const char * const DatabaseSql::sqlUpdateTrafficHour = const char * const DatabaseSql::sqlUpdateTrafficHour =
"UPDATE traffic_hour" "UPDATE traffic_hour"
" SET in_bytes = in_bytes + ?2," " SET in_bytes = in_bytes + ?2,"
" out_bytes = out_bytes + ?3" " out_bytes = out_bytes + ?3"
" WHERE unix_time = ?1;" " WHERE traf_time = ?1;"
; ;
const char * const DatabaseSql::sqlUpdateTrafficDay = const char * const DatabaseSql::sqlUpdateTrafficDay =
"UPDATE traffic_day" "UPDATE traffic_day"
" SET in_bytes = in_bytes + ?2," " SET in_bytes = in_bytes + ?2,"
" out_bytes = out_bytes + ?3" " out_bytes = out_bytes + ?3"
" WHERE unix_time = ?1;" " WHERE traf_time = ?1;"
; ;
const char * const DatabaseSql::sqlUpdateTrafficMonth = const char * const DatabaseSql::sqlUpdateTrafficMonth =
"UPDATE traffic_month" "UPDATE traffic_month"
" SET in_bytes = in_bytes + ?2," " SET in_bytes = in_bytes + ?2,"
" out_bytes = out_bytes + ?3" " out_bytes = out_bytes + ?3"
" WHERE unix_time = ?1;" " WHERE traf_time = ?1;"
; ;
const char * const DatabaseSql::sqlUpdateTrafficAppTotal = const char * const DatabaseSql::sqlUpdateTrafficAppTotal =