Skip to content

Commit 5c4a76d

Browse files
committed
add reader for aeson
1 parent 43146dd commit 5c4a76d

File tree

2 files changed

+29
-5
lines changed

2 files changed

+29
-5
lines changed

absbox/client.py

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,8 @@
1717
from absbox.local.util import mkTag,mapValsBy \
1818
, _read_cf, _read_asset_pricing, mergeStrWithDict \
1919
, earlyReturnNone, searchByFst, filter_by_tags \
20-
, enumVals, lmap, inferPoolTypeFromAst, getValWithKs, mapNone
20+
, enumVals, lmap, inferPoolTypeFromAst, getValWithKs, mapNone\
21+
, readAeson
2122
from absbox.local.component import mkPool, mkAssumpType, mkNonPerfAssumps, mkLiqMethod \
2223
, mkAssetUnion, mkRateAssumption, mkDatePattern, mkPoolType
2324

@@ -718,10 +719,11 @@ def runFirstLoss(self, deal, bName, poolAssump=None, runAssump=[], read=True, sh
718719
if result is None or 'error' in result or 'Left' in result:
719720
leftVal = result.get("Left","")
720721
raise AbsboxError(f"❌{MsgColor.Error.value}Failed to get response from run: {leftVal}")
721-
# rawWarnMsg = map( lambda x:f"{MsgColor.Warning.value}{x['contents']}", filter_by_tags(result[RunResp.LogResp.value], enumVals(ValidationMsg)))
722-
# if rawWarnMsg and showWarning:
723-
# console.print("Warning Message from server:\n"+"\n".join(list(rawWarnMsg)))
724-
return result['Right']
722+
723+
if read:
724+
return readAeson(result['Right'])
725+
else:
726+
result['Right']
725727

726728
def runAsset(self, date, _assets, poolAssump=None, rateAssump=None
727729
, pricing=None, read=True, debug=False) -> tuple:

absbox/local/util.py

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -450,3 +450,25 @@ def patchDicts(dict1:dict,dict2:dict)-> dict:
450450
if key only exists in either one, use the only one value
451451
"""
452452
return tz.merge_with(lambda xs: xs[1] if len(xs)==2 else xs[0] ,dict1 ,dict2)
453+
454+
455+
def readAeson(x:dict):
456+
match x:
457+
case {"tag": tag,"contents": contents} if isinstance(contents,list):
458+
return {tag:readAeson(contents)}
459+
case {"tag": tag,"contents": contents} if isinstance(contents,dict):
460+
return {tag:readAeson(contents)}
461+
case {"tag": tag,"contents": contents} if isinstance(contents,str):
462+
return {tag: contents}
463+
case {"tag": tag} if isinstance(tag,str):
464+
return tag
465+
case x if isinstance(x,list):
466+
return [readAeson(_x) for _x in x]
467+
case {'numerator': n,'denominator': de}:
468+
return (n/de)
469+
case n if isinstance(n,float) or isinstance(n,int):
470+
return n
471+
case None:
472+
return None
473+
case _:
474+
raise RuntimeError("failed to match",x)

0 commit comments

Comments
 (0)