Commit 9723be42 authored by Hiro's avatar Hiro 🏄
Browse files

Update create_db script and stats db operations

parent adceca12
......@@ -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):
......
......@@ -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))
......
......@@ -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
......
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment