From ffdd7c5b5caeaeac14c060be5a8997400ff505db Mon Sep 17 00:00:00 2001 From: Simon Krughoff Date: Mon, 10 May 2021 13:21:12 -0700 Subject: [PATCH 1/5] Make sort function return full list if num is None --- src/rubintv/handlers/external/endpoints.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/rubintv/handlers/external/endpoints.py b/src/rubintv/handlers/external/endpoints.py index 57f12ce6..56c096ac 100644 --- a/src/rubintv/handlers/external/endpoints.py +++ b/src/rubintv/handlers/external/endpoints.py @@ -154,4 +154,4 @@ def timeSort( if num: return [Image(p) for p in clean_URLs][:num] - return [Image(p) for p in clean_URLs][:num] + return [Image(p) for p in clean_URLs] From 178f388281851c2559abd0ff03f3c98bde8de487 Mon Sep 17 00:00:00 2001 From: Simon Krughoff Date: Mon, 10 May 2021 13:28:05 -0700 Subject: [PATCH 2/5] Sort by file date rather than upload time --- src/rubintv/handlers/external/endpoints.py | 10 ++++------ 1 file changed, 4 insertions(+), 6 deletions(-) diff --git a/src/rubintv/handlers/external/endpoints.py b/src/rubintv/handlers/external/endpoints.py index 56c096ac..6cd4ae5c 100644 --- a/src/rubintv/handlers/external/endpoints.py +++ b/src/rubintv/handlers/external/endpoints.py @@ -147,11 +147,9 @@ def timeSort( bucket: Bucket, prefix: str, num: Optional[int] = None ) -> List[Image]: blobs = bucket.list_blobs(prefix=prefix) - sblobs = sorted(blobs, key=lambda x: x.time_created, reverse=True) - clean_URLs = [ - el.public_url for el in sblobs if el.public_url.endswith(".png") - ] + imgs = [Image(el.public_url) for el in blobs if el.public_url.endswith('.png')] + simgs = sorted(imgs, key=lambda x: (x.date, x.seq), reverse=True) if num: - return [Image(p) for p in clean_URLs][:num] - return [Image(p) for p in clean_URLs] + return simgs[:num] + return simgs From 276e8b4a2e23ce676f51c7741fae846d2569c253 Mon Sep 17 00:00:00 2001 From: Simon Krughoff Date: Mon, 10 May 2021 13:57:19 -0700 Subject: [PATCH 3/5] Add time sorting and window selection --- src/rubintv/handlers/external/endpoints.py | 59 ++++++++++++++++++++-- 1 file changed, 55 insertions(+), 4 deletions(-) diff --git a/src/rubintv/handlers/external/endpoints.py b/src/rubintv/handlers/external/endpoints.py index 6cd4ae5c..daace53d 100644 --- a/src/rubintv/handlers/external/endpoints.py +++ b/src/rubintv/handlers/external/endpoints.py @@ -8,6 +8,7 @@ "speccurrent", ] +from datetime import datetime from typing import List, Optional from aiohttp import web @@ -26,8 +27,18 @@ async def get_table(request: web.Request) -> web.Response: num = int(request.query["num"]) else: num = 10 + if "beg_date" in request.query: + beg_date = datetime.fromisoformat(request.query["beg_date"]) + else: + beg_date = None + if "end_date" in request.query: + end_date = datetime.fromisoformat(request.query["end_date"]) + else: + end_date = None bucket = request.config_dict["rubintv/gcs_bucket"] - page = get_formatted_table("table.html", bucket, num=num) + page = get_formatted_table( + "table.html", bucket, num=num, beg_date=beg_date, end_date=end_date + ) return web.Response(text=page, content_type="text/html") @@ -68,9 +79,23 @@ def get_formatted_table( template: str, bucket: Bucket, num: int = None, + beg_date: datetime = None, + end_date: datetime = None, ) -> str: - imimgs = timeSort(bucket, "summit_imexam", num) - specimgs = timeSort(bucket, "summit_specexam", num) + if beg_date or end_date: + imimgs = timeWindowSort( + bucket, "summit_imexam", num, beg_date=beg_date, end_date=end_date + ) + specimgs = timeWindowSort( + bucket, + "summit_specexam", + num, + beg_date=beg_date, + end_date=end_date, + ) + else: + imimgs = timeSort(bucket, "summit_imexam", num) + specimgs = timeSort(bucket, "summit_specexam", num) trimmed_specims = [] for img in imimgs: match = False @@ -147,9 +172,35 @@ def timeSort( bucket: Bucket, prefix: str, num: Optional[int] = None ) -> List[Image]: blobs = bucket.list_blobs(prefix=prefix) - imgs = [Image(el.public_url) for el in blobs if el.public_url.endswith('.png')] + imgs = [ + Image(el.public_url) for el in blobs if el.public_url.endswith(".png") + ] simgs = sorted(imgs, key=lambda x: (x.date, x.seq), reverse=True) if num: return simgs[:num] return simgs + + +def timeWindowSort( + bucket: Bucket, + prefix: str, + num: Optional[int] = None, + beg_date: Optional[datetime] = None, + end_date: Optional[datetime] = None, +) -> List[Image]: + imgs = timeSort(bucket, prefix) + if beg_date and end_date: + simgs = [ + el for el in imgs if beg_date < el.date and end_date > el.date + ] + elif beg_date: + simgs = [el for el in imgs if beg_date < el.date] + elif end_date: + simgs = [el for el in imgs if end_date > el.date] + else: + raise RuntimeError(f"Something went wrong: {beg_date} and {end_date}") + + if num: + return simgs[:num] + return simgs From 6ab786f89f190c8be5279ff567c53a023d9c65d1 Mon Sep 17 00:00:00 2001 From: Simon Krughoff Date: Mon, 10 May 2021 14:15:49 -0700 Subject: [PATCH 4/5] Add description of window parameters The typing addition is so I don't have a big elif block figuring out which arguments to send and which not to. --- src/rubintv/handlers/external/endpoints.py | 4 ++-- src/rubintv/templates/table.html | 7 ++++++- 2 files changed, 8 insertions(+), 3 deletions(-) diff --git a/src/rubintv/handlers/external/endpoints.py b/src/rubintv/handlers/external/endpoints.py index daace53d..8c6ba819 100644 --- a/src/rubintv/handlers/external/endpoints.py +++ b/src/rubintv/handlers/external/endpoints.py @@ -30,11 +30,11 @@ async def get_table(request: web.Request) -> web.Response: if "beg_date" in request.query: beg_date = datetime.fromisoformat(request.query["beg_date"]) else: - beg_date = None + beg_date = None # type: ignore[assignment] if "end_date" in request.query: end_date = datetime.fromisoformat(request.query["end_date"]) else: - end_date = None + end_date = None # type: ignore[assignment] bucket = request.config_dict["rubintv/gcs_bucket"] page = get_formatted_table( "table.html", bucket, num=num, beg_date=beg_date, end_date=end_date diff --git a/src/rubintv/templates/table.html b/src/rubintv/templates/table.html index 80c0c1e5..36d9c9be 100644 --- a/src/rubintv/templates/table.html +++ b/src/rubintv/templates/table.html @@ -85,12 +85,17 @@
https://roundtable.lsst.codes/rubintv/imevents/<date>/<seq>
 
