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 identity block for the object ticket*
6:Author:
7 David Young
8"""
10import re
11import datetime
12import sys
13import os
14import numpy as np
15import string
16import khufu
18from marshall_webapp.templates.commonelements import commonutils as cu
21def identity_block(
22 log,
23 request,
24 discoveryDataDictionary,
25 objectAkas):
26 """
27 *get ticket identity block*
29 **Key Arguments**
31 - ``log`` -- logger
32 - ``request`` -- the pyramid request
33 - ``discoveryDataDictionary`` -- a dictionary of the discovery data for this transient.
34 - ``objectAkas`` -- the object akas
37 **Return**
39 - ``identity_block`` -- the ticket identity block for the pesssto object
41 """
42 log.debug('starting the ``identity_block`` function')
44 annotations = []
46 pesstoCredentialsPopover = khufu.popover(
47 tooltip=True,
48 placement="bottom", # [ top | bottom | left | right ]
49 trigger="hover", # [ False | click | hover | focus | manual ]
50 title="""username: 'pessto'<br>password: '!explosions'""",
51 content=False,
52 delay=20
53 )
55 asassnCredentialsPopover = khufu.popover(
56 tooltip=True,
57 placement="bottom", # [ top | bottom | left | right ]
58 trigger="hover", # [ False | click | hover | focus | manual ]
59 title="""username: 'public'<br>password: 'not@public&yet!'""",
60 content=False,
61 delay=20
62 )
64 title = cu.block_title(
65 log,
66 title="identity"
67 )
69 q = discoveryDataDictionary['marshallWorkflowLocation'].lower()
71 if discoveryDataDictionary['snoozed'] == 1:
72 q = "snoozed"
74 icon = ""
75 if q == "inbox":
76 icon = """<i class="icon-inbox"></i> inbox"""
77 elif q == "review for followup":
78 icon = """<i class="icon-eye"></i> review for followup"""
79 elif q == "following":
80 icon = """<i class="icon-pin"></i> following"""
81 elif q == "archive":
82 icon = """<i class="icon-archive"></i> archive"""
83 elif q == "pending observation":
84 icon = """<i class="icon-target2"></i> classification targets"""
85 elif q == "followup complete":
86 icon = """<i class="icon-checkmark-circle"></i> followup complete"""
87 elif q == "snoozed":
88 icon = """<i class="icon-alarm3"></i> snoozed""" % locals()
90 if discoveryDataDictionary['snoozed'] == 2:
91 unsnoozedIcon = """ <i class="icon-alarm3"></i> unsnoozed""" % locals()
92 unsnoozedIcon = khufu.coloredText(
93 text=unsnoozedIcon,
94 color="red",
95 size=3, # 1-10
96 pull=False, # "left" | "right"
97 )
98 else:
99 unsnoozedIcon = ""
101 icon = khufu.coloredText(
102 text=icon + unsnoozedIcon,
103 color="cyan",
104 size=3, # 1-10
105 pull=False, # "left" | "right"
106 )
108 surveyObjectUrl = discoveryDataDictionary["surveyObjectUrl"]
109 if surveyObjectUrl and "portal.nersc.gov/" in surveyObjectUrl:
110 user = request.registry.settings["credentials"]["lsq"]["username"]
111 pwd = request.registry.settings["credentials"]["lsq"]["password"]
112 surveyObjectUrl = surveyObjectUrl.replace(
113 "portal.", "%(user)s:%(pwd)s@portal." % locals())
114 if surveyObjectUrl and "ps1gw" in surveyObjectUrl:
115 annotations.append("within sky map of gravitational wave source")
117 # AKA NAMES
118 masterName = False
119 akaRows = []
120 for item in objectAkas:
121 surveyObjectUrl = item["url"]
122 if item["transientBucketId"] == discoveryDataDictionary["transientBucketId"]:
123 if not masterName:
124 # MASTER NAME
125 masterAka = item
126 masterName = masterAka["name"]
127 name = masterName
129 if masterAka["url"]:
130 if "skymapper" in masterAka["url"] or "ps1gw" in masterAka["url"] or "ps1fgss" in masterAka["url"] or "ps13pi" in masterAka["url"]:
131 popover = pesstoCredentialsPopover
132 else:
133 popover = False
135 masterNameLink = khufu.a(
136 content=masterName,
137 href=masterAka["url"],
138 openInNewTab=True,
139 popover=popover
140 )
141 else:
142 masterNameLink = masterName
143 else:
144 if surveyObjectUrl and "@" not in surveyObjectUrl:
145 if surveyObjectUrl and "portal.nersc.gov/" in surveyObjectUrl:
146 user = request.registry.settings[
147 "credentials"]["lsq"]["username"]
148 pwd = request.registry.settings[
149 "credentials"]["lsq"]["password"]
150 surveyObjectUrl = surveyObjectUrl.replace(
151 "portal.", "%(user)s:%(pwd)s@portal." % locals())
153 if surveyObjectUrl and "ps1gw" in surveyObjectUrl and "within sky map of gravitational wave source" not in annotations:
154 annotations.append(
155 "within sky map of gravitational wave source")
157 item["url"] = surveyObjectUrl
158 akaRows.append(item)
160 numerator = 70.
161 if discoveryDataDictionary["classifiedFlag"]:
162 numerator = 60.
164 size = int(numerator / len(discoveryDataDictionary["masterName"]))
165 if size > 6:
166 size = 6
168 masterName = khufu.coloredText(
169 text="""%(masterNameLink)s""" % locals(),
170 color="green",
171 size=size, # 1-10
172 pull=False, # "left" | "right"
173 )
175 masterName = """%(masterName)s""" % locals()
177 masterName = khufu.grid_row(
178 responsive=True,
179 columns=masterName,
180 htmlId=False,
181 htmlClass="name",
182 onPhone=True,
183 onTablet=True,
184 onDesktop=True
185 )
187 # IMAGE STAMP
188 transient_cache = request.static_url(f'marshall_webapp:caches/transients/')
189 download_prefix = "/marshall/caches/transients/"
191 sourceImages = []
192 dsourceImages = []
193 objectNames = []
195 stampFlags = {
196 "user_added_stamp": "useradded_target_stamp.jpeg",
197 "ps1_target_stamp": "ps1_target_stamp.jpeg",
198 "gaia_stamp": "gaia_stamp.jpeg",
199 "ogle_target_stamp": "ogle_target_stamp.jpeg",
200 "atlas_target_stamp": "atlas_target_stamp.jpeg",
201 "css_stamp": "css_stamp.jpeg",
202 "des_target_stamp": "des_target_stamp.gif",
203 "mls_stamp": "mls_stamp.jpeg",
204 "sss_stamp": "sss_stamp.jpeg",
205 "lsq_stamp": "lsq_stamp.jpeg",
206 "master_stamp": "master_stamp.jpeg",
207 "ztf_stamp": "ztf_triplet_stamp.jpeg"
208 }
210 hasStamp = False
211 href = False
212 for k, v in stampFlags.items():
213 if discoveryDataDictionary[k] == 1:
214 hasStamp = True
215 src = "%s%s/%s" % (transient_cache,
216 discoveryDataDictionary["transientBucketId"], v)
217 dsrc = "%s%s/%s" % (download_prefix,
218 discoveryDataDictionary["transientBucketId"], v)
219 sourceImages.append(src)
220 dsourceImages.append(dsrc)
221 objectName = ""
222 for item in objectAkas:
223 if k.split("_")[0] in item["name"].lower():
224 objectName = item["name"]
225 objectName = khufu.a(
226 content=objectName,
227 href=item["url"],
228 tableIndex=False,
229 # [ False | "dropdown" | "tab" | "modal" ],
230 triggerStyle=False,
231 htmlClass=False,
232 postInBackground=False,
233 openInNewTab=True,
234 popover=False
235 )
236 objectNames.append(objectName)
238 if discoveryDataDictionary["bsl_stamp"] and discoveryDataDictionary["tripletImageUrl"]:
239 hasStamp = True
240 remoteUrl = discoveryDataDictionary["tripletImageUrl"]
241 theseLines = string.split(remoteUrl, '.')
242 extension = theseLines[-1]
243 stampName = "bsl_stamp.%(extension)s" % locals()
244 src = "%s%s/bsl_stamp.%s" % (transient_cache,
245 discoveryDataDictionary["transientBucketId"], extension)
246 sourceImages.append(src)
247 dsourceImages.append(src)
248 objectNames.append("Bright SN List Stamp")
250 if discoveryDataDictionary["targetImageUrl"] and hasStamp == False:
251 src = discoveryDataDictionary["targetImageUrl"]
252 dsrc = discoveryDataDictionary["targetImageUrl"]
253 href = discoveryDataDictionary["targetImageUrl"]
254 objectNames.append("User Added Stamp")
255 sourceImages.append(src)
256 dsourceImages.append(dsrc)
258 if len(sourceImages) == 0:
259 src = 'holder.js/400x400/auto/industrial/text:no stamp'
260 dsrc = src
261 sourceImages.append(src)
262 dsourceImages.append(dsrc)
264 src = sourceImages[0]
265 dsrc = dsourceImages[0]
267 objectName = discoveryDataDictionary["masterName"]
268 if not href:
269 href = request.route_path(
270 'download', _query={'url': dsrc, "webapp": "marshall_webapp", "filename": "%(objectName)s_image_stamp" % locals()})
272 imageSource = khufu.a(
273 content='image source',
274 href=surveyObjectUrl,
275 )
277 allImage = ""
279 count = 0
280 for s, d, n in zip(sourceImages, dsourceImages, objectNames):
281 count += 1
282 reminderImages = len(sourceImages) % 3
283 if reminderImages == 0:
284 span = 4
285 offset = 0
286 elif count < len(sourceImages[:-reminderImages]):
287 span = 4
288 offset = 0
289 elif reminderImages == 2:
290 span = 6
291 offset = 0
292 else:
293 span = 6
294 offset = 3
296 if "marshall_webapp:" in s:
297 href = request.static_path('%(s)s' % locals())
298 else:
299 href = s
300 thisImage = khufu.image(
301 src=s, # [ industrial | gray | social ]
302 href=href,
303 display="rounded", # [ rounded | circle | polaroid | False ]
304 pull=False, # [ "left" | "right" | "center" | False ]
305 htmlClass=False,
306 width="90%"
307 )
308 thisImage = khufu.grid_row(
309 responsive=True,
310 columns=thisImage,
311 )
312 # add text color
313 name = khufu.coloredText(
314 text=n,
315 color="blue",
316 size=7, # 1-10
317 pull=False, # "left" | "right",
318 addBackgroundColor=False
319 )
321 name = khufu.grid_row(
322 responsive=True,
323 columns=name,
324 )
325 column = khufu.grid_column(
326 span=span, # 1-12
327 offset=offset, # 1-12
328 content=thisImage + name,
329 pull=False, # ["right", "left", "center"]
330 htmlId=False,
331 htmlClass=False,
332 onPhone=True,
333 onTablet=True,
334 onDesktop=True
335 )
336 allImage += column
338 grid_row = khufu.grid_row(
339 responsive=True,
340 columns=allImage,
341 htmlId=False,
342 htmlClass=False,
343 onPhone=True,
344 onTablet=True,
345 onDesktop=True
346 )
348 randNum = int(np.random.rand() * 10000)
349 modal = khufu.modal(
350 modalHeaderContent="Image Stamps for %(masterNameLink)s" % locals(
351 ),
352 modalBodyContent=grid_row,
353 modalFooterContent="",
354 htmlId="hookId%(randNum)s" % locals(),
355 centerContent=True
356 )
357 objectStamp = khufu.image(
358 src=sourceImages[0], # [ industrial | gray | social ]
359 href="#hookId%(randNum)s" % locals(),
360 display="rounded", # [ rounded | circle | polaroid | False ]
361 pull=False, # [ "left" | "right" | "center" | False ]
362 htmlClass=False,
363 width="100%",
364 modal=True
365 )
366 objectStamp = objectStamp + modal
368 akaList = ""
369 if len(akaRows) == 0:
370 akaTitle = ""
371 elif len(akaRows) == 1:
372 akaTitle = "aka: "
373 row = akaRows[0]
374 aka = row["name"]
375 size = 3
376 if len(aka) > 19:
377 size = 2
379 if row["url"] and ("skymapper" in row["url"] or "ps1gw" in row["url"] or "ps1fgss" in row["url"] or "ps13pi" in row["url"] or "atlas" in row["url"]):
380 popover = pesstoCredentialsPopover
381 elif row["url"] and "asassn.china" in row["url"]:
382 popover = asassnCredentialsPopover
383 else:
384 popover = False
386 if row["url"]:
387 aka = khufu.a(
388 content=aka,
389 href=row["url"],
390 openInNewTab=True,
391 popover=popover
392 )
394 aka = khufu.coloredText(
395 text=aka,
396 color="orange",
397 size=size, # 1-10
398 pull=False, # "left" | "right"
399 )
400 akaList = aka
401 else:
402 akaTitle = "akas: "
404 for row in akaRows:
405 log.debug('aka: %s' % (row,))
406 aka = row["name"]
407 if aka in akaList:
408 continue
410 if row["url"] and ("skymapper" in row["url"] or "ps1gw" in row["url"] or "ps1fgss" in row["url"] or "ps13pi" in row["url"] or "atlas" in row["url"]):
411 popover = pesstoCredentialsPopover
412 elif row["url"] and "asassn.china" in row["url"]:
413 popover = asassnCredentialsPopover
414 else:
415 popover = False
417 aka = khufu.a(
418 content=aka,
419 href=row["url"],
420 openInNewTab=True,
421 popover=popover
422 )
423 aka = """   %(aka)s """ % locals()
425 aka = khufu.coloredText(
426 text=aka,
427 color="orange",
428 size=3, # 1-10
429 pull=False, # "left" | "right"
430 )
432 aka = khufu.grid_row(
433 responsive=True,
434 columns=aka,
435 htmlId=False,
436 htmlClass="aka",
437 onPhone=True,
438 onTablet=True,
439 onDesktop=True
440 )
441 akaList = "%(akaList)s %(aka)s" % locals()
443 if len(akaList) != 0:
444 akaTitle = cu.little_label(
445 text=akaTitle,
446 lineBreak=False
447 )
448 akaList = "%(akaTitle)s %(akaList)s" % locals()
449 akaList = khufu.grid_row(
450 responsive=True,
451 columns=akaList,
452 htmlId=False,
453 htmlClass="akaList",
454 onPhone=True,
455 onTablet=True,
456 onDesktop=True
457 )
459 pi = ""
460 if discoveryDataDictionary["classifiedFlag"] == 1:
462 pi = cu.little_label(
463 text="PI: ",
464 lineBreak=False
465 )
467 if discoveryDataDictionary["pi_name"]:
468 pi_name = discoveryDataDictionary["pi_name"]
469 firstName = pi_name.split(' ', 1)[0]
470 thisName = discoveryDataDictionary["masterName"]
471 pi_email = discoveryDataDictionary["pi_email"]
472 pi_name = khufu.a(
473 content="""%(pi_name)s <i class="icon-mail7"></i>""" % locals(),
474 href="mailto:%(pi_email)s?subject=%(thisName)s&body=Hi %(firstName)s," % locals(
475 ),
476 tableIndex=False,
477 triggerStyle=False, # [ False | "dropdown" | "tab" ],
478 htmlClass=False,
479 postInBackground=False
480 )
481 else:
482 pi_name = "no pi set"
484 pi_name = khufu.coloredText(
485 text=pi_name,
486 color="cyan",
487 size=3,
488 )
490 pi = khufu.grid_row(
491 responsive=True,
492 columns="%(pi)s %(pi_name)s" % locals(),
493 htmlId=False,
494 htmlClass=False,
495 onPhone=True,
496 onTablet=True,
497 onDesktop=True
498 )
500 transientId = cu.little_label(
501 text="pessto id: ",
502 lineBreak=False
503 )
504 thisTransientBucketId = khufu.coloredText(
505 text=discoveryDataDictionary["transientBucketId"],
506 color="magenta",
507 size=3,
508 )
510 observationalPriority = ""
511 if discoveryDataDictionary["marshallWorkflowLocation"] in ["following", "pending observation"]:
512 observationalPriority = cu.little_label(
513 text="priority: ",
514 lineBreak=False
515 )
516 if discoveryDataDictionary["marshallWorkflowLocation"] == "following":
517 pList = ["CRITICAL", "IMPORTANT", "USEFUL", "NONE"]
518 for n, w, c in zip([1, 2, 3, 4], pList, ["green", "yellow", "red", "blue"]):
519 if discoveryDataDictionary["observationPriority"] == n:
520 thisObservationalPriority = w
521 thisColor = c
522 else:
523 pList = ["HIGH", "MEDIUM", "LOW"]
524 for n, w, c in zip([1, 2, 3], pList, ["green", "yellow", "red"]):
525 if discoveryDataDictionary["observationPriority"] == n:
526 thisObservationalPriority = w
527 thisColor = c
529 thisObservationalPriority = "<strong>%(thisObservationalPriority)s</strong>" % locals(
530 )
531 thisObservationalPriority = khufu.coloredText(
532 text=thisObservationalPriority,
533 color=thisColor,
534 size=3,
535 htmlClass="priorityLabel"
536 )
537 observationalPriority = khufu.grid_row(
538 responsive=True,
539 columns="%(observationalPriority)s %(thisObservationalPriority)s" % locals(
540 ),
541 htmlId=False,
542 htmlClass=False,
543 onPhone=True,
544 onTablet=True,
545 onDesktop=True
546 )
548 transientId = khufu.grid_row(
549 responsive=True,
550 columns="%(transientId)s %(thisTransientBucketId)s" % locals(
551 ),
552 htmlId=False,
553 htmlClass=False,
554 onPhone=True,
555 onTablet=True,
556 onDesktop=True
557 )
559 listLocation = cu.little_label(
560 text="list: ",
561 lineBreak=False
562 )
564 listLocation = khufu.grid_row(
565 responsive=True,
566 columns="%(listLocation)s %(icon)s" % locals(
567 ),
568 htmlId=False,
569 htmlClass=False,
570 onPhone=True,
571 onTablet=True,
572 onDesktop=True
573 )
575 if len(annotations):
576 icon = """<i class="icon-tag"></i>"""
577 annotations = ("<BR>").join(annotations)
578 # add text color
579 annotations = khufu.coloredText(
580 text="  %(icon)s <em>%(annotations)s</em>" % locals(),
581 color="red",
582 size=3, # 1-10
583 pull=False, # "left" | "right",
584 addBackgroundColor=False
585 )
587 annotations = khufu.grid_row(
588 responsive=True,
589 columns="%(annotations)s" % locals(
590 ),
591 htmlId=False,
592 htmlClass=False,
593 onPhone=True,
594 onTablet=True,
595 onDesktop=True
596 )
597 else:
598 annotations = ""
600 content = u"%(title)s %(masterName)s %(annotations)s %(objectStamp)s %(observationalPriority)s %(pi)s %(akaList)s %(listLocation)s %(transientId)s " % locals(
601 )
603 return content