本文整理汇总了Python中db.Db.execute_query方法的典型用法代码示例。如果您正苦于以下问题:Python Db.execute_query方法的具体用法?Python Db.execute_query怎么用?Python Db.execute_query使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类db.Db
的用法示例。
在下文中一共展示了Db.execute_query方法的4个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: project
# 需要导入模块: from db import Db [as 别名]
# 或者: from db.Db import execute_query [as 别名]
def project(cls):
data = Db.execute_query('''SELECT name, budget_value, main_color,
CASE WHEN budget_currency='EUR' THEN '315'
WHEN budget_currency='USD' THEN '260'
WHEN budget_currency='GBP' THEN '400'
ELSE budget_currency END FROM project''')
project_lista = [i[0] for i in data if i[0] is not None]
lista_color = [cls.normalize_color(i[2]) for i in data if i[0] is not None]
currency = [(i[3]) for i in data if i[0] is not None]
budget = [i[1] for i in data if i[0] is not None]
currency = map(int, currency)
budget = map(float, budget)
exchanged_budget = [a*b for a, b in zip(budget, currency)]
ultimate = [[x, lista_color[i]] for i, x in enumerate(project_lista)]
a_ultimate = [[x[0], x[1], exchanged_budget[i]] for i, x in enumerate(ultimate)]
a_ultimate = list(sorted(a_ultimate, key=lambda x: x[2], reverse=True))
text_boxes = []
counter = 0
for i in a_ultimate:
text = i[0]
color = tuple(i[1])
size = cls.size_calculate(counter)
text_boxes.append(cls(text, size, color))
counter += 1
return text_boxes
示例2: len_name
# 需要导入模块: from db import Db [as 别名]
# 或者: from db.Db import execute_query [as 别名]
def len_name(cls):
data = Db.execute_query("SELECT name, main_color FROM project WHERE name !='None' ORDER BY LENGTH(name) DESC")
name = [x[0] for x in data]
lista_color = [cls.normalize_color(x[1]) for x in data]
ultimate = [[x, lista_color[i]] for i, x in enumerate(name)]
text_boxes = []
counter = 0
for i in ultimate:
text = i[0]
size = cls.size_calculate(counter)
color = tuple(i[1])
text_boxes.append(cls(text, size, color))
counter += 1
return text_boxes
示例3: easteregg
# 需要导入模块: from db import Db [as 别名]
# 或者: from db.Db import execute_query [as 别名]
def easteregg(cls, extra):
data = Db.execute_query('''SELECT name, budget_value, budget_currency, main_color,
CASE WHEN budget_currency='EUR' THEN '315'
WHEN budget_currency='USD' THEN '260'
WHEN budget_currency='GBP' THEN '400'
ELSE budget_currency END FROM project WHERE name !='None' ''')
name = [x[0] for x in data]
lista_color = [cls.normalize_color(x[3]) for x in data]
currency = [x[2] for x in data]
budget_value = [i[1] for i in data]
budget_currency = [i[4] for i in data]
budget_value = map(float, budget_value)
budget_currency = map(int, budget_currency)
exchanged_budget = [a*b for a, b in zip(budget_value, budget_currency)]
ultimate_hyper_magnum = [[name[i], lista_color[i], exchanged_budget[i], currency[i]] for i in range(len(name))]
text_boxes = []
counter = 0
for i in ultimate_hyper_magnum:
if i[3] == 'GBP':
if extra:
i[0] = 'BREXIT'
i[1] = (0, 0, 0)
else:
i[1] = (random.choice([50, 100, 150, 200, 250]), 0, 0)
elif i[3] == 'USD':
i[1] = (0, random.choice([50, 100, 150, 200, 250]), 0)
else:
i[1] = (0, 0, random.choice([50, 100, 150, 200, 250]))
text = i[0]
color = i[1]
size = cls.size_calculate(counter)
text_boxes.append(cls(text, size, color))
counter += 1
return text_boxes
示例4: client
# 需要导入模块: from db import Db [as 别名]
# 或者: from db.Db import execute_query [as 别名]
def client(cls):
data = Db.execute_query("SELECT company_name, main_color FROM project")
lista = [i[0] for i in data]
lista_color = [cls.normalize_color(i[1]) for i in data]
clients = dict(zip(lista, [0] * len(lista)))
for i in lista:
clients[i] += 1
clients_list = list(sorted(clients, key=clients.get, reverse=True))
ultimate = [[x, lista_color[i]] for i, x in enumerate(lista)]
counter = 0
text_boxes = []
for i in clients_list:
avg_color = [0, 0, 0]
for j in ultimate:
if i == j[0]:
avg_color[0] += j[1][0]
avg_color[1] += j[1][1]
avg_color[2] += j[1][2]
avg_color[0] //= clients[i]
avg_color[1] //= clients[i]
avg_color[2] //= clients[i]
text = i
if counter < 1:
size = 4
elif counter < 5:
size = 3
elif counter < 13:
size = 2
elif counter < 27:
size = 1
else:
size = 0
color = tuple(avg_color)
text_boxes.append(cls(text, size, color))
counter += 1
return text_boxes