本文整理汇总了Python中ui.UI.get_bloc_table方法的典型用法代码示例。如果您正苦于以下问题:Python UI.get_bloc_table方法的具体用法?Python UI.get_bloc_table怎么用?Python UI.get_bloc_table使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类ui.UI
的用法示例。
在下文中一共展示了UI.get_bloc_table方法的5个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: list_by_type
# 需要导入模块: from ui import UI [as 别名]
# 或者: from ui.UI import get_bloc_table [as 别名]
def list_by_type(self):
"""
Displays only the apartments having a specific expense type
"""
self._validate_parsed_command(["expense_type"])
expense_type = self._parsed_command["expense_type"]
filtered_bloc_dict = {}
for apartment_id in self._bloc_dict.keys():
if self._bloc_dict[apartment_id].expenses[expense_type] != 0:
filtered_bloc_dict[apartment_id] = self._bloc_dict[apartment_id]
if filtered_bloc_dict:
UI.set_message(UI.get_bloc_table(filtered_bloc_dict))
else:
UI.set_message("There are no apartments with " + expense_type)
示例2: list_greater_than
# 需要导入模块: from ui import UI [as 别名]
# 或者: from ui.UI import get_bloc_table [as 别名]
def list_greater_than(self):
"""
Displays only the apartments with an overall expense greater than the given amount
"""
self._validate_parsed_command(["greater"])
greater_than = float(self._parsed_command["greater"])
filtered_bloc_dict = {}
for apartment_id in self._bloc_dict.keys():
if self._bloc_dict[apartment_id].get_total_expenses() > greater_than:
filtered_bloc_dict[apartment_id] = self._bloc_dict[apartment_id]
# check if empty
if filtered_bloc_dict:
UI.set_message(UI.get_bloc_table(filtered_bloc_dict))
else:
UI.set_message("There are no apartments with overall expenses greater than " + str(greater_than))
示例3: list_less_than
# 需要导入模块: from ui import UI [as 别名]
# 或者: from ui.UI import get_bloc_table [as 别名]
def list_less_than(self):
"""
Displays only the apartments with an overall expense less than the given amount
"""
self._validate_parsed_command(["less"])
less_than = float(self._parsed_command["less"])
upper_id_limit = self._parsed_command["upper_id_limit"]
filtered_bloc_dict = {}
for apartment_id in range(1, int(upper_id_limit) + 1):
apartment_id = str(apartment_id)
if self.is_apartment(apartment_id):
if self._bloc_dict[apartment_id].get_total_expenses() < less_than:
filtered_bloc_dict[apartment_id] = self._bloc_dict[apartment_id]
# check if empty
if filtered_bloc_dict:
UI.set_message(UI.get_bloc_table(filtered_bloc_dict))
else:
UI.set_message("There are no apartments with overall expenses less than " + str(less_than))
示例4: sort
# 需要导入模块: from ui import UI [as 别名]
# 或者: from ui.UI import get_bloc_table [as 别名]
def sort(self):
"""
Displays the list of apartments sorted
"""
self._validate_parsed_command(["type", "reverse"])
reverse_sort = self._parsed_command["reverse"]
if reverse_sort is True:
header_message = " sorted descending"
else:
header_message = " sorted ascending"
# simple sort by total expense
if self._parsed_command["type"] is None:
# we create a list of tuples consisting of (id, apartment_obj, total_expense)
list_of_tuples = [
(apartment_id, self._bloc_dict[apartment_id], self._bloc_dict[apartment_id].get_total_expenses()) for
apartment_id in self._bloc_dict]
# set message
header_message += " by total expenses"
else: # sort by type
expense_type = self._parsed_command["type"]
# we create a list of tuples consisting of (id, apartment_obj, expense_type_amount)
list_of_tuples = [
(apartment_id, self._bloc_dict[apartment_id], self._bloc_dict[apartment_id].expenses[expense_type]) for
apartment_id in self._bloc_dict]
# set message
header_message += " by expense '" + expense_type + "'"
# print("raw_list: ", list_of_tuples)
# use the last key of the tuple for the value
sorted_list_of_tuples = sorted(list_of_tuples, key=lambda item: item[2], reverse=reverse_sort)
# print("sorted_list: ", sorted_sort_it)
UI.set_message(UI.get_bloc_table(sorted_list_of_tuples, header_message))
示例5: list_all
# 需要导入模块: from ui import UI [as 别名]
# 或者: from ui.UI import get_bloc_table [as 别名]
def list_all(self):
"""
Displays all the apartments in the bloc
"""
UI.set_message(UI.get_bloc_table(self._bloc_dict))