-
Notifications
You must be signed in to change notification settings - Fork 0
Dynamic INDY per epoch config #3
Copy link
Copy link
Open
Description
Instead of the current static INDY constants:
indy-rewards/indy_rewards/config.py
Line 7 in c5da590
| SP_EPOCH_INDY: Final[int] = 28768 |
Have a more dynamic config like:
SP_INDY_PER_EPOCH = {
date(2022, 12, 1): 28768,
date(2023, 12, 1): 33562,
date(2024, 9, 26): 33561,
}This'll be good for backward compatibility.
How to get the INDY for any date
from datetime import date
import bisect
class NumberFromDate:
def __init__(self):
self.data = []
def add_data(self, data_dict):
# Insert all items from dictionary
for key, value in data_dict.items():
bisect.insort(self.data, (key, value))
def get_number(self, date_obj):
# Find the position where the date would be inserted
i = bisect.bisect(self.data, (date_obj,))
# If the date is before the first "beginning from" date, return None
if i == 0:
return None
# Else return the number from the latest "beginning from" date before the input date
return self.data[i-1][1]
nfd = NumberFromDate()
nfd.add_data({date(2023, 5, 20): 5, date(2023, 5, 22): 10})
print(nfd.get_number(date(2023, 5, 21))) # prints 5
print(nfd.get_number(date(2023, 5, 22))) # prints 10
print(nfd.get_number(date(2023, 5, 23))) # prints 10Reactions are currently unavailable
Metadata
Metadata
Assignees
Labels
No labels