-
Notifications
You must be signed in to change notification settings - Fork 0
/
print_html_page.py
executable file
·465 lines (376 loc) · 17.6 KB
/
print_html_page.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
#!/usr/bin/env /proj/sot/ska/bin/python
#################################################################################################
# #
# print_html_page.py update/create html page related acis does plots #
# #
# author: t. isobe (tisobe@cfa.harvard.edu) #
# #
# Last Update: Oct 29, 2013 #
# #
#################################################################################################
import os
import sys
import re
import string
import random
import operator
import math
#
#--- check whether this is a test case
#
comp_test = 'live'
if len(sys.argv) == 2:
if sys.argv[1] == 'test': #---- test case
comp_test = 'test'
elif sys.argv[1] == 'live': #---- automated read in
comp_test = 'live'
else:
comp_test = sys.argv[1].strip() #---- input data name
#
#--- reading directory list
#
if comp_test == 'test' or comp_test == 'test2':
path = '/data/mta/Script/ACIS/Count_rate/house_keeping/dir_list_py_test'
else:
path = '/data/mta/Script/ACIS/Count_rate/house_keeping/dir_list_py'
# path = '/data/mta/Script/ACIS/Count_rate/house_keeping2/dir_list_py'
f= open(path, 'r')
data = [line.strip() for line in f.readlines()]
f.close()
for ent in data:
atemp = re.split(':', ent)
var = atemp[1].strip()
line = atemp[0].strip()
exec "%s = %s" %(var, line)
#
#--- append pathes to private folders to a python directory
#
sys.path.append(bin_dir)
sys.path.append(mta_dir)
#
#--- import several functions
#
import convertTimeFormat as tcnv #---- contains MTA time conversion routines
import mta_common_functions as mcf #---- contains other functions commonly used in MTA scripts
#
#--- temp writing file name
#
rtail = int(10000 * random.random()) #---- put a romdom # tail so that it won't mix up with other scripts space
zspace = '/tmp/zspace' + str(rtail)
#--------------------------------------------------------------------------------------
#--- print_html_page: print all html pages for ACIS Dose Plots ---
#--------------------------------------------------------------------------------------
def print_html_page(comp_test, in_year=1, in_mon=1):
"""
driving function to print all html pages for ACIS Dose Plots
Input: comp_test --- test indicator. if it is "test", it will run the test version
in_year/in_mon --- if in_year and in_mon are given, the file is created for
that year/month, otherwise, the files are created in the current year/month
Output: html pages in <web_dir> and <web_dir>/<mon_dir_name> (e.g. JAN2013)
"""
#
#--- find today's date and convert them appropriately
#
if comp_test == 'test':
bchk = 0
tday = 13;
umon = 2;
uyear = 2013;
cmon = tcnv.changeMonthFormat(umon)
cmon = cmon.upper()
ldate = str(uyear) + '-' + str(umon) + '-' + str(tday) #-- update date
else:
#
#--- find today's date
#
[uyear, umon, tday, hours, min, sec, weekday, yday, dst] = tcnv.currentTime()
#
#--- change month in digit into letters
#
cmon = tcnv.changeMonthFormat(umon)
cmon = cmon.upper()
ldate = str(uyear) + '-' + str(umon) + '-' + str(tday) #-- update date
#
#--- if year and month is given, create for that month. otherwise, create for this month
#
bchk = 0
if mcf.chkNumeric(in_year) and mcf.chkNumeric(in_mon):
if in_year > 1900 and (in_mon >0 and in_mon < 13):
bchk = 1
if bchk > 0:
uyear = in_year
umon = in_mon
cmon = tcnv.changeMonthFormat(umon)
cmon = cmon.upper()
mon_dir_name = cmon + str(uyear);
#
#--- check whether this monnth web page already opens or not
#
dname = web_dir + mon_dir_name
chk = mcf.chkFile(dname)
if chk > 0:
if bchk == 0:
#
#-- create only when it is working for the current month
#
print_main_html(ldate, uyear, umon);
print_month_html(mon_dir_name, ldate, uyear, umon);
print_png_html(mon_dir_name, ldate, uyear, umon);
#
#--- change permission level and the owner of the files
#
cmd = 'chgrp mtagroup ' + web_dir + '/* ' + web_dir + '/*/*'
os.system(cmd)
cmd = 'chmod 755 '+ web_dir + '/* ' + web_dir + '/*/*'
os.system(cmd)
#--------------------------------------------------------------------------------------
#--- print_main_html: printing the main acis dose html page ---
#--------------------------------------------------------------------------------------
def print_main_html(ldate, this_year, this_month):
"""
printing the main acis dose html page
Input: ldate --- date of update
this_year --- current year in digit
this_month --- current month in digit
Output: <web_dir>/main_acis_dose_plot.html
"""
line = '<!DOCTYPE html>\n'
line = line + '<html>\n'
line = line + '<head>\n'
line = line + '<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />\n'
line = line + '<style type="text/css">\n'
line = line + 'table{text-align:center;margin-left:auto;margin-right:auto;border-style:solid;border-spacing:8px;border-width:2px;border-collapse:separate}\n'
line = line + 'td{text-align:center;padding:8px}\n'
line = line + '\n'
line = line + 'a:link {color:#00CCFF;}\n'
line = line + 'a:visited {color:yellow;}\n'
line = line + '\n'
line = line + 'span.nobr {white-space:nowrap;}\n'
line = line + '</style>\n'
line = line + '<title>ACIS Count Rate Plots </title>\n'
line = line + '<script>\n'
line = line + 'function MyWindowOpener(imgname) {\n'
line = line + ' msgWindow=open("","displayname","toolbar=no,directories=no,menubar=no,location=no,scrollbars=no,status=no,width=732,height=560,resize=yes");\n'
line = line + ' msgWindow.document.close();\n'
line = line + ' msgWindow.document.write("<!DOCTYPE html>");\n'
line = line + ' msgWindow.document.write("<html><head><title>Bias plot: "+imgname+"</title></head>");\n'
line = line + ' msgWindow.document.write("<<meta http-equiv=\'Content-Type\' content=\'text/html; charset=utf-8\' />");\n'
line = line + ' msgWindow.document.write("<body style=\'background-color:white\'>");\n'
line = line + ' msgWindow.document.write("<img src=\'./mta_days/mta_dose_count2/"+imgname+"\' style=\"width:692px;height:540px\"></body></html>");\n'
line = line + ' msgWindow.focus();\n'
line = line + '}\n'
line = line + '</script>\n'
line = line + '</head>\n'
line = line + '<body style="color:#FFFFFF;background-color:#000000;">\n'
line = line + '<h2 style="color:aqua;text-align:center">ACIS Dose Plots</h2>\n'
line = line + '<h3 style="text-align:center">Last Update: ' + ldate + '</h3>\n'
line = line + '<hr />\n'
#
#--- the links to long term plots
#
line = line + '<h3>Long Term Trend Plots</h3>\n'
line = line + '<p style="text-align:center">\n'
line = line + '<a href="javascript:MyWindowOpener(\'./long_term_plot.png\')"><img src="./long_term_plot.png" style="text-align:center; width: 60%"></a>\n'
line = line + '</p>\n'
line = line + '<h3>Monthly Averaged Plots</h3>\n'
line = line + '<p style="padding-bottom:20px">\n'
line = line + '<a href=./month_avg_img.html>Imaging CCDs</a><br />\n'
line = line + '<a href=./month_avg_spec.html>Front Side Spec CCDs</a><br />\n'
line = line + '<a href=./month_avg_bi.html>Back Side Spec CCDs</a><br />\n'
line = line + '</p>\n'
line = line + '<p style="padding-top:20px;padding-bottom:20px"><b> Please Select A Period</b> </p>\n'
#
#--- table explanation
#
line = line + '<p>\n'
line = line + 'The following tabless list links to plots of photon count rates (counts/sec) for averages of 5min intervals against time (DOM).\n'
line = line + 'They are simple photon counts for each CCD and not a back ground photon counts; \n'
line = line + 'it means that no sources are removed from the computation.\n'
line = line + '</p>\n'
line = line + '\n'
#
#--- first table from year 2010 to current
#
line = line + '<div style="padding-top:40px"></div>\n'
line = line + '<table border=1>\n'
line = line + '<tr>\n'
line = line + '<th>Year</th>\n'
for iyear in range(2010, this_year+1):
line = line + '<th><b>' + str(iyear) + '</b></th>\n'
line = line + '</tr>' + "\n"
idiff = this_year - 2009
for dmon in range(1, 13):
cmon = tcnv.changeMonthFormat(dmon)
cmon = cmon.upper()
lmon = cmon.lower()
line = line + '<tr><th>' + cmon + '</th>'
for ix in range(0, idiff):
dyear = 2010 + ix
if ix < idiff -1:
line = line + '<td>';
line = line + '<a href=./'+ cmon + str(dyear) + '/acis_' + lmon + str(dyear) + '_dose_plot.html>'
line = line + cmon + ' ' + str(dyear) + '</a></td>\n';
elif ix >= idiff-1:
if dmon > this_month:
line = line + '<td>---</td>\n'
else:
line = line + '<td>'
line = line + '<a href=./' + cmon + str(dyear) + '/acis_'+ lmon + str(dyear) + '_dose_plot.html>'
line = line + cmon + str(dyear) + '</a></td>\n'
line = line + '</tr>\n'
line = line + '</table>\n'
line = line + '<div style="padding-bottom:40px"> </div>\n'
#
#--- second table from year 2000 to 2009
#
line = line + '<table border=1>\n'
line = line + '<tr>\n'
line = line + '<th>Year</th>\n'
for iyear in range(2000, 2010):
line = line + '<th><b>' + str(iyear) + '</b></th>\n'
line = line + '</tr>' + "\n"
for dmon in range(1, 13):
cmon = tcnv.changeMonthFormat(dmon)
cmon = cmon.upper()
lmon = cmon.lower()
line = line + '<tr><th>' + cmon + '</th>'
for ix in range(0, 10):
dyear = 2000 + ix
line = line + '<td>';
line = line + '<a href=./'+ cmon + str(dyear) + '/acis_' + lmon + str(dyear) + '_dose_plot.html>'
line = line + cmon + ' ' + str(dyear) + '</a></td>\n';
line = line + '</tr>\n'
line = line + '</table>\n'
#
#--- links to monthly data files
#
line = line + '<h3>Monthly Average Data</h3>\n'
line = line + '<div style="padding-top:20px;padding-bottom:20px;text-align:left">\n'
line = line + '<table border = 1><tr>\n'
for ccd in range(0, 10):
line = line + '<th>CCD ' + str(ccd) + '</th>'
line = line + '</tr>\n'
for ccd in range(0, 10):
line = line + '<td><a href="monthly_avg_data_ccd' + str(ccd) + '.dat">Data</td>\n'
line = line + '</tr></table>\n'
line = line + '</div>\n'
line = line + '<hr />\n'
line = line + '<p style="padding-top:10px;padding-bottom:40px">\n'
line = line + 'If you have any questions about this page, please contact <a href='
line = line + '"mailto:tisobe@cfa.harvard.edu">tisobe@cfa.harvard.edu</a>.\n'
line = line + '</p>'
line = line + '</body>\n'
line = line + '</html>\n'
#
#--- print the page
#
file = web_dir + '/main_acis_dose_plot.html'
f = open(file, 'w')
f.write(line)
f.close()
#--------------------------------------------------------------------------------------
#--- print_month_html: printing html page for each month ---
#--------------------------------------------------------------------------------------
def print_month_html(mon_dir_name, ldate, this_year, this_month):
"""
printing html page for each month
Input: mon_dir_name --- a directory in which the plots are kept
ldate --- date of update
this_year --- current year in digit
this_month --- current month in digit
Output: <web_dir>/<mon_dir_name>/acis_<lmon><year>_dose_plot.html
"""
cmon = tcnv.changeMonthFormat(this_month)
cmon = cmon.upper()
lmon = cmon.lower()
line = '<!DOCTYPE html>\n'
line = line + '<html>\n'
line = line + '<head>\n'
line = line + '<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />\n'
line = line + '<style type="text/css">\n'
line = line + 'table{text-align:center;margin-left:auto;margin-right:auto;border-style:solid;border-spacing:8px;border-width:2px;border-collapse:separate}\n'
line = line + 'td{text-align:center;padding:8px}\n'
line = line + '\n'
line = line + 'a:link {color:#00CCFF;}\n'
line = line + 'a:visited {color:yellow;}\n'
line = line + '\n'
line = line + 'span.nobr {white-space:nowrap;}\n'
line = line + '</style>\n'
line = line + '<title>ACIS Count Rate Plots </title>\n'
line = line + '</head>\n'
line = line + '<body style="color:#FFFFFF;background-color:#000000;">\n'
line = line + '<h2 style="text-align:center;color:aqua">ACIS Count Rate Plot: ' + cmon + ', ' + str(this_year) + '</h2>\n'
line = line + '<h3 style="text-align:center">Created on ' + ldate + '</h3>\n'
line = line + '<hr />\n'
line = line + '<p><b> Please Select CCD:</b> </p>\n'
line = line + '<table border=0 style="margin-left:auto;margin-right:auto">\n'
line = line + '<tr><th style="font-size:110%">Plot</td><th style="font-size:110%">Data</td></tr>\n'
for ccd in range(0, 10):
line = line + '<tr><td><a href="./acis_dose_ccd' + str(ccd) + '.html">CCD ' + str(ccd) + ' Plot</a></td>'
line = line + '<td><a href="./ccd' + str(ccd) + '">CCD ' + str(ccd) + ' Data</a></td></tr>\n'
line = line + '<td><a href="./acis_dose_ccd_5_7.html">CCDs 5 - 7 Plot</a></td><td> </td></tr>\n'
line = line + '<td><a href="./ephin_rate.html">Ephin Count Rate Plot</a></td><td><a href="./ephin_rate">Ephin Data</a></td></tr>\n'
line = line + '</table>\n'
line = line + '<p style="padding-top:15px;padding-bottom:15px">To check a dose map, please go to <a href=https://cxc.cfa.harvard.edu/mta/REPORTS/MONTHLY/'
line = line + str(this_year) + cmon + '/MONTHLY.html>' + cmon + ' ' + str(this_year) + ' Monthly Report</a>.</p>\n'
line = line + '<p>Back to <a href=../main_acis_dose_plot.html>Main Page</a>\n'
line = line + '</body>\n</html>\n'
cmon = tcnv.changeMonthFormat(this_month)
cmon = cmon.upper()
lmon = cmon.lower()
name = web_dir + '/' + mon_dir_name + '/acis_' + lmon + str(this_year) + '_dose_plot.html'
f = open(name, 'w')
f.write(line)
f.close()
#--------------------------------------------------------------------------------------
#--- print_png_html: print html pages for png files ---
#--------------------------------------------------------------------------------------
def print_png_html(mon_dir_name, ldate, this_year, this_month):
"""
printing html pages for png files
Input: mon_dir_name --- a directory in which the plots are kept
ldate --- date of update
this_year --- current year in digit
this_month --- current month in digit
Output: <web_dir>/<html_name>.html
<web_dir>/<mon_dir_name>/<html_name>.html
"""
nlist = ('month_avg_img', 'month_avg_spc', 'month_avg_bi', 'long_term_plot', 'acis_dose_ccd0', \
'acis_dose_ccd1', 'acis_dose_ccd2','acis_dose_ccd3', 'acis_dose_ccd4', 'acis_dose_ccd5', \
'acis_dose_ccd6', 'acis_dose_ccd7', 'acis_dose_ccd8', 'acis_dose_ccd9', 'acis_dose_ccd_5_7',\
'ephin_rate')
for name in nlist:
html_name = name + '.html'
png_name = name + '.png'
line = '<!DOCTYPE html>\n'
line = line + '<html>\n'
line = line + '<head>\n'
line = line + '<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />\n'
line = line + '<style type="text/css">\n'
line = line + 'table{text-align:center;margin-left:auto;margin-right:auto;border-style:solid;border-spacing:8px;border-width:2px;border-collapse:separate}\n'
line = line + 'td{text-align:center;padding:8px}\n'
line = line + '\n'
line = line + 'a:link {color:#00CCFF;}\n'
line = line + 'a:visited {color:yellow;}\n'
line = line + '\n'
line = line + 'span.nobr {white-space:nowrap;}\n'
line = line + '</style>\n'
line = line + '<title>ACIS Count Rate Plots: ' + name + ' </title>\n'
line = line + '</head>\n'
line = line + '<body style="color:#FFFFFF;background-color:#000000;">\n'
line = line + '<img src="./' + png_name + '" style="text-align:center; width:90%;padding-bottom:30px">\n'
line = line + '<hr />\n'
line = line + '<h3 style="padding-top:20px">Last Update: ' + ldate + '</h3>\n'
line = line + '</body>\n</html>\n'
m1 = re.search('month', name)
m2 = re.search('long', name)
if (m1 is not None) or (m2 is not None):
file = web_dir + '/' + html_name
else:
file = web_dir + '/' + mon_dir_name + '/' + html_name
f = open(file, 'w')
f.write(line)
f.close()
#--------------------------------------------------------------------------------------
if __name__ == "__main__":
print_html_page(comp_test='no')