Skip to content
Snippets Groups Projects
Commit 4061293a authored by Branson Stephens's avatar Branson Stephens
Browse files

Merge branch 'slot_dev'

parents 929e0645 71bb7cab
No related branches found
No related tags found
No related merge requests found
......@@ -116,6 +116,11 @@ def eventToDict(event, columns=None, request=None):
"labels" : reverse("labels", args=[graceid], request=request),
"self" : reverse("event-detail", args=[graceid], request=request),
}
# XXX Jam the slots in here? Could just have a list of slot names instead of
# all these links. But the links might be useful??
rv['slots'] = {}
for slot in Slot.objects.filter(event=event).order_by('name'):
rv['slots'][slot.name] = reverse("slot", args=[graceid, slot.name], request=request)
return rv
......@@ -827,9 +832,6 @@ class EventSlot(APIView):
return Response("No slot. Search based on slotname not implemented yet.",
status=status.HTTP_404_NOT_FOUND)
filename = slot.value
dirPrefix = settings.GRACEDB_DATA_DIR
eventDir = os.path.join(dirPrefix, event.graceid())
filename = os.path.join(eventDir, "private", filename)
rv = {}
rv['value'] = filename
return Response(rv)
......@@ -843,8 +845,6 @@ class EventSlot(APIView):
# XXX Real error message.
return Response("Event does not exist.",
status=status.HTTP_404_NOT_FOUND)
dirPrefix = settings.GRACEDB_DATA_DIR
eventDir = os.path.join(dirPrefix, event.graceid())
filename = request.DATA.get('filename')
# Interestingly, the None object seems to be converted to a string
# when encoded in the HTTP request body. Hence the 'None' string
......@@ -853,15 +853,29 @@ class EventSlot(APIView):
if filename=='' or filename=='None' or filename==None:
return Response("Please submit a filename or upload a file.",
status=status.HTTP_400_BAD_REQUEST)
# UGLY hack to deal with /private vs /general dirs
general = False
if filename.startswith("general/"):
tmpFilename = filename[len("general/"):]
general = True
filepath = os.path.join(event.datadir(general), tmpFilename)
# Check for existence of the file.
filePath = os.path.join(eventDir, "private", filename)
if not os.path.exists(filePath):
if not os.path.exists(filepath):
return Response("No slot created because file does not exist",
status=status.HTTP_404_NOT_FOUND)
# Create the slot.
slot = Slot(event=event,name=slotname,value=filename)
slot.save()
return Response("Slot created.",status=status.HTTP_201_CREATED)
# Check for existence of the slot. If it exists, simply update the
# existing slot.
try:
slot = Slot.objects.filter(event=event).filter(name=slotname)[0]
slot.value = filename
slot.save()
except:
# Create the slot.
slot = Slot(event=event,name=slotname,value=filename)
slot.save()
return Response("Slot created or updated.",status=status.HTTP_201_CREATED)
# Delete a slot.
def delete(self, request, graceid, slotname):
......
......@@ -248,3 +248,11 @@ class Slot(models.Model):
event = models.ForeignKey(Event)
name = models.CharField(max_length=100)
value = models.CharField(max_length=100)
# In case the slot value is not a filename, this will just return None.
def fileurl(self):
if self.value:
return reverse('file', args=[self.event.graceid(), self.value])
else:
return None
......@@ -6,13 +6,16 @@ from ..models import Slot, EventLog
register = template.Library()
@register.filter("slot")
def slot(event,slotname):
def slot(event,name=None):
if event is None:
return mark_safe("")
return None
try:
slot = Slot.objects.filter(event=event).filter(name=slotname)[0]
out = slot.value
if name:
return Slot.objects.filter(event=event).filter(name__exact=name)[0]
else:
return Slot.objects.filter(event=event)
except:
# Either there is no such slot or something went wrong.
# In either case, we want the template to just ignore it.
return None
return mark_safe(out)
......@@ -2,6 +2,7 @@
{% load timeutil %}
{% load scientific %}
{% load sanitize_html %}
{% load slot %}
{% block title %}View {{ object.graceid }}{% endblock %}
{% block heading %}{% endblock %}
......@@ -159,6 +160,8 @@
<table>
<tr><td valign="top">
<h3> Basic Info </h3>
<table class="event">
{% if skyalert_authorized %}
<tr><td colspan="4">
......@@ -206,6 +209,11 @@
</table>
{# Analysis-specific attributes #}
{% block analysis_specific %}
{# This block is empty in the base event_detail template #}
{% endblock %}
{% if nearby %}
<p/>
<h3>Neighbors</h3>
......@@ -307,5 +315,15 @@
<br/>
{% endif %}
<p/>
<h3>Available Slots</h3>
{% if not object|slot %}
None.
{% else %}
{% for slot in object|slot %}
<a href="{{slot.fileurl}}">{{ slot.name }}</a> <br/>
{% endfor %}
{% endif %}
</td></tr></table>
{% endblock %}
{% extends "gracedb/event_detail.html" %}
{%load scientific %}
{# Analysis-specific attributes for a cWB event#}
{% block analysis_specific %}
<p/>
<h3>Analysis-Specific Attributes</h3>
<table> <tbody>
<tr>
<td> <table class="event"> <tbody>
<!-- Note: commenting out ifos so that we'll have a multiple of three -->
<!-- attributes. If you want, you can uncomment and re-introduce the -->
<!-- two funny little padding rows down below. Or not. -->
<!-- <tr> <th> ifos </th> <td> {{object.ifos}} </td> </tr> -->
<tr> <th> start_time </th> <td> {{object.start_time}} </td> </tr>
<tr> <th> start_time_ns </th> <td> {{object.start_time_ns}} </td> </tr>
<tr> <th> duration </th> <td> {{object.duration|scientific}} </td> </tr>
<tr> <th> peak_time </th> <td> {{object.peak_time}} </td> </tr>
<tr> <th> peak_time_ns </th> <td> {{object.peak_time_ns}} </td> </tr>
</tbody></table>
</td>
<td> <table class="event"> <tbody>
<tr> <th> central_freq </th> <td> {{object.central_freq|floatformat:"-4"}} </td> </tr>
<tr> <th> bandwidth </th> <td> {{object.bandwidth|floatformat:"-4"}} </td> </tr>
<tr> <th> amplitude </th> <td> {{object.amplitude|scientific}} </td> </tr>
<tr> <th> snr </th> <td> {{object.snr|floatformat:"-4"}} </td> </tr>
<tr> <th> confidence </th> <td> {{object.confidence|scientific}} </td> </tr>
<!-- <tr> <th> <div style="min-height:16px"> </div></th> <td> </td> </tr> -->
</tbody></table>
</td>
<td> <table class="event"> <tbody>
<tr> <th> false_alarm_rate </th> <td> {{object.false_alarm_rate|scientific}} </td> </tr>
<tr> <th> ligo_axis_ra </th> <td> {{object.ligo_axis_ra|floatformat:"-4"}} </td> </tr>
<tr> <th> ligo_axis_dec </th> <td> {{object.ligo_axis_dec|floatformat:"-4"}} </td> </tr>
<tr> <th> ligo_angle </th> <td> {{object.ligo_angle}} </td> </tr>
<tr> <th> ligo_angle_sig </th> <td> {{object.ligo_angle_sig}} </td></tr>
<!-- <tr> <th> <div style="min-height:16px"> </div> </th> <td> </td> </tr> -->
</tbody></table>
</td>
</tr>
</tbody> </table>
{% endblock %}
{% extends "gracedb/event_detail.html" %}
{# Analysis-specific attributes for a LowMass event#}
{% block analysis_specific %}
<p/>
<h3>Analysis-specific attributes</h3>
{% endblock %}
{% extends "gracedb/event_detail.html" %}
{% load scientific %}
{# Analysis-specific attributes for an LM event#}
{% block analysis_specific %}
<p/>
<h3>Analysis-Specific Attributes</h3>
<table> <tbody>
<tr>
<td> <table class="event"> <tbody>
<tr> <th> ifos </th> <td> {{object.ifos}} </td> </tr>
<tr> <th> end_time </th> <td> {{object.end_time}} </td> </tr>
<tr> <th> end_time_ns </th> <td> {{object.end_time_ns}} </td> </tr>
</tbody></table>
</td>
<td> <table class="event"> <tbody>
<tr> <th> mass </th> <td> {{object.mass|floatformat:"-4"}} </td> </tr>
<tr> <th> mchirp </th> <td> {{object.mchirp|floatformat:"-4"}} </td> </tr>
<tr> <th> minimum_duration </th> <td> {{object.minimum_duration|scientific}} </td> </tr>
</tbody></table>
</td>
<td> <table class="event"> <tbody>
<tr> <th> snr </th> <td> {{object.snr|floatformat:"-4"}} </td> </tr>
<tr> <th> false_alarm_rate </th> <td> {{object.false_alarm_rate|floatformat:"-4"}} </td> </tr>
<tr> <th> combined_far </th> <td> {{object.combined_far|scientific}} </td> </tr>
</tbody></table>
</td>
</tr>
</tbody> </table>
{% endblock %}
{% extends "gracedb/event_detail.html" %}
{# Analysis-specific attributes for a LowMass event#}
{% block analysis_specific %}
<p/>
<h3>Analysis-specific attributes</h3>
{% endblock %}
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment