def check_hit(t, h): """ # 检查按顺序获得的分数 :param t: list, 桌面的数字列表 :param h: list, 手上的数字列表 :return: int, 获得的分数 """ hit = collections.filter_(list(zip(t, h)), lambda x: x[0] > x[1]) return len(hit)
def generate_excel(self, data, **kwargs): from implement_table.core.classes import BConfig columns = self._get_columns() columns = filter_(columns, lambda x: x.is_shown) excel_body = self._generate_excel_body_items(columns, kwargs) file_temp = "{}.xlsx".format(mktemp()) wb = xlsxwriter.Workbook(file_temp, {'constant_memory': True}) worksheet = wb.add_worksheet(data.get('page_name')) # TODO add more validations on the header of the excel (search and order by) for index, column in enumerate(columns): if column.type == "date": format_t = { 'num_format': get(BConfig(), '_date_format.value.js') } fmt = wb.add_format(format_t) worksheet.set_column(0, index, 12, fmt) else: worksheet.set_column(0, index, 30) value = get(data, column.label) worksheet.write(0, index, value) for row, items in enumerate(excel_body): worksheet.write_row(row + 1, 0, items) wb.close() with open(file_temp, 'rb') as file: body = file.read() generated_at = datetime.now().strftime(BConfig().date_format) return WsFile(body=body, name="{}-{}.xlsx".format(data.get('file_name'), generated_at))
def filter(listData, keyWord): return collections.filter_(listData, lambda item: _filterCallBack(item, keyWord))