Add constants.py and its test

Task: MIL-001#3
This commit is contained in:
2026-10-13 15:26:20 +08:00
parent 3db6634b15
commit a44339927c
4 changed files with 114 additions and 0 deletions
+14
View File
@@ -0,0 +1,14 @@
## @package weather
# @brief Reading CSV weather data, from Udemy's 100 Days of Code (day 25).
#
# @mainpage Weather Data
#
# The day-25 lectures read the weather data of one week from the file
# weather_data.csv: first with Python's built-in csv library, then with the
# pandas library, which makes the same work a one-liner. The package keeps the
# two ways side by side: csv_reader.py uses the standard library only, and
# analysis.py and export.py need the optional pandas extra.
#
# The constants of the package are in constants.py.
"""Reading CSV weather data, from Udemy's 100 Days of Code (day 25)."""
+48
View File
@@ -0,0 +1,48 @@
## @file constants.py
# @brief Constants of the weather data project.
#
# Every value that the day-25 lectures fix lives here, so that no other module
# contains a magic string or number: the name of the data file, the names of
# its columns, the factors of the Fahrenheit conversion and the name of the
# exported file.
"""Constants of the weather data project, as fixed by the day-25 lectures."""
from pathlib import Path
from typing import Final
## @brief Folder of this package; the data file lies next to the modules.
PACKAGE_DIR: Final[Path] = Path(__file__).resolve().parent
## @brief Name of the weather data file of the lecture.
DATA_FILE_NAME: Final[str] = "weather_data.csv"
## @brief Full path of the weather data file, independent of the working folder.
DATA_FILE: Final[Path] = PACKAGE_DIR / DATA_FILE_NAME
## @brief Name of the file that the exported table is written to by default.
EXPORT_FILE_NAME: Final[str] = "new_data.csv"
## @brief Encoding of the CSV files that are read and written.
FILE_ENCODING: Final[str] = "utf-8"
## @brief Name of the column that holds the day of the week.
COLUMN_DAY: Final[str] = "day"
## @brief Name of the column that holds the temperature in degrees Celsius.
COLUMN_TEMP: Final[str] = "temp"
## @brief Name of the column that holds the weather condition, such as `Sunny`.
COLUMN_CONDITION: Final[str] = "condition"
## @brief Position of the temperature in a row that `csv.reader` returns.
TEMP_COLUMN_INDEX: Final[int] = 1
## @brief Numerator of the Celsius to Fahrenheit factor: `temp * 9 / 5 + 32`.
FAHRENHEIT_NUMERATOR: Final[int] = 9
## @brief Denominator of the Celsius to Fahrenheit factor: `temp * 9 / 5 + 32`.
FAHRENHEIT_DENOMINATOR: Final[int] = 5
## @brief Offset of the Celsius to Fahrenheit conversion: `temp * 9 / 5 + 32`.
FAHRENHEIT_OFFSET: Final[int] = 32