def make_bar(color, data): plot = Bar(data, width=200, height=200, palette=[color, COLOR_PRIMARY_DARK], tools='', stacked=True) plot.toolbar_location = None plot.outline_line_color = None plot.min_border = 5 plot.y_range = Range1d(0, 10) # Get chart items legend = plot.select({'type': Legend}) hover = plot.select({'type': HoverTool}) glyphs = plot.select({'type': GlyphRenderer}) xaxis = plot.select({'type': CategoricalAxis}) yaxis = plot.select({'type': LinearAxis}) ygrid = plot.select({'type': Grid}) # Format chart properties plot.toolbar_location = None plot.background_fill = COLOR_PRIMARY plot.border_fill = COLOR_PRIMARY plot.outline_line_color = None plot.min_border_top = 0 # Format legent legend.label_text_color = COLOR_PRIMARY_CONTRAST legend.border_line_color = COLOR_PRIMARY_CONTRAST # Tweak hover hover.tooltips = [('hours', '$y')] hover.point_policy = 'follow_mouse' # Format plots for g in glyphs: g.glyph.fill_alpha = 1 g.glyph.line_color = None # Set xaxis properties xaxis.major_label_text_color = COLOR_PRIMARY_CONTRAST xaxis.major_label_orientation = 0 xaxis.major_label_standoff = 15 xaxis.major_tick_out = None xaxis.major_tick_in = None xaxis.axis_line_color = None # Set yaxis properties yaxis.major_label_text_color = COLOR_PRIMARY_CONTRAST yaxis.major_tick_out = None yaxis.major_tick_in = None yaxis.axis_line_color = None yaxis.ticker = SingleIntervalTicker(interval=3) ygrid.grid_line_color = None return plot
def bokehplot(): try: rundate = str( subprocess.check_output( 'ls ' + logfilepath + '| grep * | grep -o "[0-9]\+" | cut -c 1-8', shell=True)) except: rundate = str(time.strftime("%Y%m%d")) path = logfilepath + '/*.log' files = glob.glob(path) allduration = [] allstatus = [] allstart = [] allend = [] onlyfilenamelist = [] for file in files: head, onlyfilename = os.path.split(file) onlyfilename = onlyfilename[:-13] onlyfilenamelist.append(onlyfilename) try: # dont think we need complete complete = subprocess.check_output( 'tail -8 ' + file + ' | grep -o "Query complete:.*" | cut -f 2 -d ":" ', shell=True) duration = subprocess.check_output( 'tail -8 ' + file + ' | grep -o "Duration.*" | cut -f 2 -d ":" ', shell=True) status = subprocess.check_output( 'tail -8 ' + file + ' | grep -o "Status.*" | cut -f 2 -d ":" ', shell=True) starttime = subprocess.check_output( 'tail -8 ' + file + '| grep -e Start' + '| awk -F "Start Time:"' + " '{print $2}' ", shell=True) endtime = subprocess.check_output( 'tail -8 ' + file + '| grep -e End' + '| awk -F "End Time:"' + " '{print $2}' ", shell=True) allduration.append(duration) allstatus.append(status) allstart.append(starttime) allend.append(endtime) except: pass cleanupalllines = map(lambda s: s.strip(), onlyfilenamelist) cleanupduration = map(lambda s: s.strip(), allduration) cleanupstatus = map(lambda s: s.strip(), allstatus) cleanupstart = map(lambda s: s.strip(), allstart) cleanupend = map(lambda s: s.strip(), allend) sumd = 0 floatallduration = [] for item in cleanupduration: try: floatallduration.append(float(item)) sumd += float(item) except: pass zipper = zip(cleanupalllines, floatallduration, cleanupstatus, cleanupstart, cleanupend) df = pd.DataFrame(zipper) df = df.rename( columns={ 0: 'QUERY', 1: 'DURATION(MINS)', 2: 'STATUS', 3: 'START TIME', 4: 'END TIME' }) df['Col5'] = df['QUERY'].map(lambda x: str(x)[-8:]) df['QUERY'] = df['QUERY'].map(lambda x: str(x)[:-13]) df = df.rename(columns={'Col5': 'RunDate'}) df = df.sort_values(by='QUERY', ascending=True) df = df[df['STATUS'].isin(["SUCCESS"])] pivot = pd.pivot_table(df.reset_index(), index='QUERY', columns='RunDate', values='DURATION(MINS)') pivot = pivot.fillna(0) TOOLS = 'crosshair,pan,wheel_zoom,box_zoom,reset,hover,previewsave' p = Bar(pivot, xlabel='QUERY', stacked=True, title="Log Query Comparison", legend='top_right', width=1100, height=800, tools=TOOLS) hover = p.select(dict(type=HoverTool)) script, div = components(p, INLINE) # output_file("bar.html") # show(p) html = render_template("bokeh.html", script=script, div=div) return encode_utf8(html)
def bokehplot(): try: rundate = str(subprocess.check_output( 'ls ' + logfilepath + '| grep * | grep -o "[0-9]\+" | cut -c 1-8', shell=True)) except: rundate = str(time.strftime("%Y%m%d")) path = logfilepath + '/*.log' files = glob.glob(path) allduration = [] allstatus = [] allstart = [] allend = [] onlyfilenamelist = [] for file in files: head, onlyfilename = os.path.split(file) onlyfilename = onlyfilename[:-13] onlyfilenamelist.append(onlyfilename) try: # dont think we need complete complete = subprocess.check_output('tail -8 ' + file + ' | grep -o "Query complete:.*" | cut -f 2 -d ":" ', shell=True) duration = subprocess.check_output('tail -8 ' + file + ' | grep -o "Duration.*" | cut -f 2 -d ":" ', shell=True) status = subprocess.check_output('tail -8 ' + file + ' | grep -o "Status.*" | cut -f 2 -d ":" ', shell=True) starttime = subprocess.check_output( 'tail -8 ' + file + '| grep -e Start' + '| awk -F "Start Time:"' + " '{print $2}' ", shell=True) endtime = subprocess.check_output( 'tail -8 ' + file + '| grep -e End' + '| awk -F "End Time:"' + " '{print $2}' ", shell=True) allduration.append(duration) allstatus.append(status) allstart.append(starttime) allend.append(endtime) except: pass cleanupalllines = map(lambda s: s.strip(), onlyfilenamelist) cleanupduration = map(lambda s: s.strip(), allduration) cleanupstatus = map(lambda s: s.strip(), allstatus) cleanupstart = map(lambda s: s.strip(), allstart) cleanupend = map(lambda s: s.strip(), allend) sumd = 0 floatallduration = [] for item in cleanupduration: try: floatallduration.append(float(item)) sumd += float(item) except: pass zipper = zip(cleanupalllines, floatallduration, cleanupstatus, cleanupstart, cleanupend) df = pd.DataFrame(zipper) df = df.rename(columns={0: 'QUERY', 1: 'DURATION(MINS)', 2: 'STATUS', 3: 'START TIME', 4: 'END TIME'}) df['Col5'] = df['QUERY'].map(lambda x: str(x)[-8:]) df['QUERY'] = df['QUERY'].map(lambda x: str(x)[:-13]) df = df.rename(columns={'Col5': 'RunDate'}) df = df.sort_values(by='QUERY', ascending=True) df = df[df['STATUS'].isin(["SUCCESS"])] pivot = pd.pivot_table(df.reset_index(), index='QUERY', columns='RunDate', values='DURATION(MINS)') pivot = pivot.fillna(0) TOOLS = 'crosshair,pan,wheel_zoom,box_zoom,reset,hover,previewsave' p = Bar(pivot, xlabel='QUERY', stacked=True, title="Log Query Comparison", legend='top_right', width=1100, height=800, tools=TOOLS) hover = p.select(dict(type=HoverTool)) script, div = components(p, INLINE) # output_file("bar.html") # show(p) html = render_template("bokeh.html", script=script, div=div) return encode_utf8(html)