66from decimal import Decimal
77import sys
88from typing import Any , Dict , Optional
9+ from attr import dataclass
910import urllib3
1011
1112from rich .pretty import pprint
1617
1718urllib3 .disable_warnings (urllib3 .exceptions .InsecureRequestWarning )
1819
19- AdjustedCoins : namedtuple = namedtuple ("AdjustedCoins" ,
20- ["coins" , "fc" , "ac" , "aac" ])
20+ @dataclass
21+ class AdjustedCoins :
22+ coins : Decimal
23+ fc : Decimal
24+ ac : Decimal
25+ aac : Decimal
2126
2227
2328def main (c_args : argparse .Namespace ) -> None :
@@ -37,7 +42,7 @@ def main(c_args: argparse.Namespace) -> None:
3742 password = env .admin_password ,
3843 )
3944 if not token :
40- console .log (f "[bold red]ERROR[/bold red] Failed to get token" )
45+ console .log ("[bold red]ERROR[/bold red] Failed to get token" )
4146 sys .exit (1 )
4247
4348 # Get the product details.
@@ -131,27 +136,28 @@ def main(c_args: argparse.Namespace) -> None:
131136 "Coins (Adjusted)" : f"{ ac .fc } + { ac .aac } = { ac .coins } " ,
132137 }
133138
134- additional_coins : Decimal = total_uncommitted_processing_coins + burn_rate * remaining_days
139+ burn_rate_contribution : Decimal = burn_rate * remaining_days
140+ additional_coins : Decimal = total_uncommitted_processing_coins + burn_rate_contribution
135141 predicted_total_coins : Decimal = total_coins
136142 zero : Decimal = Decimal ()
137- if remaining_days > 0 :
138- if burn_rate > zero :
139-
140- predicted_total_coins += additional_coins
141- p_ac : AdjustedCoins = _calculate_adjusted_coins (
142- predicted_total_coins ,
143- allowance ,
144- allowance_multiplier )
145-
146- invoice [ "Prediction" ] = {
147- "Coins (Burn Rate)" : str ( burn_rate ) ,
148- "Coins (Additional Spend)" : f"{ total_uncommitted_processing_coins } + { remaining_days } x { burn_rate } = { additional_coins } " ,
149- "Coins (Total Raw)" : f"{ total_coins } + { additional_coins } = { predicted_total_coins } " ,
150- "Coins (Penalty Free)" : str (p_ac .fc ),
151- "Coins (In Allowance Band)" : str (p_ac .ac ),
152- "Coins (Allowance Charge)" : f"{ p_ac .ac } x { allowance_multiplier } = { p_ac .aac } " ,
153- "Coins (Adjusted)" : f"{ p_ac .fc } + { p_ac .aac } = { p_ac .coins } " ,
154- }
143+ if remaining_days > 0 and burn_rate > zero :
144+
145+ predicted_total_coins += additional_coins
146+ p_ac : AdjustedCoins = _calculate_adjusted_coins (
147+ predicted_total_coins ,
148+ allowance ,
149+ allowance_multiplier )
150+
151+ invoice [ "Prediction" ] = {
152+ "Coins (Burn Rate)" : str ( burn_rate ),
153+ "Coins (Burn Rate Contribution )" : f" { remaining_days } x { burn_rate } = { burn_rate_contribution } " ,
154+ "Coins (Additional Spend)" : f"{ total_uncommitted_processing_coins } + { burn_rate_contribution } = { additional_coins } " ,
155+ "Coins (Total Raw)" : f"{ total_coins } + { additional_coins } = { predicted_total_coins } " ,
156+ "Coins (Penalty Free)" : str (p_ac .fc ),
157+ "Coins (In Allowance Band)" : str (p_ac .ac ),
158+ "Coins (Allowance Charge)" : f"{ p_ac .ac } x { allowance_multiplier } = { p_ac .aac } " ,
159+ "Coins (Adjusted)" : f"{ p_ac .fc } + { p_ac .aac } = { p_ac .coins } " ,
160+ }
155161
156162 # Now just pre-tty-print the invoice
157163 pprint (invoice )
0 commit comments