ssb-konjunk 0.0.1__tar.gz
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- ssb_konjunk-0.0.1/LICENSE +21 -0
- ssb_konjunk-0.0.1/PKG-INFO +101 -0
- ssb_konjunk-0.0.1/README.md +77 -0
- ssb_konjunk-0.0.1/pyproject.toml +125 -0
- ssb_konjunk-0.0.1/src/ssb_konjunk/__init__.py +1 -0
- ssb_konjunk-0.0.1/src/ssb_konjunk/__main__.py +12 -0
- ssb_konjunk-0.0.1/src/ssb_konjunk/functions.py +35 -0
- ssb_konjunk-0.0.1/src/ssb_konjunk/prompts.py +191 -0
- ssb_konjunk-0.0.1/src/ssb_konjunk/py.typed +0 -0
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
MIT License
|
|
2
|
+
|
|
3
|
+
Copyright © 2024 Statistics Norway
|
|
4
|
+
|
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
6
|
+
of this software and associated documentation files (the "Software"), to deal
|
|
7
|
+
in the Software without restriction, including without limitation the rights
|
|
8
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
9
|
+
copies of the Software, and to permit persons to whom the Software is
|
|
10
|
+
furnished to do so, subject to the following conditions:
|
|
11
|
+
|
|
12
|
+
The above copyright notice and this permission notice shall be included in all
|
|
13
|
+
copies or substantial portions of the Software.
|
|
14
|
+
|
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
17
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
18
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
19
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
20
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
21
|
+
SOFTWARE.
|
|
@@ -0,0 +1,101 @@
|
|
|
1
|
+
Metadata-Version: 2.1
|
|
2
|
+
Name: ssb-konjunk
|
|
3
|
+
Version: 0.0.1
|
|
4
|
+
Summary: SSB Konjunk
|
|
5
|
+
Home-page: https://github.com/statisticsnorway/ssb-konjunk
|
|
6
|
+
License: MIT
|
|
7
|
+
Author: Edvard Garmannslund
|
|
8
|
+
Author-email: ged@ssb.no
|
|
9
|
+
Requires-Python: >=3.9,<4.0
|
|
10
|
+
Classifier: Development Status :: 1 - Planning
|
|
11
|
+
Classifier: License :: OSI Approved :: MIT License
|
|
12
|
+
Classifier: Programming Language :: Python :: 3
|
|
13
|
+
Classifier: Programming Language :: Python :: 3.9
|
|
14
|
+
Classifier: Programming Language :: Python :: 3.10
|
|
15
|
+
Classifier: Programming Language :: Python :: 3.11
|
|
16
|
+
Classifier: Programming Language :: Python :: 3.12
|
|
17
|
+
Requires-Dist: click (>=8.0.1)
|
|
18
|
+
Requires-Dist: pandas (>=2.2.0,<3.0.0)
|
|
19
|
+
Project-URL: Changelog, https://github.com/statisticsnorway/ssb-konjunk/releases
|
|
20
|
+
Project-URL: Documentation, https://statisticsnorway.github.io/ssb-konjunk
|
|
21
|
+
Project-URL: Repository, https://github.com/statisticsnorway/ssb-konjunk
|
|
22
|
+
Description-Content-Type: text/markdown
|
|
23
|
+
|
|
24
|
+
# SSB Konjunk
|
|
25
|
+
|
|
26
|
+
[][pypi status]
|
|
27
|
+
[][pypi status]
|
|
28
|
+
[][pypi status]
|
|
29
|
+
[][license]
|
|
30
|
+
|
|
31
|
+
[][documentation]
|
|
32
|
+
[][tests]
|
|
33
|
+
[][sonarcov]
|
|
34
|
+
[][sonarquality]
|
|
35
|
+
|
|
36
|
+
[][pre-commit]
|
|
37
|
+
[][black]
|
|
38
|
+
[](https://github.com/astral-sh/ruff)
|
|
39
|
+
[][poetry]
|
|
40
|
+
|
|
41
|
+
[pypi status]: https://pypi.org/project/ssb-konjunk/
|
|
42
|
+
[documentation]: https://statisticsnorway.github.io/ssb-konjunk
|
|
43
|
+
[tests]: https://github.com/statisticsnorway/ssb-konjunk/actions?workflow=Tests
|
|
44
|
+
|
|
45
|
+
[sonarcov]: https://sonarcloud.io/summary/overall?id=statisticsnorway_ssb-konjunk
|
|
46
|
+
[sonarquality]: https://sonarcloud.io/summary/overall?id=statisticsnorway_ssb-konjunk
|
|
47
|
+
[pre-commit]: https://github.com/pre-commit/pre-commit
|
|
48
|
+
[black]: https://github.com/psf/black
|
|
49
|
+
[poetry]: https://python-poetry.org/
|
|
50
|
+
|
|
51
|
+
## Features
|
|
52
|
+
|
|
53
|
+
- Masse
|
|
54
|
+
|
|
55
|
+
## Requirements
|
|
56
|
+
|
|
57
|
+
- TODO
|
|
58
|
+
|
|
59
|
+
## Installation
|
|
60
|
+
|
|
61
|
+
You can install _SSB Konjunk_ via [pip] from [PyPI]:
|
|
62
|
+
|
|
63
|
+
```console
|
|
64
|
+
pip install ssb-konjunk
|
|
65
|
+
```
|
|
66
|
+
|
|
67
|
+
## Usage
|
|
68
|
+
|
|
69
|
+
Please see the [Reference Guide] for details.
|
|
70
|
+
|
|
71
|
+
## Contributing
|
|
72
|
+
|
|
73
|
+
Contributions are very welcome.
|
|
74
|
+
To learn more, see the [Contributor Guide].
|
|
75
|
+
|
|
76
|
+
## License
|
|
77
|
+
|
|
78
|
+
Distributed under the terms of the [MIT license][license],
|
|
79
|
+
_SSB Konjunk_ is free and open source software.
|
|
80
|
+
|
|
81
|
+
## Issues
|
|
82
|
+
|
|
83
|
+
If you encounter any problems,
|
|
84
|
+
please [file an issue] along with a detailed description.
|
|
85
|
+
|
|
86
|
+
## Credits
|
|
87
|
+
|
|
88
|
+
This project was generated from [Statistics Norway]'s [SSB PyPI Template].
|
|
89
|
+
|
|
90
|
+
[statistics norway]: https://www.ssb.no/en
|
|
91
|
+
[pypi]: https://pypi.org/
|
|
92
|
+
[ssb pypi template]: https://github.com/statisticsnorway/ssb-pypitemplate
|
|
93
|
+
[file an issue]: https://github.com/statisticsnorway/ssb-konjunk/issues
|
|
94
|
+
[pip]: https://pip.pypa.io/
|
|
95
|
+
|
|
96
|
+
<!-- github-only -->
|
|
97
|
+
|
|
98
|
+
[license]: https://github.com/statisticsnorway/ssb-konjunk/blob/main/LICENSE
|
|
99
|
+
[contributor guide]: https://github.com/statisticsnorway/ssb-konjunk/blob/main/CONTRIBUTING.md
|
|
100
|
+
[reference guide]: https://statisticsnorway.github.io/ssb-konjunk/reference.html
|
|
101
|
+
|
|
@@ -0,0 +1,77 @@
|
|
|
1
|
+
# SSB Konjunk
|
|
2
|
+
|
|
3
|
+
[][pypi status]
|
|
4
|
+
[][pypi status]
|
|
5
|
+
[][pypi status]
|
|
6
|
+
[][license]
|
|
7
|
+
|
|
8
|
+
[][documentation]
|
|
9
|
+
[][tests]
|
|
10
|
+
[][sonarcov]
|
|
11
|
+
[][sonarquality]
|
|
12
|
+
|
|
13
|
+
[][pre-commit]
|
|
14
|
+
[][black]
|
|
15
|
+
[](https://github.com/astral-sh/ruff)
|
|
16
|
+
[][poetry]
|
|
17
|
+
|
|
18
|
+
[pypi status]: https://pypi.org/project/ssb-konjunk/
|
|
19
|
+
[documentation]: https://statisticsnorway.github.io/ssb-konjunk
|
|
20
|
+
[tests]: https://github.com/statisticsnorway/ssb-konjunk/actions?workflow=Tests
|
|
21
|
+
|
|
22
|
+
[sonarcov]: https://sonarcloud.io/summary/overall?id=statisticsnorway_ssb-konjunk
|
|
23
|
+
[sonarquality]: https://sonarcloud.io/summary/overall?id=statisticsnorway_ssb-konjunk
|
|
24
|
+
[pre-commit]: https://github.com/pre-commit/pre-commit
|
|
25
|
+
[black]: https://github.com/psf/black
|
|
26
|
+
[poetry]: https://python-poetry.org/
|
|
27
|
+
|
|
28
|
+
## Features
|
|
29
|
+
|
|
30
|
+
- Masse
|
|
31
|
+
|
|
32
|
+
## Requirements
|
|
33
|
+
|
|
34
|
+
- TODO
|
|
35
|
+
|
|
36
|
+
## Installation
|
|
37
|
+
|
|
38
|
+
You can install _SSB Konjunk_ via [pip] from [PyPI]:
|
|
39
|
+
|
|
40
|
+
```console
|
|
41
|
+
pip install ssb-konjunk
|
|
42
|
+
```
|
|
43
|
+
|
|
44
|
+
## Usage
|
|
45
|
+
|
|
46
|
+
Please see the [Reference Guide] for details.
|
|
47
|
+
|
|
48
|
+
## Contributing
|
|
49
|
+
|
|
50
|
+
Contributions are very welcome.
|
|
51
|
+
To learn more, see the [Contributor Guide].
|
|
52
|
+
|
|
53
|
+
## License
|
|
54
|
+
|
|
55
|
+
Distributed under the terms of the [MIT license][license],
|
|
56
|
+
_SSB Konjunk_ is free and open source software.
|
|
57
|
+
|
|
58
|
+
## Issues
|
|
59
|
+
|
|
60
|
+
If you encounter any problems,
|
|
61
|
+
please [file an issue] along with a detailed description.
|
|
62
|
+
|
|
63
|
+
## Credits
|
|
64
|
+
|
|
65
|
+
This project was generated from [Statistics Norway]'s [SSB PyPI Template].
|
|
66
|
+
|
|
67
|
+
[statistics norway]: https://www.ssb.no/en
|
|
68
|
+
[pypi]: https://pypi.org/
|
|
69
|
+
[ssb pypi template]: https://github.com/statisticsnorway/ssb-pypitemplate
|
|
70
|
+
[file an issue]: https://github.com/statisticsnorway/ssb-konjunk/issues
|
|
71
|
+
[pip]: https://pip.pypa.io/
|
|
72
|
+
|
|
73
|
+
<!-- github-only -->
|
|
74
|
+
|
|
75
|
+
[license]: https://github.com/statisticsnorway/ssb-konjunk/blob/main/LICENSE
|
|
76
|
+
[contributor guide]: https://github.com/statisticsnorway/ssb-konjunk/blob/main/CONTRIBUTING.md
|
|
77
|
+
[reference guide]: https://statisticsnorway.github.io/ssb-konjunk/reference.html
|
|
@@ -0,0 +1,125 @@
|
|
|
1
|
+
[tool.poetry]
|
|
2
|
+
name = "ssb-konjunk"
|
|
3
|
+
version = "0.0.1"
|
|
4
|
+
description = "SSB Konjunk"
|
|
5
|
+
authors = ["Edvard Garmannslund <ged@ssb.no>"]
|
|
6
|
+
license = "MIT"
|
|
7
|
+
readme = "README.md"
|
|
8
|
+
homepage = "https://github.com/statisticsnorway/ssb-konjunk"
|
|
9
|
+
repository = "https://github.com/statisticsnorway/ssb-konjunk"
|
|
10
|
+
documentation = "https://statisticsnorway.github.io/ssb-konjunk"
|
|
11
|
+
classifiers = ["Development Status :: 1 - Planning"]
|
|
12
|
+
|
|
13
|
+
[tool.poetry.urls]
|
|
14
|
+
Changelog = "https://github.com/statisticsnorway/ssb-konjunk/releases"
|
|
15
|
+
|
|
16
|
+
[tool.poetry.dependencies]
|
|
17
|
+
python = "^3.9"
|
|
18
|
+
click = ">=8.0.1"
|
|
19
|
+
pandas = "^2.2.0"
|
|
20
|
+
|
|
21
|
+
[tool.poetry.group.dev.dependencies]
|
|
22
|
+
pygments = ">=2.10.0"
|
|
23
|
+
black = { extras = ["jupyter"], version = ">=23.1.0" }
|
|
24
|
+
coverage = { extras = ["toml"], version = ">=6.2" }
|
|
25
|
+
darglint = ">=1.8.1"
|
|
26
|
+
furo = ">=2021.11.12"
|
|
27
|
+
mypy = ">=0.930"
|
|
28
|
+
pre-commit = ">=2.16.0"
|
|
29
|
+
pre-commit-hooks = ">=4.1.0"
|
|
30
|
+
ruff = ">=0.0.284"
|
|
31
|
+
pytest = ">=6.2.5"
|
|
32
|
+
sphinx = ">=6.2.1"
|
|
33
|
+
sphinx-autobuild = ">=2021.3.14"
|
|
34
|
+
sphinx-autodoc-typehints = ">=1.24.0"
|
|
35
|
+
sphinx-click = ">=3.0.2"
|
|
36
|
+
typeguard = ">=2.13.3"
|
|
37
|
+
xdoctest = { extras = ["colors"], version = ">=0.15.10" }
|
|
38
|
+
myst-parser = { version = ">=0.16.1" }
|
|
39
|
+
ipykernel = ">=6.0.0"
|
|
40
|
+
pandas-stubs = "^2.1.4.231227"
|
|
41
|
+
|
|
42
|
+
[tool.pytest.ini_options]
|
|
43
|
+
pythonpath = ["src"]
|
|
44
|
+
|
|
45
|
+
[tool.poetry.scripts]
|
|
46
|
+
ssb-konjunk = "ssb_konjunk.__main__:main"
|
|
47
|
+
|
|
48
|
+
[tool.coverage.paths]
|
|
49
|
+
source = ["src", "*/site-packages"]
|
|
50
|
+
tests = ["tests", "*/tests"]
|
|
51
|
+
|
|
52
|
+
[tool.coverage.run]
|
|
53
|
+
branch = true
|
|
54
|
+
source = ["ssb_konjunk", "tests"]
|
|
55
|
+
|
|
56
|
+
[tool.coverage.report]
|
|
57
|
+
show_missing = true
|
|
58
|
+
fail_under = 50
|
|
59
|
+
|
|
60
|
+
[tool.mypy]
|
|
61
|
+
strict = true
|
|
62
|
+
warn_unreachable = true
|
|
63
|
+
pretty = true
|
|
64
|
+
show_column_numbers = true
|
|
65
|
+
show_error_context = true
|
|
66
|
+
|
|
67
|
+
[tool.ruff]
|
|
68
|
+
force-exclude = true # Apply excludes to pre-commit
|
|
69
|
+
show-fixes = true
|
|
70
|
+
src = ["src", "tests"]
|
|
71
|
+
target-version = "py39" # Minimum Python version supported
|
|
72
|
+
|
|
73
|
+
# Ruff rules may be customized as desired: https://docs.astral.sh/ruff/rules/
|
|
74
|
+
select = [
|
|
75
|
+
"A", # prevent using keywords that clobber python builtins
|
|
76
|
+
"B", # bugbear: security warnings
|
|
77
|
+
"E", # pycodestyle
|
|
78
|
+
"F", # pyflakes
|
|
79
|
+
"ISC", # implicit string concatenation
|
|
80
|
+
"I", # sort imports
|
|
81
|
+
"UP", # alert you when better syntax is available in your python version
|
|
82
|
+
"RUF", # the ruff developer's own rules
|
|
83
|
+
]
|
|
84
|
+
ignore = [
|
|
85
|
+
"ANN101", # Supress missing-type-self.
|
|
86
|
+
"D100", # Supress undocumented-public-module. Only doc of public api required.
|
|
87
|
+
"E402", # Supress module-import-not-at-top-of-file, needed in jupyter notebooks.
|
|
88
|
+
"E501", # Supress line-too-long warnings: trust black's judgement on this one.
|
|
89
|
+
]
|
|
90
|
+
include = ["*.py", "*.pyi", "**/pyproject.toml", "*.ipynb"]
|
|
91
|
+
extend-exclude = [
|
|
92
|
+
"__pycache__",
|
|
93
|
+
"old",
|
|
94
|
+
".ipynb_checkpoints",
|
|
95
|
+
"noxfile.py",
|
|
96
|
+
"docs/conf.py",
|
|
97
|
+
]
|
|
98
|
+
|
|
99
|
+
[tool.ruff.isort]
|
|
100
|
+
force-single-line = true
|
|
101
|
+
|
|
102
|
+
[tool.ruff.mccabe]
|
|
103
|
+
max-complexity = 15
|
|
104
|
+
|
|
105
|
+
[tool.ruff.pydocstyle]
|
|
106
|
+
convention = "google" # You can also use "numpy".
|
|
107
|
+
|
|
108
|
+
[tool.ruff.pep8-naming]
|
|
109
|
+
classmethod-decorators = ["classmethod", "validator", "root_validator", "pydantic.validator"]
|
|
110
|
+
|
|
111
|
+
[tool.ruff.per-file-ignores]
|
|
112
|
+
"*/__init__.py" = ["F401"]
|
|
113
|
+
"**/tests/*" = [
|
|
114
|
+
# asserts are encouraged in pytest
|
|
115
|
+
"S101",
|
|
116
|
+
# return annotations don't add value for test functions
|
|
117
|
+
"ANN201",
|
|
118
|
+
# docstrings are overkill for test functions
|
|
119
|
+
"D103",
|
|
120
|
+
"D100",
|
|
121
|
+
]
|
|
122
|
+
|
|
123
|
+
[build-system]
|
|
124
|
+
requires = ["poetry-core>=1.0.0"]
|
|
125
|
+
build-backend = "poetry.core.masonry.api"
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
"""SSB Konjunk."""
|
|
@@ -0,0 +1,35 @@
|
|
|
1
|
+
"""A collection of useful functions.
|
|
2
|
+
|
|
3
|
+
The template and this example uses Google style docstrings as described at:
|
|
4
|
+
https://sphinxcontrib-napoleon.readthedocs.io/en/latest/example_google.html
|
|
5
|
+
|
|
6
|
+
"""
|
|
7
|
+
|
|
8
|
+
|
|
9
|
+
def example_function(number1: int, number2: int) -> str:
|
|
10
|
+
"""Compare two integers.
|
|
11
|
+
|
|
12
|
+
This is merely an example function can be deleted. It is used to show and test generating
|
|
13
|
+
documentation from code, type hinting, testing, and testing examples
|
|
14
|
+
in the code.
|
|
15
|
+
|
|
16
|
+
|
|
17
|
+
Args:
|
|
18
|
+
number1: The first number.
|
|
19
|
+
number2: The second number, which will be compared to number1.
|
|
20
|
+
|
|
21
|
+
Returns:
|
|
22
|
+
A string describing which number is the greatest.
|
|
23
|
+
|
|
24
|
+
Examples:
|
|
25
|
+
Examples should be written in doctest format, and should illustrate how
|
|
26
|
+
to use the function.
|
|
27
|
+
|
|
28
|
+
>>> example_function(1, 2)
|
|
29
|
+
1 is less than 2
|
|
30
|
+
|
|
31
|
+
"""
|
|
32
|
+
if number1 < number2:
|
|
33
|
+
return f"{number1} is less than {number2}"
|
|
34
|
+
|
|
35
|
+
return f"{number1} is greater than or equal to {number2}"
|
|
@@ -0,0 +1,191 @@
|
|
|
1
|
+
"""Function for date prompts in python.
|
|
2
|
+
|
|
3
|
+
The functions should be used to prompt which period to read files from og which period to run a statistic for.
|
|
4
|
+
"""
|
|
5
|
+
|
|
6
|
+
import re
|
|
7
|
+
from calendar import monthrange
|
|
8
|
+
from datetime import datetime
|
|
9
|
+
from datetime import timedelta
|
|
10
|
+
|
|
11
|
+
|
|
12
|
+
def days_in_month(year: int, month: int) -> list[str]:
|
|
13
|
+
"""Function to get number of days in month.
|
|
14
|
+
|
|
15
|
+
Parameters
|
|
16
|
+
----------
|
|
17
|
+
year (int): Year.
|
|
18
|
+
month (int): Month.
|
|
19
|
+
|
|
20
|
+
Returns:
|
|
21
|
+
-------
|
|
22
|
+
days_list (list): List with days in month.
|
|
23
|
+
"""
|
|
24
|
+
num_days = monthrange(year, month)[
|
|
25
|
+
1
|
|
26
|
+
] # Get the number of days in the specified month
|
|
27
|
+
days_list = [f"{year}-{month:02d}-{day:02d}" for day in range(1, num_days + 1)]
|
|
28
|
+
return days_list
|
|
29
|
+
|
|
30
|
+
|
|
31
|
+
def extract_start_end_dates(file_name: str) -> tuple[datetime, datetime]:
|
|
32
|
+
"""Function to extract start and end dates from file name.
|
|
33
|
+
|
|
34
|
+
Parameters
|
|
35
|
+
----------
|
|
36
|
+
file_name (str): String value with name of file.
|
|
37
|
+
|
|
38
|
+
Returns:
|
|
39
|
+
-------
|
|
40
|
+
start_date (datetime): Start date of file.
|
|
41
|
+
end_date (datetime): End date of file.
|
|
42
|
+
"""
|
|
43
|
+
match = re.search(r"_p(\d{4})-(\d{2})-(\d{2})_p(\d{4})-(\d{2})-(\d{2})_", file_name)
|
|
44
|
+
if match:
|
|
45
|
+
start_date = datetime.strptime(
|
|
46
|
+
f"{match.group(1)}-{match.group(2)}-{match.group(3)}", "%Y-%m-%d"
|
|
47
|
+
)
|
|
48
|
+
end_date = datetime.strptime(
|
|
49
|
+
f"{match.group(4)}-{match.group(5)}-{match.group(6)}", "%Y-%m-%d"
|
|
50
|
+
)
|
|
51
|
+
return start_date, end_date
|
|
52
|
+
|
|
53
|
+
|
|
54
|
+
def next_month(desired_year: int, desired_month: int) -> str:
|
|
55
|
+
"""Get the next month of a given year and month.
|
|
56
|
+
|
|
57
|
+
Parameters
|
|
58
|
+
----------
|
|
59
|
+
desired_year (int): year
|
|
60
|
+
desired_month (int): month
|
|
61
|
+
|
|
62
|
+
Returns:
|
|
63
|
+
-------
|
|
64
|
+
next_month_str (str): next month in the format 'YYYY-MM'
|
|
65
|
+
"""
|
|
66
|
+
# Create a datetime object for the desired year and month
|
|
67
|
+
current_date = datetime(desired_year, desired_month, 1)
|
|
68
|
+
|
|
69
|
+
# Add one month to the current date
|
|
70
|
+
next_date = current_date + timedelta(days=32)
|
|
71
|
+
|
|
72
|
+
# Get the year and month of the next date
|
|
73
|
+
next_year = next_date.year
|
|
74
|
+
next_month = next_date.month
|
|
75
|
+
|
|
76
|
+
# Format the year and month as 'YYYY-MM'
|
|
77
|
+
next_month_str = f"{next_year}-{next_month:02d}"
|
|
78
|
+
|
|
79
|
+
return next_month_str
|
|
80
|
+
|
|
81
|
+
|
|
82
|
+
def input_desired_year() -> int:
|
|
83
|
+
"""Get the desired year from the user.
|
|
84
|
+
|
|
85
|
+
Returns:
|
|
86
|
+
-------
|
|
87
|
+
desired_year (int): year
|
|
88
|
+
"""
|
|
89
|
+
# Get the desired year from the user
|
|
90
|
+
while True:
|
|
91
|
+
user_input = input("Skriv inn år(åååå): ")
|
|
92
|
+
|
|
93
|
+
try:
|
|
94
|
+
desired_year = int(user_input)
|
|
95
|
+
break # Break the loop if a valid integer is entered
|
|
96
|
+
except ValueError:
|
|
97
|
+
print("Vennligst sett inn gyldig år, som:", 2023)
|
|
98
|
+
|
|
99
|
+
return desired_year
|
|
100
|
+
|
|
101
|
+
|
|
102
|
+
def input_desired_month() -> int:
|
|
103
|
+
"""Get the desired month from the user.
|
|
104
|
+
|
|
105
|
+
Returns:
|
|
106
|
+
-------
|
|
107
|
+
desired_month (int): month
|
|
108
|
+
"""
|
|
109
|
+
# Get the desired month from the user
|
|
110
|
+
while True:
|
|
111
|
+
user_input = input("Skriv inn måned(m): ")
|
|
112
|
+
|
|
113
|
+
try:
|
|
114
|
+
desired_month = int(user_input)
|
|
115
|
+
print("Leter i måned:", desired_month)
|
|
116
|
+
break # Break the loop if a valid integer is entered
|
|
117
|
+
except ValueError:
|
|
118
|
+
print("Vennligst sett inn gyldig måned, som:", 1)
|
|
119
|
+
|
|
120
|
+
return desired_month
|
|
121
|
+
|
|
122
|
+
|
|
123
|
+
def input_desired_term() -> int:
|
|
124
|
+
"""Get the desired term from the user.
|
|
125
|
+
|
|
126
|
+
Returns:
|
|
127
|
+
-------
|
|
128
|
+
desired_term (int): term
|
|
129
|
+
"""
|
|
130
|
+
# Get the desired month from the user
|
|
131
|
+
while True:
|
|
132
|
+
user_input = input("Skriv inn termin(t): ")
|
|
133
|
+
|
|
134
|
+
try:
|
|
135
|
+
desired_term = int(user_input)
|
|
136
|
+
if desired_term < 7:
|
|
137
|
+
print("Leter i termin:", desired_term)
|
|
138
|
+
break # Break the loop if a valid integer is entered
|
|
139
|
+
except ValueError:
|
|
140
|
+
print("Vennligst sett inn gyldig termin, som:", 1)
|
|
141
|
+
|
|
142
|
+
return desired_term
|
|
143
|
+
|
|
144
|
+
|
|
145
|
+
def months_in_term(term: int) -> tuple[int, int]:
|
|
146
|
+
"""Gives out months as ints from term as int.
|
|
147
|
+
|
|
148
|
+
Parameters
|
|
149
|
+
----------
|
|
150
|
+
term (int): term
|
|
151
|
+
|
|
152
|
+
Returns:
|
|
153
|
+
-------
|
|
154
|
+
month_term_dict[term] (tuple[int]): months
|
|
155
|
+
"""
|
|
156
|
+
month_term_dict = {
|
|
157
|
+
1: (1, 2),
|
|
158
|
+
2: (3, 4),
|
|
159
|
+
3: (5, 6),
|
|
160
|
+
4: (7, 8),
|
|
161
|
+
5: (9, 10),
|
|
162
|
+
6: (11, 12),
|
|
163
|
+
}
|
|
164
|
+
|
|
165
|
+
return month_term_dict[term]
|
|
166
|
+
|
|
167
|
+
|
|
168
|
+
def find_file_for_month_daily(
|
|
169
|
+
files: list[str], desired_year: int, desired_month: int
|
|
170
|
+
) -> str:
|
|
171
|
+
"""Function to retrieve spesific file str for period form list of file strings.
|
|
172
|
+
|
|
173
|
+
Parameters
|
|
174
|
+
----------
|
|
175
|
+
files (list[str]): List of file strings.
|
|
176
|
+
desired_year (int): Int to represent year(yyyy).
|
|
177
|
+
desired_month (int): Int to represent a month(m).
|
|
178
|
+
|
|
179
|
+
Returns:
|
|
180
|
+
-------
|
|
181
|
+
file (str): Filename on linux, Filepath on dapla
|
|
182
|
+
"""
|
|
183
|
+
for file in files:
|
|
184
|
+
if (
|
|
185
|
+
extract_start_end_dates(file)[0].year == desired_year
|
|
186
|
+
and extract_start_end_dates(file)[1].year == desired_year
|
|
187
|
+
and extract_start_end_dates(file)[0].month == desired_month
|
|
188
|
+
and extract_start_end_dates(file)[1].month == desired_month
|
|
189
|
+
):
|
|
190
|
+
break
|
|
191
|
+
return file
|
|
File without changes
|