def create_plot(): (candidatos, porcentajes) = get_plot_data() # (candidatos, porcentajes) = json_load_unicode("databokeh.json") primero, segundo = porcentajes[:2] falta = min(45, max(40 , (segundo + 10))) - primero if falta <= 0: sobra = -falta fserie = [sobra] + [0] * 5 porcentajes[0] -= sobra resultado = "Gana %s en Primera Vuelta" % candidatos[0] PALETTE = ["#54BBE2", "#5EDF4D"] data = OrderedDict([("porcentajes", porcentajes), ("sobra", fserie)]) else: PALETTE = ["#54BBE2", "#E5162A"] fserie = [falta] + [0] * 5 resultado = "Hay Ballotage" data = OrderedDict([("porcentajes", porcentajes), ("falta", fserie)]) # build a dict containing the grouped data output_file("primervueltometro.html") # Flyer derecho fijo : 300 x 500 # Zonas de columna auxiliar : 300 x 300 (1er y 2do rolado) # Puente largo : 975 x 80 # Puente corto : 650 x 80 width, height = 300, 300 z = 2 width *= z height *= z params = { "title": resultado, "stacked": True, "width": width, "height": height, "tools": "", "palette": PALETTE, "legend": 'top_right' } bar = Bar(data, candidatos, **params) show(bar)
def create_plot(): candidatos, (porcentajes, falta) = get_plot_data() if falta <= 0: sobra = -falta fserie = [sobra] + [0] * 5 porcentajes[0] -= sobra resultado = "Gana %s en Primera Vuelta" % candidatos[0] data = OrderedDict([("porcentajes", porcentajes), ("sobra", fserie)]) else: fserie = [falta] + [0] * 5 resultado = "Hay Ballotage" data = OrderedDict([("porcentajes", porcentajes), ("falta", fserie)]) # build a dict containing the grouped data output_file("primervueltometro.html") # Flyer derecho fijo : 300 x 500 # Zonas de columna auxiliar : 300 x 300 (1er y 2do rolado) # Puente largo : 975 x 80 # Puente corto : 650 x 80 width, height = 300, 300 z = 2 width *= z height *= z params = { "title": "PrimerVueltómetro: %s" % resultado, "stacked": True, "width": width, "height": height, "tools": "", "palette": PALETTE, "legend": 'top_right' } bar = Bar(data, candidatos, **params) show(bar)
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)
from collections import OrderedDict import pandas as pd from bokeh._legacy_charts import Bar, output_file, show from bokeh.sampledata.olympics2014 import data df = pd.io.json.json_normalize(data['data']) # filter by countries with at least one medal and sort df = df[df['medals.total'] > 0] df = df.sort("medals.total", ascending=False) # get the countries and we group the data by medal type countries = df.abbr.values.tolist() gold = df['medals.gold'].astype(float).values silver = df['medals.silver'].astype(float).values bronze = df['medals.bronze'].astype(float).values # build a dict containing the grouped data medals = OrderedDict(bronze=bronze, silver=silver, gold=gold) # any of the following commented are also alid Bar inputs #medals = pd.DataFrame(medals) #medals = list(medals.values()) output_file("stacked_bar.html") bar = Bar(medals, countries, title="Stacked bars", stacked=True) show(bar)