Esempio n. 1
0
def getLineImg(dish,filename):
        conn = pymysql.connect(host='127.0.0.1', port=3306, user='******', passwd='123456', db='biafinal_db')
        cur = conn.cursor()
        cmd = "select rating,review_count from restaurant_info "
        print cmd
        cur.execute(cmd)
        print(cur.description)

        ratings = []
        reviews = []
        for r in cur:
            #print (r[2])
            ratings.append(float(r[0]))
            reviews.append(float(r[1]))

        print ratings ,reviews
        #d3py

        
        T = 5*np.pi
        x = np.asarray(ratings)
        a = 0.05
        y = np.exp(-a*x) * np.sin(x)

        df = pandas.DataFrame({
            'x': x,
            'y': y
        })


        with d3py.PandasFigure(df, 'd3py_line', width=600, height=200) as fig:
            fig += d3py.geoms.Line('x', 'y', stroke='BlueViolet')
            fig += d3py.xAxis('x')
            fig += d3py.yAxis('y')
            fig.show(False,filename)
Esempio n. 2
0
def knn(ipaddress="localhost", port="9999"):
    '''
    用D3.JS展示Knn算法的运行结果
    :return:
    '''
    testNum, errorRate, errorCount, classifierData, realData = knn1.displayData(
        'data/edx_knn.csv')
    x = np.linspace(0, testNum, testNum)
    df = pandas.DataFrame({
        'x': x,
        'y': classifierData[:testNum],
        'z': realData[:testNum],
    })

    print "testNummber = %d \n" % testNum, "error rate : %f \n" % (
        errorCount / float(testNum)), "error count:%d \n" % errorCount

    webbrowser.open_new_tab("http://%s:%s/%s.html" %
                            (ipaddress, port, "disply_knn"))
    with d3py.PandasFigure(df,
                           'disply_knn',
                           width=20000,
                           height=200,
                           port=int(port)) as fig:
        fig += d3py.geoms.Line('x', 'y', stroke='BlueViolet')
        fig += d3py.geoms.Line('x', 'z', stroke='DeepPink')
        fig += d3py.xAxis('x', label="test number")
        fig += d3py.yAxis('y', label="test label")
        fig.show()
Esempio n. 3
0
 def getD3(self, xlabel="item", ylabel="count"):
     df = pd.DataFrame({xlabel: [], ylabel: []})
     p = d3py.PandasFigure(df)
     p += d3py.Bar(x=xlabel, y=ylabel)
     # p += d3py.Line(x = xlabel, y=ylabel)
     p += d3py.xAxis(x=xlabel)
     p += d3py.yAxis(y=ylabel)
     p.update()
     p.js.merge(p.js_geoms)
     d3 = {}
     d3['js'] = p.js
     d3['css'] = "%s\n%s" % (p.css, p.css_geoms)
     return d3
Esempio n. 4
0
	def getD3(self, xlabel="item", ylabel="count"):
		df = pd.DataFrame({xlabel:[],ylabel:[]})
		p = d3py.PandasFigure(df)
		p += d3py.Bar(x = xlabel, y=ylabel)
		# p += d3py.Line(x = xlabel, y=ylabel)
		p += d3py.xAxis(x = xlabel)
		p += d3py.yAxis(y = ylabel)
		p.update()
		p.js.merge(p.js_geoms)
		d3 = {}
		d3['js'] = p.js
		d3['css'] = "%s\n%s"%(p.css, p.css_geoms)
		return d3
Esempio n. 5
0
    def get(self):
        self.response.headers['Content-Type'] = 'text/plain'
        conn = MySQLdb.connect(host='127.0.0.1', port=3306, user='******',passwd='123456', db='biafinal_db')
        #conn = get_connection()
        #conn = pymysql.connect(host='127.0.0.1', port=3306, user='******', passwd='123456', db='biafinal_db')
        cur = conn.cursor()
        cur.execute("select rest_name,rating,review_count from restaurant_info where rest_id in"\
                "(" \
                "select rest_id from rest_category where cate_id in "\
                "(SELECT cate_id FROM biafinal_db.category where cate_name like 'Burgers%')"\
                ")")
        r = cur.fetchall()

        ratings = []
        titles = []
        c = 'a'
        for r in cur:
            #self.response.write(r[2])
            ratings.append(r[2])
            titles.append(c)
            c+=1

        #d3py
        df = pandas.DataFrame(
            {
                "count" : ratings,
                "apple_type": titles,
            }
        )

        ratioimg = "./ratios.png"
        with d3py.PandasFigure(df) as p:
            p += d3py.Bar(x = "apple_type", y = "count", fill = "MediumAquamarine")
            p += d3py.xAxis(x = "apple_type")
            p.show(False,ratioimg)

        cur.close()
        conn.close()
        return "<img src=%s >"%(ratioimg)
