def clean_the_input(line): """ check the input is numeric and if so, round to two decimal input: line --- input quantity output: line --- if it is a numeric value, a value of two decimal, otherwise, just return the value as it was """ if mcf.chkNumeric(line): line = str(ecf.round_up(float(line))) return line
def make_table_with_year(hlist, y_list, title, color): """ creata a html table for a give list of sub html page with year of violation input: hlist --- a list of sub html page names output: line --- a line contain html descriptions of a table """ if len(hlist) == 0: line = '' else: line = '<table border=1 cellpadding=5 style="margin-left:auto;margin-right:auto">\n' line = line + '<tr><th style="color:' + color + '">' + title + '</th><th>Predicted Year</th></tr>\n<tr>' ecnt = 0 for k in range(0, len(hlist)): msid = hlist[k] year = y_list[k] line = line + '<td><a href="' + web_address + 'Htmls/' + msid + '_plot.html">' + msid + '</a></td>\n' line = line + '<td>' + str(ecf.round_up(year)) + '</td></tr>\n' line = line + '</table>\n' return line
def make_table_with_year(hlist, y_list, title, color): """ creata a html table for a give list of sub html page with year of violation input: hlist --- a list of sub html page names output: line --- a line contain html descriptions of a table """ if len(hlist) == 0: line = '' else: line = '<table border=1 cellpadding=5 style="margin-left:auto;margin-right:auto">\n' line = line + '<tr><th style="color:' + color +'">' + title + '</th><th>Predicted Year</th></tr>\n<tr>' ecnt = 0 for k in range(0, len(hlist)): msid = hlist[k] year = y_list[k] line = line + '<td><a href="' + web_address + 'Htmls/' + msid + '_plot.html">' + msid + '</a></td>\n' line = line + '<td>' + str(ecf.round_up(year)) + '</td></tr>\n' line = line + '</table>\n' return line
def unit_modification(val, tchk): """ modify value depending on unit input: val --- original value tchk --- whether this is temp and need to be converted into k if degc tchk = 1 degf tchk = 2 psia tchk = 3 output: val --- updated value """ tchk = int(float(tchk)) if tchk == 1: val += 273.15 #--- C to K conversion elif tchk == 2: val = ecf.f_to_k(val) #--- F to K conversion elif tchk == 3: val /= 0.145038 #--- kp to psia conversion # #--- round off the value to 2 dicimal points # val = ecf.round_up(val) return val
def create_violation_notification(msid, pdata, min_a, min_b, max_a, max_b, tmax): """ check violation and create notification input: msid --- msid pdata --- data set (see "read_data" for details) min_a --- intercept value of the lower envelope prediction min_b --- slope value of the lower envelope prediction max_a --- intercept value of the upper envelope prediction max_b --- slope value of the upper envelope prediction tmax --- prediction ending point in time output: line --- lower violation description (can be empty) line2 --- upper violation description (can be empty0 pchk_l --- indicator of whether there is lower violation (if 1) pchk_u --- indicator of whether there is upper violation (if 1) """ # #--- predict violation # line = '' line2 = '' yl_time = 0.0 yt_time = 0.0 rl_time = 0.0 rt_time = 0.0 pchk_l = 0 pchk_u = 0 # #--- check lower violations # vlimit = pdata[15][-1] if vlimit not in ['-999', '-998', '998', '999']: vtime1 = predict_violation(min_a, min_b, tmax, vlimit, side = 0) if vtime1 == tmax: line = 'The data are aready in Red Lower Violation' rl_time = -1.0 else: vlimit = pdata[13][-1] vtime2 = predict_violation(min_a, min_b, tmax, vlimit, side = 0) if vtime2 == tmax: line = 'The data are aready in Yellow Lower Violation' yl_time = -1.0 elif (vtime2 > 0) and (vtime2 < tmax + 5): line = 'The data may violate the lower yellow limit at Year: ' + str(ecf.round_up(vtime2)) yl_time = vtime2 pchk_l = 1 # #--- check upper violations # vlimit = pdata[16][-1] if vlimit not in ['-999', '-998', '998', '999']: vtime1 = predict_violation(min_a, min_b, tmax, vlimit, side = 1) if vtime1 == tmax: if line == '': line = 'The data are aready in Red Upper Violation' line2 = '' else: line2 = 'The data are aready in Red Upper Violation' rt_time = -1.0 else: vlimit = pdata[14][-1] vtime2 = predict_violation(max_a, max_b, tmax, vlimit, side = 1) if (vtime2 > 0) and (vtime2 < tmax + 5): if line == '': if vtime2 == tmax: line = 'The data are aready in Yellow Upper Violation' yt_time = -1.0 else: line = 'The data may violate the upper yellow limit at Year: ' + str(ecf.round_up(vtime2)) line2 = '' yt_time = vtime2 pchk_u = 1 else: if vtime2 == tmax: line2 = 'The data are aready in Yellow Upper Violation' yt_time = -1.0 else: line2 = 'The data may violate the upper yellow limit at Year: ' + str(ecf.round_up(vtime2)) yt_time = vtime2 pchk_u = 1 # #-- update violation time estimate database # vtdata = [yl_time, yt_time, rl_time, rt_time] ved.incert_data(msid, vtdata) return [line, line2, pchk_l, pchk_u]
def compute_stats(data, y_min, y_max, r_min, r_max): """ compute basic statistics for the given data input: data --- data y_min --- yellow lower limit y_max --- yellow upper limit r_min --- red lower limit r_max --- red upper limit output: a list of stat results: cnt --- number of the data points avg --- mean med --- median dmin --- min dmax --- max y_min_cnt --- the number of times the data violoated the lower yellow limit y_max_cnt --- the number of times the data violoated the upper yellow limit r_min_cnt --- the number of times the data violoated the lower red limit r_max_cnt --- the number of times the data violoated the upper red limit """ # #--- remove out layers # data.sort() dlen = len(data) cut = int(0.025 * dlen) ndata = data[cut:dlen - cut] if len(ndata) == 0: ndata = data darray = numpy.array(ndata) # #--- compute data statistics # cnt = len(data) avg = ecf.round_up(numpy.mean(darray)) med = ecf.round_up(numpy.median(darray)) std = ecf.round_up(numpy.std(darray)) dmin = ecf.round_up(min(ndata)) dmax = ecf.round_up(max(ndata)) # #--- fine the numbers of times the data violated limits #--- if they is no limit (998, 999 etc), just use huge numbers as limit # if r_min in [-999, -998, -99]: r_min = -1.0e12 if y_min in [-999, -998, -99]: y_min = -1.0e12 if r_max in [999, 998, 99]: r_max = 1.0e12 if y_max in [999, 998, 99]: y_max = 1.0e12 y_min_cnt = 0 y_max_cnt = 0 r_min_cnt = 0 r_max_cnt = 0 for k in range(0, cnt): if data[k] < r_min: r_min_cnt += 1 elif data[k] < y_min: y_min_cnt += 1 if data[k] > r_max: r_max_cnt += 1 elif data[k] > y_max: y_max_cnt += 1 return [ cnt, avg, med, std, dmin, dmax, y_min_cnt, y_max_cnt, r_min_cnt, r_max_cnt ]
def create_violation_notification(msid, pdata, min_a, min_b, max_a, max_b, tmax): """ check violation and create notification input: msid --- msid pdata --- data set (see "read_data" for details) min_a --- intercept value of the lower envelope prediction min_b --- slope value of the lower envelope prediction max_a --- intercept value of the upper envelope prediction max_b --- slope value of the upper envelope prediction tmax --- prediction ending point in time output: line --- lower violation description (can be empty) line2 --- upper violation description (can be empty0 pchk_l --- indicator of whether there is lower violation (if 1) pchk_u --- indicator of whether there is upper violation (if 1) """ # #--- predict violation # line = '' line2 = '' yl_time = 0.0 yt_time = 0.0 rl_time = 0.0 rt_time = 0.0 pchk_l = 0 pchk_u = 0 # #--- check lower violations # vlimit = pdata[15][-1] if vlimit not in ['-999', '-998', '998', '999']: vtime1 = predict_violation(min_a, min_b, tmax, vlimit, side=0) if vtime1 == tmax: line = 'The data are aready in Red Lower Violation' rl_time = -1.0 else: vlimit = pdata[13][-1] vtime2 = predict_violation(min_a, min_b, tmax, vlimit, side=0) if vtime2 == tmax: line = 'The data are aready in Yellow Lower Violation' yl_time = -1.0 elif (vtime2 > 0) and (vtime2 < tmax + 5): line = 'The data may violate the lower yellow limit at Year: ' + str( ecf.round_up(vtime2)) yl_time = vtime2 pchk_l = 1 # #--- check upper violations # vlimit = pdata[16][-1] if vlimit not in ['-999', '-998', '998', '999']: vtime1 = predict_violation(min_a, min_b, tmax, vlimit, side=1) if vtime1 == tmax: if line == '': line = 'The data are aready in Red Upper Violation' line2 = '' else: line2 = 'The data are aready in Red Upper Violation' rt_time = -1.0 else: vlimit = pdata[14][-1] vtime2 = predict_violation(max_a, max_b, tmax, vlimit, side=1) if (vtime2 > 0) and (vtime2 < tmax + 5): if line == '': if vtime2 == tmax: line = 'The data are aready in Yellow Upper Violation' yt_time = -1.0 else: line = 'The data may violate the upper yellow limit at Year: ' + str( ecf.round_up(vtime2)) line2 = '' yt_time = vtime2 pchk_u = 1 else: if vtime2 == tmax: line2 = 'The data are aready in Yellow Upper Violation' yt_time = -1.0 else: line2 = 'The data may violate the upper yellow limit at Year: ' + str( ecf.round_up(vtime2)) yt_time = vtime2 pchk_u = 1 # #-- update violation time estimate database # vtdata = [yl_time, yt_time, rl_time, rt_time] ved.incert_data(msid, vtdata) return [line, line2, pchk_l, pchk_u]
def compute_stats(data, y_min, y_max, r_min, r_max): """ compute basic statistics for the given data input: data --- data y_min --- yellow lower limit y_max --- yellow upper limit r_min --- red lower limit r_max --- red upper limit output: a list of stat results: cnt --- number of the data points avg --- mean med --- median dmin --- min dmax --- max y_min_cnt --- the number of times the data violoated the lower yellow limit y_max_cnt --- the number of times the data violoated the upper yellow limit r_min_cnt --- the number of times the data violoated the lower red limit r_max_cnt --- the number of times the data violoated the upper red limit """ # #--- remove out layers # data.sort() dlen = len(data) cut = int(0.025 * dlen) ndata = data[cut:dlen-cut] if len(ndata) == 0: ndata = data darray = numpy.array(ndata) # #--- compute data statistics # cnt = len(data) avg = ecf.round_up(numpy.mean(darray)) med = ecf.round_up(numpy.median(darray)) std = ecf.round_up(numpy.std(darray)) dmin = ecf.round_up(min(ndata)) dmax = ecf.round_up(max(ndata)) # #--- fine the numbers of times the data violated limits #--- if they is no limit (998, 999 etc), just use huge numbers as limit # if r_min in [-999, -998, -99]: r_min = -1.0e12 if y_min in [-999, -998, -99]: y_min = -1.0e12 if r_max in [999, 998, 99]: r_max = 1.0e12 if y_max in [999, 998, 99]: y_max = 1.0e12 y_min_cnt = 0 y_max_cnt = 0 r_min_cnt = 0 r_max_cnt = 0 for k in range(0, cnt): if data[k] < r_min: r_min_cnt += 1 elif data[k] < y_min: y_min_cnt += 1 if data[k] > r_max: r_max_cnt += 1 elif data[k] > y_max: y_max_cnt += 1 return [cnt, avg, med, std, dmin, dmax, y_min_cnt, y_max_cnt, r_min_cnt, r_max_cnt]