Hot-keys on this page
r m x p toggle line displays
j k next/prev highlighted chunk
0 (zero) top of page
1 (one) first highlighted chunk
1#!/usr/local/bin/python
2# encoding: utf-8
3"""
4*The Object Info block for the object ticket*
6:Author:
7 David Young
8"""
9import sys
10import os
11import re
12import datetime
13from marshall_webapp.templates.commonelements import commonutils as cu
14import khufu
15from fundamentals import times
17def object_info_block(
18 log,
19 request,
20 discoveryDataDictionary):
21 """get ticket object info block
23 **Key Arguments**
25 - ``log`` -- logger
26 - ``request`` -- the pyramid request
27 - ``discoveryDataDictionary`` -- a dictionary of the discovery data for this transient.
30 **Return**
32 - ``object_info_block`` -- the ticket identity block for the pesssto object
34 """
35 log.debug('starting the ``object_info_block`` function')
37 title = cu.block_title(
38 log,
39 title="object info"
40 )
42 raDecLabel = cu.little_label(
43 text="ra & dec:"
44 )
46 ra = ""
47 dec = ""
48 if discoveryDataDictionary["raDeg"]:
49 ra = khufu.coloredText(
50 text="[ %8.5f" % (discoveryDataDictionary["raDeg"],),
51 color="violet",
52 size=3,
53 )
54 dec = khufu.coloredText(
55 text="%8.5f ]" % (discoveryDataDictionary["decDeg"],),
56 color="cyan",
57 size=3
58 )
60 glat = ""
61 glon = ""
62 if discoveryDataDictionary["gLat"]:
63 glat = khufu.coloredText(
64 text="%8.5f" % (discoveryDataDictionary["gLat"],),
65 color="blue",
66 size=3,
67 )
68 glon = khufu.coloredText(
69 text="%8.5f" % (discoveryDataDictionary["gLon"],),
70 color="blue",
71 size=3
72 )
74 raSex = khufu.coloredText(
75 text=discoveryDataDictionary["raSex"][0:11],
76 color="violet",
77 size=3,
79 )
81 decSex = khufu.coloredText(
82 text=discoveryDataDictionary["decSex"][0:12],
83 color="cyan",
84 size=3
85 )
87 raDecSex = khufu.grid_row(
88 responsive=True,
89 columns="""%(raDecLabel)s %(raSex)s %(decSex)s<br>     %(ra)s %(dec)s""" % locals(
90 ),
91 )
92 raDec = raDecSex
94 galCoordLabel = cu.little_label(
95 text="galactic coords:"
96 )
97 galCoord = khufu.grid_row(
98 responsive=True,
99 columns="""%(galCoordLabel)s %(glon)s %(glat)s""" % locals(
100 ),
101 )
103 # PEAK MAGNITUDE
104 label = cu.little_label(
105 text="abs peak mag:",
106 lineBreak=True
107 )
108 absMag = ""
109 if discoveryDataDictionary["absolutePeakMagnitude"]:
110 text = khufu.coloredText(
111 text="%4.2f" % (discoveryDataDictionary["absolutePeakMagnitude"],),
112 color="yellow",
113 size=6,
114 )
115 absMag = khufu.grid_row(
116 responsive=True,
117 columns="""%s %s""" % (label, text,),
118 )
120 # PRE-DISCOVERY NON-DETECTION
121 label = cu.little_label(
122 text="pre-disc non-detection:",
123 pull=False
124 )
125 lastNonDetectionDate = discoveryDataDictionary["lastNonDetectionDate"]
126 if not lastNonDetectionDate:
127 lastNonDetectionDate = "unknown"
128 daysPast = "unknown"
129 else:
131 daysPast = times.datetime_relative_to_now(lastNonDetectionDate)[2:]
133 if daysPast[-1] == "d":
134 daysPast = "%s days ago" % (daysPast[0:-1],)
135 else:
136 daysPast = "(+%s)" % (daysPast,)
137 lastNonDetectionDate = datetime.date.isoformat(lastNonDetectionDate)
139 daysPast = khufu.coloredText(
140 text=daysPast,
141 color="green",
142 size=5
143 )
144 if "unknown" not in lastNonDetectionDate:
145 text = khufu.coloredText(
146 text="""(%(lastNonDetectionDate)s)""" % locals(),
147 color="red",
148 size=3,
149 )
150 nonDect = khufu.grid_row(
151 responsive=True,
152 columns="""%s %s<br>          %s""" % (
153 label, daysPast, text),
154 )
155 else:
156 nonDect = khufu.grid_row(
157 responsive=True,
158 columns="""%s %s""" % (
159 label, daysPast),
160 )
162 label = cu.little_label(
163 text="date added to marshall:"
164 )
165 dateAdded = discoveryDataDictionary["dateAdded"]
166 if dateAdded:
167 daysPast = times.datetime_relative_to_now(dateAdded)[2:]
168 if daysPast[-1] == "d":
169 daysPast = "%s days ago" % (daysPast[0:-1],)
170 else:
171 daysPast = "(+%s)" % (daysPast,)
172 dateAdded = datetime.date.isoformat(dateAdded)
173 else:
174 dateAdded = "?"
175 t = discoveryDataDictionary["transientBucketId"]
176 log.error("Could not get date added for %(t)s" % locals())
177 dateAdded = khufu.coloredText(
178 text="""(%(dateAdded)s)""" % locals(),
179 color="magenta",
180 size=3,
181 )
182 daysPast = khufu.coloredText(
183 text=daysPast,
184 color="orange",
185 size=4
186 )
188 dateAdded = khufu.grid_row(
189 responsive=True,
190 columns="""%s %s<br>          %s""" % (
191 label, daysPast, dateAdded),
192 )
194 label = cu.little_label(
195 text="discovery date:"
196 )
197 discoveryDate = discoveryDataDictionary["earliestDetection"]
198 if discoveryDate:
199 daysPast = times.datetime_relative_to_now(discoveryDate)[2:]
200 if daysPast[-1] == "d":
201 daysPast = "%s days ago" % (daysPast[0:-1],)
202 else:
203 daysPast = "(+%s)" % (daysPast,)
204 discoveryDate = datetime.date.isoformat(discoveryDate)
205 else:
206 discoveryDate = "?"
207 discoveryDate = khufu.coloredText(
208 text="""(%(discoveryDate)s)""" % locals(),
209 color="blue",
210 size=3,
211 )
212 daysPast = khufu.coloredText(
213 text=daysPast,
214 color="yellow",
215 size=4
216 )
218 discoveryDate = khufu.grid_row(
219 responsive=True,
220 columns="""%s %s<br>          %s""" % (
221 label, daysPast, discoveryDate),
222 )
224 return "%(title)s %(raDec)s %(galCoord)s %(absMag)s %(nonDect)s %(discoveryDate)s %(dateAdded)s" % locals()