Skip to main content

Befolkning Fagfunksjoner

Project description

Befolkning Fagfunksjoner

PyPI Status Python Version License

Documentation Tests Coverage Quality Gate Status

pre-commit Black Ruff Poetry

Collection of python functions used in statistics production in the Division for Population Statistics at Statistics Norway.

Features

  • TODO

Requirements

  • TODO

Installation

poetry add ssb-befolkning-fagfunksjoner

Usage

EventParams

EventParams contains logic for:

  • Prompting and validating parameters for event periods
  • Creating period labels
  • Computing calendar window for the chosen period
  • Exposing event parameters for parameterising SQL queries

Supported period types are:

  • year
  • halfyear (1-2)
  • quarter (1-4)
  • month (1-12)
  • week (ISO week, 1-53)

The class can be constructed with explicit arguments in code:

from ssb_befolkning_fagfunksjoner import EventParams

# Example: March 2024, with default wait period (1 month, 0 days)
params = EventParams(
    year=2024,
    period_type="month",
    period_number=3,
    specify_wait_period=False,  # default; can be omitted
)

If input arguments are omitted, the user will be prompted:

  • year: prompts for an integer between 1900 and current year
  • period_type: prompts for a valid period type
    • Accepts both full names ("quarter", "month", etc.) and single-letter abbreviations ("q", "m", etc.)
  • period_number: prompted only when needed, with appropriate range checks (e.g. 1-12 for months)
from ssb_befolkning_fagfunksjoner import EventParams

# Will ask the user for missing values in the terminal
params = EventParams()

Once the class is constructed, get the period label as follows:

# Example: March 2024, with default wait period
period_label = params.period_label
# "p2024-03"

Get the start and end dates of the period using the window property:

# Example: March 2024, with default wait period
start_date, end_date = params.window
# datetime.date(2024, 3, 1), datetime.date(2024, 3, 31)

Get a dict used for parameterising SQL-queries:

sql_param = params.to_query_params()
# {
#   "start_date": datetime.date(2024, 3, 1),
#   "end_date": datetime.date(2024, 3, 31),
#   "etterslep_start": datetime.date(2024, 4, 1),
#   "etterslep_end": datetime.date(2024, 4, 30)
# }

Demographics

KLASS utils

Kommnr

Contributing

Contributions are very welcome. To learn more, see the Contributor Guide.

License

Distributed under the terms of the MIT license, Befolkning Fagfunksjoner is free and open source software.

Issues

If you encounter any problems, please file an issue along with a detailed description.

Credits

This project was generated from Statistics Norway's SSB PyPI Template.

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

ssb_befolkning_fagfunksjoner-0.1.3.tar.gz (21.0 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

ssb_befolkning_fagfunksjoner-0.1.3-py3-none-any.whl (24.4 kB view details)

Uploaded Python 3

File details

Details for the file ssb_befolkning_fagfunksjoner-0.1.3.tar.gz.

File metadata

File hashes

Hashes for ssb_befolkning_fagfunksjoner-0.1.3.tar.gz
Algorithm Hash digest
SHA256 5bdb3e2d4c9fd0f530c06a5992104fb1f49d8ebf5c45daf99e0b0dbd2b7dccf4
MD5 d705ab30064796852c8128884f9ba473
BLAKE2b-256 587ae311463bdb1f2d38b6968e70d8c9ea4d9d2a39fb769aa2651519ccfa4fde

See more details on using hashes here.

Provenance

The following attestation bundles were made for ssb_befolkning_fagfunksjoner-0.1.3.tar.gz:

Publisher: release.yml on statisticsnorway/ssb-befolkning-fagfunksjoner

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

File details

Details for the file ssb_befolkning_fagfunksjoner-0.1.3-py3-none-any.whl.

File metadata

File hashes

Hashes for ssb_befolkning_fagfunksjoner-0.1.3-py3-none-any.whl
Algorithm Hash digest
SHA256 f20043904f1f99c4adc97d5d69ada9ec72a1b3636858173b86c8454a047e11e1
MD5 e9fad012ba7c19a248b9e951a1518b51
BLAKE2b-256 781a60d3ca823db8dcc9687f8fc2368ac5466ca5452f26e1783bec58b4156c57

See more details on using hashes here.

Provenance

The following attestation bundles were made for ssb_befolkning_fagfunksjoner-0.1.3-py3-none-any.whl:

Publisher: release.yml on statisticsnorway/ssb-befolkning-fagfunksjoner

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page