-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathconfig.py
More file actions
60 lines (50 loc) · 1.73 KB
/
config.py
File metadata and controls
60 lines (50 loc) · 1.73 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
"""Configuration module for Graphomotor."""
import dataclasses
import logging
import warnings
import numpy as np
@dataclasses.dataclass(frozen=True)
class SpiralConfig:
"""Class for the parameters of anticipated spiral drawing."""
center_x: float = 50
center_y: float = 50
start_radius: float = 0
growth_rate: float = 1.075
start_angle: float = 0
end_angle: float = 8 * np.pi
num_points: int = 10000
@classmethod
def add_custom_params(cls, config_dict: dict[str, float | int]) -> "SpiralConfig":
"""Update the SpiralConfig instance with custom parameters.
Args:
config_dict: Dictionary with configuration parameters.
Returns:
SpiralConfig instance with updated parameters.
"""
config = cls()
for key, value in config_dict.items():
if hasattr(config, key):
setattr(config, key, value)
else:
valid_params = ", ".join(
f.name for f in cls.__dataclass_fields__.values()
)
warnings.warn(
f"Unknown configuration parameters will be ignored: {key}. "
f"Valid parameters are: {valid_params}"
)
return config
def get_logger() -> logging.Logger:
"""Get the Graphomotor logger."""
logger = logging.getLogger("graphomotor")
if logger.handlers:
return logger
logger.setLevel(logging.INFO)
formatter = logging.Formatter(
"%(asctime)s - %(name)s - %(levelname)s - "
"%(filename)s:%(lineno)s - %(funcName)s - %(message)s",
)
handler = logging.StreamHandler()
handler.setFormatter(formatter)
logger.addHandler(handler)
return logger