Esempio n. 6
0
def getRatioImg(dish,filename):
        conn = pymysql.connect(host='127.0.0.1', port=3306, user='******', passwd='123456', db='biafinal_db')
        cur = conn.cursor()
        cmd = "select rest_name,rating,review_count from restaurant_info where rest_id in"\
                "(" \
                "select rest_id from rest_category where cate_id in "\
                "(SELECT cate_id FROM biafinal_db.category where cate_name like '{0}%')"\
                ")".format(dish)
        print cmd
        cur.execute(cmd)
        print(cur.description)
        #r = cur.fetchall()

        ratings = []
        titles = []
        c = 1
        for r in cur:
            #print (r[2])
            ratings.append(r[1])
            titles.append("T{0}".format(c))
            c += 1 

        print ratings ,titles
        #d3py
        df = pandas.DataFrame(
            {
                "count" : ratings,
                "ratio": titles,
            }
        )

        with d3py.PandasFigure(df) as p:
            p += d3py.Bar(x = "ratio", y = "count", fill = "MediumAquamarine")
            p += d3py.xAxis(x = "ratio")
            p.show(False,filename)

        cur.close()
        conn.close()
        return filename 
Esempio n. 7
0
def knn(ipaddress = "localhost",port = "9999"):
    '''
    用D3.JS展示Knn算法的运行结果
    :return:
    '''
    testNum,errorRate, errorCount, classifierData, realData = knn1.displayData(
        'data/edx_knn.csv');
    x = np.linspace(0,testNum,testNum)
    df = pandas.DataFrame({
    'x' : x,
    'y' : classifierData[:testNum],
    'z' : realData[:testNum],
    })

    print "testNummber = %d \n" % testNum, "error rate : %f \n" % (errorCount/float(testNum)), "error count:%d \n" % errorCount

    webbrowser.open_new_tab("http://%s:%s/%s.html" % (ipaddress, port, "disply_knn"))
    with d3py.PandasFigure(df, 'disply_knn', width=20000, height=200, port = int(port)) as fig:
        fig += d3py.geoms.Line('x', 'y', stroke='BlueViolet')
        fig += d3py.geoms.Line('x', 'z', stroke='DeepPink')
        fig += d3py.xAxis('x', label="test number")
        fig += d3py.yAxis('y', label="test label")
        fig.show()
Esempio n. 8
0
def getScatterImg(dish,filename):
        conn = pymysql.connect(host='127.0.0.1', port=3306, user='******', passwd='123456', db='biafinal_db')
        cur = conn.cursor()
        cmd = "select rest_name,rating,review_count from restaurant_info where rest_id in"\
                "(" \
                "select rest_id from rest_category where cate_id in "\
                "(SELECT cate_id FROM biafinal_db.category where cate_name like '{0}%')"\
                ")".format(dish)
        print cmd
        cur.execute(cmd)
        print(cur.description)

        ratings = []
        reviews = []
        for r in cur:
            #print (r[2])
            ratings.append(r[1])
            reviews.append(r[2])

        print ratings ,reviews
        #d3py

        df = pandas.DataFrame({
            'd1': ratings,
            'd2': reviews
        })

        with d3py.PandasFigure(df, "example scatter plot using d3py", width=400, height=400) as fig:
            fig += d3py.Point("d1", "d2", fill="DodgerBlue")
            fig += d3py.xAxis('d1', label="ratio")
            fig += d3py.yAxis('d2', label="review count")
            fig.show(False,filename)

        cur.close()
        conn.close()
        return filename 
Esempio n. 9
0
import pandas
import d3py
import pdb
import logging
pdb.set_trace()
logging.basicConfig(level=logging.DEBUG)


df = pandas.DataFrame(
    {
        "count" : [1,4,7,3,2,9],
        "apple_type": ["a", "b", "c", "d", "e", "f"],
    }
)

# use 'with' if you are writing a script and want to serve this up forever
with d3py.PandasFigure(df) as p:
    p += d3py.Bar(x = "apple_type", y = "count", fill = "MediumAquamarine")
    p += d3py.xAxis(x = "apple_type")
    p.show()

# if you are writing in a terminal, use without 'with' to keep everything nice
# and interactive
"""
p = d3py.PandasFigure(df)
p += d3py.Bar(x = "apple_type", y = "count", fill = "MediumAquamarine")
p += d3py.xAxis(x = "apple_type")
p.show()
"""
Esempio n. 10
0
import pandas
import d3py

df = pandas.DataFrame({
    "count": [1, 4, 7, 3, 2, 9],
    "apple_type": ["a", "b", "c", "d", "e", "f"]
})

