Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Dynamic INDY per epoch config #3

Open
karleitner opened this issue Jun 20, 2023 · 0 comments
Open

Dynamic INDY per epoch config #3

karleitner opened this issue Jun 20, 2023 · 0 comments

Comments

@karleitner
Copy link
Contributor

Instead of the current static INDY constants:

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 10
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant