def buildHighchart(self): """ Create a Highchart chart with the algorithm result @type self: koala.SortByFront.SortByFront """ try: # Load files files = list_directory(self.path_runs.get_path_execution(), '*.xvg') methods = self.methods # Objectivies obj1 = "" obj2 = "" x = [[]]*len(files) y = [[]]*len(files) for i, f in enumerate(files): f = os.path.join(self.path_runs.get_path_execution(), f) arq = open(f, "r") # Loading File x[i] = [] y[i] = [] for line in arq: if line.find("#") == -1: x[i].append(float(line.split("\t")[0].strip())) y[i].append(float(line.split("\t")[1])) else: col = line.split("\t") if len(col) > 1: obj1 = col[0].replace('#', ' ') obj2 = col[2] arq.close() chart = Highchart(renderTo="container2") chart.title("Pareto Fronts") chart.subtitle( "A graph with %s and %s objectivies showing at most four fronts, " "but the first as line and the others as scatter" % (obj1, obj2)) graph_options = { "xAxis": { "minPadding": 0.05, "maxPadding": 0.1, "title": { 'offset': 30, 'text': obj1, 'rotation': 0, }, }, "yAxis": { "minPadding": 0.05, "maxPadding": 0.1, "title": { 'offset': 50, 'text': obj2, 'rotation': -90, }, }, "tooltip": { "shared": True, "useHTML": False, # "valueDecimals": 3, }, } data = [] it = {} i_file = 0 context = Context(prec=3, rounding=ROUND_UP) if(len(x) > 5): fronts = 4 else: fronts = len(x) for i in range(fronts): # no máximo as duas primeiras fronteiras data = [] z = x[i] for ii, w in enumerate(z): if(i == 0): it["name"] = methods[i_file] i_file += 1 else: it["name"] = "front%d" % i if(not math.isinf(z[ii])): it["x"] = (context.create_decimal_from_float(z[ii])).quantize( Decimal('.2'), rounding=ROUND_UP) else: it["x"] = "0.0" if(not math.isinf(y[i][ii])): it["y"] = (context.create_decimal_from_float(y[i][ii])).quantize( Decimal('.2'), rounding=ROUND_UP) else: it["y"] = "0.0" data.append(it) it = {} if(i == 0): chart.add_data_set(data, name="front%d" % i, index=i, marker={"enabled": True}) else: chart.add_data_set(data, series_type="scatter", name="front%d" % i, index=i) chart.set_options(graph_options) return chart.generate() except Exception, e: show_error_message("Error on building highcharts.\n%s" % e)
def build_Highchart(self, objectivies, container="container"): """ Create a Highchart chart with the algorithm result @type self: koala.DominanceRanking.DominanceRanking @type objectivies: string @type container: string """ try: # Load files objs = objectivies.split(",") files = list_directory( self.path_runs.get_path_execution(), '*%s_%s*.xvg' % (objs[0], objs[1])) images = self.methods x = [[]]*len(files) y = [[]]*len(files) for i, f in enumerate(files): f = os.path.join(self.path_runs.get_path_execution(), f) arq = open(f, "r") # Loading File x[i] = [] y[i] = [] for line in arq: if line.find("#") == -1: x[i].append(float(line.split("\t")[0].strip())) y[i].append(float(line.split("\t")[1])) arq.close() chart = Highchart(renderTo=container) chart.title("Pareto Fronts") chart.subtitle("A graph with %s and %s objectivies" % (objs[0], objs[1])) graph_options = { "xAxis": { "minPadding": 0.05, "maxPadding": 0.1, "title": { 'offset': 30, 'text': objs[0], 'rotation': 0, }, }, "yAxis": { "minPadding": 0.05, "maxPadding": 0.1, "title": { 'offset': 50, 'text': objs[1], 'rotation': -90, }, }, "tooltip": { "shared": True, "useHTML": False, "valueDecimals": 3, }, } data = [] it = {} i_file = 0 context = Context(prec=3, rounding=ROUND_UP) if(len(x) >= 4): fronts = 4 else: # fronts = 2 fronts = len(x) for i in range(fronts): data = [] z = x[i] for ii, w in enumerate(z): if(i_file < len(images)): it["name"] = images[i_file] i_file += 1 else: it["name"] = "front%d" % i it["x"] = (context.create_decimal_from_float(z[ii])).quantize( Decimal('.1'), rounding=ROUND_UP) it["y"] = (context.create_decimal_from_float(y[i][ii])).quantize( Decimal('.1'), rounding=ROUND_UP) data.append(it) it = {} if(i == 0): chart.add_data_set(data, name="front%d" % i, index=i, marker={"enabled": True}) else: chart.add_data_set(data, series_type="scatter", name="front%d" % i, index=i) chart.set_options(graph_options) return chart.generate() except Exception, e: show_error_message("Error while building the Highchart:\n%s" % e)