Convert to HAVING

Signed-off-by: Etzelia <etzelia@hotmail.com>
develop
Etzelia 2019-08-16 12:38:10 -05:00
parent a1731ce47f
commit 75730c8a7c
No known key found for this signature in database
GPG Key ID: 3CAEB74806C4ADE5
2 changed files with 26 additions and 11 deletions

View File

@ -1,5 +1,6 @@
from django_coreprotect.models import SessionResult, ActivityResult
from django_coreprotect.utils import safe_int
from datetime import datetime
class ActivityForm:
@ -26,17 +27,31 @@ def activity_data(request):
def activity_results(form):
query = ""
players = []
players_clause = ""
if form.players:
players = []
for player in form.players.split(","):
players.append(player.strip())
players_clause = " WHERE ({}) ".format(" OR ".join(["player LIKE '%%{}%%'".format(p) for p in players]))
time_clause = ""
if form.date_from or form.date_to:
df, dt = form.date_from, form.date_to
if form.date_from and not form.date_to:
dt = datetime.now().timestamp()
if form.date_to and not form.date_from:
df = datetime.now().timestamp()
time_clause = " HAVING unix BETWEEN {} AND {} ".format(df, dt)
if players_clause or time_clause:
query = '''SELECT
0 AS id, cs.time AS unix, cu.user AS player, cs.action
FROM co_session cs
JOIN co_user cu ON cs.user = cu.rowid
{players}
'''.format(players=players_clause)
0 AS id, cs.time AS unix, cu.user AS player, cs.action
FROM co_session cs
JOIN co_user cu ON cs.user = cu.rowid
{players}
{time}
'''.format(players=players_clause, time=time_clause)
if query:
print(query)

8
gui.py
View File

@ -94,7 +94,7 @@ def gui_data(request):
def gui_results(form):
queries = []
ignore_environment = " AND player NOT LIKE '#%%' " if form.ignore_environment else ""
ignore_environment = " AND cu.user NOT LIKE '#%%' " if form.ignore_environment else ""
oldest_first = " ASC " if form.oldest_first else " DESC "
coords = []
@ -112,12 +112,12 @@ def gui_results(form):
if form.players:
for player in form.players.split(","):
players.append(player.strip())
players_clause = " AND ({})".format(" OR ".join(["player LIKE '%%{}%%'".format(p) for p in players]))
players_clause = " AND ({})".format(" OR ".join(["cu.user LIKE '%%{}%%'".format(p) for p in players]))
worlds_clause = ""
worlds = [world["id"] for world in form.worlds if world["checked"]]
if len(worlds):
worlds_clause = " AND cw.id IN ({})".format(",".join(worlds))
worlds_clause = " AND cw.rowid IN ({})".format(",".join(worlds))
time_clause = ""
if form.date_from or form.date_to:
@ -126,7 +126,7 @@ def gui_results(form):
dt = datetime.now().timestamp()
if form.date_to and not form.date_from:
df = datetime.now().timestamp()
time_clause = " AND unix BETWEEN {} AND {} ".format(df, dt)
time_clause = " HAVING unix BETWEEN {} AND {} ".format(df, dt)
# Block Break, Block Place, and Interact
block_actions = []