feat: add option to exclude current month data

Enhanced `get_transparency_data` to support an `allow_current` flag, preventing the inclusion of data from the current month. This ensures historical data analysis remains consistent when current month data might be incomplete. Updated calls to the function to pass appropriate parameters.
This commit is contained in:
Kumi 2024-07-01 06:57:16 +02:00
parent 7ac2d0e63a
commit a37e8ec5c3
Signed by: kumi
GPG key ID: ECBCC9082395383F
2 changed files with 15 additions and 2 deletions

View file

@ -22,13 +22,24 @@ def get_latest_month(data, allow_current=False):
return int(latest_month), int(latest_year)
def get_transparency_data(data, year=None, month=None):
def get_transparency_data(data, year=None, month=None, allow_current=False):
if year is None:
year = max(data.keys())
if month is None:
month = max(data[year].keys())
if (
not allow_current
and year == str(datetime.now().year)
and month == str(datetime.now().month)
):
try:
month = max([m for m in data[year].keys() if m != str(datetime.now().month)])
except ValueError:
year = str(int(year) - 1)
month = max(data[year].keys())
assert year in data, f"Year {year} not found in data"
assert month in data[year], f"Month {month}-{year} not found in data"

View file

@ -61,7 +61,9 @@ def catch_all(path):
finances_period_str = finances_period.strftime("%B %Y")
finances_table = generate_transparency_table(
get_transparency_data(finances)
get_transparency_data(
finances, finances_year, finances_month
)
)
kwargs.update(