def linewithfocuschart(request,choice): """ linewithfocuschart page """ CHART_CHOICES = { 'stock':U'STOCK', 'fund':U'FUND', } CHART_CHOICES_NAME = { 'stock':U'红马股票净值', 'fund':U'红马期货净值', } chart_name = CHART_CHOICES_NAME.get(choice) choice2 = CHART_CHOICES.get(choice) print(chart_name) chart = lineWithFocusChart(name='lineWithFocusChart', x_is_date=True, x_axis_format="%d %b %Y") stock_list = HmChart.objects.filter(chart_in_hm_choices=choice2) xdata = [int(calendar.timegm(t.chart_time.timetuple()))*1000 for t in stock_list] ydata = [float("%.2f"%v.chart_value) for v in stock_list] extra_serie = {"tooltip": {"y_start": "净值", "y_end": ""},"date_format": "%Y年%m月%d日"} chart.add_serie(name=chart_name, y=ydata, x=xdata, extra=extra_serie) chart.buildhtml() chart_html = chart.jschart return render_to_response('artical_hmcharts.html', locals())
def draw(handle, type, logs, **kwargs): kwparams = { 'name': "lineChart", 'width': 1000, 'height': 500, 'chart_attr': { 'forceX': x_axis_scale(logs), 'forceY': y_axis_scale(logs), # 'yAxis.scale': y_axis_scale(logs), 'xAxis.axisLabel': ('"%s"' % kwargs['xlabel']), 'yAxis.axisLabel': ('"%s"' % kwargs['ylabel']), 'useInteractiveGuideline': 'true', # 'x2Axis.scale': xAxisScale(logs), # 'y2Axis.scale': yAxisScale(logs), }, } chart = None if type == LINE_CHART: chart = lineChart(**kwparams) elif type == LINE_WITH_FOCUS_CHART: chart = lineWithFocusChart(**kwparams) chart.show_labels = True count = 0 for alg in logs: extra_serie = { "tooltip": {"y_start": kwargs['ylabel'] + "is ", "y_end": "!"}, } chart.add_serie(y=logs[alg]['y'], x=logs[alg]['x'], color=COLOR_LIST[count], extra=extra_serie, name=alg) count += 1 chart.buildhtml() handle.write(str(chart))
def draw(handle, type, logs, **kwargs): kwparams = { 'name': "lineChart", 'width': 1000, 'height': 500, 'chart_attr': { 'forceY': yAxisScale(logs), 'forceX': xAxisScale(logs), 'xAxis.axisLabel': ('"%s"' % kwargs['xlabel']), 'yAxis.axisLabel': ('"%s"' % kwargs['ylabel']), }, } chart = None if type == LINE_CHART: chart = lineChart(**kwparams) elif type == LINE_WITH_FOCUS_CHART: chart = lineWithFocusChart(**kwparams) chart.show_labels = True for alg in logs: extra_serie = { "tooltip": { "y_start": kwargs['ylabel'] + "is ", "y_end": "!" } } chart.add_serie(y=logs[alg]['y'], x=logs[alg]['x'], extra=extra_serie, name=alg) chart.buildhtml() handle.write(str(chart))
def indexOLD(): chart = lineWithFocusChart( height=600, width='800', show_legend=False, name='lineWithFocusChart') data = saxsAnalyzer.getdata(5) for index, saxsdata in enumerate(data): chart.add_serie(name="Serie " + str(index), y=saxsdata[1], x=range(len(saxsdata[1]))) chart.buildhtml() return chart.htmlcontent
def test_lineWithFocusChart(self): """Test Line With Focus Chart""" type = "lineWithFocusChart" chart = lineWithFocusChart(name=type, date=True, height=350) nb_element = 100 xdata = list(range(nb_element)) xdata = [1365026400000 + x * 100000 for x in xdata] ydata = [i + random.randint(-10, 10) for i in range(nb_element)] ydata2 = [x * 2 for x in ydata] chart.add_serie(y=ydata, x=xdata) chart.add_serie(y=ydata2, x=xdata) chart.buildhtml()
def test_lineWithFocusChart(self): """Test Line With Focus Chart""" type = "lineWithFocusChart" chart = lineWithFocusChart(name=type, date=True, height=350) nb_element = 100 xdata = range(nb_element) xdata = map(lambda x: 1365026400000 + x * 100000, xdata) ydata = [i + random.randint(-10, 10) for i in range(nb_element)] ydata2 = map(lambda x: x * 2, ydata) chart.add_serie(y=ydata, x=xdata) chart.add_serie(y=ydata2, x=xdata) chart.buildhtml()
def test_lineWithFocusChart(self): """Test Line With Focus Chart""" type = "lineWithFocusChart" chart = lineWithFocusChart(name=type, date=True, height=350) nb_element = 100 xdata = range(nb_element) xdata = list(map(lambda x: 1365026400000 + x * 100000, xdata)) ydata = [i + random.randint(-10, 10) for i in range(nb_element)] ydata2 = list(map(lambda x: x * 2, ydata)) chart.add_serie(y=ydata, x=xdata) chart.add_serie(y=ydata2, x=xdata) chart.buildhtml()
def graph(request, data_id): """ graph the data page """ json_data = JSONModel.objects.last().json_model id = 'id_' + str(int(data_id)+1) xdata = map(int, json_data['id_2']['data']) ydata = map(float, json_data[id]['data']) #C id tooltip_date = "%d %b %Y %H:%M:%S %p" extra_serie = {"tooltip": {"y_start": "The value is ", "y_end": " "}, "date_format": tooltip_date} chartdata = { 'x': xdata, 'name1': json_data[id]['name'], 'y1': ydata, 'extra1': extra_serie,#C id } charttype = "lineWithFocusChart" chartcontainer = 'linewithfocuschart_container' # container name data = { 'charttype': charttype, 'chartdata': chartdata, 'chartcontainer': chartcontainer, 'extra': { 'x_is_date': True, 'tag_script_js': False, 'jquery_on_ready': False, } } ####From example output_file = open('test-nvd3.html', 'w') chart = lineWithFocusChart(name='lineWithFocusChart', x_is_date=True, x_axis_format="%d %b %Y") chart.add_serie(name="Serie 1", y=ydata, x=xdata, extra=extra_serie) chart.buildhtml() output_file.write(chart.htmlcontent) # close Html file output_file.close() return render_to_response('linewithfocuschart.html', data)
def linewithfocuschart(request, choice): """ linewithfocuschart page """ CHART_CHOICES = { 'stock': U'STOCK', 'fund': U'FUND', } CHART_CHOICES_NAME = { 'stock': U'红马股票净值', 'fund': U'红马期货净值', } chart_name = CHART_CHOICES_NAME.get(choice) choice2 = CHART_CHOICES.get(choice) print(chart_name) chart = lineWithFocusChart(name='lineWithFocusChart', x_is_date=True, x_axis_format="%d %b %Y") stock_list = HmChart.objects.filter(chart_in_hm_choices=choice2) xdata = [ int(calendar.timegm(t.chart_time.timetuple())) * 1000 for t in stock_list ] ydata = [float("%.2f" % v.chart_value) for v in stock_list] extra_serie = { "tooltip": { "y_start": "净值", "y_end": "" }, "date_format": "%Y年%m月%d日" } chart.add_serie(name=chart_name, y=ydata, x=xdata, extra=extra_serie) chart.buildhtml() chart_html = chart.jschart return render_to_response('artical_hmcharts.html', locals())
nb_element = 100 xdata = range(nb_element) xdata = map(lambda x: start_time + x * 1000000000, xdata) ydata = [i + random.randint(1, 10) for i in range(nb_element)] ydata2 = map(lambda x: x * 2, ydata) chart.add_serie(y=ydata, x=xdata) chart.add_serie(y=ydata2, x=xdata) chart.buildhtml() output_file.write(chart.htmlcontent) # --------------------------------------- type = "lineWithFocusChart" chart = lineWithFocusChart(name=type, date=True) chart.set_containerheader("\n\n<h2>" + type + "</h2>\n\n") nb_element = 100 xdata = range(nb_element) xdata = map(lambda x: start_time + x * 1000000000, xdata) ydata = [i + random.randint(-10, 10) for i in range(nb_element)] ydata2 = map(lambda x: x * 2, ydata) ydata3 = map(lambda x: x * 3, ydata) ydata4 = map(lambda x: x * 4, ydata) chart.add_serie(y=ydata, x=xdata) chart.add_serie(y=ydata2, x=xdata) chart.add_serie(y=ydata3, x=xdata) chart.add_serie(y=ydata4, x=xdata) chart.buildhtml()
kwargs2 = {'color': 'red'} extra_serie = {"tooltip": {"y_start": "There is ", "y_end": " calls"}, "date_format": "%d %b %Y %I:%M:%S %p"} chart.add_serie(name="Count", y=ydata, x=xdata, extra=extra_serie, **kwargs1) extra_serie = {"tooltip": {"y_start": "", "y_end": " min"}} chart.add_serie(name="Duration", y=ydata2, x=xdata, extra=extra_serie, **kwargs2) chart.buildcontent() output_file.write(chart.htmlcontent) # --------------------------------------- type = "lineWithFocusChart" chart = lineWithFocusChart(color_category='category20b', x_is_date=True, height=400, width=800, x_axis_format="%d %b %Y", jquery_on_ready=True) chart.set_containerheader("\n\n<h2>" + type + "</h2>\n\n") xdata = list(range(nb_element)) xdata = [start_time + x * 1000000000 for x in xdata] ydata = [i + random.randint(-10, 10) for i in list(range(nb_element))] ydata2 = [x * 2 for x in ydata] ydata3 = [x * 3 for x in ydata] ydata4 = [x * 4 for x in ydata] extra_serie = {"tooltip": {"y_start": "There is ", "y_end": " calls"}, "date_format": "%d %b %Y %I:%M:%S"} # extra_serie = None chart.add_serie(name="serie 1", y=ydata, x=xdata, extra=extra_serie)
title = title[:-len(suffix)] ydata.append((title, values)) # Dump the results as a CSV file #print '"time", ' + ', '.join('"%s"' % title for title, values in ydata) #for i in xrange(len(xdata)): # print '%d, %s' % (xdata[i], ', '.join('%g' % values[i] for title, values in ydata)) # Are we just listing the results? if args.list: for title, values in ydata: print title sys.exit(0) # open the output file output_file = open(args.output, 'w') #--------------------------------------- if args.focus: chart = lineWithFocusChart(name='statlog', height=450 + 10 * len(ydata), x_is_date=args.abstime, x_axis_format='%H:%M:%S', y_axis_format='g', assets_directory='http://source.wiredtiger.com/graphs/') else: chart = lineChart(name='statlog', height=450 + 10 * len(ydata), x_is_date=args.abstime, y_axis_format='g', assets_directory='http://source.wiredtiger.com/graphs/') for title, values in ydata: chart.add_serie(y=values, x=xdata, name=title) chart.buildhtml() output_file.write(chart.htmlcontent) #close Html file output_file.close()
kwargs1 = {'color': 'green'} kwargs2 = {'color': 'red'} extra_serie = {"tooltip": {"y_start": "There is ", "y_end": " calls"}, "date_format": "%d %b %Y %I:%M:%S %p"} chart.add_serie(name="Count", y=ydata, x=xdata, extra=extra_serie, **kwargs1) extra_serie = {"tooltip": {"y_start": "", "y_end": " min"}} chart.add_serie(name="Duration", y=ydata2, x=xdata, extra=extra_serie, **kwargs2) chart.buildcontent() output_file.write(chart.htmlcontent) #--------------------------------------- type = "lineWithFocusChart" chart = lineWithFocusChart(name=type, color_category='category20b', date=True, x_axis_format="%d %b %Y", jquery_on_ready=True) chart.set_containerheader("\n\n<h2>" + type + "</h2>\n\n") xdata = list(range(nb_element)) xdata = [start_time + x * 1000000000 for x in xdata] ydata = [i + random.randint(-10, 10) for i in list(range(nb_element))] ydata2 = [x * 2 for x in ydata] ydata3 = [x * 3 for x in ydata] ydata4 = [x * 4 for x in ydata] extra_serie = {"tooltip": {"y_start": "There is ", "y_end": " calls"}, "date_format": "%d %b %Y %I:%M:%S"} #extra_serie = None chart.add_serie(name="serie 1", y=ydata, x=xdata, extra=extra_serie) chart.add_serie(name="serie 2", y=ydata2, x=xdata, extra=extra_serie)
def get(self, request, *args, **kwargs): ''' Overriding get to return only JSON. ''' context = {} # self.get_context_data(**kwargs) hostname = kwargs.get('hostname') data_requested = self.request.GET.get('module') context['module'] = data_requested if data_requested == 'hostnames': # Update HostNames DB for row in HostNames.objects.all(): poll_healthinfo.delay(row.hostname) # Retrieve data from DB and return the table body # http://www.djangobook.com/en/2.0/chapter04.html cdata = HostNamesView().get_context_data() t = loader.get_template('hostnames/hostnames.table.html') tbody_html = t.render(Context(cdata)) context['data'] = tbody_html elif hostname: if data_requested == 'osinfo': from dashboardperdevice.tasks import poll_osinfo from dashboardperdevice.models import OSInfo poll_osinfo.delay(hostname=hostname) cdata = dict() try: o = OSInfo.objects.get(hostname__hostname=hostname) cdata['ostime'] = o.ostime cdata['osuptime'] = o.osuptime cdata['osplatform'] = o.osplatform cdata['osdevicename'] = o.osdevicename except: pass t = loader.get_template('dashboardperdevice/osinfo.table.html') tbody_html = t.render(Context(cdata)) context['data'] = tbody_html elif data_requested == 'overallhealth': poll_healthinfo.delay(hostname) hostname_obj = HostNames.objects.get(hostname=hostname) cdata = dict() cdata['error_online'] = hostname_obj.error_online try: hs = eval(hostname_obj.health_statuses) except: hs = list() else: if not isinstance(hs, list): hs = list() cdata['health_statuses'] = hs t = loader.get_template('dashboardperdevice/overallhealth.table.html') tbody_html = t.render(Context(cdata)) context['data'] = tbody_html elif data_requested == 'intstats': poll_intstats.delay(hostname=hostname) intstats_table_data = list() hs = InterfacesStats.objects.filter(hostname__hostname=hostname) last_timestamp = hs.latest('polling_timestamp').polling_timestamp last_poll = hs.filter(polling_timestamp=last_timestamp) # Create table data for r in last_poll: status = '{0}/{1}'.format(r.int_state, r.int_adminstate) if r.int_ipaddr == r.int_ipmask == '': ip = '' else: ip = '{0}/{1}'.format(r.int_ipaddr, r.int_ipmask) provided_interval = int(HostNames.objects.get(hostname=hostname).polling_interval) interval = int(r.int_loadinterval) + provided_interval e = [r.int_name, status, r.int_hwdesc, ip, r.int_hwaddr, r.int_mtu, r.int_bw, r.int_desc, r.int_bpsrate_rx, r.int_bpsrate_tx, interval] intstats_table_data.append(e) context['data'] = intstats_table_data # Graph related # https://github.com/mbostock/d3/wiki/Time-Formatting charts_content = list() # Nested list: [(int_name, html_chart_content),] for JSON data tooltip_date = "%d %b %Y %H:%M:%S %p" try: unique_interfaces = hs.values_list('int_name').distinct() up_unique_interfaces = unique_interfaces.filter(int_state='up') up_unique_interfaces_with_bps = up_unique_interfaces.exclude(int_bpsrate_tx='', int_bpsrate_rx='') list_of_interfaces = zip(*up_unique_interfaces_with_bps)[0] except IndexError: list_of_interfaces = list() for int_name in list_of_interfaces: per_int_entries = hs.filter(int_name=int_name).order_by('polling_timestamp') try: xdata = zip(*per_int_entries.values_list('polling_timestamp'))[0] def int_n_mult(i): return int(i)*settings.D3_PY_TIME_DIFF xdata = list(map(int_n_mult, xdata)) ydata_tx = zip(*per_int_entries.values_list('int_bpsrate_tx'))[0] ydata_tx = list(map(int, ydata_tx)) ydata_rx = zip(*per_int_entries.values_list('int_bpsrate_rx'))[0] ydata_rx = list(map(int, ydata_rx)) except IndexError: xdata = list() ydata_tx = list() ydata_rx = list() try: int_latest_state = per_int_entries.reverse()[0].int_state except IndexError: int_latest_state = 'NA' name_display_rx = 'Input/Rx (bps) - {name} ({state})'.format(name=int_name, state=int_latest_state) name_display_tx = 'Output/Tx (bps) - {name} ({state})'.format(name=int_name, state=int_latest_state) extra_serie = {"tooltip": {"y_start": "Rate ", "y_end": "bps"}, "date_format": tooltip_date} chart = lineWithFocusChart(name='interfaceStatsGraph-{0}'.format(int_name), x_is_date=True, x_axis_format="%H:%M:%S") try: chart.add_serie(y=ydata_tx, x=xdata, name=name_display_tx, extra=extra_serie) chart.add_serie(y=ydata_rx, x=xdata, name=name_display_rx, extra=extra_serie) chart.buildcontent() charts_content.append([int_name, chart.htmlcontent]) except IndexError: pass context['graph_data'] = charts_content elif data_requested == 'loadavg': poll_cpustats.delay(hostname=hostname) hs = CpuStats.objects.filter(hostname__hostname=hostname) last_timestamp = hs.latest('polling_timestamp').polling_timestamp last_poll = hs.filter(polling_timestamp=last_timestamp) try: vals = last_poll.values_list('per1min', 'per5min', 'per15min')[0] percents = [int(float(i)*100) for i in vals] cpudata = zip(vals, percents) except IndexError: cpudata = list() context['data'] = cpudata elif data_requested == 'mem': poll_memstats.delay(hostname=hostname) hs = MemStats.objects.filter(hostname__hostname=hostname) last_timestamp = hs.latest('polling_timestamp').polling_timestamp last_poll = hs.filter(polling_timestamp=last_timestamp) try: memdata = last_poll.values_list('mem_total', 'mem_used', 'mem_free')[0] except IndexError: memdata = list() context['data'] = memdata elif data_requested == 'df': poll_dirstats.delay(hostname=hostname) hs = DirStats.objects.filter(hostname__hostname=hostname) last_timestamp = hs.latest('polling_timestamp').polling_timestamp last_poll = hs.filter(polling_timestamp=last_timestamp) diskdata = last_poll.values_list('dirpath', 'total', 'used', 'free', 'used_percent', 'module') diskdata = [list(i) for i in diskdata] context['data'] = diskdata elif data_requested == 'modstats': poll_modulestats.delay(hostname=hostname) hs = ModulesStats.objects.filter(hostname__hostname=hostname) last_timestamp = hs.latest('polling_timestamp').polling_timestamp last_poll = hs.filter(polling_timestamp=last_timestamp) modinfo = last_poll.values_list('mod_id', 'ports', 'hw_desc', 'hw_model', 'serial_no', 'status', 'diag_stat') modinfo = [list(i) for i in modinfo] context['data'] = modinfo return HttpResponse(json.dumps(context), content_type="application/json")
nb_element = 100 xdata = range(nb_element) xdata = map(lambda x: start_time + x * 1000000000, xdata) ydata = [i + random.randint(1, 10) for i in range(nb_element)] ydata2 = map(lambda x: x * 2, ydata) chart.add_serie(y=ydata, x=xdata) chart.add_serie(y=ydata2, x=xdata) chart.buildhtml() output_file.write(chart.htmlcontent) #--------------------------------------- type = "lineWithFocusChart" chart = lineWithFocusChart(name=type, date=True) chart.set_containerheader("\n\n<h2>" + type + "</h2>\n\n") nb_element = 100 xdata = range(nb_element) xdata = map(lambda x: start_time + x * 1000000000, xdata) ydata = [i + random.randint(-10, 10) for i in range(nb_element)] ydata2 = map(lambda x: x * 2, ydata) ydata3 = map(lambda x: x * 3, ydata) ydata4 = map(lambda x: x * 4, ydata) chart.add_serie(y=ydata, x=xdata) chart.add_serie(y=ydata2, x=xdata) chart.add_serie(y=ydata3, x=xdata) chart.add_serie(y=ydata4, x=xdata) chart.buildhtml()
from nvd3 import lineWithFocusChart # Open File to write the D3 Graph output_file = open('test-nvd3.html', 'w') chart = lineWithFocusChart(name='lineWithFocusChart', x_is_date=True, x_axis_format="%d %b %Y") xdata = [1365026400000, 1365026500000, 1365026600000, 1365026700000, 1365026800000, 1365026900000, 1365027000000] ydata = [-6, 5, -1, 2, 4, 8, 10] extra_serie = {"tooltip": {"y_start": "", "y_end": " ext"}, "date_format": "%d %b %Y"} chart.add_serie(name="Serie 1", y=ydata, x=xdata, extra=extra_serie) chart.buildhtml() output_file.write(chart.htmlcontent) # close Html file output_file.close()
from nvd3 import lineWithFocusChart import random import datetime import time start_time = int(time.mktime(datetime.datetime(2012, 6, 1).timetuple()) * 1000) nb_element = 100 # Open File for test output_file = open('test_lineWithFocusChart.html', 'w') # --------------------------------------- type = "lineWithFocusChart" chart = lineWithFocusChart(name=type, height=550, width=850, color_category='category20b', x_is_date=True, x_axis_format="%d %b %Y %H", focus_enable=True) chart.set_containerheader("\n\n<h2>" + type + "</h2>\n\n") xdata = list(range(nb_element)) xdata = [start_time + x * 1000000000 for x in xdata] ydata = [i + random.randint(-10, 10) for i in range(nb_element)] ydata2 = [x * 2 for x in ydata] ydata3 = [x * 3 for x in ydata] ydata4 = [x * 4 for x in ydata] extra_serie = { "tooltip": {
""" from nvd3 import lineWithFocusChart import random import datetime import time start_time = int(time.mktime(datetime.datetime(2012, 6, 1).timetuple()) * 1000) nb_element = 100 #Open File for test output_file = open('test_lineWithFocusChart.html', 'w') #--------------------------------------- type = "lineWithFocusChart" chart = lineWithFocusChart(name=type, color_category='category20b', x_is_date=True, x_axis_format="%d %b %Y %H") chart.set_containerheader("\n\n<h2>" + type + "</h2>\n\n") xdata = list(range(nb_element)) xdata = [start_time + x * 1000000000 for x in xdata] ydata = [i + random.randint(-10, 10) for i in range(nb_element)] ydata2 = [x * 2 for x in ydata] ydata3 = [x * 3 for x in ydata] ydata4 = [x * 4 for x in ydata] extra_serie = {"tooltip": {"y_start": "There is ", "y_end": " calls"}, "date_format": "%d %b %Y %H:%M:%S %p"} #extra_serie = None chart.add_serie(name="serie 1", y=ydata, x=xdata, extra=extra_serie) chart.add_serie(name="serie 2", y=ydata2, x=xdata, extra=extra_serie)
def hello(): events = requests.get( "https://autism-tracker-server.appspot.com/events").json() emotion_dict = get_emotion_dict(events) type = 'pieChart' moodchart = pieChart(name=type, color_category='category20c', height=450, width=450) xdata = [ key for key in ['😁 joy', '😢 sorrow', '😠 anger', '😲 surprise', '😐 neutral'] ] ydata = [emotion_dict[key] for key in emotion_dict] extra_serie = {"tooltip": {"y_start": "", "y_end": " %"}} moodchart.add_serie(y=ydata, x=xdata, extra=extra_serie) moodchart.buildcontent() stresschart = lineWithFocusChart(name='lineWithFocusChart', x_is_date=True, x_axis_format="%d %b %Y") xdata, ydata_stress, ydata_harm, ydata_physical = get_stress_level(events) extra_serie = { "tooltip": { "y_start": "", "y_end": " ext" }, "date_format": "%d %b %Y %H" } stresschart.add_serie(name="Stress Level", y=ydata_stress, x=xdata, extra=extra_serie) stresschart.add_serie(name="Self Harm Level", y=ydata_harm, x=xdata, extra=extra_serie) stresschart.add_serie(name="Physical Activity Level", y=ydata_physical, x=xdata, extra=extra_serie) stresschart.buildhtml() html = """<table> <tr> <th>Trigger</th> <th>Resolution</th> <th>Additional Notes</th> </tr> {0} </table>""" items = get_table_items(events) tr = "<tr>{0}</tr>" td = "<td>{0}</td>" subitems = [ tr.format(''.join([td.format(a) for a in item])) for item in items ] table = html.format("".join(subitems)) return render_template('index.html', table=table, moodchart=moodchart, stresschart=stresschart)
wdir = modeldata[m]['dir'] wnam = modeldata[m]['name'] db = pjoin(wdir, 'synop_{n}_{par}_{dtg}.db'.format(n=wnam, par=p, dtg=yms)) print db, os.path.exists(db) if os.path.exists(db): conn = sqlite3.connect(db) c = conn.cursor() else: print 'Database does not exist', db sys.exit(1) chart = nvd3.lineWithFocusChart( name='lineWithFocusChart', height=400, x_is_date=True, #x_axis_format="%_d,%m,%Y,%H%M", x_axis_format="%d %b %Y", assets_directory=thisdir) if p == 'fss': for t in thresholds: for nb in nbpts: sql = 'select * from "stats" where threshold = {thr} and nbpts = {nbp}'.format( thr=t, nbp=nb) c.execute(sql) data = c.fetchall() conn.close() elif p in ('t2m', 'wind', 'apcp'): sql = 'select * from "{p}" where sid = "{s}"'.format(p=p, s=s)
continue speed = str(speed_i) + 'K' speedList.append(SpeedObject(date, uri, speed)) date = date + timedelta(0, delta) print speed speedList.append(SpeedObject(date + timedelta(0, 3), uri, "10K")) except IndexError as e: pass output_file = open(directory+'/'+name+'.htm', 'w') chart_name = "Speed Test" chart = lineWithFocusChart(name=chart_name, width="1280", height="720", color_category='category20b', x_is_date=True, x_axis_format="%m-%d %H:%M") title = "\n\n<h2>" + chart_name + "</h2> " href = "<a href=\""+name+".htm\">"+name+"</a>" for filename in os.listdir(directory): if filename.endswith('.htm') and filename != name+".htm": href = href + " <a href=\""+filename+"\">"+filename[:-4]+"</a>" href = href + " <a href=\""+name+".txt\">RAW</a>" chart.set_containerheader(title + href + "\n\n") extra_series = {"tooltip": {"y_start": "", "y_end": " K/s"}, "date_format": "%d %b %Y %H:%M:%S %p"}
extra_serie = {"tooltip": {"y_start": "", "y_end": " min"}} chart.add_serie(name="Duration", y=ydata2, x=xdata, extra=extra_serie, **kwargs2) chart.buildcontent() output_file.write(chart.htmlcontent) #--------------------------------------- type = "lineWithFocusChart" chart = lineWithFocusChart(name=type, color_category='category20b', date=True, x_axis_format="%d %b %Y", jquery_on_ready=True) chart.set_containerheader("\n\n<h2>" + type + "</h2>\n\n") xdata = list(range(nb_element)) xdata = [start_time + x * 1000000000 for x in xdata] ydata = [i + random.randint(-10, 10) for i in list(range(nb_element))] ydata2 = [x * 2 for x in ydata] ydata3 = [x * 3 for x in ydata] ydata4 = [x * 4 for x in ydata] extra_serie = { "tooltip": { "y_start": "There is ",
from nvd3 import lineWithFocusChart import random import datetime import time start_time = int(time.mktime(datetime.datetime(2012, 6, 1).timetuple()) * 1000) nb_element = 100 # Open File for test output_file = open('test_lineWithFocusChart.html', 'w') # --------------------------------------- type = "lineWithFocusChart" chart = lineWithFocusChart(name=type, height=550, width=850, color_category='category20b', x_is_date=True, x_axis_format="%d %b %Y %H", focus_enable=True) chart.set_containerheader("\n\n<h2>" + type + "</h2>\n\n") xdata = list(range(nb_element)) xdata = [start_time + x * 1000000000 for x in xdata] ydata = [i + random.randint(-10, 10) for i in range(nb_element)] ydata2 = [x * 2 for x in ydata] ydata3 = [x * 3 for x in ydata] ydata4 = [x * 4 for x in ydata] extra_serie = {"tooltip": {"y_start": "There is ", "y_end": " calls"}, "date_format": "%d %b %Y %H:%M:%S %p"} # extra_serie = None chart.add_serie(name="serie 1", y=ydata, x=xdata, extra=extra_serie)
""" from nvd3 import lineWithFocusChart import random import datetime import time start_time = int(time.mktime(datetime.datetime(2012, 6, 1).timetuple()) * 1000) nb_element = 100 #Open File for test output_file = open('test_lineWithFocusChart.html', 'w') #--------------------------------------- type = "lineWithFocusChart" chart = lineWithFocusChart(name=type, color_category='category20b', date=True) chart.set_containerheader("\n\n<h2>" + type + "</h2>\n\n") xdata = range(nb_element) xdata = map(lambda x: start_time + x * 1000000000, xdata) ydata = [i + random.randint(-10, 10) for i in range(nb_element)] ydata2 = map(lambda x: x * 2, ydata) ydata3 = map(lambda x: x * 3, ydata) ydata4 = map(lambda x: x * 4, ydata) extra_serie = {"tooltip": {"y_start": "There is ", "y_end": " calls"}} #extra_serie = None chart.add_serie(name="serie 1", y=ydata, x=xdata, extra=extra_serie) chart.add_serie(name="serie 2", y=ydata2, x=xdata, extra=extra_serie) chart.add_serie(name="serie 3", y=ydata3, x=xdata, extra=extra_serie)