Skip to content

Commit a638bf7

Browse files
committed
Fix HTML report & asset breakdown
1 parent c4304fc commit a638bf7

4 files changed

Lines changed: 45 additions & 54 deletions

File tree

absbox/client.py

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -96,8 +96,6 @@ class EnginePath(str, enum.Enum):
9696
DEV = "https://absbox.org/api/dev"
9797
NY_DEV = "https://spv.run/api/dev"
9898
NY_PROD = "https://spv.run/api/latest"
99-
LDN_DEV = "https://ldn.spv.run/api/dev"
100-
LDN_PROD = "https://ldn.spv.run/api/latest"
10199
USE_ENV = "USE_ENV"
102100
""" USE_ENV (str): Use environment variable (`ABSBOX_SERVER`) for engine path """
103101

absbox/local/cf.py

Lines changed: 11 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -29,9 +29,12 @@ def readToCf(xs, header=None, idx=None, sort_index=False) -> pd.DataFrame:
2929
def buildDaySeq(_df):
3030
""" https://stackoverflow.com/questions/23435270/add-a-sequential-counter-column-on-groups-to-a-pandas-dataframe """
3131
df = _df.reset_index()
32-
dfGrp = df['date'].ne(df['date'].shift()).cumsum()
33-
df['daySeq'] = df['date'].groupby(dfGrp).cumcount()
34-
return df.set_index(["date", "daySeq"])
32+
date_col = 'date' if 'date' in df.columns else ('Date' if 'Date' in df.columns else None)
33+
if date_col is None:
34+
raise KeyError("Neither 'date' nor 'Date' column found in DataFrame.")
35+
dfGrp = df[date_col].ne(df[date_col].shift()).cumsum()
36+
df['daySeq'] = df[date_col].groupby(dfGrp).cumcount()
37+
return df.set_index([date_col, "daySeq"])
3538

3639

3740
def buildDaySeq2(_df):
@@ -133,6 +136,10 @@ def readFeesCf(fMap, popColumns=["due","剩余支付"]) -> pd.DataFrame:
133136
def readLedgers(lMap, **k) -> pd.DataFrame:
134137
return buildJointCf(lMap, **k)
135138

139+
def readPoolsCfBreakdown(cfs) -> pd.DataFrame:
140+
m = dict(zip(range(len(cfs)), cfs))
141+
return buildJointCf(m)
142+
136143

137144
def readPoolsCf(pMap) -> pd.DataFrame:
138145
''' read a map of pools in dataframes to a single dataframe, with key as 1st level index'''
@@ -150,6 +157,7 @@ def readPoolsCf(pMap) -> pd.DataFrame:
150157
return df
151158

152159

160+
153161
def readTriggers(tMap) -> pd.DataFrame:
154162
''' read a map of triggers in dataframes to a single dataframe, with key as 1st level index'''
155163
if tMap == {} or tMap is None:

absbox/report.py

Lines changed: 27 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44
import json, enum, os, pathlib, re
55
from htpy import body, h1, head, html, li, title, ul, div, span, h3, h2, a, h4,h5, h6
66
from markupsafe import Markup
7-
from .local.cf import readInspect
7+
from .local.cf import readInspect,readPoolsCfBreakdown
88
from .local.cf import readBondsCf,readFeesCf,readAccsCf,readPoolsCf,readLedgers,readTriggers
99

1010
class OutputType(int, enum.Enum):
@@ -82,17 +82,18 @@ def toHtml(r:dict, p:str, style=OutputType.Plain, debug=False):
8282

8383
# section 1
8484
poolDf = ("Pool", r['pool']['flow'])
85+
poolOsDf = ("Pool-OS", r['pool_outstanding']['flow'])
8586
accDf = ("Accounts", r['accounts'])
8687
feeDf = ("Fee", r['fees'])
87-
section1 = buildSection([poolDf, feeDf, accDf])
88+
section1 = buildSection([poolDf, poolOsDf, feeDf, accDf])
8889

