From 7cc65810bfa0f52b962d112fffa37c0070b1e47d Mon Sep 17 00:00:00 2001 From: Alexander Pace <alexander.pace@ligo.org> Date: Mon, 8 May 2023 19:53:54 -0500 Subject: [PATCH 1/3] pipeline preferred table changes: Added gpstime, p_astro, em_bright. TODO: decide what the public sees --- .../superevents/templatetags/pastro_text.py | 21 +++++++++++++++++++ gracedb/templates/superevents/detail.html | 2 +- .../pipeline_preferred_event_info_table.html | 9 +++++++- 3 files changed, 30 insertions(+), 2 deletions(-) diff --git a/gracedb/superevents/templatetags/pastro_text.py b/gracedb/superevents/templatetags/pastro_text.py index ce572461d..183341e33 100644 --- a/gracedb/superevents/templatetags/pastro_text.py +++ b/gracedb/superevents/templatetags/pastro_text.py @@ -30,3 +30,24 @@ def pastro_text(graceid): return mark_safe(', '.join([html_format.format(source=i, value=round(data[i], 6)) for i in data])) +@register.filter(is_safe=True) +def embright_text(graceid): + try: + ev = Event.getByGraceid(graceid) + except: + return "Event {} does not exist".format(graceid) + + embright_file_name = 'em_bright.json' + embright_file = pathlib.Path(ev.datadir, embright_file_name) + + try: + with open(embright_file, 'r') as f: + data = json.load(f) + except IOError: + return "File {} not found or could not be opened".format(embright_file_name) + except json.JSONDecodeError: + return "Could not json-decode file {}".format(embright_file_name) + + return mark_safe(', '.join([html_format.format(source=i, + value=round(data[i], 6)) for i in data])) + diff --git a/gracedb/templates/superevents/detail.html b/gracedb/templates/superevents/detail.html index 4920225d1..e9fcc74db 100644 --- a/gracedb/templates/superevents/detail.html +++ b/gracedb/templates/superevents/detail.html @@ -47,7 +47,7 @@ paging:false, searching:false, info:false, - order: [[4, 'desc']], + order: [[5, 'desc']], }); }); </script> diff --git a/gracedb/templates/superevents/pipeline_preferred_event_info_table.html b/gracedb/templates/superevents/pipeline_preferred_event_info_table.html index 056ebbaa5..45d557cab 100644 --- a/gracedb/templates/superevents/pipeline_preferred_event_info_table.html +++ b/gracedb/templates/superevents/pipeline_preferred_event_info_table.html @@ -1,20 +1,24 @@ {% load timeutil %} {% load scientific %} +{% load pastro_text %} <table id="pipeline-preferred" class="table-hover table-condensed table-resp-gracedb shadow p-3 mb-5 rounded "> <!-- Table Header --> <thead> <tr> - <th colspan="5"><h3>Per-Pipeline Event Information</h3></th> + <th colspan="8"><h3>Per-Pipeline Event Information</h3></th> </tr> <tr> <th> UID </th> <th> Group </th> <th> Pipeline </th> + <th> gpstime </th> <th> FAR (Hz) </th> <th> SNR </th> + <th><span style="font-family: monospace">p_astro</span></th> + <th><span style="font-family: monospace">em_bright</span></th> </tr> </thead> @@ -24,6 +28,7 @@ <td><a href="{% url "view" e.graceid %}">{{ e.graceid }}</a></td> <td> {{ e.group.name }} </td> <td> {{ e.pipeline.name }} </td> + <td> {{ e.gpstime | floatformat:"3" }} </td> <td> {% if e.far|scientific %} {{ e.far|scientific }} @@ -40,6 +45,8 @@ {% endif %} </td> + <td> {{ preferred_event.graceid | pastro_text }} </td> + <td> {{ preferred_event.graceid | embright_text }} </td> </tr> -- GitLab From d6e74be656f81d3a989ff0304c6ea5e9d318eabb Mon Sep 17 00:00:00 2001 From: Alexander Pace <alexander.pace@ligo.org> Date: Tue, 9 May 2023 11:27:26 -0500 Subject: [PATCH 2/3] tweaks to pipeline preferred table and how json files are displayed --- .../superevents/templatetags/pastro_text.py | 68 ++++++++++++------- gracedb/templates/superevents/detail.html | 3 + .../pipeline_preferred_event_info_table.html | 4 +- ...ine_preferred_event_info_table_public.html | 45 ++++++++++++ .../templates/superevents/rrt_info_table.html | 2 +- 5 files changed, 94 insertions(+), 28 deletions(-) create mode 100644 gracedb/templates/superevents/pipeline_preferred_event_info_table_public.html diff --git a/gracedb/superevents/templatetags/pastro_text.py b/gracedb/superevents/templatetags/pastro_text.py index 183341e33..447d880db 100644 --- a/gracedb/superevents/templatetags/pastro_text.py +++ b/gracedb/superevents/templatetags/pastro_text.py @@ -6,48 +6,66 @@ import pathlib from events.models import Event register = template.Library() + +# Some formatting options: pastro_file_template = "{pipeline}.p_astro.json" html_format = '<span style="font-weight: bold">p_{source}</span>= {value}' + +# Display the contents of a json file associated with a g-event. +# data_file is either: 'p_astro' or 'em_bright'. +# optionally, append ',newline' to show each value on its own line +# optionally, append ',clean' to remove zero values from the file @register.filter(is_safe=True) -def pastro_text(graceid): +def json_text(graceid, data_format): + + # Get the associated event. If not, return an error. try: ev = Event.getByGraceid(graceid) except: return "Event {} does not exist".format(graceid) - pastro_file_name = pastro_file_template.format(pipeline=ev.pipeline.name.lower()) - pastro_file = pathlib.Path(ev.datadir, pastro_file_name) + # Format the remaining arguments: + args = data_format.split(',') - try: - with open(pastro_file, 'r') as f: - data = json.load(f) - except IOError: - return "File {} not found or could not be opened".format(pastro_file_name) - except json.JSONDecodeError: - return "Could not json-decode file {}".format(pastro_file_name) + # the filename is the first value. get the name of the file, + # and format the input filename as needed: + input_file = args[0].strip() + if input_file == 'p_astro': + json_file_name = pastro_file_template.format(pipeline=ev.pipeline.name.lower()) + elif input_file == 'em_bright': + json_file_name = 'em_bright.json' + else: + return "Unrecognized input file." - return mark_safe(', '.join([html_format.format(source=i, - value=round(data[i], 6)) for i in data])) + # See if we're doing newlines or clean or whatever. + newline=clean=False + if len(args) > 1: + extra_args = [i.strip() for i in args[1:]] -@register.filter(is_safe=True) -def embright_text(graceid): - try: - ev = Event.getByGraceid(graceid) - except: - return "Event {} does not exist".format(graceid) + if 'newline' in extra_args: newline=True + if 'clean' in extra_args: clean=True - embright_file_name = 'em_bright.json' - embright_file = pathlib.Path(ev.datadir, embright_file_name) + # define input file path and open it: + json_file = pathlib.Path(ev.datadir, json_file_name) try: - with open(embright_file, 'r') as f: + with open(json_file, 'r') as f: data = json.load(f) except IOError: - return "File {} not found or could not be opened".format(embright_file_name) + return "File {} not found or could not be opened".format(json_file_name) except json.JSONDecodeError: - return "Could not json-decode file {}".format(embright_file_name) + return "Could not json-decode file {}".format(json_file_name) - return mark_safe(', '.join([html_format.format(source=i, - value=round(data[i], 6)) for i in data])) + # Formatting stuff: + if newline: + join_char = '<br>' + else: + join_char = ', ' + # get rid of zero values: + if clean: + data = {x:y for x,y in data.items() if y != 0} + + return mark_safe(join_char.join([html_format.format(source=i, + value=round(data[i], 6)) for i in data])) diff --git a/gracedb/templates/superevents/detail.html b/gracedb/templates/superevents/detail.html index e9fcc74db..a0ed00977 100644 --- a/gracedb/templates/superevents/detail.html +++ b/gracedb/templates/superevents/detail.html @@ -189,6 +189,9 @@ {% include "superevents/pipeline_preferred_event_info_table.html" %} {% else %} {% include "superevents/preferred_event_info_table_public.html" %} + <br /> + <br /> + {% include "superevents/pipeline_preferred_event_info_table_public.html" %} {% endif %} {% endblock %} diff --git a/gracedb/templates/superevents/pipeline_preferred_event_info_table.html b/gracedb/templates/superevents/pipeline_preferred_event_info_table.html index 45d557cab..b12e8258e 100644 --- a/gracedb/templates/superevents/pipeline_preferred_event_info_table.html +++ b/gracedb/templates/superevents/pipeline_preferred_event_info_table.html @@ -45,8 +45,8 @@ {% endif %} </td> - <td> {{ preferred_event.graceid | pastro_text }} </td> - <td> {{ preferred_event.graceid | embright_text }} </td> + <td> {{ preferred_event.graceid | json_text:"p_astro,newline" }} </td> + <td> {{ preferred_event.graceid | json_text:"em_bright,newline" }} </td> </tr> diff --git a/gracedb/templates/superevents/pipeline_preferred_event_info_table_public.html b/gracedb/templates/superevents/pipeline_preferred_event_info_table_public.html new file mode 100644 index 000000000..faf6fa00a --- /dev/null +++ b/gracedb/templates/superevents/pipeline_preferred_event_info_table_public.html @@ -0,0 +1,45 @@ +{% load timeutil %} +{% load scientific %} +{% load pastro_text %} + + <table id="pipeline-preferred" class="table-hover table-condensed + table-resp-gracedb shadow p-3 mb-5 rounded "> + <!-- Table Header --> + <thead> + <tr> + <th colspan="8"><h3>Per-Pipeline Event Information</h3></th> + </tr> + + <tr> + <th> UID </th> + <th> Group </th> + <th> Pipeline </th> + <th> gpstime </th> + <th> FAR (Hz) </th> + <th><span style="font-family: monospace">p_astro</span></th> + <th><span style="font-family: monospace">em_bright</span></th> + </tr> + </thead> + + <tbody style=""> + {% for e in pipeline_preferred_events %} + <tr> + <td> {{ e.graceid }} </td> + <td> {{ e.group.name }} </td> + <td> {{ e.pipeline.name }} </td> + <td> {{ e.gpstime | floatformat:"3" }} </td> + <td> + {% if e.far|scientific %} + {{ e.far|scientific }} + {% else %} + + {% endif %} + <td> {{ preferred_event.graceid | json_text:"p_astro,newline,clean" }} </td> + <td> {{ preferred_event.graceid | json_text:"em_bright,newline,clean" }} </td> + + + </tr> + {% endfor %} + </tbody> + </table> + diff --git a/gracedb/templates/superevents/rrt_info_table.html b/gracedb/templates/superevents/rrt_info_table.html index 1fd776082..d5a3297e4 100644 --- a/gracedb/templates/superevents/rrt_info_table.html +++ b/gracedb/templates/superevents/rrt_info_table.html @@ -138,7 +138,7 @@ <tr> <td> <span style="font-family: monospace">p_astro</span></td> <td> - {{ preferred_event.graceid | pastro_text }} + {{ preferred_event.graceid | json_text:"p_astro" }} </td> </tr> -- GitLab From f8c689ce4f7267230280a9dcdbf6a422e1c98aa8 Mon Sep 17 00:00:00 2001 From: Alexander Pace <alexander.pace@ligo.org> Date: Tue, 9 May 2023 11:45:49 -0500 Subject: [PATCH 3/3] un-cleaning public pastro and embright --- .../pipeline_preferred_event_info_table_public.html | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/gracedb/templates/superevents/pipeline_preferred_event_info_table_public.html b/gracedb/templates/superevents/pipeline_preferred_event_info_table_public.html index faf6fa00a..e78ee59b2 100644 --- a/gracedb/templates/superevents/pipeline_preferred_event_info_table_public.html +++ b/gracedb/templates/superevents/pipeline_preferred_event_info_table_public.html @@ -34,8 +34,8 @@ {% else %} {% endif %} - <td> {{ preferred_event.graceid | json_text:"p_astro,newline,clean" }} </td> - <td> {{ preferred_event.graceid | json_text:"em_bright,newline,clean" }} </td> + <td> {{ preferred_event.graceid | json_text:"p_astro,newline" }} </td> + <td> {{ preferred_event.graceid | json_text:"em_bright,newline" }} </td> </tr> -- GitLab