def find_violation():
    """
    find msids which violate yellow and/or red upper and lower limits
    input:  none but read from sqlite database (<house_keeping>/v_table.sqlite3
    output: v_list  --- a list of msids
            vdict   --- a dictionary of msids<--->[yl_lim, yt_lim, rl_lim, rt_lim]
    """
    #
    #--- find which msids have the sub html page cared
    #
    cmd = 'ls ' + web_dir + '*_plot.html > ' + zspace
    os.system(cmd)

    data = ecf.read_file_data(zspace, 1)

    v_list = []
    vdict = {}
    for ent in data:
        atemp = re.split('\/', ent)
        btemp = re.split('_plot', atemp[-1])
        msid = btemp[0]
        #
        #--- check the violation status of the msid from the database
        #
        out = ved.read_v_estimate(msid)
        chk = 0
        for test in out:
            if (test != 0) or (test != na):
                chk = 1
                break
        if chk > 0:
            v_list.append(msid)
            vdict[msid] = out

    return [v_list, vdict]
def find_violation():
    """
    find msids which violate yellow and/or red upper and lower limits
    input:  none but read from sqlite database (<house_keeping>/v_table.sqlite3
    output: v_list  --- a list of msids
            vdict   --- a dictionary of msids<--->[yl_lim, yt_lim, rl_lim, rt_lim]
    """
#
#--- find which msids have the sub html page cared
#
    cmd = 'ls ' + web_dir + '*_plot.html > ' + zspace
    os.system(cmd)

    data  = ecf.read_file_data(zspace, 1)

    v_list = []
    vdict  = {}
    for ent in data:
        atemp = re.split('\/', ent)
        btemp = re.split('_plot', atemp[-1])
        msid  = btemp[0]
#
#--- check the violation status of the msid from the database
#
        out   = ved.read_v_estimate(msid)
        chk   = 0
        for test in out:
            if (test != 0) or (test != na):
                chk = 1
                break
        if  chk > 0:
            v_list.append(msid)
            vdict[msid] = out

    return [v_list, vdict]
Example #3
0
def create_status(msid, group,  ytime):
    """
    check the status of the msid and return an appropriate comment
    input:  msid    --- msid
            group   --- group name
            ytime   --- corrent time
    output: [<comment>, <font color>]
    """
#
#--- read violation status of the msid
#
    if group in sub_group_list:
        tmsid = msid + '_' + group.lower()
    else:
        tmsid = msid

    out   = ved.read_v_estimate(tmsid)
#
#--- if there is no data, tell so and return
#
    if len(out) < 4:
        return ["No Violation Check", 'black']
#
#--- if all entries are "0", no violation
#
    chk = 0
    for k in range(0, 4):
        if out[k] != 0.0:
            chk =1
            break

    if chk == 0:
        return ["No Violation", 'black']
#
#--- if there are violation, create the description and choose a color for it
#
    else:
        line  = ''
        line0 = ''
        line1 = ''
        line2 = ''
        line3 = ''
        color = 'black'
        if out[0] != 0:
            if out[0] < ytime:
                line0 = 'Already Lower Yellow Violation'
                color = '#FF8C00'
            else:
                line0 = "Yellow Lower Violation: " + clean_the_input(out[0])
                color = '#FF8C00'

        if out[1] != 0:
            if out[1] < ytime:
                line1 = 'Already Upper Yellow Violation'
                color = '#FF8C00'
            else:
                line1 = "Yellow Upper Violation: " + clean_the_input(out[1])
                color = '#FF8C00'

        if out[2] != 0:
            if out[2] < ytime:
                line2 = 'Already Lower Red Violation'
                color = 'red'
            else:
                line2 = "Red Lower Violation: " + clean_the_input(out[2])
                color = 'red'

        if out[3] != 0:
            if out[3] < ytime:
                line3 = 'Already Upper Red Violation'
                color = 'red'
            else:
                line3 = "Red Upper Violation: " + clean_the_input(out[3])
                color = 'red'

        if line2 != '':
            line =  line2
            color = 'red'
        else:
            if line0 != '':
                line = line0
                color = '#FF8C00'


        if line3 != '':
            if line != '':
                line = line + '<br />' + line3
                color = 'red'
            else:
                line = line3
                color = 'red'
        else:
            if line1 != '':
                if line != '':
                    line = line + '<br />' + line1
                    if color == 'black':
                        color = '#FF8C00'
                else:
                    line = line1
                    color = '#FF8C00'


        return [line, color]
def create_html(catg, h_list, ytime, udict, ddict):
    """
    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>
    output: <catg>_main.html
    """

    line = '<!DOCTYPE html>\n<html>\n<head>\n\t<title>Envelope Trending  Plots: ' + catg.upper() + '</title>\n'
    line = line + '</head>\n<body style="width:95%;margin-left:10px; margin-right;10px;background-color:#FAEBD7;'
    line = line + 'font-family:Georgia, "Times New Roman", Times, serif">\n\n'
    line = line + '<a href="' + web_address + 'envelope_main.html" '
    line = line + 'style="float:right;padding-right:50px;font-size:120%"><b>Back to Top</b></a>\n'

    line = line + '<h3>' + catg.upper() + '</h3>\n'

    line = line + '<div style="text-align:center">\n\n'
    line = line + '<table border=1 cellspacing=2 style="margin-left:auto;margin-right:auto;text-align:center;">\n'
    line = line + '<th>MSID</th><th>Unit</th><th>Description</th><th>Limit Violation</th>\n'
#
#--- create a table with one row for each msid
#
    for ent in h_list:
        atemp = re.split('_plot', ent)
        msid  = atemp[0]
#
#--- check whether plot html file exist
#
        if check_plot_existance(msid, pchk=0) == 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
