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 latest magnitudes block for the object ticket* 

5 

6:Author: 

7 David Young 

8""" 

9import sys 

10import os 

11import re 

12import datetime as datetime 

13import khufu 

14from marshall_webapp.templates.commonelements import commonutils as cu 

15from fundamentals import times 

16 

17def latest_magnitudes_block( 

18 log, 

19 request, 

20 discoveryDataDictionary, 

21 lightcurveData, 

22 displayTitle=True): 

23 """get ticket lightcurve block 

24 

25 **Key Arguments** 

26 

27 - ``log`` -- logger 

28 - ``request`` -- the pyramid request 

29 - ``discoveryDataDictionary`` -- a dictionary of the discovery data for this transient. 

30 - ``lightcurveData`` -- the lightcurve data for the objects displayed on the webpage 

31 - ``displayTitle`` -- display the title for this block? 

32  

33 

34 **Return** 

35 

36 - ``latest_magnitudes_block`` -- the ticket identity block for the pesssto object 

37  

38 """ 

39 log.debug('starting the ``latest_magnitudes_block`` function') 

40 

41 if displayTitle: 

42 title = cu.block_title( 

43 log, 

44 title="latest magnitudes" 

45 ) 

46 else: 

47 title = "" 

48 

49 # GET CURRENT MAGNITUDE ESTIMATE 

50 currentMagEstimate = discoveryDataDictionary["currentMagnitudeEstimate"] 

51 currentMagEstimateUpdated = discoveryDataDictionary[ 

52 "currentMagnitudeEstimateUpdated"] 

53 

54 if currentMagEstimateUpdated and currentMagEstimate not in [9999, -9999]: 

55 now = datetime.datetime.now() 

56 if now - currentMagEstimateUpdated < datetime.timedelta(days=2): 

57 littleTitle = cu.little_label( 

58 text="current mag estimate:" 

59 ) 

60 # add text color 

61 if currentMagEstimate > 21.: 

62 text = "&nbsp&nbsp> 21.0" 

63 else: 

64 text = "&nbsp&nbsp%(currentMagEstimate)0.2f" % locals() 

65 currentMagEstimate = khufu.coloredText( 

66 text=text, 

67 color="violet", 

68 size=7, # 1-10 

69 pull=False, # "left" | "right" 

70 ) 

71 currentMagEstimateUpdated = khufu.coloredText( 

72 text=currentMagEstimateUpdated, 

73 color="red", 

74 size=False, # 1-10 

75 pull=False, # "left" | "right" 

76 ) 

77 currentMagEstimate = khufu.grid_row( 

78 responsive=True, 

79 columns="%(littleTitle)s %(currentMagEstimate)s" % locals() 

80 ) 

81 else: 

82 currentMagEstimate = "" 

83 else: 

84 currentMagEstimate = "" 

85 

86 # GET LATEST MAGNITUDES 

87 littleTitle = """<span class="colortext grey littlelabel ">magnitudes:</span>""" 

88 numOfPointsToDisplay = 5 

89 count = 0 

90 rows = [] 

91 magnitudes = "" 

92 # for k, v in discoveryDataDictionary.items(): 

93 # print k, v 

94 for dataPoint in lightcurveData: 

95 if dataPoint["transientBucketId"] == discoveryDataDictionary["transientBucketId"]: 

96 row = dataPoint 

97 rows.append(row) 

98 count += 1 

99 if count >= numOfPointsToDisplay: 

100 littleTitle = """<span class="colortext grey littlelabel ">latest %(numOfPointsToDisplay)s magnitudes:</span>""" % locals( 

101 ) 

102 break 

103 

104 for row in rows: 

105 ffilter = "" 

106 if row["filter"]: 

107 ffilter = row["filter"] 

108 ffilter = """%(ffilter)s-band""" % locals() 

109 

110 survey = khufu.coloredText( 

111 text="""%s %s""" % (row["survey"], ffilter, ), 

112 color="orange", 

113 size=3, 

114 pull="left" 

115 ) 

116 

117 relDate = times.datetime_relative_to_now(row["observationDate"]) 

118 dateObs = khufu.coloredText( 

119 text="""%s""" % ( 

120 str(row["observationDate"])[0:10],), 

121 color="violet", 

122 pull="left", 

123 size=2 

124 ) 

125 relDate = khufu.coloredText( 

126 text=""" %s""" % (relDate[1:]), 

127 color="magenta", 

128 pull="left", 

129 size=2 

130 ) 

131 survey = khufu.grid_row( 

132 responsive=True, 

133 columns=survey 

134 ) 

135 dateObs = khufu.grid_row( 

136 responsive=True, 

137 columns="%(dateObs)s %(relDate)s" % locals() 

138 ) 

139 info = khufu.grid_column( 

140 span=6, # 1-12 

141 offset=0, # 1-12 

142 content="%(survey)s %(dateObs)s" % locals(), 

143 pull="left", # ["right", "left", "center"] 

144 ) 

145 

146 if row["magnitude"]: 

147 mag = khufu.coloredText( 

148 text="""%4.2f""" % (row["magnitude"],), 

149 color="green", 

150 size=6, 

151 pull="right" 

152 ) 

153 else: 

154 mag = khufu.coloredText( 

155 text="""%s""" % (row["magnitude"],), 

156 color="green", 

157 size=6, 

158 pull="right" 

159 ) 

160 

161 mag = khufu.grid_column( 

162 span=3, # 1-12 

163 offset=1, # 1-12 

164 content=mag, 

165 ) 

166 

167 thisMag = khufu.grid_row( 

168 responsive=True, 

169 columns="%(mag)s %(info)s" % locals(), 

170 ) 

171 magnitudes = "%(magnitudes)s %(thisMag)s" % locals() 

172 

173 magnitudes = "%(littleTitle)s<span>%(magnitudes)s</span>" % locals() 

174 

175 return "%(title)s %(magnitudes)s %(currentMagEstimate)s" % locals()