Skip to content

Commit

Permalink
增加系统数据显示
Browse files Browse the repository at this point in the history
  • Loading branch information
kingzeus committed Nov 25, 2024
1 parent c99c585 commit c04f14a
Show file tree
Hide file tree
Showing 3 changed files with 142 additions and 6 deletions.
25 changes: 22 additions & 3 deletions models/database.py
Original file line number Diff line number Diff line change
Expand Up @@ -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, # 基金持仓总数
}


Expand Down
103 changes: 103 additions & 0 deletions pages/home/overview.py
Original file line number Diff line number Diff line change
Expand Up @@ -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,
)
20 changes: 17 additions & 3 deletions pages/home/page.py
Original file line number Diff line number Diff line change
Expand Up @@ -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,
)

Expand Down Expand Up @@ -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"},
),
Expand Down

0 comments on commit c04f14a

Please sign in to comment.