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 generate object form for the PESSTO Marshall* 

5 

6:Author: 

7 David Young 

8""" 

9from builtins import str 

10import sys 

11import os 

12from datetime import datetime, date, time 

13from fundamentals import times 

14import khufu 

15from marshall_webapp.templates.commonelements.tickets.single_ticket.ticket_building_blocks.lightcurve_block import lightcurve_block as lcb 

16 

17 

18def generate_ob_form( 

19 log, 

20 request, 

21 discoveryDataDictionary, 

22 lightcurveData, 

23 objectAkas 

24): 

25 """generate object form 

26 

27 **Key Arguments** 

28 

29 - ``log`` -- the logger 

30 - ``request`` -- the pyramid request 

31 - ``discoveryDataDictionary`` -- dictionary of the transient's discovery data 

32 - ``lightcurveData`` -- lightcurve data 

33 - ``objectAkas`` -- akas for this object 

34 

35 

36 **Return** 

37 

38 - ``modalForm``, ``thisButton`` -- the modal form and the button used to trigger the modal 

39 

40 """ 

41 # Header Text 

42 lsqExists = False 

43 masterName = discoveryDataDictionary["masterName"] 

44 if discoveryDataDictionary["classifiedFlag"] == 0: 

45 headerText = "Generate Classification OB for %(masterName)s" % locals() 

46 else: 

47 headerText = "Generate Followup OB for %(masterName)s" % locals() 

48 

49 # Get Lightcurve Image URL 

50 lightCurveImage = "" 

51 if discoveryDataDictionary["master_pessto_lightcurve"]: 

52 lightCurveImage = 'caches/transients/%s/master_lightcurve.png' % ( 

53 discoveryDataDictionary["transientBucketId"],) 

54 lightCurveImage = request.static_url(f'marshall_webapp:{lightCurveImage}') 

55 # Override for LSQ lightcurves 

56 lightcurveSwitchAttempt = True 

57 transientBucketId = discoveryDataDictionary["transientBucketId"] 

58 for row in lightcurveData: 

59 if row["transientBucketId"] == discoveryDataDictionary["transientBucketId"] and row["survey"] and "lsq-disc" in row["survey"].lower(): 

60 lightcurveSwitchAttempt = False 

61 if lightcurveSwitchAttempt == True: 

62 filePath = request.registry.settings[ 

63 "cache-directory"] + "/transients/%(transientBucketId)s/lsq_lightcurve.gif" % locals() 

64 lsqExists = os.path.exists(filePath) 

65 

66 if lsqExists: 

67 transientBucketId = discoveryDataDictionary["transientBucketId"] 

68 lightCurveImage = 'caches/transients/%(transientBucketId)s/lsq_lightcurve.gif' % locals( 

69 ) 

70 lightCurveImage = request.static_url(f'marshall_webapp:{lightCurveImage}') 

71 if not len(lightCurveImage): 

72 lightCurveImage = khufu.image( 

73 # [ industrial | gray | social ] 

74 src="""holder.js/190x190/auto/industrial/text:master lightcurve not ready""", 

75 display="polaroid", # [ rounded | circle | polaroid | False ] 

76 ) 

77 

78 # CONVERT LIGHTCURVE INTO IMAGE 

79 lightCurveImage = khufu.image( 

80 src=lightCurveImage, # [ industrial | gray | social ] 

81 pull=False, # [ "left" | "right" | "center" | False ] 

82 width=400 

83 ) 

84 

85 # GET LATEST MAGNITUDES 

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

87 numOfPointsToDisplay = 3 

88 count = 0 

89 rows = [] 

90 magnitudes = "" 

91 for dataPoint in lightcurveData: 

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

93 row = dataPoint 

94 rows.append(row) 

95 count += 1 

96 if count >= numOfPointsToDisplay: 

97 break 

98 for row in rows: 

99 ffilter = "" 

100 if row["filter"]: 

101 ffilter = row["filter"] 

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

103 survey = khufu.coloredText( 

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

105 color="orange", 

106 size=3, 

107 pull="left" 

108 ) 

109 

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

111 dateObs = khufu.coloredText( 

112 text="""%s""" % ( 

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

114 color="violet", 

115 pull="left", 

116 size=2 

117 ) 

118 relDate = khufu.coloredText( 

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

120 color="magenta", 

121 pull="left", 

122 size=2 

123 ) 

124 survey = khufu.grid_row( 

125 responsive=True, 

126 columns=survey 

127 ) 

128 dateObs = khufu.grid_row( 

129 responsive=True, 

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

131 ) 

132 info = khufu.grid_column( 

133 span=6, # 1-12 

134 offset=0, # 1-12 

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

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

137 htmlId=False, 

138 htmlClass=False, 

139 onPhone=True, 

140 onTablet=True, 

141 onDesktop=True 

142 ) 

143 if row["magnitude"]: 

144 mag = khufu.coloredText( 

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

146 color="green", 

147 size=6, 

148 pull="left" 

149 ) 

150 else: 

151 mag = khufu.coloredText( 

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

153 color="green", 

154 size=6, 

155 pull="left" 

156 ) 

157 mag = khufu.grid_column( 

158 span=3, # 1-12 

159 offset=0, # 1-12 

160 content=mag, 

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

162 ) 

163 mag = khufu.grid_column( 

164 span=5, # 1-12 

165 offset=0, # 1-12 

166 content="%(mag)s %(info)s" % locals(), 

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

168 ) 

169 magnitudes = "%(magnitudes)s<BR><p>%(mag)s</p>" % locals() 

170 

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

172 

173 downloadButton = khufu.button( 

174 buttonText="""<i class="icon-download-alt"></i>""", 

175 # [ default | primary | info | success | warning | danger | inverse | link ] 

176 buttonStyle='info', 

177 buttonSize='default', # [ large | default | small | mini ] 

178 htmlId="generateOBForm%(transientBucketId)s" % discoveryDataDictionary, 

179 htmlClass="generateOBSubmitButton", 

180 href=False, 

181 pull=False, # right, left, center 

182 submit=True, 

183 block=False, 

184 disable=False, 

185 dataToggle=False, 

186 close=False 

187 ) 

188 

189 postToScript = request.route_path( 

190 'transients_element_obs', elementId=discoveryDataDictionary["transientBucketId"], _query={"method": "get"}) 

191 

192 thisModal = khufu.modals.modalForm( 

193 log=log, 

194 title=headerText, 

195 postToScriptUrl=postToScript, 

196 reloadToUrl=False 

197 ) 

198 thisModal.submitButtonText = """<i class="icon-download-alt"></i>""" 

199 

200 thisModal.add_form_object( 

201 formObject=magnitudes, 

202 label=lightCurveImage 

203 ) 

204 seeing = khufu.checkbox( 

205 optionText='seeing > 1.5 arcsec', 

206 inline=True, 

207 htmlId="badSeeing", 

208 optionNumber=1, 

209 inlineHelpText=False, 

210 blockHelpText=False, 

211 disabled=False 

212 ) 

213 

214 defaultValue = discoveryDataDictionary["currentMagnitude"] 

215 if defaultValue and defaultValue < 20.5: 

216 defaultValue = """%(defaultValue)5.2f""" % locals() 

217 elif defaultValue and defaultValue > 20.5: 

218 defaultValue = "20.5" 

219 else: 

220 defaultValue = "?" 

221 

222 magnitudeInput = khufu.formInput( 

223 # [ text | password | datetime | datetime-local | date | month | time | week | number | float | email | url | search | tel | color ] 

224 ttype='text', 

225 placeholder='', 

226 span=2, 

227 htmlId="currentMag", 

228 required=True, 

229 defaultValue=defaultValue, 

230 divWrap=False 

231 ) 

232 thisModal.add_form_object( 

233 formObject=magnitudeInput + "&nbsp" + seeing, 

234 label="current mag estimate" 

235 ) 

236 

237 modalForm, modalTrigger = thisModal.get() 

238 

239 popover = khufu.popover( 

240 tooltip=True, 

241 placement="right", 

242 trigger="hover", 

243 title="generate an OB for this object", 

244 content=False, 

245 ) 

246 

247 thisButton = khufu.button( 

248 # [ default | primary | info | success | warning | danger | inverse | link ] 

249 buttonText="OB", 

250 buttonStyle='success', 

251 buttonSize='large', # [ large | default | small | mini ] 

252 href=modalTrigger, 

253 pull=False, # right, left, center 

254 submit=False, 

255 block=False, 

256 disable=False, 

257 dataToggle="modal", # [ modal ] 

258 popover=popover 

259 ) 

260 

261 return modalForm, thisButton 

262 

263if __name__ == '__main__': 

264 main()