Skip to content

Commit

Permalink
Merge pull request #59 from statisticsnorway/triennal_func
Browse files Browse the repository at this point in the history
Periodic func
  • Loading branch information
joxssb authored Oct 3, 2024
2 parents dcfdbb5 + 4772698 commit fa7bea7
Show file tree
Hide file tree
Showing 6 changed files with 53 additions and 17 deletions.
24 changes: 9 additions & 15 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,11 @@
*.xlsx
*.zip

# Notebooks shall be stored in .py or .R-format.
# See https://adr.ssb.no/0020-lagringsformat-for-jupyter-notebooks/
*.ipynb


# The section below is from the GitHub .gitignore template for Python:
# https://raw.githubusercontent.com/github/gitignore/main/Python.gitignore

Expand Down Expand Up @@ -204,18 +209,7 @@ rsconnect/

# ignore poetry in .config
.poetry/**
/.python-version
/.pytype/
/docs/_build/

# Visual Studio Code
.vscode/*
!.vscode/settings.json
!.vscode/tasks.json
!.vscode/launch.json
!.vscode/extensions.json
!.vscode/*.code-snippets
# Local History for Visual Studio Code
.history/
# Built Visual Studio Code Extensions
*.vsix

# Blaise specific ignores
*.bdix
*.bdbx
8 changes: 8 additions & 0 deletions docs/ssb_konjunk.rst
Original file line number Diff line number Diff line change
Expand Up @@ -49,3 +49,11 @@ ssb\_konjunk.xml\_handling module
:members:
:undoc-members:
:show-inheritance:

ssb\_konjunk.rounding module
---------------------------------

.. automodule:: ssb_konjunk.rounding
:members:
:undoc-members:
:show-inheritance:
3 changes: 2 additions & 1 deletion poetry.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion pyproject.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[tool.poetry]
name = "ssb-konjunk"
version = "0.1.9"
version = "0.1.10"
description = "SSB Konjunk"
authors = ["Edvard Garmannslund <[email protected]>"]
license = "MIT"
Expand Down
23 changes: 23 additions & 0 deletions src/ssb_konjunk/timestamp.py
Original file line number Diff line number Diff line change
Expand Up @@ -263,3 +263,26 @@ def get_ssb_timestamp(*args: int, frequency: str = "M") -> str | None:
return _get_timestamp_yearly(*valid_args)
else:
return _get_timestamp_special(*valid_args, frequency=frequency)


def check_periodic_year(year: int, cycle_year: int, period: int) -> bool:
"""Check if a year is a part of a periodic cycle.
An example of use: a functionality should be performed every third
year, starting in year 2021. I.e. not in 2022 and 2023, but in
2024. Then this function should return True when passing
2024 as the year argument, 2021 (or 2015, 2018, 2024 and so) is
passed as the cycle year and period is passed as 3 (triennal period).
Args:
year: the year to check.
cycle_year: a year in the cycle.
period: the number of years in a period.
Returns:
bool: whether or not the year is part of the triennal cycle.
"""
if abs(year - cycle_year) % period == 0:
return True
else:
return False
10 changes: 10 additions & 0 deletions tests/test_timestamp.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@
from ssb_konjunk.timestamp import _get_timestamp_daily
from ssb_konjunk.timestamp import _get_timestamp_special
from ssb_konjunk.timestamp import _get_timestamp_yearly
from ssb_konjunk.timestamp import check_periodic_year
from ssb_konjunk.timestamp import get_ssb_timestamp


Expand Down Expand Up @@ -173,3 +174,12 @@ def test_check_valid_year() -> None:
match=f"The order of args is start date and then end date. Therefore first year arg can not be bigger than the last. Your args are start year:{year1} end year:{year2}.",
):
_check_valid_year(year1, year2)


def test_check_periodic_year() -> None:
"""Test of function check_periodic_year."""
assert check_periodic_year(2024, 2021, 3)
assert not check_periodic_year(2024, 2021, 2)
assert check_periodic_year(2021, 2024, 3)
assert check_periodic_year(2021, 2021, 3)
assert check_periodic_year(2021, 2022, 1)

0 comments on commit fa7bea7

Please sign in to comment.