def update_violation_page(line, line2, color): """ update violation pages input: line --- table contents pos --- lower or upper color --- yellow or red output: <house_keeping>/<pos>_<color>_violation.html """ title = color.capitalize() + ' Violation' head = chs.read_template('html_head') jscript = chs.read_template('java_script_deposit') tstyle = chs.read_template('two_col_style') tail = chs.read_template('html_close') head = head.replace('#MSID#', title) head = head.replace('#JAVASCRIPT#', jscript) head = head.replace('#STYLE#', tstyle) if color == 'yellow': ocolor = 'red' other = 'Go to Red Violation' else: ocolor = 'yellow' other = 'Go to Yellow Violation' tline = head + '<h2 style="background-color:' + color + ';">' + title + '</h2>\n' tline = tline + '<div style="text-align:right;">\n' tline = tline + '<a href="https://cxc.cfa.harvard.edu/mta/MSID_Trends/mta_trending_main.html">' tline = tline + 'Back to Top</a>\n' tline = tline + '<br />\n' tline = tline + '<a href="https://cxc.cfa.harvard.edu/mta/MSID_Trends/' tline = tline + ocolor + '_violation.html">' tline = tline + other + '</a>\n' tline = tline + '</div>\n' tline = tline + '<div class="row">\n' tline = tline + '<div class="column">\n' tline = tline + '<h3>Lower Violation</h3>\n' tline = tline + '<table border=1 cellpadding=2>\n' tline = tline + line tline = tline + '</table>\n' tline = tline + '</div>\n' tline = tline + '<div class="column2">\n' tline = tline + '<h3>Upper Violation</h3>\n' tline = tline + '<table border=1 cellpadding=2>\n' tline = tline + line2 tline = tline + '</table>\n' tline = tline + '</div>\n' tline = tline + '</div>\n' tline = tline + tail # #--- print out the page # page = web_dir + color + '_violation.html' mcf.rm_files(page) with open(page, 'w') as fo: fo.write(tline)
def create_html(catg, h_list, ytime, udict, ddict, ltype, mtype, ptype): """ create a html page for category <catg> input: catg --- category of the msids h_list --- a list of msids of the category ytime --- current time udict --- a dictionary of unit: <msid> <---> <unit> ddict --- a dictionary of description: <msid> <---> <description> ltype --- date length: week, short, one, five, long mtype --- data type: mid, min, max ptype --- static or interactive output: <catg>_main.html """ # #--- create links to other pages # line = '<!DOCTYPE html>\n<html>\n<head>\n\t<title>Envelope Trending Plots: ' line = line + catg.upper() + '</title>\n' line = line + '</head>\n<body style="width:95%;margin-left:10px; margin-right;' line = line + '10px;background-color:#FAEBD7;' line = line + 'font-family:Georgia, "Times New Roman", Times, serif">\n\n' line = line + '<div style="float:right;padding-right:50px;font-size:120%">\n' line = line + '<a href="../mta_trending_main.html" ' line = line + 'style="float:right;padding-right:50px;font-size:80%">' line = line + '<b>Back to Top</b></a><br />\n' line = line + '</div>\n' line = line + '<h3 style="padding-bottom:0px">' + catg.upper() + ' ' if ptype == 'static': line = line + '<br /> Static Version: ' else: line = line + '<br /> Interactive Version: ' if mtype == 'min': line = line + ' Min --- ' elif mtype == 'max': line = line + ' Max --- ' else: line = line + ' Mean --- ' if ltype == 'week': line = line + ' One Week ' elif ltype == 'short': line = line + ' Last Three Months ' elif ltype == 'one': line = line + ' Last One Years ' elif ltype == 'five': line = line + ' Last Five years ' else: line = line + ' Full Range ' line = line + '</h3>\n' # #--- link to the other plot category # line = line + create_link_names(catg, ltype, mtype, ptype) line = line + '<p style="margin-left:35px; margin-right:35px;">' line = line + '<em><b>Delta/Yr</b></em> below is a slope of the liear fitting ' line = line + 'over the data of the period. ' line = line + '<em><b>Delta/Yr/Yr</b></em> is a slope of the liner fitting ' line = line + 'over the devivative data of the period. <em><b>Slope</b></em> ' line = line + 'listed on a linked plot is the slope computed on ' line = line + 'the last few periods of the data to show the direction of the trend, ' line = line + 'and different from that of Delta/Yr.</p>' line = line + '<div style="padding-bottom:30px;"></div>' line = line + '<div style="text-align:center">\n\n' line = line + '<table border=1 cellspacing=2 style="margin-left:auto;margin-right:auto;' line = line + 'text-align:center;">\n' line = line + '<th>MSID</th><th>Mean</th><th>RMS</th><th>Delta/Yr</th><th>Delta/Yr/Yr</th>' line = line + '<th>Unit</th><th>Description</th><th>Limit Violation</th>\n' # #--- create a table with one row for each msid # violation_save = [] for ent in h_list: atemp = re.split('_plot', ent) msid = atemp[0] # #--- read fitting results # try: [a, b, d, avg, std, da, db, dd] = extract_data(catg, msid, ltype, mtype) except: [a, b, d, avg, std, da, db, dd] = [0, 0, 0, 0, 0, 0, 0, 0] # #--- check whether plot html file exist # cfile = check_plot_existance(msid, catg, ltype, mtype, ptype) if cfile == False: continue # #--- hrc has 4 different entries (all, hrc i, hrc s, and off cases) #--- but share the same unit and descriptions # msidp = msid.replace('_i', '') msidp = msidp.replace('_s', '') msidp = msidp.replace('_off', '') try: unit = udict[msidp] discp = ddict[msidp] # #--- convert all F and most C temperature to K, exception: if the uint is "C", leave as it is # if unit == 'DEGF': unit = 'K' elif unit == 'DEGC': if msid[:-2].lower() != 'tc': unit = 'K' except: unit = '---' discp = msid # #--- check violation status; if it is 'na', there is no data # [vnote, color] = create_status(msid, catg, ytime) # #--- save the violation description if msid is in the violation range # if color != 'black': violation_save.append([msid, vnote]) cfile = check_plot_existance(msid, catg, ltype, mtype, ptype) if (abs(float(b)) > 100) or (abs(float(b)) < 0.001): fline = ecf.modify_slope_dicimal(float(b), float(d)) else: fline = b + '+/-' + d fline = check_na_std(fline) if (abs(float(db)) > 100) or (abs(float(db)) < 0.001): dline = ecf.modify_slope_dicimal(float(db), float(dd)) else: dline = db + '+/-' + dd dline = check_na_std(dline) if cfile == False: line = line + '<tr>\n<th>' + msid +'</a></th>' line = line + '<td>' + avg + '</td><td>' + std + '</td><td>' + fline + '</td>' line = line + '<td>' + dline + '</td><td>' + unit +'</td><td>' + discp + '</td>' line = line + '<th style="font-size:90%;color:#B22222;padding-left:10px;' line = line + 'padding-right:10px">No Data</th>\n</tr>\n' else: xfile = cfile.replace('www\/','') ctemp = re.split('\/', cfile) xfile = ctemp[-2] + '/' + ctemp[-1] line = line + '<tr>\n<th><a href="'+ xfile + '">' + msid +'</a></th>' line = line + '<td>' + avg + '</td><td>' + std + '</td><td>' + fline + '</td>' line = line + '<td>' + dline + '</td><td>' + unit +'</td><td>' + discp + '</td>' line = line + '<th style="font-size:90%;color:' + color + ';padding-left:10px;' line = line + 'padding-right:10px">' + vnote + '</th>\n</tr>\n' line = line + '</table>\n' line = line + '</div>\n' fout = chs.read_template('html_close') line = line + fout # #--- category html has the tail of "_main.html" # try: name = create_out_name(catg, ltype, mtype, ptype) with open(name, 'w') as fo: fo.write(line) except: pass vout = web_dir + catg + '/violations' if len(violation_save) == 0: mcf.rm_files(vout) else: line = '' for ent in violation_save: if len(ent[0]) < 8: line = line + ent[0] + '\t\t' + ent[1] + '\n' else: line = line + ent[0] + '\t' + ent[1] + '\n' with open(vout, 'w') as fo: fo.write(line)
def create_plot_html_page(msid, msid_list, group, descrip, trend_list, dev_list, dtype, mtype, mta_msids): """ create a html page to display the trend plot input: msid --- msid msid_list --- the list of msids in the group group --- group name to which msid belongs descrip --- description of the msid trend_list --- a list of trend plot files dev_list --- a list of deviation plot files dtype --- data type, week, short, year, five, or long mtype --- data type, mid, min, max mta_msids --- a list of mta created msids output: plot <web_dir>/<msid>_plot.html """ # #--- read javascript file # jscript = chs.read_template('java_script_deposit') # #--- set web page names including link back pages # [tweb, hname, other, other_list] = set_link_htmls(group, msid, dtype, mtype) # #--- pop up limit table web address # file_name = web_address + group + '/Limit_table/' + msid + '_limit_table.html' # #--- start creating html page # repl = [["#MSID#", msid.upper()], ["#JAVASCRIPT#", jscript], ["#STYLE#", '']] out = chs.read_template('html_head', repl ) out = out + '<div style="float:right;padding-right:50px;">' out = out + '<a href="' + tweb + '" ' out = out + 'style="text-align:right"><b>Back to ' + group + ' Page</b></a><br />\n' out = out + '<b><a href = "' + web_address + 'mta_trending_main.html">Back To Top</a><br />\n' # #--- interactive/static page link back # out = out + '<a href="' + other + '" style="text-align:right">' out = out + '</a><br />\n' out = out + '<b><a href="javascript:popitup(\'' + web_address out = out + '/how_to_create_plots.html\')" style="text-align:right">' out = out + 'How the Plots Are Created</a></b><br />\n' # #--- prev and next msid # out = out + make_msid_link(msid, msid_list, group, dtype, mtype) out = out + '</div>\n' # #--- title of the page # out = out + set_title(msid, descrip, dtype, mtype) # #--- popup limit table link # out = out + '<div style="paddng-top:10px"><h3>' out = out + 'Open <a href="javascript:popitup(\'' + file_name + '\')" ' out = out + 'style="text-align:right">Limit Table</a>.' out = out + '</h3>\n' out = out + '</div>\n' # #--- link to the other type of length plots # out = out + create_period_link(other_list, msid, dtype, mtype) for plotname in trend_list: out = out + '<img src="' + plotname + '" width=80%>' out = out + '<br />\n' # #--- msid is mta created one, don't put the interactive page link # if msid in mta_msids: out = out + '<br><br>\n' else: phpfile = web_address + "Interactive/msid_data_interactive.php" int_note = web_address + 'interactive_note.html' out = out + '<div style="padding-bottom:10px;font-size:90%;">\n'; if msid.lower() in exclude_from_interactive: out = out + '<h3>This Data Set Cannot Produce an Interactive Plot</h3>\n' else: out = out + '<h3>Create an Interactive Plot (' out = out + '<a href="javascript:popitup(\'' + int_note + '\')" ' out = out + 'style="text-align:right">Usage Note</a>' out = out + ')</h3>\n' out = out + '<form method="post" action=' + phpfile + '>\n' out = out + '<b>Starting Time:</b> <input type="text" name="tstart" size=20>\n' out = out + '<b>Stopping Time:</b> <input type="text" name="tstop" size=20>\n' out = out + '<b>Bin Size:</b> <input type="text" name="binsize" ' out = out + 'value=300.0 size=10>\n ' out = out + '<b>Data Type:</b>\n ' out = out + '<select id="mstype", name="mstype">\n' if mtype == 'mid': out = out + ' <option value="mid" selected>Mean</option>\n' else: out = out + ' <option value="mid">Mean</option>\n' out = out + ' <option value="med">Median</option>\n' if mtype == 'min': out = out + ' <option value="min" selected>Minimum</option>\n' else: out = out + ' <option value="min">Minimum</option>\n' if mtype == 'max': out = out + ' <option value="max" selected>Maximum</option>\n' else: out = out + ' <option value="max">Maximum</option>\n' out = out + '</select>\n' out = out + '<input type="hidden" name="dtype" value="' + dtype + '">\n' out = out + '<input type="hidden" name="mtype" value="' + mtype + '">\n' out = out + '<input type="hidden" name="msid" value="' + msid + '">\n' out = out + '<input type="hidden" name="group" value="' + group + '">\n' out = out + '</br><span style="text-align:right;"><input type=submit ' out = out + 'name="submit" value="Submit"></span>\n' out = out + '<br />\n' out = out + '</form>\n' out = out + '</div>\n' # #--- add the derivative plot # out = out + '<h3>Derivative Plot</h3>\n' for ent in dev_list: out = out + '<img src="' + ent + '" width=80%>' out = out + '<br />' # #--- add the link to other plots in a table format # [lout, gname] = get_group_names(msid, group, dtype, mtype) if lout != '': out = out + '<h3>Other msids in this group: ' + gname + '</h3>' out = out + lout # #--- close html page # date = mcf.today_date_display2() out = out + chs.read_template('html_close', repl=[['#TODAY#', date]]) # #--- write out the html data # with open(hname, 'w') as fo: fo.write(out)
def create_plot_html_page(msid, group, ltype, mtype, descrip, pout, bin_size): """ create a html page to display the trend plot input: msid --- msid group --- group name to which msid belongs ltype --- week, short etc, but usually week for the interactive mtype --- mid, max, min, but usually mid descrip --- description of the msid pout --- plot in html format' it is <blank> if this is a static version output: plot <web_dir>/Interactive/<msid>_tmin_avg.html """ # #--- copy an empty page to the position so that the user won't get an error message # hname = web_dir + 'Interactive/' + msid + '_inter_avg.html' cmd = 'cp ' + house_keeping + '/Templates/no_page_yet ' + hname os.system(cmd) cmd = 'chmod 777 ' + hname os.system(cmd) # #--- read javascript file # jscript = chs.read_template('java_script_deposit') # #--- pop up limit table web address # file_name = web_address + group + '/Limit_table/' + msid + '_limit_table.html' # #--- start creating html page # repl = [["#MSID#", msid.upper()], ["#JAVASCRIPT#", jscript], ["#STYLE#", '']] out = chs.read_template('html_head', repl) # #--- title of the page # if bin_size == 0.0: out = out + '<h2>' + msid + ' <span style="font-size:90%;">(Full Resolution)</span></h2>' else: out = out + '<h2>' + msid + ' <span style="font-size:90%;">(Bin Size: ' + str( bin_size) + ' sec)</span></h2>' # #--- popup limit table link # out = out + '<div style="paddng-top:10px"><h3>' out = out + 'Open <a href="javascript:popitup(\'' + file_name + '\')" style="text-align:right">Limit Table</a>.' out = out + '</h3>\n' out = out + '</div>\n' # #--- interactive page case # if (pout == False) or (str(pout) == 'na'): out = out + '<h3 style="padding-top:200px;padding-bottom:200px">No Data/No Plot</h3>' else: out = out + '<div style="text-align:center;">' out = out + pout out = out + '</div>' # #---- changing the time span, step etc again # phpfile = web_address + "Interactive/msid_data_interactive.php" int_note = web_address + 'interactive_note.html' out = out + '<div style="padding-bottom:10px;font-size:90%;">\n' out = out + '<h3>Change the Interactive Plot Parameters (' out = out + '<a href="javascript:popitup(\'' + int_note + '\')" style="text-align:right">Usage Note</a>' out = out + ')</h3>\n' out = out + '<form method="post" action=' + phpfile + '>\n' out = out + '<b>Starting Time:</b> <input type="text" name="tstart" size=20>\n' out = out + '<b>Stopping Time:</b> <input type="text" name="tstop" size=20>\n' out = out + '<b>Bin Size:</b> <input type="text" name="binsize" value=300.0 size=10>\n ' out = out + '<input type="hidden" name="ltype" value="' + ltype + '">\n' out = out + '<input type="hidden" name="mtype" value="' + mtype + '">\n' out = out + '<input type="hidden" name="msid" value="' + msid + '">\n' out = out + '<input type="hidden" name="group" value="' + group + '">\n' out = out + '</br><span style="text-align:right;"><input type=submit name="submit" value="Submit"></span>\n' out = out + '<br />\n' out = out + '</form>\n' out = out + '</div>\n' out = out + chs.read_template('interact_descript') # #--- add the derivative plot # ### dplotname = web_dir + 'Interactive/' + msid + '_inters_avg_dev.png' ### ### out = out + '<h3>Derivative Plot</h3>\n' ### out = out + '<img src="' + dplotname + '" width=80%>' # #--- close html page # out = out + chs.read_template('html_close') # #--- write out the html data # mcf.rm_file(hname) fo = open(hname, 'w') fo.write(out) fo.close() cmd = 'chmod 777 ' + hname os.system(cmd)
def create_top_html(): """ create the top html page input: none output: <web_dir>/mta_trending_main.html """ dline = '<th colspan=4 class="blue">Full Range</th>\n' dline = dline + '<th colspan=4 class="blue">Past 5 Years</th>\n' dline = dline + '<th colspan=4 class="blue">Past 1 Year</th>\n' dline = dline + '<th colspan=4 class="blue">Quarterly</th>\n' dline = dline + '<th colspan=4 class="blue">Weekly</th>\n' dline = dline + '</tr>\n' # #--- read descriptions of groups and create dictionaries etc # gfile = house_keeping + 'group_descriptions' gdata = mcf.read_data_file(gfile) g_list = [] gn_dict = {} gd_dict = {} gn_list = [] g_disc = [] p_dict = {} for ent in gdata: mc = re.search('#', ent) if mc is not None: ent = ent.replace('#', '') g_list.append(ent) gname = ent elif ent == "": gn_dict[gname] = gn_list gd_dict[gname] = g_disc gn_list = [] g_disc = [] else: atemp = re.split('::', ent) gn_list.append(atemp[0]) g_disc.append(atemp[1]) p_dict[atemp[0].lower()] = atemp[1] mlist = ('mid', 'min', 'max') mname = ('Avg', 'Min', 'Max') # #--- go through each main group # line = '' for gval in g_list: group_list = gn_dict[gval] discip_list = gd_dict[gval] line = line + '<tr><th class="blue">' + gval + '</th>\n' line = line + dline for k in range(0, len(group_list)): gnam = group_list[k].lower() if gnam == 'hrcveto_eph': continue line = line + '<tr>\n' line = line + '<th>' + discip_list[k] + '</th</tr>\n' mpart = '<td><a href="./' + gnam.capitalize() + '/' + gnam + '_' for ltype in ('long', 'five', 'one', 'short', 'week'): for m in range(0, 3): line = line + mpart + mlist[m] + '_static_' + ltype line = line + '_main.html">' + mname[m] + '</a></td>\n' line = line + '<td class="blue"></td>\n' line = line + '</tr>\n' line = line + '<tr><th colspan=21> </th></tr>\n\n' line = line + '</tr>\n' j_script = chs.read_template('java_script_deposit') # #--- the template for the main part # page = chs.read_template('top_template') top_note = '<p><b><em>This page provides trending and limit predictions ' top_note = top_note + 'for various Chandra subsystems.</em></b></p>' page = page.replace('#JAVASCRIPT#', j_script) page = page.replace('#TITLE#', 'MTA MSID Trending') page = page.replace('#TABLE#', line) page = page.replace('<!-- INTRO -->', top_note) page = page.replace('#EXPLANATIONS#', '') page = page.replace('#OTHER_H#', 'mta_trending_sun_angle_main.html') page = page.replace('#OTHER#', 'Sun Angle Page') page = page.replace('#OTHER_H2#', 'mta_trending_eph_tephin_main.html') page = page.replace('#OTHER2#', 'EPHIN Values vs. Temperature Page') page = page.replace('#OTHER_H3#', 'mta_trending_hrcveto_eph_main.html') page = page.replace('#OTHER3#', 'HRC Shield Rates vs. EPHIN Rates') page = page.replace('#VIO1#', 'yellow_violation.html') page = page.replace('#VIO2#', 'red_violation.html') page = page.replace('#PAGE_EXP#', 'how_to_create_plots.html') # #--- add the potential violation candidate table # violation_table = find_future_violation(p_dict) if violation_table != 'na': page = page.replace('#VIOLATION#', violation_table) # #--- the template for the closing part # pclose = chs.read_template('html_close') page = page + pclose outfile = web_dir + 'mta_trending_main.html' with open(outfile, 'w') as fo: fo.write(page) # #---- update violation pages # find_current_violation()
def create_plot_html_page(msid, msid_list, group, descrip, pout, plotname, ltype, mtype, plink): """ create a html page to display the trend plot input: msid --- msid msid_list --- the list of msids in the group group --- group name to which msid belongs descrip --- description of the msid pout --- plot in html format' it is <blank> if this is a static version plotname --- the name of the png file; it is <blank> if this is an interacitve version ltype --- data type, week, short, one, five, or long mtype --- data type, mid, min, max output: plot <web_dir>/<msid>_plot.html """ if plotname == "": ptype = 'inter' else: ptype = 'static' # #--- read javascript file # jscript = chs.read_template('java_script_deposit') # #--- set web page names including link back pages # [tweb, hname, other, other_list] = set_link_htmls(group, msid, ltype, mtype, ptype) # #--- pop up limit table web address # file_name = web_address + group + '/Limit_table/' + msid + '_limit_table.html' # #--- start creating html page # repl = [["#MSID#", msid.upper()], ["#JAVASCRIPT#", jscript], ["#STYLE#", '']] out = chs.read_template('html_head', repl ) out = out + '<div style="float:right;padding-right:50px;">' out = out + '<a href="' + tweb + '" ' out = out + 'style="text-align:right"><b>Back to ' + group + ' Page</b></a><br />\n' out = out + '<b><a href = "' + web_address + 'mta_trending_main.html">Back To Top</a><br />\n' # #--- interactive/static page link back # out = out + '<a href="' + other + '" style="text-align:right">' if ptype == 'inter': out = out + '<b>Open Static Version</b>' else: if plink == 'inter': out = out + '<b>Open Interactive Version</b>' out = out + '</a><br />\n' out = out + '<b><a href="javascript:popitup(\'' + web_address out = out + '/how_to_create_plots.html\')" style="text-align:right">' out = out + 'How the Plots Are Created</a></b><br />\n' # #--- prev and next msid # out = out + make_msid_link(msid, msid_list, group, ltype, mtype, ptype) out = out + '</div>\n' # #--- title of the page # out = out + set_title(msid, descrip, ltype, mtype, ptype) # #--- popup limit table link # out = out + '<div style="paddng-top:10px"><h3>' out = out + 'Open <a href="javascript:popitup(\'' + file_name + '\')" ' out = out + 'style="text-align:right">Limit Table</a>.' out = out + '</h3>\n' out = out + '</div>\n' # #--- link to the other type of length plots # out = out + create_period_link(other_list) # #--- interactive page case # if plotname == "": if (pout == False) or (str(pout) == 'na'): out = out + '<h3 style="padding-top:200px;padding-bottom:200px">No Data/No Plot</h3>' else: out = out + '<div style="margin-left:-30px;">' out = out + pout out = out + '</div>' out = out + chs.read_template('interact_descript') # #--- static page case # else: out = out + '<img src="' + plotname + '" width=80%>' phpfile = web_address + "Interactive/msid_data_interactive.php" int_note = web_address + 'interactive_note.html' out = out + '<div style="padding-bottom:10px;font-size:90%;">\n'; if group.lower() in exclude_from_interactive: out = out + '<h3>This Data Set Cannot Produce an Interactive Plot</h3>\n' else: out = out + '<h3>Create an Interactive Plot (' out = out + '<a href="javascript:popitup(\'' + int_note + '\')" ' out = out + 'style="text-align:right">Usage Note</a>' out = out + ')</h3>\n' out = out + '<form method="post" action=' + phpfile + '>\n' out = out + '<b>Starting Time:</b> <input type="text" name="tstart" size=20>\n' out = out + '<b>Stopping Time:</b> <input type="text" name="tstop" size=20>\n' out = out + '<b>Bin Size:</b> <input type="text" name="binsize" ' out = out + 'value=300.0 size=10>\n ' out = out + '<input type="hidden" name="ltype" value="' + ltype + '">\n' out = out + '<input type="hidden" name="mtype" value="' + mtype + '">\n' out = out + '<input type="hidden" name="msid" value="' + msid + '">\n' out = out + '<input type="hidden" name="group" value="' + group + '">\n' out = out + '</br><span style="text-align:right;"><input type=submit ' out = out + 'name="submit" value="Submit"></span>\n' out = out + '<br />\n' out = out + '</form>\n' out = out + '</div>\n' # #--- add the derivative plot # dplotname = web_address + group.capitalize() + '/' + msid.capitalize() dplotname = dplotname + '/Plots/' + msid + '_' + ltype + '_' + mtype + '_dev.png' out = out + '<h3>Derivative Plot</h3>\n' out = out + '<img src="' + dplotname + '" width=80%>' # #--- add the link to other plots in a table format # [lout, gname] = get_group_names(msid, group, ltype, mtype, ptype) if lout != '': out = out + '<h3>Other msids in this group: ' + gname + '</h3>' out = out + lout # #--- close html page # out = out + chs.read_template('html_close') # #--- write out the html data # with open(hname, 'w') as fo: fo.write(out)
def create_html(catg, msid_list, ytime, udict, ddict, dtype, mtype, ptype='static'): """ create a html page for category <catg> input: catg --- category of the msids msid_list --- a list of msids of the category ytime --- current time udict --- a dictionary of unit: <msid> <---> <unit> ddict --- a dictionary of description: <msid> <---> <description> dtype --- date length: week, short, year, five, long mtype --- data type: mid, min, max output: <catg>_main.html """ # #--- create links to other pages # line = '<!DOCTYPE html>\n<html>\n<head>\n\t<title>Envelope Trending Plots: ' line = line + catg.upper() + '</title>\n' line = line + '</head>\n<body style="width:95%;margin-left:10px; margin-right;' line = line + '10px;background-color:#FAEBD7;' line = line + 'font-family:Georgia, "Times New Roman", Times, serif">\n\n' line = line + '<div style="float:right;padding-right:50px;font-size:120%">\n' line = line + '<a href="../mta_trending_main.html" ' line = line + 'style="float:right;padding-right:50px;font-size:80%">' line = line + '<b>Back to Top</b></a><br />\n' line = line + '</div>\n' line = line + '<h3 style="padding-bottom:0px">' + catg.upper() + ' ' if ptype == 'static': line = line + '<br /> Static Version: ' else: line = line + '<br /> Interactive Version: ' if mtype == 'min': line = line + ' Min --- ' elif mtype == 'max': line = line + ' Max --- ' else: line = line + ' Mean --- ' if dtype == 'week': line = line + ' One Week ' elif dtype == 'short': line = line + ' Last Three Months ' elif dtype == 'year': line = line + ' Last One Years ' elif dtype == 'five': line = line + ' Last Five years ' else: line = line + ' Full Range ' line = line + '</h3>\n' # #--- link to the other plot category # line = line + create_link_names(catg, dtype, mtype, ptype) line = line + '<p style="margin-left:35px; margin-right:35px;">' line = line + '<em><b>Delta/Yr</b></em> below is a slope of the liear fitting ' line = line + 'over the data of the period. ' line = line + '<em><b>Delta/Yr/Yr</b></em> is a slope of the liner fitting ' line = line + 'over the devivative data of the period. <em><b>Slope</b></em> ' line = line + 'listed on a linked plot is the slope computed on ' line = line + 'the last few periods of the data to show the direction of the trend, ' line = line + 'and different from that of Delta/Yr.</p>' line = line + '<div style="padding-bottom:30px;"></div>' line = line + '<div style="text-align:center">\n\n' line = line + '<table border=1 cellspacing=2 style="margin-left:auto;margin-right:auto;' line = line + 'text-align:center;">\n' line = line + '<th>MSID</th><th> </th><th>Mean</th><th>RMS</th><th>Delta/Yr</th><th>Delta/Yr/Yr</th>' line = line + '<th>Unit</th><th>Description</th><th>Limit Violation</th>\n' # #--- create a table with one row for each msid # violation_save = [] for msid in msid_list: # #--- check whether plot html file exist # cfile = check_plot_existance(msid, catg, dtype, mtype, ptype) if cfile == False: continue [states, fit_dict] = extract_data(catg, msid, dtype, mtype) slen = len(states) try: unit = udict[msid] discp = ddict[msid] # #--- convert all F and most C temperature to K, exception: if the uint is "C", leave as it is # if unit == 'DEGF': unit = 'K' elif unit == 'DEGC': if msid[:-2].lower() != 'tc': unit = 'K' except: unit = '---' discp = msid xfile = cfile.replace('www\/', '') ctemp = re.split('\/', cfile) xfile = ctemp[-2] + '/' + ctemp[-1] # #--- for the case there are more than one state # if slen > 1: line = line + '<tr>\n' line = line + '<th rowspan=' + str(slen) + '>' line = line + '<a href="' + xfile + '">' + msid + '</a></th>' for k in range(0, slen): state = states[k] fit_save = fit_dict[state] [avg, std] = set_avg_std(fit_save[0], fit_save[1]) [fline, dline] = set_slope_lines(fit_save[2], fit_save[3], \ fit_save[4], fit_save[5]) # #--- check violation status; if it is 'na', there is no data # [vnote, color] = create_status(msid, dtype, mtype, state, catg, ytime) if color != 'black': violation_save.append([msid, vnote]) if slen == 1 and state == 'none': state = ' ' line = line + '<td>' + state + '</td>' line = line + '<td>' + str(avg) + '</td>' line = line + '<td>' + str(std) + '</td>' line = line + '<td>' + fline + '</td>' line = line + '<td>' + dline + '</td>' if k == 0: line = line + '<td rowspan=' + str( slen) + '>' + unit + '</td>' line = line + '<td rowspan=' + str( slen) + '>' + discp + '</td>' line = line + '<th style="font-size:90%;color:' + color + ';padding-left:10px;' line = line + 'padding-right:10px">' + vnote + '</th>\n</tr>\n' # #--- for the case there is only one state # else: fit_save = fit_dict[states[0]] [avg, std] = set_avg_std(fit_save[0], fit_save[1]) [fline, dline] = set_slope_lines(fit_save[2], fit_save[3], \ fit_save[4], fit_save[5]) [vnote, color] = create_status(msid, dtype, mtype, 'none', catg, ytime) if color != 'black': violation_save.append([msid, vnote]) line = line + '<tr>\n<th><a href="' + xfile + '">' + msid + '</a></th>' line = line + '<th> </th><td>' + str(avg) + '</td><td>' line = line + str(std) + '</td><td>' + fline + '</td>' line = line + '<td>' + dline + '</td><td>' + unit + '</td><td>' + discp + '</td>' line = line + '<th style="font-size:90%;color:' + color + ';padding-left:10px;' line = line + 'padding-right:10px">' + vnote + '</th>\n</tr>\n' line = line + '</table>\n' line = line + '</div>\n' out = mcf.today_date_display2() fout = chs.read_template('html_close', repl=[['#TODAY#', out]]) line = line + fout # #--- category html has the tail of "_main.html" # try: name = create_out_name(catg, dtype, mtype, ptype) with open(name, 'w') as fo: fo.write(line) except: pass # #--- update violation file; this will be used by the top html page # if mtype == 'mid': vout = web_dir + catg + '/violations' if len(violation_save) == 0: mcf.rm_files(vout) else: line = '' for ent in violation_save: if len(ent[0]) < 8: line = line + ent[0] + '\t\t' + ent[1] + '\n' else: line = line + ent[0] + '\t' + ent[1] + '\n' with open(vout, 'w') as fo: fo.write(line)