8990
# section 2
9091
section2 = buildSectionFlat([("Status",r['result']['status'])
91-
,("Pricing",r["pricing"])
92-
,("Bond Summary",r['result']['bonds'])
93-
,("Log",r['result']['logs'])
94-
,("Waterfall",r['result']['waterfall'])
95-
,("Inspect",readInspect(r['result']))])
92+
,("Pricing",r["pricing"])
93+
,("Bond Summary",r['result']['bonds'])
94+
,("Log",r['result']['logs'])
95+
,("Waterfall",r['result']['waterfall'])
96+
,("Inspect",readInspect(r['result']))])
9697
# section 3
9798
#section3 = [div[h2(id=f"anchor-{_t}")[_t], mapToList(x)]
9899
# for (_t, x) in [("Finanical Reports", r['result'].get('report', {}))]]
@@ -102,18 +103,28 @@ def toHtml(r:dict, p:str, style=OutputType.Plain, debug=False):
102103
# section 4
103104
ledgerDf = ("Ledger", r.get("ledgers",{}))
104105
section4 = buildSectionFlat([("MultiFee",readFeesCf(feeDf[1]))
105-
,("MultiBond",readBondsCf(bondDf[1],popColumns=[]))
106-
,("MultiAccounts",readAccsCf(accDf[1]))
107-
,("MultiPools", readPoolsCf(poolDf[1]))
108-
,("MultiLedger", readLedgers(ledgerDf[1]))
109-
,("MultiTrigger", readTriggers(r.get("triggers",{})))
110-
])
111-
106+
,("MultiBond",readBondsCf(bondDf[1],popColumns=[]))
107+
,("MultiAccounts",readAccsCf(accDf[1]))
108+
,("MultiPools", readPoolsCf(poolDf[1]))
109+
,("MultiOsPools", readPoolsCf(poolOsDf[1]))
110+
,("MultiLedger", readLedgers(ledgerDf[1]))
111+
,("MultiTrigger", readTriggers(r.get("triggers",{})))
112+
])
113+
114+
# section 5 : breakdown cashflow
115+
if r['pool']['breakdown']:
116+
section5 = buildSectionFlat([(f"PoolBreakdown_{k}", readPoolsCfBreakdown(vs))
117+
for k,vs in r['pool']['breakdown'].items()]
118+
)
119+
else:
120+
section5 = []
121+
# section5
112122

113-
dealName = r['_deal']['contents']['name']
123+
dealName = r['_deal'] & lens.Values()['name'].get()
124+
114125
c = html[
115126
head[title[dealName]],
116-
body[section0, section1, section2, section3 ,section4],
127+
body[section0, section1, section2, section3 ,section4, section5],
117128
]
118129

119130
if debug:

pyproject.toml

Lines changed: 7 additions & 33 deletions
Original file line numberDiff line numberDiff line change
@@ -88,46 +88,20 @@ filename = "CHANGELOG.rst"
8888

8989
start_string = ".. towncrier release notes start\n"
9090
underlines = ["-", "~", "\""]
91-
title_format = "`{version} <https://github.com/yellowbean/AbsBox/tree/{version}>`_ - {project_date}"
91+
title_format = "{version} - {project_date}"
9292
issue_format = "`{issue} <https://github.com/yellowbean/AbsBox/issues/{issue}>`_"
9393

9494
[[tool.towncrier.type]]
95-
directory = "security"
96-
name = "Security"
95+
directory = "feature"
96+
name = "Features"
9797
showcontent = true
9898

9999
[[tool.towncrier.type]]
100-
directory = "removed"
101-
name = "Removed"
102-
showcontent = true
103-
104-
[[tool.towncrier.type]]
105-
directory = "deprecated"
106-
name = "Deprecated"
107-
showcontent = true
108-
109-
[[tool.towncrier.type]]
110-
directory = "added"
111-
name = "Added"
112-
showcontent = true
113-
114-
[[tool.towncrier.type]]
115-
directory = "changed"
116-
name = "Changed"
117-
showcontent = true
118-
119-
[[tool.towncrier.type]]
120-
directory = "fixed"
121-
name = "Fixed"
122-
showcontent = true
123-
124-
[[tool.towncrier.type]]
125-
directory = "performance"
126-
name = "Performance"
100+
directory = "enhance"
101+
name = "Enhance"
127102
showcontent = true
128103

129-
130104
[[tool.towncrier.type]]
131-
directory = "enhance"
132-
name = "Enhance"
105+
directory = "bug"
106+
name = "Bug"
133107
showcontent = true

0 commit comments

Comments
 (0)