Hide keyboard shortcuts

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 data model module for the `transients_lightcurves_get` resource* 

5 

6:Author: 

7 David Young 

8""" 

9from builtins import zip 

10from builtins import object 

11import sys 

12import os 

13import khufu 

14import collections 

15from dryxPyramid.models.models_base import base_model 

16 

17class models_transients_lightcurves_get(base_model): 

18 """ 

19 The worker class for the models_transients_lightcurves_get module 

20 

21 **Key Arguments** 

22 

23 - ``log`` -- logger 

24 - ``request`` -- the pyramid request 

25 - ``elementId`` -- the specific element id requests (or False) 

26  

27 """ 

28 

29 def __init__(self, log, request, elementId=False, search=False): 

30 super().__init__(log, request, elementId, search) 

31 self.resourceName = "transients_lightcurves" 

32 self._set_default_parameters() 

33 

34 log.debug( 

35 "instansiating a new 'models_transients_lightcurves_get' object") 

36 return None 

37 

38 def close(self): 

39 del self 

40 return None 

41 

42 def get(self): 

43 """execute the get method on the models_transients_lightcurves_get object 

44 

45 **Return** 

46 

47 - ``responseContent`` -- the reponse to send to the browser 

48  

49 """ 

50 self.log.debug('starting the ``get`` method') 

51 

52 transientBucketId = self.elementId 

53 

54 # GRAB THE LIGHTCURVE DATA FOR THE OBJECT 

55 sqlQuery = """ 

56 select observationMJD, observationDate, magnitude, magnitudeError, limitingMag, filter, survey from transientBucket where replacedByRowId = 0 and transientBucketId = %(transientBucketId)s and observationDate is not null and observationDate != 0000-00-00 and magnitude is not null and magnitude < 50 and survey != "bright sn list" order by observationDate asc; 

57 """ % locals() 

58 lightCurveTmp = self.request.db.execute(sqlQuery).fetchall() 

59 odict = collections.OrderedDict(sorted({}.items())) 

60 lightCurve = [] 

61 

62 for row in lightCurveTmp: 

63 odict = collections.OrderedDict(sorted({}.items())) 

64 for key in list(row.keys()): 

65 if row[key] == None: 

66 value = "-" 

67 else: 

68 value = row[key] 

69 odict[key] = value 

70 lightCurve.append(odict) 

71 

72 self.log.debug('completed the ``get`` method') 

73 return lightCurve 

74 

75 def _set_default_parameters( 

76 self): 

77 """ set default parameters 

78 """ 

79 self.log.debug('starting the ``_set_default_parameters`` method') 

80 

81 if "format" not in self.qs: 

82 self.qs["format"] = self.defaultQs["format"] 

83 

84 self.log.debug('completed the ``_set_default_parameters`` method') 

85 return None 

86 

87 def get_metadata( 

88 self): 

89 """Get some extra transient metadata 

90 """ 

91 self.log.debug('starting the ``get_metadata`` method') 

92 

93 transientBucketId = self.elementId 

94 

95 sqlQuery = u""" 

96 select * from transientBucketSummaries where transientBucketId = %(transientBucketId)s 

97 """ % locals() 

98 extraMetadataTmp = self.request.db.execute(sqlQuery).fetchall() 

99 extraMetadata = [] 

100 extraMetadata[:] = [dict(list(zip(list(row.keys()), row))) 

101 for row in extraMetadataTmp] 

102 

103 self.log.debug('completed the ``get_metadata`` method') 

104 return extraMetadata 

105 

106 # xt-class-method