将按时间顺序排列的余额调整事件转换为持有特定余额期间的时间线。
refund_calculation的Python项目详细描述
例如,此事件序列…
- 答:$10
- b:$10
- c:($18)
- d:($2)
…变成这个时间轴:
A B C D | | | | |_____________|_____________| | | | | | $10 | | |___________________________| | | | | | $8 | | |_____________|_____________| | | | $2 | |___________________________|
这样,您就可以为每个余额减少事件确定 加上了余额。在本例中,我们可以看到:
- 活动C的18美元降幅来自活动A的10美元和活动B的8美元。
- 事件D中的2美元降幅完全来自事件B。
此示例的代码:
fromrefund_calculationimport*history_from_event_sequence([Event(time='A',delta='10'),Event(time='B',delta='10'),Event(time='C',delta='-18'),Event(time='D',delta='-2'),])# Result:History(closed=(Closed(amount=Decimal('10'),start='A',end='C'),Closed(amount=Decimal('8'),start='B',end='C'),Closed(amount=Decimal('2'),start='B',end='D'),),open=(),debt=Decimal('0'),)