From c04f14a50b317ce11f8c5a10cbe5bda595f35160 Mon Sep 17 00:00:00 2001 From: kingzeus Date: Mon, 25 Nov 2024 11:04:43 +0800 Subject: [PATCH] =?UTF-8?q?=E5=A2=9E=E5=8A=A0=E7=B3=BB=E7=BB=9F=E6=95=B0?= =?UTF-8?q?=E6=8D=AE=E6=98=BE=E7=A4=BA?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- models/database.py | 25 ++++++++-- pages/home/overview.py | 103 +++++++++++++++++++++++++++++++++++++++++ pages/home/page.py | 20 ++++++-- 3 files changed, 142 insertions(+), 6 deletions(-) diff --git a/models/database.py b/models/database.py index 5ad18b4..70157b6 100644 --- a/models/database.py +++ b/models/database.py @@ -120,13 +120,32 @@ def get_statistics() -> Dict[str, int]: # 获取组合总数 portfolio_count = ModelPortfolio.select().count() # pylint: disable=E1120 + # 获取基金总数 + fund_count = ModelFund.select().count() # pylint: disable=E1120 + + # 获取基金净值总数 + fund_nav_count = ModelFundNav.select().count() # pylint: disable=E1120 + # 基金今日净值更新数量 + today_fund_nav_count = ( + ModelFundNav.select().where(ModelFundNav.nav_date == datetime.now().date()).count() + ) # pylint: disable=E1120 + + # 今天更新的基金净值数量 + today_update_fund_nav_count = ( + ModelFundNav.select().where(ModelFundNav.updated_at >= datetime.now().date()).count() + ) # pylint: disable=E1120 + # 获取基金持仓总数 position_count = ModelFundPosition.select().count() # pylint: disable=E1120 return { - "account_count": account_count, - "portfolio_count": portfolio_count, - "position_count": position_count, + "account_count": account_count, # 账户总数 + "portfolio_count": portfolio_count, # 组合总数 + "fund_count": fund_count, # 基金总数 + "fund_nav_count": fund_nav_count, # 基金净值总数 + "today_fund_nav_count": today_fund_nav_count, # 今日更新基金净值数量 + "today_update_fund_nav_count": today_update_fund_nav_count, # 今天更新的基金净值数量 + "position_count": position_count, # 基金持仓总数 } diff --git a/pages/home/overview.py b/pages/home/overview.py index 32cbd88..2453957 100644 --- a/pages/home/overview.py +++ b/pages/home/overview.py @@ -204,3 +204,106 @@ def render_account_count_card(initial_stats: Dict[str, Any]) -> fac.AntdCard: hoverable=True, style=CARD_STYLES, ) + + +def render_fund_data_card(initial_stats: Dict[str, Any]) -> fac.AntdCard: + """渲染基金数据卡片""" + return fac.AntdCard( + fac.AntdRow( + [ + fac.AntdCol( + html.H2( + str(initial_stats["fund_count"]), + id="fund-count", + style={ + "color": "#1890ff", + "fontSize": "96px", + "margin": "-13px 15px", + "lineHeight": "1", + }, + ), + span=12, + ), + fac.AntdCol( + fac.AntdStatistic( + title="基金净值数", + titleTooltip="基金净值总记录数", + value=initial_stats["fund_nav_count"], + valueStyle={"color": "#52c41a"}, + ), + span=12, + ), + ], + gutter=10, + style={ + "width": "100%", + "height": "70px", + }, + ), + title="基金数据", + hoverable=True, + style=CARD_STYLES, + ) + + +def render_today_fund_card(initial_stats: Dict[str, Any]) -> fac.AntdCard: + """渲染今日基金数据卡片""" + return fac.AntdCard( + fac.AntdRow( + [ + fac.AntdCol( + html.Span( + str(initial_stats["fund_count"]), + id="fund-count", + style={ + "color": "#1890ff", + "fontSize": "96px", + "fontWeight": "700", + "height": "96px", + "margin": "-13px 15px", + "lineHeight": "1", + }, + ), + # html.Span( + # [ + # html.Span( + # f"{initial_stats['today_fund_nav_count']}", + # id="today-fund-count", + # style={ + # "color": "#1890ff", + # "fontSize": "96px", + # "margin": "-13px 15px", + # "lineHeight": "1", + # }, + # ), + # html.Span( + # f"/{initial_stats['fund_count']}", + # id="today-fund-count", + # style={ + # "color": "#1890ff", + # }, + # ), + # ] + # ), + span=12, + ), + fac.AntdCol( + fac.AntdStatistic( + title="基金净值更新", + titleTooltip="今天更新的基金净值数量", + value=initial_stats["today_update_fund_nav_count"], + valueStyle={"color": "#52c41a"}, + ), + span=12, + ), + ], + gutter=10, + style={ + "width": "100%", + "height": "70px", + }, + ), + title="今日更新基金", + hoverable=True, + style=CARD_STYLES, + ) diff --git a/pages/home/page.py b/pages/home/page.py index bb32259..5b2c1fd 100644 --- a/pages/home/page.py +++ b/pages/home/page.py @@ -23,7 +23,9 @@ from pages.home.overview import ( render_account_count_card, render_fund_count_card, + render_fund_data_card, render_return_rate_card, + render_today_fund_card, render_total_assets_card, ) @@ -75,17 +77,29 @@ def render_home_page() -> html.Div: style={"padding": "12px"}, ), fac.AntdCol( - render_fund_count_card(), + render_return_rate_card(), span=6, style={"padding": "8px"}, ), fac.AntdCol( - render_return_rate_card(), + render_account_count_card(initial_stats), + span=6, + style={"padding": "8px"}, + ), + ] + ), + # 系统数据概览卡片 + fac.AntdRow( + [ + # 当前系统基金数据 + fac.AntdCol( + render_fund_data_card(initial_stats), span=6, style={"padding": "8px"}, ), + # 今日更新基金数据 fac.AntdCol( - render_account_count_card(initial_stats), + render_today_fund_card(initial_stats), span=6, style={"padding": "8px"}, ),