pythermodb-settings 0.1.1__py3-none-any.whl → 0.1.2__py3-none-any.whl
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.
- pythermodb_settings/configs/about.py +1 -1
- pythermodb_settings/models/__init__.py +2 -1
- pythermodb_settings/models/components.py +21 -0
- pythermodb_settings/utils/__init__.py +7 -0
- pythermodb_settings/utils/component_utils.py +107 -0
- {pythermodb_settings-0.1.1.dist-info → pythermodb_settings-0.1.2.dist-info}/METADATA +1 -1
- {pythermodb_settings-0.1.1.dist-info → pythermodb_settings-0.1.2.dist-info}/RECORD +10 -8
- {pythermodb_settings-0.1.1.dist-info → pythermodb_settings-0.1.2.dist-info}/WHEEL +0 -0
- {pythermodb_settings-0.1.1.dist-info → pythermodb_settings-0.1.2.dist-info}/licenses/LICENSE +0 -0
- {pythermodb_settings-0.1.1.dist-info → pythermodb_settings-0.1.2.dist-info}/top_level.txt +0 -0
@@ -1,5 +1,5 @@
|
|
1
1
|
# NOTE: app info
|
2
|
-
__version__ = "0.1.
|
2
|
+
__version__ = "0.1.2"
|
3
3
|
__description__ = """PyThermoDB Settings is a Python package that acts as an interface between pythermdb and other applications, providing robust, Pydantic-based data models and configuration structures for managing thermodynamic database (ThermoDB) settings."""
|
4
4
|
__author__ = "Sina Gilassi"
|
5
5
|
__author_email__ = "sina.gilassi@gmail.com"
|
@@ -1,5 +1,5 @@
|
|
1
1
|
# export
|
2
|
-
from .components import Component
|
2
|
+
from .components import Component, ComponentIdentity
|
3
3
|
from .conditions import Temperature, Pressure
|
4
4
|
from .configs import ComponentConfig
|
5
5
|
from .references import (
|
@@ -13,6 +13,7 @@ from .source import ComponentThermoDBSource
|
|
13
13
|
|
14
14
|
__all__ = [
|
15
15
|
"Component",
|
16
|
+
"ComponentIdentity",
|
16
17
|
"Temperature",
|
17
18
|
"Pressure",
|
18
19
|
"ComponentConfig",
|
@@ -39,3 +39,24 @@ class Component(BaseModel):
|
|
39
39
|
arbitrary_types_allowed=True,
|
40
40
|
extra="allow"
|
41
41
|
)
|
42
|
+
|
43
|
+
|
44
|
+
class ComponentIdentity(BaseModel):
|
45
|
+
"""
|
46
|
+
Model for component identity.
|
47
|
+
|
48
|
+
Attributes
|
49
|
+
----------
|
50
|
+
name_state : str
|
51
|
+
Component name-state identifier.
|
52
|
+
formula_state : str
|
53
|
+
Component formula-state identifier.
|
54
|
+
"""
|
55
|
+
name_state: str = Field(
|
56
|
+
...,
|
57
|
+
description="Component name-state identifier"
|
58
|
+
)
|
59
|
+
formula_state: str = Field(
|
60
|
+
...,
|
61
|
+
description="Component formula-state identifier"
|
62
|
+
)
|
@@ -0,0 +1,107 @@
|
|
1
|
+
# import libs
|
2
|
+
import logging
|
3
|
+
from typing import Literal
|
4
|
+
from pythermodb_settings.models import Component
|
5
|
+
# local
|
6
|
+
from ..models import ComponentIdentity
|
7
|
+
|
8
|
+
# NOTE: logger
|
9
|
+
logger = logging.getLogger(__name__)
|
10
|
+
|
11
|
+
|
12
|
+
def create_component_id(
|
13
|
+
component: Component,
|
14
|
+
separator_symbol: str = '-'
|
15
|
+
) -> ComponentIdentity:
|
16
|
+
'''
|
17
|
+
Create component name-state and formula-state identifiers.
|
18
|
+
|
19
|
+
Parameters
|
20
|
+
----------
|
21
|
+
component : Component
|
22
|
+
The component for which to create the identifiers.
|
23
|
+
separator_symbol : str, optional
|
24
|
+
The symbol to use as a separator between the name/formula and
|
25
|
+
|
26
|
+
Returns
|
27
|
+
-------
|
28
|
+
ComponentIdentity
|
29
|
+
The component identity containing name-state and formula-state
|
30
|
+
identifiers.
|
31
|
+
'''
|
32
|
+
try:
|
33
|
+
# NOTE: extract component name
|
34
|
+
component_name = component.name.strip()
|
35
|
+
component_formula = component.formula.strip()
|
36
|
+
component_state = component.state.strip().lower()
|
37
|
+
|
38
|
+
# >> separator
|
39
|
+
separator_symbol = separator_symbol.strip()
|
40
|
+
|
41
|
+
# SECTION: create component identifiers
|
42
|
+
name_state = f"{component_name}{separator_symbol}{component_state}"
|
43
|
+
formula_state = f"{component_formula}{separator_symbol}{component_state}"
|
44
|
+
|
45
|
+
return ComponentIdentity(
|
46
|
+
name_state=name_state,
|
47
|
+
formula_state=formula_state
|
48
|
+
)
|
49
|
+
except Exception as e:
|
50
|
+
logger.error(
|
51
|
+
f"Failed to create component identifiers for "
|
52
|
+
f"'{component}': {e}"
|
53
|
+
)
|
54
|
+
raise e
|
55
|
+
|
56
|
+
|
57
|
+
def set_component_id(
|
58
|
+
component: Component,
|
59
|
+
component_key: Literal[
|
60
|
+
'Name-State', 'Formula-State'
|
61
|
+
],
|
62
|
+
separator_symbol: str = '-',
|
63
|
+
) -> str:
|
64
|
+
'''
|
65
|
+
Set component identifier based on the specified key.
|
66
|
+
|
67
|
+
Parameters
|
68
|
+
----------
|
69
|
+
component : Component
|
70
|
+
The component for which to set the identifier.
|
71
|
+
component_key : str
|
72
|
+
The key to determine which identifier to use.
|
73
|
+
Options are:
|
74
|
+
- 'Name-State': Use the name-state identifier.
|
75
|
+
- 'Formula-State': Use the formula-state identifier.
|
76
|
+
separator_symbol : str, optional
|
77
|
+
The symbol to use as a separator between the name/formula and state.
|
78
|
+
Default is '-'.
|
79
|
+
|
80
|
+
Returns
|
81
|
+
-------
|
82
|
+
str
|
83
|
+
The component identifier based on the specified key.
|
84
|
+
'''
|
85
|
+
try:
|
86
|
+
# NOTE: create component id
|
87
|
+
component_idx: ComponentIdentity = create_component_id(
|
88
|
+
component=component,
|
89
|
+
separator_symbol=separator_symbol
|
90
|
+
)
|
91
|
+
|
92
|
+
# set component id
|
93
|
+
if component_key == "Name-State":
|
94
|
+
return component_idx.name_state
|
95
|
+
elif component_key == "Formula-State":
|
96
|
+
return component_idx.formula_state
|
97
|
+
else:
|
98
|
+
raise ValueError(
|
99
|
+
f"Invalid component_key '{component_key}'. "
|
100
|
+
f"Must be 'Name-State' or 'Formula-State'."
|
101
|
+
)
|
102
|
+
except Exception as e:
|
103
|
+
logger.error(
|
104
|
+
f"Failed to set component identifier for "
|
105
|
+
f"'{component}': {e}"
|
106
|
+
)
|
107
|
+
raise e
|
@@ -1,16 +1,18 @@
|
|
1
1
|
pythermodb_settings/__init__.py,sha256=VzJSYgJJNw_j5NmnIbq0pJhBd_9Kp-bbfOsRLepplSw,229
|
2
2
|
pythermodb_settings/app.py,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
|
3
3
|
pythermodb_settings/configs/__init__.py,sha256=QR38PBCzgoFwYqcViR9bFT2YIR5m9s7q8C7cV4fZjz4,211
|
4
|
-
pythermodb_settings/configs/about.py,sha256=
|
5
|
-
pythermodb_settings/models/__init__.py,sha256=
|
6
|
-
pythermodb_settings/models/components.py,sha256=
|
4
|
+
pythermodb_settings/configs/about.py,sha256=vOAWpWG2BtmC2n4vqLEpLmZeytlYxk4WMGk0CQhMbXA,379
|
5
|
+
pythermodb_settings/models/__init__.py,sha256=N0zptTFnWTNEcQQ00WFXXF5i3Xxq_zjbpSdIyhGRu7g,649
|
6
|
+
pythermodb_settings/models/components.py,sha256=4CwZcGpbm1PiEBQUpEmo6T6mP4y3S3LIiHCM0y9C7XU,1674
|
7
7
|
pythermodb_settings/models/conditions.py,sha256=Zm5JcM2kyMlS6b8hPbs6awa_6ps3xFoCVA4zwNPc5eg,1083
|
8
8
|
pythermodb_settings/models/configs.py,sha256=57nXShSbtiVo9fP2OFIbzRqS87oT4ITRLYJi_bp5cFI,674
|
9
9
|
pythermodb_settings/models/references.py,sha256=_MicXRkUdmZLMiuQEhMm2kJzmApHvz_CnjLaxxnueLg,5399
|
10
10
|
pythermodb_settings/models/rules.py,sha256=1a9CyTHwpQkZQXFJWDMrEcKQAOTOwquepoOQPGznTlc,74
|
11
11
|
pythermodb_settings/models/source.py,sha256=liN4v1o8mqxclz8khca4anTOzLHO-5gCnK0MsfVgxGY,533
|
12
|
-
pythermodb_settings
|
13
|
-
pythermodb_settings
|
14
|
-
pythermodb_settings-0.1.
|
15
|
-
pythermodb_settings-0.1.
|
16
|
-
pythermodb_settings-0.1.
|
12
|
+
pythermodb_settings/utils/__init__.py,sha256=Vc3UjM42beWALBoqNV6Vx71ofC2CjYNxUUvFgR44lvk,148
|
13
|
+
pythermodb_settings/utils/component_utils.py,sha256=uL-_WWl8Wat1LEFMpodmQe1BklzY7yI8enguWYeSWwo,3196
|
14
|
+
pythermodb_settings-0.1.2.dist-info/licenses/LICENSE,sha256=pHRAx3wjVKpt2ec3NyhntY6_bGgJqV2SyE8xNUJ7MYE,1090
|
15
|
+
pythermodb_settings-0.1.2.dist-info/METADATA,sha256=SDi6-9y2tSUaG6d2azVYan79R_767aGA009AU-nMwt0,4894
|
16
|
+
pythermodb_settings-0.1.2.dist-info/WHEEL,sha256=_zCd3N1l69ArxyTb8rzEoP9TpbYXkqRFSNOD5OuxnTs,91
|
17
|
+
pythermodb_settings-0.1.2.dist-info/top_level.txt,sha256=6IdVIbW__wHFsKQYx7DDnXArm10qiJVIyaoSEFQylK4,20
|
18
|
+
pythermodb_settings-0.1.2.dist-info/RECORD,,
|
File without changes
|
{pythermodb_settings-0.1.1.dist-info → pythermodb_settings-0.1.2.dist-info}/licenses/LICENSE
RENAMED
File without changes
|
File without changes
|