From 85f95deef15e47d27b572103a30ccacce1c8d4fd Mon Sep 17 00:00:00 2001 From: Lukas Winkler Date: Fri, 17 Apr 2020 18:00:42 +0200 Subject: [PATCH] fix and add colors and optimize server SQL --- colors.py | 11 ++++++++--- data.py | 14 +++++++++++++- server.py | 7 +++++-- 3 files changed, 26 insertions(+), 6 deletions(-) diff --git a/colors.py b/colors.py index e3d1230..79e853a 100644 --- a/colors.py +++ b/colors.py @@ -1,10 +1,15 @@ -from data import colors_c2 +from data import colors_c2, colors_c1 from models import Person, Series +campaign2 = Series.select().where(Series.title == "Campaign 2").get() +campaign1 = Series.select().where(Series.title == "Campaign 1").get() + p: Person for p in Person.select(): - campaign2 = Series.select().where(Series.title == "Campaign 2") - print(p) + if p.name in colors_c1.keys() and p.series == campaign1: + print(p.name) + p.color = colors_c1[p.name] + p.save() if p.name in colors_c2.keys() and p.series == campaign2: print(p.name) p.color = colors_c2[p.name] diff --git a/data.py b/data.py index ad09010..9184505 100644 --- a/data.py +++ b/data.py @@ -1,3 +1,14 @@ +colors_c1 = { + "Travis": "#7592a4", + "Marisha": "#bd6b1e", + "Taliesin": "#3c487d", + "Ashley": "#fdd9be", + "Sam": "#781485", + "Liam": "#3d7580", + "Laura": "#28607d", + "Orion": "#933326" +} + colors_c2 = { "Laura": "#59c3f9", "Marisha": "#00146e", @@ -6,7 +17,8 @@ colors_c2 = { "Ashley": "#868984", "Sam": "#dae1dd", "Travis": "#076708", - "Matt": "#471f0e" # random color + "Matt": "#005d73", # random color + "Khary": "#bcc9e3" } single_speaker = { diff --git a/server.py b/server.py index 1e9ad7b..d6d71a5 100644 --- a/server.py +++ b/server.py @@ -51,13 +51,16 @@ def search(): a = Alias(fn.ts_rank(Line.search_text, fn.plainto_tsquery('english', query)), "rank") - results = Line.select(Line, Person, Episode, a).where( + results = Line.select(Line, Person, Episode, Series, a).where( (Line.search_text.match(query, language="english", plain=True)) & (Episode.episode_number <= until) & (Episode.series == series) - ).order_by(SQL("rank DESC")).join(Person).switch(Line).join(Episode).limit(20) + ).order_by(SQL("rank DESC")) \ + .join(Person).switch(Line) \ + .join(Episode).join(Series) \ + .limit(20) if len(results) == 0: result: cursor = db.execute_sql("select plainto_tsquery('english',%s)", [query])