def hello(): input_data = list( csv.reader(open('noCrimeOutput.txt', 'rb'), delimiter='\t')) chart = discreteBarChart(name='discreteBarChart', height=800, width=1800, margin_bottom=200, margin_top=40, margin_left=60, margin_right=60) crimes = [] for row in input_data: if int(row[1]) >= 5: crimes.append([row[0], int(row[1])]) xdata = [] ydata = [] crimes = sorted(crimes, key=lambda crimes: crimes[1], reverse=True) for place in crimes[:20]: xdata.append(place[0]) ydata.append(place[1]) chart.add_serie(y=ydata, x=xdata) chart.buildhtml() return chart.htmlcontent
def test_discreteBarChart(self): """Test discrete Bar Chart""" type = "discreteBarChart" chart = discreteBarChart(name=type, date=True, height=350) xdata = ["A", "B", "C", "D", "E", "F", "G"] ydata = [3, 12, -10, 5, 35, -7, 2] chart.add_serie(y=ydata, x=xdata) chart.buildhtml()
def bar_chart(): content = read_data('/var/www/html/assignment5/static/dataset_chart1.csv') station, ydata = validate_data(content) chart = discreteBarChart(name='discreteBarChart', height=800, width=1800,margin_top=30, margin_bottom=200, margin_left=60, margin_right=10) xdata = str("january,feburary,march,april,may,june,july,august,september,outober,november,december").split(",") for it in range(0,1): chart.add_serie(y=ydata[it],x=xdata,name=station[it]) chart.buildhtml() return chart.htmlcontent
def get_html(self): chart_type = self.chart_name chart = discreteBarChart( name=chart_type, height=self.height, width=self.width, jquery_on_ready=True) chart.add_serie( y=self.ydata, x=self.xdata) chart.buildhtml() return Markup(chart.htmlcontent)
def test_discreteBarChart(self): """Test discrete Bar Chart""" type = "discreteBarChart" chart = discreteBarChart(name=type, height=350) xdata = ["A", "B", "C", "D", "E", "F", "G"] ydata = [3, 12, -10, 5, 35, -7, 2] chart.add_serie(y=ydata, x=xdata) chart.buildhtml() # We don't modify the xAxis, so make sure that it's not invoked. assert ("chart.xAxis" not in chart.htmlcontent)
def test_discreteBarChart(self): """Test discrete Bar Chart""" type = "discreteBarChart" chart = discreteBarChart(name=type, height=350) xdata = ["A", "B", "C", "D", "E", "F", "G"] ydata = [3, 12, -10, 5, 35, -7, 2] chart.add_serie(y=ydata, x=xdata) chart.buildhtml() # We don't modify the xAxis, so make sure that it's not invoked. assert("chart.xAxis" not in chart.htmlcontent)
def ave_temp_chart(): output_file = open('Average-Temp.html', 'w') chart = discreteBarChart(name="lineChart of average Temperature", width=1244) xdata = ["Ayuthaya", "Bangsai", "Chainat", "Dowkanong", "Nakhonsawan", "Pamok", "Samlea"] ydata = all_ave_temp extra_serie = {"tooltip": {"y_start": "", "y_end": " C"}} chart.add_serie(y=ydata, x=xdata, name='Temperature', extra=extra_serie) chart.buildhtml() output_file.write(chart.htmlcontent) # close Html file output_file.close()
def make_chart(*series, **kwargs): """ Makes a bar chart of the given results using nvd3 """ # Generate a chart ID chart_id = "chart_{0}".format(str(uuid.uuid4()).replace("-", "")) # Options required_keys = kwargs.get("required", None) # Prepare the chart chart = nvd3.discreteBarChart(name=chart_id, height=400, width=800) for serie in series: if not serie: # Ignore empty series continue if isinstance(serie, dict): # If the results are stored as a candidate -> score dictionary xdata, ydata = zip(*((key, serie[key]) for key in serie)) else: # Rotate results list((score, candidate) # ==> list(candidate), list(scores) ydata, xdata = zip(*serie) # Add missing keys if required_keys: to_add = [key for key in required_keys if key not in xdata] if to_add: # We have to add those keys: make data modifiable xdata = list(xdata) ydata = list(ydata) for key in to_add: xdata.append(key) ydata.append(0) # Normalize series ydata, xdata = zip(*sorted(zip(_normalize(ydata), _normalize(xdata)), reverse=True)) # Add the serie chart.add_serie(y=ydata, x=xdata) # Generate the HTML chart.buildcontainer() chart.buildjschart() # Return its HTML code return "{0}\n{1}\n".format(chart.container, chart.jschart)
def plotBarGraph(self, xValues, yValues, filename): """create BarPlot with nvd3""" output_file = open(filename, 'w') type = "discreteBarChart" chart = discreteBarChart(height=400, width=600) chart.set_containerheader("\n\n<h2>" + type + "</h2>\n\n") extra_serie = {"tooltip": {"y_start": "", "y_end": " cal"}} chart.add_serie(y=yValues, x=xValues, extra=extra_serie) chart.buildhtml() output_file.write(chart.htmlcontent) output_file.close()
def hello(): input_data = list(csv.reader(open('noCrimeOutput.txt', 'rb'), delimiter='\t')) chart = discreteBarChart(name='discreteBarChart', height=800, width=1800, margin_bottom=200, margin_top=40, margin_left=60, margin_right=60) crimes = [] for row in input_data: if int(row[1])>=5: crimes.append([row[0], int(row[1])]) xdata = [] ydata = [] crimes = sorted(crimes, key=lambda crimes: crimes[1], reverse=True) for place in crimes[:20]: xdata.append(place[0]) ydata.append(place[1]) chart.add_serie(y=ydata, x=xdata) chart.buildhtml() return chart.htmlcontent
def generate_distribution_chart(topics, name, key, mult=10.0, bars=10, include_none=False): chart = discreteBarChart(name=name, height=400, width=60 * bars) total_population = [] for topic in topics: population = retrieve_by_topic(topic, "users") for p in population: total_population.append(p) xdata = [str(((i + 1) * mult) * 100)[:-2] for i in range(bars)] if include_none: xdata.insert(0, "0") xdata.insert(-1, str(((100 * bars) * mult) - 1)[:-2] + " >") xdata.append(str((100 * bars) * mult)[:-2] + " >") ydata = get_distribution_stats(total_population, key, mult, bars) chart.add_serie(y=ydata, x=xdata) str(chart) return chart.content
def data(): #use this while sending a response #jdata=jsonify(get_data()) import json jdata = json.dumps(get_data()) objects = json.loads(jdata) rows = list(objects['children']) #print(columns.ite) good_columns = ["symbol", "volume", "percent_change", "net_change"] mydata = [] xdata = [] ydata = [] ydata2 = [] for row in rows: selected_row = [] for item in good_columns: selected_row.append(row[item]) mydata.append(selected_row) xdata.append(selected_row[0]) ydata.append(selected_row[2]) ydata2.append(selected_row[3]) import pandas as pd #stops = pd.DataFrame(data, columns=good_columns) from nvd3 import discreteBarChart chart = discreteBarChart(name='Stock Values', title='Stok Values', color_category='category20c', height=450, width=900) chart.add_serie(ydata, xdata, 'Percent Change') chart.add_serie(ydata2, xdata, 'Net Change') chart.buildcontent() #print (chart.htmlcontent) return render_template( 'stock.html', html_part=chart.htmlcontent, scripts=chart.header_js, year=datetime.now().year, app_name='MobilMed', )
html_open = """ <!DOCTYPE html> <html lang="en"> <head> <script src="https://ajax.googleapis.com/ajax/libs/jquery/1.10.2/jquery.min.js"></script> <link href="https://cdnjs.cloudflare.com/ajax/libs/nvd3/1.7.0/nv.d3.min.css" rel="stylesheet" /> <script src="https://cdnjs.cloudflare.com/ajax/libs/d3/3.5.5/d3.min.js"></script> <script src="https://cdnjs.cloudflare.com/ajax/libs/nvd3/1.7.0/nv.d3.min.js"></script> </head> """ output_file.write(html_open) type = "discreteBarChart" chart = discreteBarChart(name='my graphname', height=400, width=800, jquery_on_ready=True) chart.set_containerheader("\n\n<h2>" + type + "</h2>\n\n") xdata = ["A", "B", "C", "D", "E", "F", "G"] ydata = [3, 12, -10, 5, 25, -7, 2] extra_serie = {"tooltip": {"y_start": "", "y_end": " cal"}} chart.add_serie(y=ydata, x=xdata, extra=extra_serie) chart.buildcontent() output_file.write(chart.htmlcontent) # --------------------------------------- type = "pie Chart" chart = pieChart(name=type, color_category='category20c', height=400, width=400, jquery_on_ready=True) chart.set_containerheader("\n\n<h2>" + type + "</h2>\n\n")
html_open = """ <!DOCTYPE html> <html lang="en"> <head> <script src="http://ajax.googleapis.com/ajax/libs/jquery/1.10.2/jquery.min.js"></script> <link media="all" href="./bower_components/nvd3/src/nv.d3.css" type="text/css" rel="stylesheet" /> <script src="./bower_components/d3/d3.min.js" type="text/javascript"></script> <script src="./bower_components/nvd3/nv.d3.min.js" type="text/javascript"></script> </head> """ output_file.write(html_open) type = "discreteBarChart" chart = discreteBarChart(name=type, height=400, jquery_on_ready=True) chart.set_containerheader("\n\n<h2>" + type + "</h2>\n\n") xdata = ["A", "B", "C", "D", "E", "F", "G"] ydata = [3, 12, -10, 5, 35, -7, 2] extra_serie = {"tooltip": {"y_start": "", "y_end": " cal"}} chart.add_serie(y=ydata, x=xdata, extra=extra_serie) chart.buildcontent() output_file.write(chart.htmlcontent) #--------------------------------------- type = "pieChart" chart = pieChart(name=type, color_category='category20c', height=400, width=400, jquery_on_ready=True) chart.set_containerheader("\n\n<h2>" + type + "</h2>\n\n")
#!/usr/bin/env python # -*- coding: UTF-8 -*- from nvd3 import discreteBarChart d = {'ภาคกลาง': {'ฉะเชิงเทรา': {2552: 7040, 2545: 12204, 2547: 17961, 2549: 20599, 2550: 23235}, 'ปทุมธานี': {2552: 9474, 2545: 16592, 2547: 20006, 2549: 24569, 2550: 25225}, 'ประจวบคีรีขันธ์': {2552: 6814, 2545: 7311, 2547: 8695, 2549: 9729, 2550: 10015}, 'นนทบุรี': {2552: 11925, 2545: 7974, 2547: 9259, 2549: 11464, 2550: 12301}, 'กาญจนบุรี': {2552: 4986, 2545: 4706, 2547: 5074, 2549: 6131, 2550: 6807}, 'จันทบุรี': {2552: 7787, 2545: 6932, 2547: 7713, 2549: 9308, 2550: 10690}, 'ตราด': {2552: 6667, 2545: 6870, 2547: 7886, 2549: 9259, 2550: 9969}, 'อ่างทอง': {2552: 7773, 2545: 3828, 2547: 4634, 2549: 5269, 2550: 5507}, 'เพชรบุรี': {2552: 8582, 2545: 5622, 2547: 6848, 2549: 7679, 2550: 8066}, 'สระแก้ว': {2552: 6122, 2545: 2311, 2547: 2730, 2549: 3441, 2550: 3782}, 'นครปฐม': {2552: 7916, 2545: 9976, 2547: 11603, 2549: 13592, 2550: 12761}, 'นครนายก': {2552: 6064, 2545: 3877, 2547: 4181, 2549: 4349, 2550: 4770}, 'ปราจีนบุรี': {2552: 8983, 2545: 13669, 2547: 19484, 2549: 25662, 2550: 31645}, 'สุพรรณบุรี': {2552: 4691, 2545: 3274, 2547: 4044, 2549: 4718, 2550: 4954}, 'กรุงเทพมหานคร': {2552: 11829, 2545: 25448, 2547: 29167, 2549: 32986, 2550: 34240}, 'พระนครศรีอยุธยา': {2552: 7489, 2545: 19266, 2547: 23289, 2549: 26376, 2550: 30024}, 'สมุทรปราการ': {2552: 8902, 2545: 26409, 2547: 27235, 2549: 29890, 2550: 37437}, 'ชัยนาท': {2552: 6920, 2545: 3769, 2547: 4076, 2549: 4341, 2550: 4892}, 'สมุทรสาคร': {2552: 7114, 2545: 27617, 2547: 33819, 2549: 36274, 2550: 37318}, 'สิงห์บุรี': {2552: 7629, 2545: 4429, 2547: 5592, 2549: 6598, 2550: 7075}, 'สระบุรี': {2552: 7179, 2545: 12207, 2547: 15502, 2549: 18344, 2550: 18792}, 'ชลบุรี': {2552: 8489, 2545: 20456, 2547: 24351, 2549: 35347, 2550: 40532}, 'ลพบุรี': {2552: 6552, 2545: 5682, 2547: 6049, 2549: 6570, 2550: 6521}, 'ระยอง': {2552: 8262, 2545: 45448, 2547: 56429, 2549: 78547, 2550: 88512}, 'ราชบุรี': {2552: 7469, 2545: 7853, 2547: 8875, 2549: 10014, 2550: 10181}, 'สมุทรสงคราม': {2552: 7495, 2545: 3860, 2547: 4629, 2549: 6118, 2550: 5974}}, 'ภาคตะวันออกเฉียงเหนือ': {'กาฬสินธุ์': {2552: 6834, 2545: 1577, 2547: 1940, 2549: 2340, 2550: 2506}, 'อำนาจเจริญ': {2552: 3221, 2545: 1330, 2547: 1592, 2549: 1957, 2550: 2180}, 'สกลนคร': {2552: 4783, 2545: 1603, 2547: 2033, 2549: 2095, 2550: 2228}, 'นครราชสีมา': {2552: 5586, 2545: 3581, 2547: 4087, 2549: 4499, 2550: 4704}, 'อุดรธานี': {2552: 8184, 2545: 2037, 2547: 2428, 2549: 2779, 2550: 3182}, 'มุกดาหาร': {2552: 5551, 2545: 2025, 2547: 2351, 2549: 2776, 2550: 2918}, 'ยโสธร': {2552: 3181, 2545: 1445, 2547: 1760, 2549: 1915, 2550: 2045}, 'ร้อยเอ็ด': {2552: 3862, 2545: 1570, 2547: 1912, 2549: 2225, 2550: 2514}, 'บึงกาฬ': {2552: 0, 2545: 0, 2547: 0, 2549: 0, 2550: 0}, 'ขอนแก่น': {2552: 5914, 2545: 3241, 2547: 3888, 2549: 4836, 2550: 5164}, 'เลย': {2552: 4513, 2545: 1893, 2547: 2124, 2549: 2459, 2550: 2982}, 'สุรินทร์': {2552: 3067, 2545: 1512, 2547: 1797, 2549: 2106, 2550: 2303}, 'หนองบัวลำภู': {2552: 5311, 2545: 1267, 2547: 1673, 2549: 2048, 2550: 2239}, 'ชัยภูมิ': {2552: 3563, 2545: 1622, 2547: 1815, 2549: 2142, 2550: 2285}, 'บุรีรัมย์': {2552: 4172, 2545: 1664, 2547: 1850, 2549: 2183, 2550: 2297}, 'หนองคาย': {2552: 4793, 2545: 1855, 2547: 2154, 2549: 2558, 2550: 2611}, 'ศรีสะเกษ': {2552: 3011, 2545: 1265, 2547: 1528, 2549: 1854, 2550: 2034}, 'มหาสารคาม': {2552: 5579, 2545: 1513, 2547: 2130, 2549: 2134, 2550: 2367}, 'อุบลราชธานี': {2552: 3695, 2545: 1935, 2547: 2207, 2549: 2462, 2550: 2610}, 'นครพนม': {2552: 3940, 2545: 1639, 2547: 1847, 2549: 2134, 2550: 2267}}, 'ภาคใต้': {'นครศรีธรรมราช': {2552: 9434, 2545: 4285, 2547: 5233, 2549: 5811, 2550: 5989}, 'ระนอง': {2552: 7495, 2545: 5641, 2547: 7325, 2549: 8075, 2550: 8405}, 'พังงา': {2552: 8211, 2545: 5638, 2547: 7777, 2549: 9519, 2550: 9821}, 'กระบี่': {2552: 6098, 2545: 5640, 2547: 8471, 2549: 9808, 2550: 11024}, 'สตูล': {2552: 5419, 2545: 5523, 2547: 6294, 2549: 7240, 2550: 7417}, 'ปัตตานี': {2552: 4183, 2545: 4006, 2547: 4014, 2549: 4319, 2550: 4034}, 'ตรัง': {2552: 5779, 2545: 4491, 2547: 6000, 2549: 7650, 2550: 7504}, 'พัทลุง': {2552: 6317, 2545: 2274, 2547: 3170, 2549: 4164, 2550: 4270}, 'นราธิวาส': {2552: 3251, 2545: 2292, 2547: 3251, 2549: 4324, 2550: 4444}, 'ชุมพร': {2552: 8318, 2545: 5279, 2547: 6652, 2549: 7665, 2550: 8617}, 'ภูเก็ต': {2552: 10873, 2545: 16912, 2547: 19294, 2549: 21373, 2550: 24727}, 'สุราษฎร์ธานี': {2552: 8333, 2545: 5874, 2547: 8256, 2549: 10488, 2550: 10167}, 'สงขลา': {2552: 8772, 2545: 6896, 2547: 8171, 2549: 9504, 2550: 9401}, 'ยะลา': {2552: 5700, 2545: 3433, 2547: 4851, 2549: 6386, 2550: 6718}}, 'ภาคเหนือ': {'ลำพูน': {2552: 4758, 2545: 7171, 2547: 7933, 2549: 9699, 2550: 9908}, 'กำแพงเพชร': {2552: 5346, 2545: 4503, 2547: 6149, 2549: 7514, 2550: 8006}, 'เชียงราย': {2552: 5051, 2545: 2314, 2547: 2778, 2549: 3310, 2550: 3654}, 'พิจิตร': {2552: 6291, 2545: 2514, 2547: 2956, 2549: 3616, 2550: 3653}, 'เพชรบูรณ์': {2552: 6773, 2545: 2222, 2547: 2645, 2549: 3288, 2550: 3546}, 'อุตรดิตถ์': {2552: 5934, 2545: 2490, 2547: 2897, 2549: 3620, 2550: 3591}, 'แม่ฮ่องสอน': {2552: 2861, 2545: 1968, 2547: 2220, 2549: 2510, 2550: 2648}, 'พะเยา': {2552: 4555, 2545: 2091, 2547: 2533, 2549: 3176, 2550: 3356}, 'น่าน': {2552: 4285, 2545: 2136, 2547: 2427, 2549: 2760, 2550: 3043}, 'นครสวรรค์': {2552: 5528, 2545: 3121, 2547: 3938, 2549: 4776, 2550: 4826}, 'ลำปาง': {2552: 5162, 2545: 3476, 2547: 3774, 2549: 4046, 2550: 4170}, 'สุโขทัย': {2552: 6686, 2545: 2212, 2547: 2641, 2549: 3000, 2550: 3178}, 'พิษณุโลก': {2552: 6491, 2545: 3585, 2547: 3930, 2549: 4703, 2550: 4952}, 'ตาก': {2552: 4574, 2545: 2864, 2547: 3603, 2549: 4564, 2550: 4659}, 'แพร่': {2552: 6399, 2545: 2063, 2547: 2459, 2549: 2704, 2550: 2857}, 'อุทัยธานี': {2552: 5878, 2545: 2650, 2547: 3236, 2549: 3849, 2550: 4475}, 'เชียงใหม่': {2552: 5793, 2545: 4470, 2547: 5202, 2549: 6064, 2550: 6241}}} output_file = open('test-nvd3.html', 'w') chart = discreteBarChart(name='discreteBarChart', height=600, width=2000) xdata = [] ydata = [] for i in d: for j in d[i]: xdata.append(j) ydata.append(d[i][j][2552]) chart.add_serie(y=ydata, x=xdata) chart.buildhtml() output_file.write(chart.htmlcontent) # close Html file output_file.close()
""" Examples for Python-nvd3 is a Python wrapper for NVD3 graph library. NVD3 is an attempt to build re-usable charts and chart components for d3.js without taking away the power that d3.js gives you. Project location : https://github.com/areski/python-nvd3 """ from nvd3 import discreteBarChart #Open File for test output_file = open('test_discreteBarChart.html', 'w') type = "discreteBarChart" chart = discreteBarChart(name='mygraphname', height=400, width=600) chart.set_containerheader("\n\n<h2>" + type + "</h2>\n\n") xdata = ["A", "B", "C", "D", "E", "F", "G"] ydata = [3, 12, -10, 5, 25, -7, 2] extra_serie = {"tooltip": {"y_start": "", "y_end": " cal"}} chart.add_serie(y=ydata, x=xdata, extra=extra_serie) chart.buildhtml() output_file.write(chart.htmlcontent) #--------------------------------------- #close Html file output_file.close()
#!/usr/bin/python # -*- coding: utf-8 -*- """ Examples for Python-nvd3 is a Python wrapper for NVD3 graph library. NVD3 is an attempt to build re-usable charts and chart components for d3.js without taking away the power that d3.js gives you. Project location : https://github.com/areski/python-nvd3 """ from nvd3 import discreteBarChart #Open File for test output_file = open('test_discreteBarChart.html', 'w') type = "discreteBarChart" chart = discreteBarChart(name=type, height=400, width=400) chart.set_containerheader("\n\n<h2>" + type + "</h2>\n\n") xdata = ["A", "B", "C", "D", "E", "F", "G"] ydata = [3, 12, -10, 5, 35, -7, 2] extra_serie = {"tooltip": {"y_start": "", "y_end": " cal"}} chart.add_serie(y=ydata, x=xdata, extra=extra_serie) chart.buildhtml() output_file.write(chart.htmlcontent) #--------------------------------------- #close Html file output_file.close()
import os import csv from nvd3 import discreteBarChart output = open('static/index.html', 'w') input_data = list(csv.reader(open('noCrimeOutput.txt', 'rb'), delimiter='\t')) chart = discreteBarChart(name='discreteBarChart', height=800, width=1800, margin_bottom=200, margin_top=40, margin_left=60, margin_right=60, xAxis_rotateLabels=-90) crimes = [] for row in input_data: if int(row[1])>=5: crimes.append([row[0], int(row[1])]) xdata = [] ydata = [] crimes = sorted(crimes, key=lambda crimes: crimes[1], reverse=True) # print crimes for place in crimes: xdata.append(place[0]) ydata.append(place[1]) chart.add_serie(y=ydata, x=xdata) chart.buildhtml() output.write(chart.htmlcontent)
# -*- coding: utf-8 -*- """ Examples for Python-nvd3 is a Python wrapper for NVD3 graph library. NVD3 is an attempt to build re-usable charts and chart components for d3.js without taking away the power that d3.js gives you. Project location : https://github.com/areski/python-nvd3 """ from nvd3 import discreteBarChart # Open File for test output_file = open('test_discreteBarChart.html', 'w') type = "discreteBarChart" chart = discreteBarChart(name='mygraphname', height=400, width=600) chart.set_containerheader("\n\n<h2>" + type + "</h2>\n\n") xdata = ["A", "B", "C", "D", "E", "F", "G"] ydata = [3, 12, -10, 5, 25, -7, 2] extra_serie = {"tooltip": {"y_start": "", "y_end": " cal"}} chart.add_serie(y=ydata, x=xdata, extra=extra_serie) chart.buildhtml() output_file.write(chart.htmlcontent) # --------------------------------------- # close Html file output_file.close() output_file = open('test_discreteBarChart2.html', 'w')
from github import Github import getpass from nvd3 import discreteBarChart #https://github.com/PyGithub/PyGithub #outputs a html file that contains a bar chart of commits in a repo that the user owns. #uses python-nvd3 for graphs # Open File to write the D3 Graph output_file = open('master-commits-bar-chart.html', 'w') xdata = [] ydata = [] chart = discreteBarChart(name='discreteBarChart', height=400, width=400) # using username and password user = raw_input("Enter username: "******"Enter repository name: ") g = Github(user, password) # Then play with your Github objects: repo = g.get_user().get_repo(r) i = 0 for con in repo.get_contributors(): xdata.insert(i, con.login) ydata.insert(i, con.contributions) i += 1
from nvd3 import multiBarChart from nvd3 import scatterChart 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_demo_all.html', 'w') #--------------------------------------- type = "discreteBarChart" chart = discreteBarChart(name=type, height=400) chart.set_containerheader("\n\n<h2>" + type + "</h2>\n\n") xdata = ["A", "B", "C", "D", "E", "F", "G"] ydata = [3, 12, -10, 5, 35, -7, 2] extra_serie = {"tooltip": {"y_start": "", "y_end": " cal"}} chart.add_serie(y=ydata, x=xdata, extra=extra_serie) chart.buildhtml() output_file.write(chart.htmlcontent) #--------------------------------------- type = "pieChart" chart = pieChart(name=type, color_category='category20c', height=400, width=400) chart.set_containerheader("\n\n<h2>" + type + "</h2>\n\n")
import numpy as np import nvd3 np.random.seed(100) chart_type = 'discreteBarChart' chart = nvd3.discreteBarChart(name=chart_type, color_category='category20c', height=450, width=450) ydata = [3, 4, 0, 1, 5, 7, 3] xdata = ["Orange", "Banana", "Pear", "Kiwi", "Apple", "Strawberry", "Pineapple"] chart.add_serie(y=ydata, x=xdata) chart.buildhtml() chart_html = chart.htmlcontent (print(chart_html))
#!/usr/bin/python # -*- coding: utf-8 -*- """ Examples for Python-nvd3 is a Python wrapper for NVD3 graph library. NVD3 is an attempt to build re-usable charts and chart components for d3.js without taking away the power that d3.js gives you. Project location : https://github.com/areski/python-nvd3 """ from nvd3 import discreteBarChart # Open File for test output_file = open('test_discreteBarChart.html', 'w') type = "discreteBarChart" chart = discreteBarChart(name='mygraphname', height=400, width=600) chart.set_containerheader("\n\n<h2>" + type + "</h2>\n\n") xdata = ["A", "B", "C", "D", "E", "F", "G"] ydata = [3, 12, -10, 5, 25, -7, 2] extra_serie = {"tooltip": {"y_start": "", "y_end": " cal"}} chart.add_serie(y=ydata, x=xdata, extra=extra_serie) chart.buildhtml() output_file.write(chart.htmlcontent) # --------------------------------------- # close Html file output_file.close()
from nvd3 import discreteBarChart import random import datetime import time # Open File for test output_file = open('test_discreteBarChart_with_date.html', 'w') type = "discreteBarChart" start_time = int(time.mktime(datetime.datetime(2012, 6, 1).timetuple()) * 1000) nb_element = 10 xdata = list(range(nb_element)) xdata = [start_time + x * 1000000000 for x in xdata] ydata = [i + random.randint(1, 10) for i in range(nb_element)] chart = discreteBarChart(name=type, height=400, width=600, x_is_date=True, x_axis_format="%d-%b") chart.set_containerheader("\n\n<h2>" + type + "</h2>\n\n") extra_serie = {"tooltip": {"y_start": "", "y_end": " cal"}} chart.add_serie(y=ydata, x=xdata, extra=extra_serie) chart.buildhtml() output_file.write(chart.htmlcontent) # --------------------------------------- # close Html file output_file.close()
def hello(): chart_algo = [] loop10Time = [] def getSize(filename): st = os.stat(filename) return st.st_size # Python program for KMP Algorithm def KMPSearch(pat, txt, filename, counter, s1): M = len(pat) N = len(txt) # create lps[] that will hold the longest prefix suffix # values for pattern lps = [0] * M j = 0 # index for pat[] # Preprocess the pattern (calculate lps[] array) computeLPSArray(pat, M, lps) i = 0 # index for txt[] while i < N: if pat[j] == txt[i]: i += 1 j += 1 if j == M: #print "Found pattern at index " + str(i-j) #global s1 #global counter s1[counter] = 1 #print "Plagarized from file : "+filename #print "Plagarized sentence : "+pat+"\n\n" j = lps[j - 1] return (pat, counter, s1) # mismatch after j matches elif i < N and pat[j] != txt[i]: # Do not match lps[0..lps[j-1]] characters, # they will match anyway if j != 0: j = lps[j - 1] else: i += 1 return (None, counter, s1) def computeLPSArray(pat, M, lps): len = 0 # length of the previous longest prefix suffix lps[0] # lps[0] is always 0 i = 1 # the loop calculates lps[i] for i = 1 to M-1 while i < M: if pat[i] == pat[len]: len += 1 lps[i] = len i += 1 else: if len != 0: # This is tricky. Consier the example AAACAAAA # and i = 7 len = lps[len - 1] # Also, note that we do not increment i here else: lps[i] = 0 i += 1 def comparefile(inputfile, targetfile, sentences, s1, algo): global filecontent global searchcontent input = open(inputfile, "rb") test = open(targetfile, "rb") filecontent = input.read() searchcontent = test.read() #global sentences #print s1 print "FILE: " + targetfile + " SIZE: " + str(getSize(targetfile)) #global counter counter = 0 plagarized_sentences = [] all_time = [] for run10 in range(0, 10): counter = 0 before = time.time() for sentence in sentences: if sentence != "": #print str(counter)+" ) "+sentence+"\n" if algo == "NAIVE": plagarized_sentence, counter, s1 = naive.search( sentence, searchcontent, os.path.basename(targetfile), counter, s1) if algo == "KMP": plagarized_sentence, counter, s1 = KMPSearch( sentence, searchcontent, os.path.basename(targetfile), counter, s1) if algo == "LCSS": plagarized_sentence, counter, s1 = lcss.lcss( sentence, searchcontent, os.path.basename(targetfile), counter, s1) if algo == "BM": plagarized_sentence, counter, s1 = moore.BMSearch( searchcontent, sentence, os.path.basename(targetfile), counter, s1) counter = counter + 1 if (str(plagarized_sentence) != "None"): plagarized_sentences.append(plagarized_sentence) after = time.time() timetaken = after - before all_time.append(timetaken) print timetaken #print "----------------------------------------------------------------------" #print "\n\n\nPlagarized from file : "+os.path.basename(targetfile) +"\n" #print plagarized_sentences avgtime = sum(all_time) / len(all_time) all_time = [] loop10Time.append(avgtime) print "Average Time Taken : " + str(avgtime) print "---------------------------------------------------------------------" return (sentences, s1) def reset_s1_and_counter(sentences, s1, counter): s1 = [] for i in range(len( sentences)): # This is just to tell you how to create a list. s1.append(0) counter = 0 return (sentences, s1, counter) def compareallfiles(inputfile, sentences, s1, algo): global filecontent global searchcontent print "---------------------------------------------------------------------" print "Algorithm = " + algo + "\n\n" sentences, s1, counter = reset_s1_and_counter(sentences, s1=[], counter=0) for filepath in allfiles: #outputfile = relativefolder+"/A.txt" sentences, s1 = comparefile(inputfile, filepath, sentences, s1, algo) #print s1 sum = 0 for s in s1: sum = sum + s prob = float(sum) * 100 / len(s1) #print sum #print len(s1) print str(prob) + " % Plagarized" return (sentences, s1) inputfile = "input.txt" relativefolder = "target" allfiles = glob.glob(relativefolder + "/*.txt") #print os.path.basename(a[0]) input = open(inputfile, "rb") sentences = [] sentences = filter(None, input.read().split(".")) sentences, s1, counter = reset_s1_and_counter(sentences, s1=[], counter=0) algo = "NAIVE" sentences, s1 = compareallfiles(inputfile, sentences, s1, algo) algo = "KMP" sentences, s1 = compareallfiles(inputfile, sentences, s1, algo) algo = "LCSS" sentences, s1 = compareallfiles(inputfile, sentences, s1, algo) algo = "BM" sentences, s1 = compareallfiles(inputfile, sentences, s1, algo) chart_algo = [ "Naive String : " + str(loop10Time[0]), "KMP : " + str(loop10Time[1]), "LCSS : " + str(loop10Time[2]), "BM : " + str(loop10Time[3]) ] chart = discreteBarChart(name='multiBarChart', height=800, width=1800, margin_bottom=30, margin_top=40, margin_left=260, margin_right=300) chart.add_serie(y=loop10Time, x=chart_algo) chart.buildhtml() return chart.htmlcontent + "Pattern Size: " + str( len(filecontent)) + "<br>File Size: " + str(len(searchcontent))
html_open = """ <!DOCTYPE html> <html lang="en"> <head> <script src="//ajax.googleapis.com/ajax/libs/jquery/1.10.2/jquery.min.js"></script> <link media="all" href="http://nvd3.org/src/nv.d3.css" type="text/css" rel="stylesheet" /> <script src="//nvd3.org/lib/d3.v2.js" type="text/javascript"></script> <script src="//nvd3.org/nv.d3.js" type="text/javascript"></script> </head> """ output_file.write(html_open) type = "discreteBarChart" chart = discreteBarChart(name=type, height=400, jquery_on_ready=True) chart.set_containerheader("\n\n<h2>" + type + "</h2>\n\n") xdata = ["A", "B", "C", "D", "E", "F", "G"] ydata = [3, 12, -10, 5, 35, -7, 2] extra_serie = {"tooltip": {"y_start": "", "y_end": " cal"}} chart.add_serie(y=ydata, x=xdata, extra=extra_serie) chart.buildcontent() output_file.write(chart.htmlcontent) #--------------------------------------- type = "pieChart" chart = pieChart(name=type, color_category='category20c', height=400,
def graph_experiment_factors(): requete="SELECT experiment.experiment_factors,experiment.project_id "\ "FROM chips.experiment;" r, data = getdata(requete) list_element = [] comptability = {} for j in range(len(data)): text = data[j][0] for elemnt in text.split(','): if elemnt[0] == ' ': elemnt = elemnt[1:] elemnt = elemnt.replace('\t', '') if elemnt[-1] == ' ': elemnt = elemnt[0:-1] if elemnt[-5:] == 'a wt)': elemnt = elemnt[0:-4] if elemnt[0:2] != '--': list_element.append(elemnt) if elemnt not in comptability.keys(): comptability[elemnt] = [data[j][1]] else: cpt = comptability[elemnt] cpt.append(data[j][1]) comptability[elemnt] = list(set(cpt)) #data_plot={} #for element in comptability.keys(): # data_plot[0] from nvd3 import discreteBarChart chart = discreteBarChart(name='discreteBarChart', height=400, width=800) xdata = [] ydata = [] list1 = list(comptability.keys()) #[0:20] dataplost = {} for element in list1: dataplost[element] = len(comptability[element]) a = sorted(dataplost, key=dataplost.__getitem__, reverse=True) ######a corriger car fixer for element in a[0:30]: xdata.append(element) ydata.append(dataplost[element]) #xdata.append(element)# = ["A", "B", "C", "D", "E", "F"] #ydata.append(len(comptability[element]))# = [3, 4, 0, -3, 5, 7] #array=np.array([xdata,ydata]) #a=np.sort(array,axis=1) chart.add_serie(y=ydata, x=xdata) chart.buildhtml() text = chart.htmlcontent argument1 = "var chart = nv.models.discreteBarChart();\n\n" argument2 = "var chart = nv.models.discreteBarChart();\n\n chart.xAxis.rotateLabels(-90); \n\n" text = text.replace(argument1, argument2) argument3 = "nv.addGraph(function() {\n" argument4 = "function rungraphdiscret(){ \n nv.addGraph(function() {\n" text = text.replace(argument3, argument4) argument5 = "</script>" argument6 = "};\n rungraphdiscret(); alert();\n </script>" text = text.replace(argument5, argument6) return text
#print(all_data) print("iterate") alldata_count = 0 while alldata_count < int(len(all_data)): x_data.append(all_data[alldata_count][0]) y_data.append(all_data[alldata_count][1]) # print(all_data[alldata_count][0]) # print(all_data[alldata_count][1]) alldata_count += 1 #Open File to write the D3 Graph output_file = open(report_name, 'w') chart_type = 'discreteBarChart' chart = discreteBarChart(name=chart_type, height=500, width=5000) title = 'Github BarChart showing Repo commits for ' + org_name + ' with ' + str( repo_count) + ' repos' chart.set_containerheader("\n\n<h2>" + title + "</h2>\n\n") chart.add_serie(y=y_data, x=x_data) chart.buildhtml() chart_html = chart.htmlcontent output_file.write(chart.htmlcontent) #close Html file output_file.close() print("finished report") path = os.path.abspath(report_name)
import time # Open File for test output_file = open('test_discreteBarChart_with_date.html', 'w') type = "discreteBarChart" start_time = int(time.mktime(datetime.datetime(2012, 6, 1).timetuple()) * 1000) nb_element = 10 xdata = list(range(nb_element)) xdata = [start_time + x * 1000000000 for x in xdata] ydata = [i + random.randint(1, 10) for i in range(nb_element)] chart = discreteBarChart(name=type, height=400, width=600, x_is_date=True, x_axis_format="%d-%b") chart.set_containerheader("\n\n<h2>" + type + "</h2>\n\n") extra_serie = {"tooltip": {"y_start": "", "y_end": " cal"}} chart.add_serie(y=ydata, x=xdata, extra=extra_serie) chart.buildhtml() output_file.write(chart.htmlcontent) # --------------------------------------- # close Html file output_file.close()