Skip to content

Instantly share code, notes, and snippets.

@DannyMor
Last active April 20, 2020 15:37
Show Gist options
  • Save DannyMor/2cd5274d69e6891f3a9097c6d446e665 to your computer and use it in GitHub Desktop.
Save DannyMor/2cd5274d69e6891f3a9097c6d446e665 to your computer and use it in GitHub Desktop.
@staticmethod
def get_tokens_amount_to_consume(consumption_rate, current_consumption_time, last_consumption_time, total_tokens):
time_from_last_consumption = current_consumption_time - last_consumption_time
calculated_tokens_to_consume = math.floor(time_from_last_consumption / consumption_rate)
tokens_to_consume = min(total_tokens, calculated_tokens_to_consume)
return tokens_to_consume
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment