本文整理匯總了Python中db.DB.get_data方法的典型用法代碼示例。如果您正苦於以下問題:Python DB.get_data方法的具體用法?Python DB.get_data怎麽用?Python DB.get_data使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類db.DB
的用法示例。
在下文中一共展示了DB.get_data方法的2個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Python代碼示例。
示例1: index
# 需要導入模塊: from db import DB [as 別名]
# 或者: from db.DB import get_data [as 別名]
def index():
'''
The only view we have. All in one page, where we check if user GETs or POSTs.
If user is POSTing we create a single list and append each from element into it.
Very important here is the sequence, since we are using it in the DB api.
When we get all data from the user we execute same procedure we do in GET:
- get all data and render out main html with it.
'''
api = DB()
if request.method == 'POST':
new_movie = []
_title = request.form.get('title')
new_movie.append(_title)
_story = request.form.get('story')
new_movie.append(_story)
_poster = request.form.get('poster')
new_movie.append(_poster)
_trailer = request.form.get('trailer')
new_movie.append(_trailer)
_cast = request.form.get('cast')
new_movie.append(_cast)
api.add(new_movie)
result = api.get_data()
return render_template("index.html", pname=pname, result=result)
result = api.get_data()
return render_template("index.html", pname=pname, result=result)
示例2: __init__
# 需要導入模塊: from db import DB [as 別名]
# 或者: from db.DB import get_data [as 別名]
class Caida:
def __init__(self):
self.db = DB('caida2')
def plot(self, day):
sql = "select source, dest from raw%d " % day
data = self.db.get_data(sql)
G = nx.Graph()
for tup in data:
G.add_edge(tup[0], tup[1])
print "plotting"
C = nx.connected_component_subgraphs(G)
l = []
for c in C:
edges = len(c.edges())
vertices = len(c.nodes())
l.append((edges, vertices))
sum_edges, sum_vertices = 0, 0
size = len(l)
for ele in l:
sum_edges += ele[0]
sum_vertices += ele[1]
print "%d, %f, %f" % (size, sum_edges / size, sum_vertices / size)
def line_plot(self, xarray, yarray, xlabel="x", ylabel="y"):
plt.plot(xarray, yarray)
plt.xlabel(xlabel)
plt.ylabel(ylabel)
def plotgeo(self, table):
sql = "select lat, lng, country from %s order by source limit 1000" % table
data = self.db.get_data(sql)
# x = [tup[0] for tup in data]
# y = [tup[1] for tup in data]
# self.line_plot(x, y, "lat", "lng")
plt.scatter()
for (xe, ye, country) in data:
plt.annotate(country, xy=(xe, ye), xytext=(-20, 20), textcoords='offset points', ha='right', va='bottom',
bbox=dict(boxstyle='round,pad=0.5', fc='yellow', alpha=0.5),
arrowprops=dict(arrowstyle='->', connectionstyle='arc3,rad=0'))
def plotgeo2(self, table):
sql = "select lat, lng, country, count(*) from %s group by country order by source" % table
data = self.db.get_data(sql)
x = [tup[0] for tup in data]
y = [tup[1] for tup in data]
size = [tup[3] for tup in data]
countries = [tup[0] for tup in self.db.get_data("select distinct country from %s" % table)]
colors = np.random.rand(len(countries))
colormap = {}
for index, c in enumerate(countries):
colormap[c] = colors[index]
npy = np.array(y)
npx = np.array(x)
plt.scatter(npx, npy, s=2, c=colors)
# for (x, y, label, ct) in data:
# plt.annotate(
# label,
# xy=(x, y), xytext=(-20, 20),
# textcoords='offset points', ha='right', va='bottom',
# bbox=dict(boxstyle='round,pad=0.5', fc='yellow', alpha=0.5),
# arrowprops=dict(arrowstyle='->', connectionstyle='arc3,rad=0'))
def plotgeo3(self, table):
colormap = {}
countries = [tup[0] for tup in self.db.get_data("select distinct country from %s" % table)]
colors = np.random.rand(len(countries))
for index, c in enumerate(countries):
colormap[c] = colors[index]
plots = []
for c in countries:
sql = "select lat, lng, country, count(*) from %s where country='%s' order by source" % (table, c)
data = self.db.get_data(sql)
x = [tup[0] for tup in data]
y = [tup[1] for tup in data]
size = [tup[3] for tup in data]
npy = np.array(y)
npx = np.array(x)
c_ = colormap[c]
print c_
plots.append(plt.scatter(npx, npy, s=size, c=c_))
plt.legend(tuple(plots),
tuple(countries),
scatterpoints=1,
loc='lower left',
ncol=3,
fontsize=8)
def addfromgen(self, conns1, gs):
for i in conns1:
#.........這裏部分代碼省略.........