some utils and tests
This commit is contained in:
parent
622cefc4d4
commit
7012cbec97
2 changed files with 81 additions and 0 deletions
|
|
@ -1,4 +1,8 @@
|
|||
import datetime
|
||||
from itertools import combinations
|
||||
from typing import Set
|
||||
|
||||
from money.currency import Currency
|
||||
|
||||
|
||||
class DateRange:
|
||||
|
|
@ -55,3 +59,31 @@ class DateRange:
|
|||
|
||||
def __repr__(self) -> str:
|
||||
return f"""Date Range: {self.start_date.strftime("%Y-%m-%d")} to {self.end_date.strftime("%Y-%m-%d")}."""
|
||||
|
||||
def __iter__(self):
|
||||
current_date = self.start_date
|
||||
while current_date <= self.end_date:
|
||||
yield current_date
|
||||
current_date += datetime.timedelta(days=1)
|
||||
|
||||
|
||||
def generate_currency_and_dates_combinations(
|
||||
date_range: DateRange, currencies: Set[Currency]
|
||||
):
|
||||
currency_pairs = list(combinations(currencies, 2))
|
||||
|
||||
combinations = []
|
||||
for date in date_range:
|
||||
for from_currency, to_currency in currency_pairs:
|
||||
combinations.append(
|
||||
{
|
||||
"from_currency": from_currency,
|
||||
"to_currency": to_currency,
|
||||
"date": date,
|
||||
}
|
||||
)
|
||||
|
||||
combinations = tuple(combinations)
|
||||
|
||||
# Convert the result to a tuple
|
||||
return combinations
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue