mirror of
https://github.com/tnodir/fort
synced 2024-11-15 08:25:20 +00:00
DB: Rename "unix_time" to "traf_time".
This commit is contained in:
parent
8fcf4854d6
commit
d42f4941dd
@ -79,27 +79,27 @@ void Test::debugProcNew(SqliteDb *sqliteDb)
|
||||
void Test::debugStatTraf(SqliteDb *sqliteDb)
|
||||
{
|
||||
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;");
|
||||
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;");
|
||||
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;");
|
||||
|
||||
debugStatTrafStep(sqliteDb, "traffic_hour",
|
||||
"SELECT 0, unix_time, in_bytes, out_bytes"
|
||||
"SELECT 0, traf_time, in_bytes, out_bytes"
|
||||
" FROM traffic_hour;");
|
||||
debugStatTrafStep(sqliteDb, "traffic_day",
|
||||
"SELECT 0, unix_time, in_bytes, out_bytes"
|
||||
"SELECT 0, traf_time, in_bytes, out_bytes"
|
||||
" FROM traffic_day;");
|
||||
debugStatTrafStep(sqliteDb, "traffic_month",
|
||||
"SELECT 0, unix_time, in_bytes, out_bytes"
|
||||
"SELECT 0, traf_time, in_bytes, out_bytes"
|
||||
" FROM traffic_month;");
|
||||
|
||||
debugStatTrafStep(sqliteDb, "traffic_app_total",
|
||||
"SELECT id, unix_time, in_bytes, out_bytes"
|
||||
"SELECT id, traf_time, in_bytes, out_bytes"
|
||||
" FROM app;", 1);
|
||||
}
|
||||
|
||||
@ -112,11 +112,11 @@ void Test::debugStatTrafStep(SqliteDb *sqliteDb, const char *name,
|
||||
|
||||
qDebug() << '>' << name << '<';
|
||||
while (stmt.step() == SqliteStmt::StepRow) {
|
||||
const qint64 unixTime = stmt.columnInt64(1) * timeMult;
|
||||
const qint64 trafTime = stmt.columnInt64(1) * timeMult;
|
||||
|
||||
qDebug() << '>'
|
||||
<< stmt.columnInt64(0)
|
||||
<< QDateTime::fromSecsSinceEpoch(unixTime).toString()
|
||||
<< QDateTime::fromSecsSinceEpoch(trafTime).toString()
|
||||
<< stmt.columnInt64(2)
|
||||
<< stmt.columnInt64(3);
|
||||
}
|
||||
|
@ -11,9 +11,9 @@
|
||||
DatabaseManager::DatabaseManager(const QString &filePath,
|
||||
QObject *parent) :
|
||||
QObject(parent),
|
||||
m_lastUnixHour(0),
|
||||
m_lastUnixDay(0),
|
||||
m_lastUnixMonth(0),
|
||||
m_lastTrafHour(0),
|
||||
m_lastTrafDay(0),
|
||||
m_lastTrafMonth(0),
|
||||
m_filePath(filePath),
|
||||
m_sqliteDb(new SqliteDb())
|
||||
{
|
||||
@ -53,18 +53,18 @@ void DatabaseManager::addTraffic(quint16 procCount, const quint8 *procBits,
|
||||
{
|
||||
QVector<quint16> delProcIndexes;
|
||||
|
||||
const qint64 unixTime = QDateTime::currentSecsSinceEpoch();
|
||||
const qint64 trafTime = QDateTime::currentSecsSinceEpoch();
|
||||
|
||||
const qint32 unixHour = qint32(unixTime / 3600);
|
||||
const bool isNewHour = (unixHour != m_lastUnixHour);
|
||||
const qint32 trafHour = qint32(trafTime / 3600);
|
||||
const bool isNewHour = (trafHour != m_lastTrafHour);
|
||||
|
||||
const qint32 unixDay = isNewHour ? getUnixDay(unixTime)
|
||||
: m_lastUnixDay;
|
||||
const bool isNewDay = (unixDay != m_lastUnixDay);
|
||||
const qint32 trafDay = isNewHour ? getUnixDay(trafTime)
|
||||
: m_lastTrafDay;
|
||||
const bool isNewDay = (trafDay != m_lastTrafDay);
|
||||
|
||||
const qint32 unixMonth = isNewDay ? getUnixMonth(unixTime)
|
||||
: m_lastUnixMonth;
|
||||
const bool isNewMonth = (unixMonth != m_lastUnixMonth);
|
||||
const qint32 trafMonth = isNewDay ? getUnixMonth(trafTime)
|
||||
: m_lastTrafMonth;
|
||||
const bool isNewMonth = (trafMonth != m_lastTrafMonth);
|
||||
|
||||
SqliteStmt *stmtInsertAppHour = nullptr;
|
||||
SqliteStmt *stmtInsertAppDay = nullptr;
|
||||
@ -75,31 +75,31 @@ void DatabaseManager::addTraffic(quint16 procCount, const quint8 *procBits,
|
||||
SqliteStmt *stmtInsertMonth = nullptr;
|
||||
|
||||
if (isNewHour) {
|
||||
m_lastUnixHour = unixHour;
|
||||
m_lastTrafHour = trafHour;
|
||||
|
||||
stmtInsertAppHour = getSqliteStmt(DatabaseSql::sqlInsertTrafficAppHour);
|
||||
stmtInsertHour = getSqliteStmt(DatabaseSql::sqlInsertTrafficHour);
|
||||
|
||||
stmtInsertAppHour->bindInt(1, unixHour);
|
||||
stmtInsertHour->bindInt(1, unixHour);
|
||||
stmtInsertAppHour->bindInt(1, trafHour);
|
||||
stmtInsertHour->bindInt(1, trafHour);
|
||||
|
||||
if (isNewDay) {
|
||||
m_lastUnixDay = unixDay;
|
||||
m_lastTrafDay = trafDay;
|
||||
|
||||
stmtInsertAppDay = getSqliteStmt(DatabaseSql::sqlInsertTrafficAppDay);
|
||||
stmtInsertDay = getSqliteStmt(DatabaseSql::sqlInsertTrafficDay);
|
||||
|
||||
stmtInsertAppDay->bindInt(1, unixDay);
|
||||
stmtInsertDay->bindInt(1, unixDay);
|
||||
stmtInsertAppDay->bindInt(1, trafDay);
|
||||
stmtInsertDay->bindInt(1, trafDay);
|
||||
|
||||
if (isNewMonth) {
|
||||
m_lastUnixMonth = unixMonth;
|
||||
m_lastTrafMonth = trafMonth;
|
||||
|
||||
stmtInsertAppMonth = getSqliteStmt(DatabaseSql::sqlInsertTrafficAppMonth);
|
||||
stmtInsertMonth = getSqliteStmt(DatabaseSql::sqlInsertTrafficMonth);
|
||||
|
||||
stmtInsertAppMonth->bindInt(1, unixMonth);
|
||||
stmtInsertMonth->bindInt(1, unixMonth);
|
||||
stmtInsertAppMonth->bindInt(1, trafMonth);
|
||||
stmtInsertMonth->bindInt(1, trafMonth);
|
||||
}
|
||||
}
|
||||
}
|
||||
@ -114,13 +114,13 @@ void DatabaseManager::addTraffic(quint16 procCount, const quint8 *procBits,
|
||||
|
||||
SqliteStmt *stmtUpdateAppTotal = getSqliteStmt(DatabaseSql::sqlUpdateTrafficAppTotal);
|
||||
|
||||
stmtUpdateAppHour->bindInt(1, unixHour);
|
||||
stmtUpdateAppDay->bindInt(1, unixDay);
|
||||
stmtUpdateAppMonth->bindInt(1, unixMonth);
|
||||
stmtUpdateAppHour->bindInt(1, trafHour);
|
||||
stmtUpdateAppDay->bindInt(1, trafDay);
|
||||
stmtUpdateAppMonth->bindInt(1, trafMonth);
|
||||
|
||||
stmtUpdateHour->bindInt(1, unixHour);
|
||||
stmtUpdateDay->bindInt(1, unixDay);
|
||||
stmtUpdateMonth->bindInt(1, unixMonth);
|
||||
stmtUpdateHour->bindInt(1, trafHour);
|
||||
stmtUpdateDay->bindInt(1, trafDay);
|
||||
stmtUpdateMonth->bindInt(1, trafMonth);
|
||||
|
||||
m_sqliteDb->beginTransaction();
|
||||
|
||||
@ -261,7 +261,7 @@ void DatabaseManager::insertTraffic(SqliteStmt *stmt, qint64 appId)
|
||||
}
|
||||
|
||||
void DatabaseManager::updateTraffic(SqliteStmt *stmt, quint32 inBytes,
|
||||
quint32 outBytes, qint64 appId)
|
||||
quint32 outBytes, qint64 appId)
|
||||
{
|
||||
stmt->bindInt64(2, inBytes);
|
||||
stmt->bindInt64(3, outBytes);
|
||||
|
@ -41,15 +41,15 @@ private:
|
||||
|
||||
void insertTraffic(SqliteStmt *stmt, qint64 appId = 0);
|
||||
void updateTraffic(SqliteStmt *stmt, quint32 inBytes,
|
||||
quint32 outBytes, qint64 appId = 0);
|
||||
quint32 outBytes, qint64 appId = 0);
|
||||
|
||||
static qint32 getUnixDay(qint64 unixTime);
|
||||
static qint32 getUnixMonth(qint64 unixTime);
|
||||
|
||||
private:
|
||||
qint32 m_lastUnixHour;
|
||||
qint32 m_lastUnixDay;
|
||||
qint32 m_lastUnixMonth;
|
||||
qint32 m_lastTrafHour;
|
||||
qint32 m_lastTrafDay;
|
||||
qint32 m_lastTrafMonth;
|
||||
|
||||
QString m_filePath;
|
||||
|
||||
|
@ -11,49 +11,49 @@ const char * const DatabaseSql::sqlCreateTables =
|
||||
" id INTEGER PRIMARY KEY,"
|
||||
" path TEXT UNIQUE NOT NULL,"
|
||||
" creat_time INTEGER NOT NULL,"
|
||||
" unix_time INTEGER NOT NULL,"
|
||||
" traf_time INTEGER NOT NULL,"
|
||||
" in_bytes INTEGER NOT NULL,"
|
||||
" out_bytes INTEGER NOT NULL"
|
||||
");"
|
||||
|
||||
"CREATE TABLE traffic_app_hour("
|
||||
" app_id INTEGER NOT NULL,"
|
||||
" unix_time INTEGER NOT NULL,"
|
||||
" traf_time INTEGER NOT NULL,"
|
||||
" in_bytes INTEGER NOT NULL,"
|
||||
" out_bytes INTEGER NOT NULL,"
|
||||
" PRIMARY KEY (app_id, unix_time)"
|
||||
" PRIMARY KEY (app_id, traf_time)"
|
||||
") WITHOUT ROWID;"
|
||||
|
||||
"CREATE TABLE traffic_app_day("
|
||||
" app_id INTEGER NOT NULL,"
|
||||
" unix_time INTEGER NOT NULL,"
|
||||
" traf_time INTEGER NOT NULL,"
|
||||
" in_bytes INTEGER NOT NULL,"
|
||||
" out_bytes INTEGER NOT NULL,"
|
||||
" PRIMARY KEY (app_id, unix_time)"
|
||||
" PRIMARY KEY (app_id, traf_time)"
|
||||
") WITHOUT ROWID;"
|
||||
|
||||
"CREATE TABLE traffic_app_month("
|
||||
" app_id INTEGER NOT NULL,"
|
||||
" unix_time INTEGER NOT NULL,"
|
||||
" traf_time INTEGER NOT NULL,"
|
||||
" in_bytes INTEGER NOT NULL,"
|
||||
" out_bytes INTEGER NOT NULL,"
|
||||
" PRIMARY KEY (app_id, unix_time)"
|
||||
" PRIMARY KEY (app_id, traf_time)"
|
||||
") WITHOUT ROWID;"
|
||||
|
||||
"CREATE TABLE traffic_hour("
|
||||
" unix_time INTEGER PRIMARY KEY,"
|
||||
" traf_time INTEGER PRIMARY KEY,"
|
||||
" in_bytes INTEGER NOT NULL,"
|
||||
" out_bytes INTEGER NOT NULL"
|
||||
") WITHOUT ROWID;"
|
||||
|
||||
"CREATE TABLE traffic_day("
|
||||
" unix_time INTEGER PRIMARY KEY,"
|
||||
" traf_time INTEGER PRIMARY KEY,"
|
||||
" in_bytes INTEGER NOT NULL,"
|
||||
" out_bytes INTEGER NOT NULL"
|
||||
") WITHOUT ROWID;"
|
||||
|
||||
"CREATE TABLE traffic_month("
|
||||
" unix_time INTEGER PRIMARY KEY,"
|
||||
" traf_time INTEGER PRIMARY KEY,"
|
||||
" in_bytes INTEGER NOT NULL,"
|
||||
" out_bytes INTEGER NOT NULL"
|
||||
") WITHOUT ROWID;"
|
||||
@ -64,7 +64,7 @@ const char * const DatabaseSql::sqlSelectAppId =
|
||||
;
|
||||
|
||||
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);"
|
||||
;
|
||||
|
||||
@ -73,32 +73,32 @@ const char * const DatabaseSql::sqlSelectAppPaths =
|
||||
;
|
||||
|
||||
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);"
|
||||
;
|
||||
|
||||
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);"
|
||||
;
|
||||
|
||||
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);"
|
||||
;
|
||||
|
||||
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);"
|
||||
;
|
||||
|
||||
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);"
|
||||
;
|
||||
|
||||
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);"
|
||||
;
|
||||
|
||||
@ -106,42 +106,42 @@ const char * const DatabaseSql::sqlUpdateTrafficAppHour =
|
||||
"UPDATE traffic_app_hour"
|
||||
" SET in_bytes = in_bytes + ?2,"
|
||||
" 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 =
|
||||
"UPDATE traffic_app_day"
|
||||
" SET in_bytes = in_bytes + ?2,"
|
||||
" 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 =
|
||||
"UPDATE traffic_app_month"
|
||||
" SET in_bytes = in_bytes + ?2,"
|
||||
" 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 =
|
||||
"UPDATE traffic_hour"
|
||||
" SET in_bytes = in_bytes + ?2,"
|
||||
" out_bytes = out_bytes + ?3"
|
||||
" WHERE unix_time = ?1;"
|
||||
" WHERE traf_time = ?1;"
|
||||
;
|
||||
|
||||
const char * const DatabaseSql::sqlUpdateTrafficDay =
|
||||
"UPDATE traffic_day"
|
||||
" SET in_bytes = in_bytes + ?2,"
|
||||
" out_bytes = out_bytes + ?3"
|
||||
" WHERE unix_time = ?1;"
|
||||
" WHERE traf_time = ?1;"
|
||||
;
|
||||
|
||||
const char * const DatabaseSql::sqlUpdateTrafficMonth =
|
||||
"UPDATE traffic_month"
|
||||
" SET in_bytes = in_bytes + ?2,"
|
||||
" out_bytes = out_bytes + ?3"
|
||||
" WHERE unix_time = ?1;"
|
||||
" WHERE traf_time = ?1;"
|
||||
;
|
||||
|
||||
const char * const DatabaseSql::sqlUpdateTrafficAppTotal =
|
||||
|
Loading…
Reference in New Issue
Block a user