From 6698337f05cf425fa3ca84322395d94a78fd6396 Mon Sep 17 00:00:00 2001 From: han0 Date: Tue, 1 Jun 2021 15:49:57 +0800 Subject: [PATCH] =?UTF-8?q?feat(fe=5Fsucks):=20=E6=96=B0=E5=A2=9E=E6=95=B0?= =?UTF-8?q?=E6=8D=AE=E8=A1=A5=E4=BD=8D=E7=9A=84=E5=8A=9F=E8=83=BD?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- nc_http/tools/fe_sucks.py | 24 ++++++++++++++++++++++++ 1 file changed, 24 insertions(+) diff --git a/nc_http/tools/fe_sucks.py b/nc_http/tools/fe_sucks.py index 3fbba35..f4fee3f 100644 --- a/nc_http/tools/fe_sucks.py +++ b/nc_http/tools/fe_sucks.py @@ -191,6 +191,30 @@ class FESucks: """ return list_to_tree(rows, id_key, parent_id_key, i) + @classmethod + def set_placeholder(cls, data, key, placeholder_name_list, placeholder=None): + """ + 数据补位 + :param data: + [{'count': 1, 'date': '2021-01-01'}] + :param key: + 'date' + :param placeholder_name_list: + ['2021-01-01', '2021-01-02', '2021-01-03'] + :param placeholder: + {'count': 0} + :return: + [{'count': 1, 'date': '2021-01-01'}, {'count': 0, 'date': '2021-01-02'}, {'count': 0, 'date': '2021-01-03'}] + """ + placeholder = placeholder or {} + miss_placeholder_name_list = set(placeholder_name_list) - set(item[key] for item in data) + for placeholder_name in miss_placeholder_name_list: + _placeholder = placeholder.copy() + _placeholder[key] = placeholder_name + data.append(_placeholder) + + return data + ''' # 结果处理 树转列表 todo