def main(): sites = sys.argv[1:] if len(sites) == 0: print "Must specify at least one site to plot!" sys.exit(1) url_results = get_sites_data(sites) results = {} # Determine the maximum amount of work done: for pivot, groups in url_results.items(): all_gratia = [] all_gip = [] for group, data in groups.items(): all_gratia.append(data[0]) all_gip.append(data[1]) max_gratia = max(max(all_gratia), .1) max_gip = max(max(all_gip), .1) for group, data in groups.items(): groups[group] = data[0] / max_gratia, data[1] / max_gip for pivot, groups in url_results.items(): results_dict = {} results[pivot] = results_dict for group, data in groups.items(): results_dict[data] = .001 file = open(expand_string('$HOME/tmp/gip_vs_gratia.png', os.environ), 'w') SP = ScatterPlot() metadata = {'title': 'Gratia vs. GIP', \ 'subtitle': 'Sites %s' % ', '.join(sites), \ 'xlabel': 'Gratia reported normalized amount of work', \ 'ylabel': 'GIP reported normalized amount of work', \ 'height': '800', \ } SP(results, file, metadata)
def startPlot(self, output, results, metadata, encoding='UTF-8'): gen = self.startDocument(output, encoding) query_attrs = {} name = metadata.get('name', '') if name and len(name) > 0: query_attrs['name'] = name gen.startElement('query', query_attrs) gen.characters("\n\t\t") title = expand_string(metadata.get('title', ''), metadata.get('sql_vars', '')) if title and len(title) > 0: gen.startElement('title', {}) gen.characters(title) gen.endElement('title') gen.characters("\n\t\t") graph_type = metadata.get('graph_type', False) if graph_type and len(graph_type) > 0: gen.startElement('graph', {}) gen.characters(graph_type) gen.endElement('graph') gen.characters("\n\t\t") sql_string = str(metadata.get('sql', '')) gen.startElement('sql', {}) gen.characters(sql_string) gen.characters("\n\t\t") gen.endElement('sql') gen.characters("\n\t\t") self.write_sql_vars(results, metadata, gen) gen.characters("\n\t\t") base_url = None graphs = metadata.get('grapher', None) if graphs and 'base_url' in graphs.metadata: base_url = graphs.metadata['base_url'] else: print("Base URL not specified!") print(metadata) if graphs: print(graphs.metadata) else: print("Graphs not specified") pass my_base_url = self.metadata.get('base_url', '') gen.startElement('attr', {'name': 'base_url'}) gen.characters(my_base_url) gen.endElement('attr') gen.characters('\n\t\t') try: static_location = '/static/content' static_object = self.globals['static'] static_location = static_object.metadata.get('base_url', '/static') static_location += '/content' except: pass gen.startElement('attr', {'name': 'static_base_url'}) gen.characters(static_location) gen.endElement('attr') gen.characters('\n\t\t') self.write_graph_url(results, metadata, gen, base_url=base_url) gen.characters('\n\t\t') return gen
def main(): sites = sys.argv[1:] if len(sites) == 0: print "Must specify at least one site to plot!" sys.exit(1) url_results = get_sites_data(sites) results = {} # Determine the maximum amount of work done: for pivot, groups in url_results.items(): all_gratia = [] all_gip = [] for group, data in groups.items(): all_gratia.append(data[0]) all_gip.append(data[1]) max_gratia = max(max(all_gratia), .1) max_gip = max(max(all_gip), .1) for group, data in groups.items(): groups[group] = data[0]/max_gratia, data[1]/max_gip for pivot, groups in url_results.items(): results_dict = {} results[pivot] = results_dict for group, data in groups.items(): results_dict[data] = .001 file = open(expand_string('$HOME/tmp/gip_vs_gratia.png',os.environ),'w') SP = ScatterPlot() metadata = {'title': 'Gratia vs. GIP', \ 'subtitle': 'Sites %s' % ', '.join(sites), \ 'xlabel': 'Gratia reported normalized amount of work', \ 'ylabel': 'GIP reported normalized amount of work', \ 'height': '800', \ } SP(results, file, metadata)
def handle_results(self, results, metadata, **kw): template_data = self.get_common_template_data() results_table = self.cumulate_table(results) results_table.insert(0, self.get_titles_row(results_table, metadata)) results_table = self.set_gc_params(results_table,template_data, metadata) given_kw = metadata.get('given_kw',{}) title = given_kw.get('title',metadata.get('title','')) no_frame = given_kw.get('no_html_frame',False) in ['true', '1', 't', 'y', 'yes', 'TRUE', 'True', 'YES'] given_kw['title']=title template_data.params_defaults = json.dumps(metadata.get('sql_vars',{}),separators=(',',':'),cls=CustomDecimalDateObjectJSONEncoder) template_data.html_title = expand_string(title , given_kw) template_data.json_queries_desc = json.dumps(self.get_queries_description(template_data.base_url),separators=(',',':'),cls=CustomDecimalDateObjectJSONEncoder) template_data.json_results_table = json.dumps(results_table,separators=(',',':'),cls=CustomDecimalDateObjectJSONEncoder) template_data.json_metadata = json.dumps(metadata,separators=(',',':'),indent=2,cls=CustomDecimalDateObjectJSONEncoder) template_data.matplotlib_image_url = self.get_matplotlib_url(metadata) template_data.csv_url = self.get_csv_url(metadata) template_data.sql_string = str(metadata.get('sql','')) if no_frame: tmpl = lookup.get_template("query_no_frame.mako") else: tmpl = lookup.get_template("query.mako") template_data.params = self.params_as_ordered_tuple_list(metadata) return tmpl.render(tmpl_data=template_data)
def startPlot( self, output, results, metadata, encoding='UTF-8' ): gen = self.startDocument( output, encoding ) query_attrs = {} name = metadata.get('name','') if name and len(name) > 0: query_attrs['name'] = name gen.startElement('query', query_attrs) gen.characters("\n\t\t") title = expand_string( metadata.get('title',''), metadata.get('sql_vars','') ) if title and len(title) > 0: gen.startElement('title',{}) gen.characters( title ) gen.endElement( 'title' ) gen.characters("\n\t\t") graph_type = metadata.get('graph_type',False) if graph_type and len(graph_type) > 0: gen.startElement( 'graph',{} ) gen.characters( graph_type ) gen.endElement( 'graph' ) gen.characters("\n\t\t") sql_string = str(metadata.get('sql','')) gen.startElement( 'sql',{} ) gen.characters( sql_string ) gen.characters("\n\t\t") gen.endElement( 'sql' ) gen.characters("\n\t\t") self.write_sql_vars( results, metadata, gen ) gen.characters("\n\t\t") base_url = None graphs = metadata.get('grapher',None) if graphs and 'base_url' in graphs.metadata: base_url = graphs.metadata['base_url'] else: print("Base URL not specified!") print(metadata) if graphs: print(graphs.metadata) else: print("Graphs not specified") pass my_base_url = self.metadata.get('base_url','') gen.startElement( 'attr',{'name':'base_url'} ) gen.characters( my_base_url ) gen.endElement( 'attr' ) gen.characters('\n\t\t') try: static_location = '/static/content' static_object = self.globals['static'] static_location = static_object.metadata.get('base_url','/static') static_location += '/content' except: pass gen.startElement( 'attr',{'name':'static_base_url'} ) gen.characters( static_location ) gen.endElement( 'attr' ) gen.characters('\n\t\t') self.write_graph_url( results, metadata, gen, base_url=base_url ) gen.characters('\n\t\t') return gen
def handle_results(self, results, metadata, **kw): template_data = self.get_common_template_data() results_table = self.cumulate_table(results) results_table.insert(0, self.get_titles_row(results_table, metadata)) results_table = self.set_gc_params(results_table, template_data, metadata) given_kw = metadata.get('given_kw', {}) title = given_kw.get('title', metadata.get('title', '')) no_frame = given_kw.get('no_html_frame', False) in [ 'true', '1', 't', 'y', 'yes', 'TRUE', 'True', 'YES' ] given_kw['title'] = title template_data.params_defaults = json.dumps( metadata.get('sql_vars', {}), separators=(',', ':'), cls=CustomDecimalDateObjectJSONEncoder) template_data.html_title = expand_string(title, given_kw) template_data.json_queries_desc = json.dumps( self.get_queries_description(template_data.base_url), separators=(',', ':'), cls=CustomDecimalDateObjectJSONEncoder) template_data.json_results_table = json.dumps( results_table, separators=(',', ':'), cls=CustomDecimalDateObjectJSONEncoder) template_data.json_metadata = json.dumps( metadata, separators=(',', ':'), indent=2, cls=CustomDecimalDateObjectJSONEncoder) template_data.matplotlib_image_url = self.get_matplotlib_url(metadata) template_data.csv_url = self.get_csv_url(metadata) template_data.sql_string = str(metadata.get('sql', '')) if no_frame: tmpl = lookup.get_template("query_no_frame.mako") else: tmpl = lookup.get_template("query.mako") template_data.params = self.params_as_ordered_tuple_list(metadata) return tmpl.render(tmpl_data=template_data)
def main(): sites = sys.argv[1:] if len(sites) == 0: print "Must specify at least one site to plot!" sys.exit(1) url_results = get_sites_data(sites) results = {} # Determine the maximum amount of work done: for pivot, groups in url_results.items(): all_work = [] for group, data in groups.items(): all_work.append(data[0]) max_work = max(all_work) for group, data in groups.items(): groups[group] = data[0]/max_work, data[1] ugly_points = 0 bad_points = 0 points = 0 for pivot, groups in url_results.items(): results_dict = {} results[pivot] = results_dict for group, data in groups.items(): points += 1 if data[1] > .01 and data[0] > data[1] + .1: ugly_points += 1 if data[1] < .01 and data[0] > .1: bad_points += 1 results_dict[data] = .001 print "Good points: %i; Bad points: %i; Ugly points: %i." % (points, bad_points, ugly_points) file = open(expand_string('$HOME/tmp/avail_vs_work.png',os.environ),'w') SP = ScatterPlot() metadata = {'title': 'Computation hours vs. RSV Availability', \ 'subtitle': 'Sites %s' % ', '.join(sites), \ 'xlabel': 'Normalized amount of work', \ 'ylabel': 'RSV availability', \ } SP(results, file, metadata)
def main(): sites = sys.argv[1:] if len(sites) == 0: print "Must specify at least one site to plot!" sys.exit(1) url_results = get_sites_data(sites) results = {} # Determine the maximum amount of work done: for pivot, groups in url_results.items(): all_work = [] for group, data in groups.items(): all_work.append(data[0]) max_work = max(all_work) for group, data in groups.items(): groups[group] = data[0] / max_work, data[1] ugly_points = 0 bad_points = 0 points = 0 for pivot, groups in url_results.items(): results_dict = {} results[pivot] = results_dict for group, data in groups.items(): points += 1 if data[1] > .01 and data[0] > data[1] + .1: ugly_points += 1 if data[1] < .01 and data[0] > .1: bad_points += 1 results_dict[data] = .001 print "Good points: %i; Bad points: %i; Ugly points: %i." % ( points, bad_points, ugly_points) file = open(expand_string('$HOME/tmp/avail_vs_work.png', os.environ), 'w') SP = ScatterPlot() metadata = {'title': 'Computation hours vs. RSV Availability', \ 'subtitle': 'Sites %s' % ', '.join(sites), \ 'xlabel': 'Normalized amount of work', \ 'ylabel': 'RSV availability', \ } SP(results, file, metadata)
#!/usr/bin/env python import os, random from graphtool.graphs.common_graphs import QualityBarGraph from graphtool.tools.common import expand_string # First example - we have a bar graph with text labels data = {} for i in range(40): data['Team %i' % i] = random.random() metadata = {'title':'Quality Bar Example', 'title_size':20, 'text_size':10, 'fixed-height':False } file = open(expand_string('$HOME/tmp/quality_bar.png',os.environ),'w') QBG = QualityBarGraph() QBG(data, file, metadata)
#!/usr/bin/env python import time, os, random, datetime from graphtool.graphs.common_graphs import CumulativeGraph from graphtool.tools.common import expand_string span = 3600 max_value = 40 # Generate our time series def make_time_data( ): end_time = time.time(); end_time -= end_time % span begin_time = end_time - 24*span data = {} for i in range(begin_time, end_time, span): data[i] = random.random()*max_value return begin_time, end_time, data # Create and plot cumulative plot. CG = CumulativeGraph() begin_time, end_time, data1 = make_time_data() begin_time, end_time, data2 = make_time_data() data = {'Team A': data1, 'Team B': data2} metadata = {'title':'Some Cumulative Data', 'starttime':begin_time, 'endtime':end_time, 'span':span, 'is_cumulative':False } filename = expand_string('$HOME/tmp/cumulative.png',os.environ) file = open( filename, 'w' ) CG( data, file, metadata )
# Generate our time series def make_time_data(): end_time = time.time() end_time -= end_time % span begin_time = end_time - 24 * span data = {} for i in range(begin_time, end_time, span): data[i] = random.random() return begin_time, end_time, data QM = QualityMap() # Data generation full_data = {} for i in range(10): team_name = 'Team %i' % i begin_time, end_time, data = make_time_data() full_data[team_name] = data metadata = { 'title': 'Quality Plot w.r.t. Time', 'starttime': begin_time, 'endtime': end_time, 'span': span } filename = expand_string('$HOME/tmp/quality_map.png', os.environ) file = open(filename, 'w') QM(full_data, file, metadata)
#!/usr/bin/env python import os import sys sys.path.insert(0, os.path.expandvars('$GRAPHTOOL_ROOT/src')) from graphtool.tools.common import expand_string from graphtool.graphs.common_graphs import ScatterPlot import numpy numpts = 100 data = {} for site in ['Site A', 'Site B']: data1 = numpy.random.normal(size=numpts, loc=1.0) data2 = numpy.random.normal(size=numpts, loc=1.0) data3 = numpy.random.random(numpts) data[site] = {} for i in range(numpts): data[site][data1[i], data2[i]] = .1*data3[i] metadata = {'title':'Scatter Plot Example'} file = open(expand_string('$HOME/tmp/scatter.png',os.environ),'w') SP = ScatterPlot() SP(data, file, metadata)
#!/usr/bin/env python import os, random from graphtool.graphs.common_graphs import HorizontalStackedBarGraph from graphtool.tools.common import expand_string # First example - we have a bar graph with text labels data = {} # Second example - bar graph with integer labels, bar width 2 entry1 = {}; entry2 = {} for i in range(0,10,2): entry1[str(i)] = i**2 entry2[str(i)] = i data = {'Team A':entry1, 'Team B':entry2} metadata = {'title':'Horizontal Stacked Bar Example', 'title_size':20, 'text_size':17, 'fixed-height':False } file = open(expand_string('$HOME/tmp/horizontal_stacked_bar.png',os.environ),'w') HSBG = HorizontalStackedBarGraph() HSBG(data, file, metadata)
import time, os, random, datetime from matplotlib.dates import num2date from graphtool.graphs.common_graphs import QualityMap from graphtool.tools.common import expand_string span = 3600 # Generate our time series def make_time_data( ): end_time = time.time(); end_time -= end_time % span begin_time = end_time - 24*span data = {} for i in range(begin_time, end_time, span): data[i] = random.random() return begin_time, end_time, data QM = QualityMap() # Data generation full_data = {} for i in range(100): team_name = 'Team %i' % i begin_time, end_time, data = make_time_data() full_data[team_name] = data metadata = {'title':'Tall Quality Plot w.r.t. Time', 'starttime':begin_time, 'endtime':end_time, 'span':span, 'fixed-height':False } filename = expand_string('$HOME/tmp/quality_map_tall.png',os.environ) file = open( filename, 'w' ) QM( full_data, file, metadata )
#!/usr/bin/env python import os import sys sys.path.insert(0, os.path.expandvars('$GRAPHTOOL_ROOT/src')) from graphtool.tools.common import expand_string from graphtool.graphs.common_graphs import ScatterPlot import numpy numpts = 100 data = {} for site in ['Site A', 'Site B']: data1 = numpy.random.normal(size=numpts, loc=1.0) data2 = numpy.random.normal(size=numpts, loc=1.0) data3 = numpy.random.random(numpts) data[site] = {} for i in range(numpts): data[site][data1[i], data2[i]] = .1 * data3[i] metadata = {'title': 'Scatter Plot Example'} file = open(expand_string('$HOME/tmp/scatter.png', os.environ), 'w') SP = ScatterPlot() SP(data, file, metadata)
begin_time = end_time - 24*span data = {} for i in range(begin_time, end_time, span): data[i] = random.random()*max_value return begin_time, end_time, data # Our classes class TimeBarGraph( TimeGraph, BarGraph ): pass class TimeStackedBarGraph( TimeGraph, StackedBarGraph ): pass # Bar graph stuff. TBG = TimeBarGraph() begin_time, end_time, data = make_time_data() metadata = {'title':'Bar Graph w.r.t. Time', 'starttime':begin_time, 'endtime':end_time, 'span':span } filename = expand_string('$HOME/tmp/time_bar.png',os.environ) file = open( filename, 'w' ) TBG( data, file, metadata ) # Stacked Bar graph stuff. TSBG = TimeStackedBarGraph() begin_time, end_time, data1 = make_time_data() begin_time, end_time, data2 = make_time_data() data = {'Team A': data1, 'Team B': data2} metadata = {'title':'Stacked Bar Graph w.r.t. Time', 'starttime':begin_time, 'endtime':end_time, 'span':span } filename = expand_string('$HOME/tmp/time_stacked_bar.png',os.environ) file = open( filename, 'w' ) TSBG( data, file, metadata )
#!/usr/bin/env python import os from graphtool.graphs.common_graphs import StackedBarGraph from graphtool.tools.common import expand_string # First example - we have a bar graph with text labels entry1 = {'foo':3, 'bar':5} entry2 = {'foo':4, 'bar':6} data = {'Team A':entry1, 'Team B':entry2} metadata = {'title':'First Stacked Bar Example'} file = open(expand_string('$HOME/tmp/stacked_strings.png',os.environ),'w') SBG = StackedBarGraph() SBG(data, file, metadata) # Second example - bar graph with integer labels, bar width 2 entry1 = {}; entry2 = {} for i in range(0,10,2): entry1[i] = i**2 entry2[i] = i data = {'Team A':entry1, 'Team B':entry2} metadata = {'title':'Second Stacked Bar Example', 'span':2} del entry1[6]; del entry2[6]; del entry2[8]
def startPlot( self, output, results, metadata, encoding='UTF-8' ): title = metadata.get('title','') if metadata.get('given_kw',{}).has_key('title'): title = metadata.get('given_kw',{})['title'] title = expand_string(title, metadata.get('sql_vars','') ) gen = self.startDocument( output,("Results of Query: %s"%title), encoding ) query_attrs = {} name = metadata.get('name','') if name and len(name) > 0: query_attrs['name'] = name gen.startElement('query', query_attrs) gen.characters("\n\t\t") if title and len(title) > 0: gen.startElement('title',{}) gen.characters( title ) gen.endElement( 'title' ) gen.characters("\n\t\t") graph_type = metadata.get('graph_type',False) graph_kind = metadata.get('graph_kind',False) js_chart_setup = metadata.get('js_chart_setup',False) mpl_2_gc = {} metadata['translate_mp_2_gc'] = False if not graph_kind and mpl_2_gc.has_key(graph_type): maped_gc = mpl_2_gc[graph_type] graph_type = maped_gc['gc_type'] js_chart_setup = maped_gc['gc_js_setup'] graph_kind = 'google_charts' metadata['translate_mp_2_gc'] = True gen.startElement( 'translate_mp_2_gc',{} ) if metadata['translate_mp_2_gc']: gen.characters( 'TRUE' ) else: gen.characters( 'FALSE' ) gen.endElement( 'translate_mp_2_gc') gen.characters("\n\t\t") if graph_type and len(graph_type) > 0: gen.startElement( 'graph',{} ) gen.characters( graph_type ) gen.endElement( 'graph' ) gen.characters("\n\t\t") if graph_kind and len(graph_kind) > 0: gen.startElement( 'graph_kind',{} ) gen.characters( graph_kind ) gen.endElement( 'graph_kind' ) gen.characters("\n\t\t") if js_chart_setup and len(js_chart_setup) > 0: gen.startElement( 'js_chart_setup',{} ) gen.characters( js_chart_setup ) gen.endElement( 'js_chart_setup' ) gen.characters("\n\t\t") sql_string = str(metadata.get('sql','')) gen.startElement( 'sql',{} ) gen.characters( sql_string ) gen.characters("\n\t\t") gen.endElement( 'sql' ) gen.characters("\n\t\t") self.write_sql_vars( results, metadata, gen ) gen.characters("\n\t\t") self.write_json_metadata(metadata, gen) gen.characters("\n\t\t") my_base_url = self.metadata.get('base_url','') gen.startElement( 'attr',{'name':'base_url'} ) gen.characters( my_base_url ) gen.endElement( 'attr' ) gen.characters('\n\t\t') self.write_graph_url( results, metadata, gen, graph_kind) return gen
#!/usr/bin/env python import os from graphtool.graphs.common_graphs import PieGraph from graphtool.tools.common import expand_string filename = expand_string('$HOME/tmp/pie.png',os.environ) file = open( filename, 'w' ) data = {'foo':45, 'bar':55} metadata = {'title':'Hello Graphing World!'} pie = PieGraph() coords = pie.run( data, file, metadata )
# First example - we have a bar graph with text labels data = {'Team A': 4, 'Team B': 7} print data metadata = { 'title': 'First Bar Example', 'height': 200, 'width': 400, 'title_size': 20, 'text_size': 17 } file = open(expand_string('$HOME/tmp/bar_strings.png', os.environ), 'w') BG = BarGraph() BG(data, file, metadata) # Second example - we have a bar graph with integer data data = {} for i in range(10): data[i] = i**2 print data metadata = {'title': 'Second Bar Example'} file = open(expand_string('$HOME/tmp/bar_ints.png', os.environ), 'w')
span = 3600 max_value = 40 # Generate our time series def make_time_data(): end_time = time.time() end_time -= end_time % span begin_time = end_time - 24 * span data = {} for i in range(begin_time, end_time, span): data[i] = random.random() * max_value return begin_time, end_time, data # Create and plot cumulative plot. CG = CumulativeGraph() begin_time, end_time, data1 = make_time_data() begin_time, end_time, data2 = make_time_data() data = {'Team A': data1, 'Team B': data2} metadata = { 'title': 'Some Cumulative Data', 'starttime': begin_time, 'endtime': end_time, 'span': span, 'is_cumulative': False } filename = expand_string('$HOME/tmp/cumulative.png', os.environ) file = open(filename, 'w') CG(data, file, metadata)
#!/usr/bin/env python import os from graphtool.graphs.common_graphs import PieGraph from graphtool.tools.common import expand_string filename = expand_string('$HOME/tmp/pie.png', os.environ) file = open(filename, 'w') data = {'foo': 45, 'bar': 55} metadata = {'title': 'Hello Graphing World!'} pie = PieGraph() coords = pie.run(data, file, metadata)
#!/usr/bin/env python import os, random from graphtool.graphs.common_graphs import HorizontalGroupedBarGraph from graphtool.tools.common import expand_string # First example - we have a bar graph with text labels data = {} data_groups = 3 for i in range(40): data['Team %i' % i] = [random.random() * 10 for j in range(data_groups)] metadata = { 'title': 'Horizontal Bar Example', 'title_size': 20, 'text_size': 17, 'fixed-height': False } file = open(expand_string('$HOME/tmp/horizontal_grouped_bar.png',os.environ), \ 'w') HGBG = HorizontalGroupedBarGraph() HGBG(data, file, metadata)
def startPlot(self, output, results, metadata, encoding='UTF-8'): title = metadata.get('title', '') if metadata.get('given_kw', {}).has_key('title'): title = metadata.get('given_kw', {})['title'] title = expand_string(title, metadata.get('sql_vars', '')) gen = self.startDocument(output, ("Results of Query: %s" % title), encoding) query_attrs = {} name = metadata.get('name', '') if name and len(name) > 0: query_attrs['name'] = name gen.startElement('query', query_attrs) gen.characters("\n\t\t") if title and len(title) > 0: gen.startElement('title', {}) gen.characters(title) gen.endElement('title') gen.characters("\n\t\t") graph_type = metadata.get('graph_type', False) graph_kind = metadata.get('graph_kind', False) js_chart_setup = metadata.get('js_chart_setup', False) mpl_2_gc = {} metadata['translate_mp_2_gc'] = False if not graph_kind and mpl_2_gc.has_key(graph_type): maped_gc = mpl_2_gc[graph_type] graph_type = maped_gc['gc_type'] js_chart_setup = maped_gc['gc_js_setup'] graph_kind = 'google_charts' metadata['translate_mp_2_gc'] = True gen.startElement('translate_mp_2_gc', {}) if metadata['translate_mp_2_gc']: gen.characters('TRUE') else: gen.characters('FALSE') gen.endElement('translate_mp_2_gc') gen.characters("\n\t\t") if graph_type and len(graph_type) > 0: gen.startElement('graph', {}) gen.characters(graph_type) gen.endElement('graph') gen.characters("\n\t\t") if graph_kind and len(graph_kind) > 0: gen.startElement('graph_kind', {}) gen.characters(graph_kind) gen.endElement('graph_kind') gen.characters("\n\t\t") if js_chart_setup and len(js_chart_setup) > 0: gen.startElement('js_chart_setup', {}) gen.characters(js_chart_setup) gen.endElement('js_chart_setup') gen.characters("\n\t\t") sql_string = str(metadata.get('sql', '')) gen.startElement('sql', {}) gen.characters(sql_string) gen.characters("\n\t\t") gen.endElement('sql') gen.characters("\n\t\t") self.write_sql_vars(results, metadata, gen) gen.characters("\n\t\t") self.write_json_metadata(metadata, gen) gen.characters("\n\t\t") my_base_url = self.metadata.get('base_url', '') gen.startElement('attr', {'name': 'base_url'}) gen.characters(my_base_url) gen.endElement('attr') gen.characters('\n\t\t') self.write_graph_url(results, metadata, gen, graph_kind) return gen
#!/usr/bin/env python import os, random from graphtool.graphs.common_graphs import HorizontalBarGraph from graphtool.tools.common import expand_string # First example - we have a bar graph with text labels data = {} for i in range(40): data['Team %i' % i] = random.random() * 10 metadata = {'title':'Horizontal Bar Example', 'title_size':20, 'text_size':17, 'fixed-height':False } file = open(expand_string('$HOME/tmp/horizontal_bar.png',os.environ),'w') HBG = HorizontalBarGraph() HBG(data, file, metadata)
class TimeStackedBarGraph(TimeGraph, StackedBarGraph): pass # Bar graph stuff. TBG = TimeBarGraph() begin_time, end_time, data = make_time_data() metadata = { 'title': 'Bar Graph w.r.t. Time', 'starttime': begin_time, 'endtime': end_time, 'span': span } filename = expand_string('$HOME/tmp/time_bar.png', os.environ) file = open(filename, 'w') TBG(data, file, metadata) # Stacked Bar graph stuff. TSBG = TimeStackedBarGraph() begin_time, end_time, data1 = make_time_data() begin_time, end_time, data2 = make_time_data() data = {'Team A': data1, 'Team B': data2} metadata = { 'title': 'Stacked Bar Graph w.r.t. Time', 'starttime': begin_time, 'endtime': end_time, 'span': span } filename = expand_string('$HOME/tmp/time_stacked_bar.png', os.environ)
#!/usr/bin/env python import os import sys sys.path.insert(0, os.path.expandvars('$GRAPHTOOL_ROOT/src')) from graphtool.tools.common import expand_string from graphtool.graphs.common_graphs import Histogram import numpy data = numpy.random.normal(size=100, loc=1.0) metadata = {'title':'First Histogram Example', 'nbins': 15} file = open(expand_string('$HOME/tmp/histogram.png',os.environ),'w') HG = Histogram() HG(data, file, metadata)
# Generate our time series def make_time_data( ): end_time = time.time(); end_time -= end_time % span begin_time = end_time - 24*span data = {} for i in range(begin_time, end_time, span): data[i] = random.sample(values, 1)[0] return begin_time, end_time, data QM = QualityMap() # Data generation full_data = {} for i in range(10): team_name = 'Team %i' % i begin_time, end_time, data = make_time_data() full_data[team_name] = data metadata = {'title':'Quality Plot w.r.t. Time', 'starttime':begin_time, 'endtime':end_time, 'span':span, 'color_override': {0: 'grey', .25: 'red', .5: 'yellow', 1.0: 'green'}, 'legend': legend, } filename = expand_string('$HOME/tmp/quality_map_dashboard.png',os.environ) file = open( filename, 'w' ) QM( full_data, file, metadata )