with d3py.Figure(df) as p:
    p += d3py.Bar(x="apple_type", y="count", fill="MediumAquamarine")
    p += d3py.xAxis(x="apple_type")
    p.show()
Esempio n. 11
0
import numpy as np
import d3py
import pandas
T = 5*np.pi
x = np.linspace(-T,T,100)
a = 0.05
y = np.exp(-a*x) * np.sin(x)

df = pandas.DataFrame({
    'x' : x,
    'y' : y
})

with d3py.Figure(df, 'd3py_line', width=600, height=200) as fig:
    fig += d3py.geoms.Line('x', 'y')
    fig += d3py.geoms.Point('x', 'y', fill='BlueViolet')
    fig += d3py.xAxis('x')
    fig += d3py.yAxis('y')
    fig.show()
Esempio n. 12
0
import numpy as np
import pandas
import d3py
n = 400

df = pandas.DataFrame({
    'd1': np.arange(0,n),
    'd2': np.random.normal(0, 1, n)
})

with d3py.PandasFigure(df, "example scatter plot using d3py", width=400, height=400) as fig:
    fig += d3py.Point("d1", "d2", fill="DodgerBlue")
    fig += d3py.xAxis('d1', label="Random")
    fig += d3py.yAxis('d2', label="Also random")
    fig.show()
Esempio n. 13
0
import pandas
import d3py
import numpy as np

x = np.random.gamma(1, size=100)
count, bins = np.histogram(x)

df = pandas.DataFrame({"count": count, "apple_type": bins[:-1]})

with d3py.Figure(df) as p:
    p += d3py.Bar(x="apple_type", y="count", fill="MediumAquamarine")
    p += d3py.xAxis(x="apple_type", label="Apple Type")
    p += d3py.yAxis(y="count", label="Number")
    p.show()
Esempio n. 14
0
import numpy as np
import pandas
import d3py
n = 400

df = pandas.DataFrame({'d1': np.arange(0, n), 'd2': np.random.normal(0, 1, n)})

with d3py.PandasFigure(df,
                       "example scatter plot using d3py",
                       width=400,
                       height=400) as fig:
    fig += d3py.Point("d1", "d2", fill="DodgerBlue")
    fig += d3py.xAxis('d1', label="Random")
    fig += d3py.yAxis('d2', label="Also random")
    fig.show()
Esempio n. 15
0
import numpy as np
import pandas
import d3py
n = 400

df = pandas.DataFrame({
    'd1': np.arange(0,n),
    'd2': np.random.normal(0, 1, n)
})

with d3py.Figure(df, "my_figure", width=400, height=400) as fig:
    fig += d3py.Point("d1", "d2", fill="DodgerBlue")
    fig += d3py.xAxis('d1')
    fig.show()
Esempio n. 16
0
import numpy as np
import d3py
import pandas

T = 5 * np.pi
x = np.linspace(-T, T, 100)
a = 0.05
y = np.exp(-a * x) * np.sin(x)

df = pandas.DataFrame({"x": x, "y": y})

with d3py.PandasFigure(df, "d3py_line", width=600, height=200) as fig:
    fig += d3py.geoms.Line("x", "y", stroke="BlueViolet")
    fig += d3py.xAxis("x")
    fig += d3py.yAxis("y")
    fig.show()
Esempio n. 17
0
from datetime import datetime
import d3py
import pandas

dates = [
    datetime(2006, 1, 26, 11, 17, 32),
    datetime(2006, 2, 22, 1, 37, 33),
    datetime(2006, 3, 16, 1, 30, 11),
    datetime(2006, 3, 26, 19, 16, 43),
    datetime(2006, 4, 10, 20, 49, 38),
    datetime(2006, 4, 25, 22, 5, 23),
    datetime(2006, 5, 7, 3, 8, 9)
]

values = [
    0, 3.1622776601683795, 6.9039350469423209, 9.9039350469423209,
    12.732362171688511, 16.196463786826264, 20.886879546649695
]

df = pandas.DataFrame({'x': dates, 'y': values})

with d3py.Figure(df, 'd3py_line', width=600, height=200) as fig:
    fig += d3py.geoms.Line('x', 'y')
    fig += d3py.geoms.Point('x', 'y', fill='BlueViolet')
    fig += d3py.xAxis('x')
    fig += d3py.yAxis('y')
    fig.show()
Esempio n. 18
0
import pandas
import d3py
import numpy as np

x = np.random.gamma(1, size=100)
count, bins = np.histogram(x)

df = pandas.DataFrame({
    "count" : count,
    "apple_type" : bins[:-1]
})

with d3py.Figure(df) as p:
    p += d3py.Bar(x="apple_type", y = "count", fill = "MediumAquamarine")
    p += d3py.xAxis(x="apple_type", label="Apple Type")
    p += d3py.yAxis(y="count", label="Number")
    p.show()