#
        vout  = ved.read_v_estimate(msid)

        [vnote, color] = create_status(msid, ytime)

        if check_plot_existance(msid) == False:
            line = line + '<tr>\n<th>' + msid +'</a></th>'
            line = line + '<td>' + unit +'</td><td>' + discp + '</td>'
            line = line + '<th style="font-size:90%;color:#B22222;padding-left:10px;padding-right:10px">No Data</th>\n</tr>\n'
        else:
            line = line + '<tr>\n<th><a href="'+ web_address  + 'Htmls/' + ent + '">' + msid +'</a></th>'
            line = line + '<td>' + unit +'</td><td>' + discp + '</td>'
            line = line + '<th style="font-size:90%;color:' + color + ';padding-left:10px;padding-right:10px">' + vnote + '</th>\n</tr>\n'

    line = line + '</table>\n'

    line = line + '</div>\n'

    line = line + '</body>\n</html>\n'
#
#--- category html has the tail of "_main.html"
#
    name = web_dir + catg.lower() + '_main.html'
    fo   = open(name, 'w')
    fo.write(line)
    fo.close()
def create_status(msid, ytime):
    """
    check the status of the msid and return an appropriate comment
    input:  msid    --- msid
            ytime   --- corrent time
    output: [<comment>, <font color>]
    """
#
#--- read violation status of the msid
#
    out   = ved.read_v_estimate(msid)
#
#--- if there is no data, tell so and return
#
    if len(out) < 4:
        return ["No Violation Check", 'black']
#
#--- if all entries are "0", no violation
#
    chk = 0
    for k in range(0, 4):
        if out[k] != 0.0:
            chk =1
            break

    if chk == 0:
        return ["No Violation", 'black']
#
#--- if there are violation, create the description and choose a color for it
#
    else:
        line  = ''
        line0 = ''
        line1 = ''
        line2 = ''
        line3 = ''
        color = 'black'
        if out[0] != 0:
            if out[0] < ytime:
                line0 = 'Already Lower Yellow Violation'
                color = '#FF8C00'
            else:
                line0 = "Yellow Lower Violation: " + clean_the_input(out[0])
                color = '#FF8C00'

        if out[1] != 0:
            if out[1] < ytime:
                line1 = 'Already Upper Yellow Violation'
                color = '#FF8C00'
            else:
                line1 = "Yellow Upper Violation: " + clean_the_input(out[1])
                color = '#FF8C00'

        if out[2] != 0:
            if out[2] < ytime:
                line2 = 'Already Lower Red Violation'
                color = 'red'
            else:
                line2 = "Red Lower Violation: " + clean_the_input(out[2])
                color = 'red'

        if out[3] != 0:
            if out[3] < ytime:
                line3 = 'Already Upper Red Violation'
                color = 'red'
            else:
                line3 = "Red Upper Violation: " + clean_the_input(out[3])
                color = 'red'

        if line2 != '':
            line =  line2
            color = 'red'
        else:
            if line0 != '':
                line = line0
                color = '#FF8C00'


        if line3 != '':
            if line != '':
                line = line + '<br />' + line3
                color = 'red'
            else:
                line = line3
                color = 'red'
        else:
            if line1 != '':
                if line != '':
                    line = line + '<br />' + line1
                    if color == 'black':
                        color = '#FF8C00'
                else:
                    line = line1
                    color = '#FF8C00'


        return [line, color]
Example #6
0
def create_html(catg, h_list, ytime, udict, ddict):
    """
    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>
    output: <catg>_main.html
    """

    line = '<!DOCTYPE html>\n<html>\n<head>\n\t<title>Envelope Trending  Plots: ' + catg.upper(
    ) + '</title>\n'
    line = line + '</head>\n<body style="width:95%;margin-left:10px; margin-right;10px;background-color:#FAEBD7;'
    line = line + 'font-family:Georgia, "Times New Roman", Times, serif">\n\n'
    line = line + '<a href="' + web_address + 'envelope_main.html" '
    line = line + 'style="float:right;padding-right:50px;font-size:120%"><b>Back to Top</b></a>\n'

    line = line + '<h3>' + catg.upper() + '</h3>\n'

    line = line + '<div style="text-align:center">\n\n'
    line = line + '<table border=1 cellspacing=2 style="margin-left:auto;margin-right:auto;text-align:center;">\n'
    line = line + '<th>MSID</th><th>Unit</th><th>Description</th><th>Limit Violation</th>\n'
    #
    #--- create a table with one row for each msid
    #
    for ent in h_list:
        atemp = re.split('_plot', ent)
        msid = atemp[0]
        #
        #--- check whether plot html file exist
        #
        if check_plot_existance(msid, pchk=0) == 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
#
        vout = ved.read_v_estimate(msid)

        [vnote, color] = create_status(msid, ytime)

        if check_plot_existance(msid) == False:
            line = line + '<tr>\n<th>' + msid + '</a></th>'
            line = line + '<td>' + unit + '</td><td>' + discp + '</td>'
            line = line + '<th style="font-size:90%;color:#B22222;padding-left:10px;padding-right:10px">No Data</th>\n</tr>\n'
        else:
            line = line + '<tr>\n<th><a href="' + web_address + 'Htmls/' + ent + '">' + msid + '</a></th>'
            line = line + '<td>' + unit + '</td><td>' + discp + '</td>'
            line = line + '<th style="font-size:90%;color:' + color + ';padding-left:10px;padding-right:10px">' + vnote + '</th>\n</tr>\n'

    line = line + '</table>\n'

    line = line + '</div>\n'

    line = line + '</body>\n</html>\n'
    #
    #--- category html has the tail of "_main.html"
    #
    name = web_dir + catg.lower() + '_main.html'
    fo = open(name, 'w')
    fo.write(line)
    fo.close()