https://roundtable.lsst.codes/rubintv/specevents/<date>/<seq>
 
-

where the date format is %Y-%m%-%d.

+

To enlarge the table, use

 https://roundtable.lsst.codes/rubintv/?num=<num>
 
+

To search by time window, use

+
 https://roundtable.lsst.codes/rubintv/?beg_date=<ISO date>&end_date=<ISO date>
+
+

The beg_date and end_date parameters must be ISO 8601 compliant time strings: e.g 2021-05-15. If either is missing they will be treated as lower or upper date limits respectively.

+

To get the most recent events, use

https://roundtable.lsst.codes/rubintv/im_current
 
https://roundtable.lsst.codes/rubintv/spec_current

From ed3f1b2bf97e453a1c6ef53964b7c663203baa11 Mon Sep 17 00:00:00 2001
From: Simon Krughoff 
Date: Mon, 10 May 2021 16:26:53 -0700
Subject: [PATCH 5/5] Bump tag version

---
 manifests/base/kustomization.yaml | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/manifests/base/kustomization.yaml b/manifests/base/kustomization.yaml
index 4d86e231..b7444bdc 100644
--- a/manifests/base/kustomization.yaml
+++ b/manifests/base/kustomization.yaml
@@ -3,7 +3,7 @@ kind: Kustomization
 
 images:
   - name: lsstsqre/rubintv
-    newTag: 0.0.5
+    newTag: 0.0.6
 
 resources:
   - configmap.yaml