Update create_db script and stats db operations

This commit is contained in:
hiro 2019-05-23 20:34:58 +02:00
parent adceca12db
commit 9723be4280
3 changed files with 10 additions and 9 deletions

View File

@ -88,12 +88,12 @@ class SQLite3(object):
Update statistics to the database
"""
now_str = datetime.now().strftime("%Y%m%d")
query = "REPLACE INTO stats(num_requests, platform, language, "\
"command, service, date) VALUES(COALESCE((SELECT num_requests FROM stats "\
"WHERE platform=? AND language=? AND date=?)+1, 0), ?, ?, ?, ?, ?) "\
query = "INSERT INTO stats(num_requests, platform, language, command, "\
"service, date) VALUES (1, ?, ?, ?, ?, ?) ON CONFLICT(platform, "\
"language, command, service, date) DO UPDATE SET num_requests=num_requests+1"
return self.dbpool.runQuery(
query, (platform, language, now_str, platform, language, command, service, now_str)
query, (platform, language, command, service, now_str)
).addCallback(self.query_callback).addErrback(self.query_errback)
def get_links(self, platform, language, status):

View File

@ -91,7 +91,8 @@ def main():
)
c.execute(
"CREATE TABLE stats(num_requests NUMBER, platform TEXT,"
" language TEXT, command TEXT, service TEXT, date TEXT)"
" language TEXT, command TEXT, service TEXT, date,"
" PRIMARY KEY (platform, language, command, service, date))"
)
print("Database {} created.".format(abs_filename))
elif args.clear:
@ -125,9 +126,9 @@ def main():
"PRIMARY KEY(platform, arch, version, provider, status))"
)
c.execute(
"CREATE TABLE stats(date TEXT PRIMARY KEY, "
"num_requests INTEGER, platform TEXT, language TEXT, command TEXT, "
"service TEXT)"
"CREATE TABLE stats(date TEXT, num_requests INTEGER, "
"platform TEXT, language TEXT, command TEXT, service TEXT,"
"PRIMARY KEY (platform, language, command, service, date))"
)
print("New database {} created.".format(abs_filename))

View File

@ -6,7 +6,7 @@ from twisted.internet import task
from . import conftests
class EmailServiceTests(unittest.TestCase):
class LocalesTests(unittest.TestCase):
# Fail any tests which take longer than 15 seconds.
timeout = 15