From 61c937d5d8cf53962df8e02727d90eec5685fe68 Mon Sep 17 00:00:00 2001 From: Theophile du Laz Date: Tue, 5 Nov 2024 12:52:41 -0800 Subject: [PATCH] Kowalski Filter - not_if_tns_reported (#561) * add support for the not_if_tns_reported kowalski parameter when updating filters * add frontend to edit that parameter on the filter page --- .../skyportal/handlers/api/kowalski_filter.py | 20 +++++++++++++++++++ .../js/components/filter/FilterPlugins.jsx | 19 +++++++++++++++++- fritz.defaults.yaml | 5 +++++ 3 files changed, 43 insertions(+), 1 deletion(-) diff --git a/extensions/skyportal/skyportal/handlers/api/kowalski_filter.py b/extensions/skyportal/skyportal/handlers/api/kowalski_filter.py index 5eb6c697..8ebe4e23 100644 --- a/extensions/skyportal/skyportal/handlers/api/kowalski_filter.py +++ b/extensions/skyportal/skyportal/handlers/api/kowalski_filter.py @@ -352,11 +352,31 @@ def patch(self, filter_id): "radius", "implements_update", "ignore_allocation_ids", + "not_if_tns_reported", } if not set(auto_followup.keys()).issubset(valid_keys): return self.error( f"auto_followup dict keys must be a subset of {valid_keys}" ) + if "not_if_tns_reported" in auto_followup: + # if it's not empty or None, verify it's a a float or an int + # it should be in hours + if ( + auto_followup["not_if_tns_reported"] is not None + and str(auto_followup["not_if_tns_reported"]).strip() != "" + ): + try: + auto_followup["not_if_tns_reported"] = float( + auto_followup["not_if_tns_reported"] + ) + except ValueError: + return self.error( + "not_if_tns_reported must be a float or an int, if not an empty string or None" + ) + else: + # we still want to keep it when None, for example when we want to unset it + auto_followup["not_if_tns_reported"] = None + # query the allocation by id allocation_id = auto_followup.get("allocation_id", None) diff --git a/extensions/skyportal/static/js/components/filter/FilterPlugins.jsx b/extensions/skyportal/static/js/components/filter/FilterPlugins.jsx index 84bd0e08..36311ae5 100644 --- a/extensions/skyportal/static/js/components/filter/FilterPlugins.jsx +++ b/extensions/skyportal/static/js/components/filter/FilterPlugins.jsx @@ -180,6 +180,7 @@ const FilterPlugins = ({ group }) => { const [autosaveComment, setAutosaveComment] = useState(""); const [autoFollowupComment, setAutoFollowupComment] = useState(""); const [autoFollowupRadius, setAutoFollowupRadius] = useState(0.5); + const [autoFollowupTnsAge, setAutoFollowupTnsAge] = useState(null); const [otherVersion, setOtherVersion] = React.useState(""); @@ -321,6 +322,7 @@ const FilterPlugins = ({ group }) => { const newAutoFollowup = { ...filter_v.auto_followup, radius: autoFollowupRadius, + not_if_tns_reported: autoFollowupTnsAge, }; const result = await dispatch( filterVersionActions.editAutoFollowup({ @@ -331,7 +333,7 @@ const FilterPlugins = ({ group }) => { if (result.status === "success") { dispatch( showNotification( - `Set auto_followup radius constraint to ${autoFollowupRadius}`, + `Set auto_followup radius constraint to ${autoFollowupRadius}, and TNS age constraint to ${autoFollowupTnsAge}`, ), ); } @@ -1570,6 +1572,21 @@ const FilterPlugins = ({ group }) => { } /> +
+ + Cancel if TNS reported in the last N hours. Leave empty to disable + + + setAutoFollowupTnsAge(event.target.value) + } + /> +