pydasa 0.4.7__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.
- pydasa/__init__.py +103 -0
- pydasa/_version.py +6 -0
- pydasa/analysis/__init__.py +0 -0
- pydasa/analysis/scenario.py +584 -0
- pydasa/analysis/simulation.py +1158 -0
- pydasa/context/__init__.py +0 -0
- pydasa/context/conversion.py +11 -0
- pydasa/context/system.py +17 -0
- pydasa/context/units.py +15 -0
- pydasa/core/__init__.py +15 -0
- pydasa/core/basic.py +287 -0
- pydasa/core/cfg/default.json +136 -0
- pydasa/core/constants.py +27 -0
- pydasa/core/io.py +102 -0
- pydasa/core/setup.py +269 -0
- pydasa/dimensional/__init__.py +0 -0
- pydasa/dimensional/buckingham.py +728 -0
- pydasa/dimensional/fundamental.py +146 -0
- pydasa/dimensional/model.py +1077 -0
- pydasa/dimensional/vaschy.py +633 -0
- pydasa/elements/__init__.py +19 -0
- pydasa/elements/parameter.py +218 -0
- pydasa/elements/specs/__init__.py +22 -0
- pydasa/elements/specs/conceptual.py +161 -0
- pydasa/elements/specs/numerical.py +469 -0
- pydasa/elements/specs/statistical.py +229 -0
- pydasa/elements/specs/symbolic.py +394 -0
- pydasa/serialization/__init__.py +27 -0
- pydasa/serialization/parser.py +133 -0
- pydasa/structs/__init__.py +0 -0
- pydasa/structs/lists/__init__.py +0 -0
- pydasa/structs/lists/arlt.py +578 -0
- pydasa/structs/lists/dllt.py +18 -0
- pydasa/structs/lists/ndlt.py +262 -0
- pydasa/structs/lists/sllt.py +746 -0
- pydasa/structs/tables/__init__.py +0 -0
- pydasa/structs/tables/htme.py +182 -0
- pydasa/structs/tables/scht.py +774 -0
- pydasa/structs/tools/__init__.py +0 -0
- pydasa/structs/tools/hashing.py +53 -0
- pydasa/structs/tools/math.py +149 -0
- pydasa/structs/tools/memory.py +54 -0
- pydasa/structs/types/__init__.py +0 -0
- pydasa/structs/types/functions.py +131 -0
- pydasa/structs/types/generics.py +54 -0
- pydasa/validations/__init__.py +0 -0
- pydasa/validations/decorators.py +510 -0
- pydasa/validations/error.py +100 -0
- pydasa/validations/patterns.py +32 -0
- pydasa/workflows/__init__.py +1 -0
- pydasa/workflows/influence.py +497 -0
- pydasa/workflows/phenomena.py +529 -0
- pydasa/workflows/practical.py +765 -0
- pydasa-0.4.7.dist-info/METADATA +320 -0
- pydasa-0.4.7.dist-info/RECORD +58 -0
- pydasa-0.4.7.dist-info/WHEEL +5 -0
- pydasa-0.4.7.dist-info/licenses/LICENSE +674 -0
- pydasa-0.4.7.dist-info/top_level.txt +1 -0
|
File without changes
|
|
@@ -0,0 +1,182 @@
|
|
|
1
|
+
# -*- coding: utf-8 -*-
|
|
2
|
+
"""
|
|
3
|
+
Module htme.py
|
|
4
|
+
===========================================
|
|
5
|
+
|
|
6
|
+
Module to represent the **MapEntry** data structure for the **Hash Table** in *PyDASA*.
|
|
7
|
+
|
|
8
|
+
classes:
|
|
9
|
+
**MapEntry**: Represents a key-value pair in a hash table with type validation and error handling.
|
|
10
|
+
|
|
11
|
+
*IMPORTANT:* based on the implementations proposed by the following authors/books:
|
|
12
|
+
|
|
13
|
+
# . Algorithms, 4th Edition, Robert Sedgewick and Kevin Wayne.
|
|
14
|
+
# . Data Structure and Algorithms in Python, M.T. Goodrich, R. Tamassia, M.H. Goldwasser.
|
|
15
|
+
"""
|
|
16
|
+
|
|
17
|
+
# native python modules
|
|
18
|
+
# dataclass imports
|
|
19
|
+
from dataclasses import dataclass
|
|
20
|
+
# data type imports
|
|
21
|
+
from typing import Generic, Optional
|
|
22
|
+
# code inspection imports
|
|
23
|
+
import inspect
|
|
24
|
+
|
|
25
|
+
# custom modules
|
|
26
|
+
# generic types and global variables
|
|
27
|
+
from pydasa.structs.types.generics import T
|
|
28
|
+
# generic error handling and type checking
|
|
29
|
+
from pydasa.validations.error import handle_error as error
|
|
30
|
+
|
|
31
|
+
# checking custom modules
|
|
32
|
+
assert T
|
|
33
|
+
assert error
|
|
34
|
+
|
|
35
|
+
|
|
36
|
+
@dataclass
|
|
37
|
+
class MapEntry(Generic[T]):
|
|
38
|
+
"""**MapEntry** class for creating a map entry in the **Hash Table**. Fundamental for the **Hash Table** data structure.
|
|
39
|
+
|
|
40
|
+
Args:
|
|
41
|
+
Generic (T): Generic type for a Python data structure.
|
|
42
|
+
|
|
43
|
+
Returns:
|
|
44
|
+
MapEntry: A map entry object with the following attributes:
|
|
45
|
+
- `_key`: The key of the map entry.
|
|
46
|
+
- `_value`: The value of the map entry.
|
|
47
|
+
"""
|
|
48
|
+
|
|
49
|
+
# optional key of any type
|
|
50
|
+
# :attr: _key
|
|
51
|
+
_key: Optional[T] = None
|
|
52
|
+
"""
|
|
53
|
+
Es la llave del registro del mapa.
|
|
54
|
+
"""
|
|
55
|
+
# optional value of any type
|
|
56
|
+
# _value
|
|
57
|
+
_value: Optional[T] = None
|
|
58
|
+
"""
|
|
59
|
+
Es el valor del registro del mapa.
|
|
60
|
+
"""
|
|
61
|
+
|
|
62
|
+
def _error_handler(self, err: Exception) -> None:
|
|
63
|
+
"""*_error_handler()* to process the context (package/class), function name (method), and the error (exception) that was raised to format a detailed error message and traceback.
|
|
64
|
+
|
|
65
|
+
Args:
|
|
66
|
+
err (Exception): Python raised exception.
|
|
67
|
+
"""
|
|
68
|
+
_context = self.__class__.__name__
|
|
69
|
+
_function_name = "unknown"
|
|
70
|
+
frame = inspect.currentframe()
|
|
71
|
+
if frame is not None:
|
|
72
|
+
if frame.f_back is not None:
|
|
73
|
+
_function_name = frame.f_back.f_code.co_name
|
|
74
|
+
else:
|
|
75
|
+
_function_name = "unknown"
|
|
76
|
+
error(_context, _function_name, err)
|
|
77
|
+
|
|
78
|
+
def _validate_key_type(self, key: T) -> bool:
|
|
79
|
+
"""*_validate_key_type()* checks if the type of the key is the same as the type of the *MapEntry*.
|
|
80
|
+
|
|
81
|
+
Args:
|
|
82
|
+
key (T):_key to process in the *MapEntry*.
|
|
83
|
+
|
|
84
|
+
Raises:
|
|
85
|
+
TypeError: error if the type of the key to be added is not the same as the type of the keys already contained in the *MapEntry*.
|
|
86
|
+
|
|
87
|
+
Returns:
|
|
88
|
+
bool: True if the type of the key is the same as the type of the *MapEntry*.
|
|
89
|
+
"""
|
|
90
|
+
if not isinstance(key, type(self._key)):
|
|
91
|
+
_msg = f"Invalid data type: {type(self._key)} "
|
|
92
|
+
_msg += f"for key data: {type(key)}"
|
|
93
|
+
raise TypeError(_msg)
|
|
94
|
+
return True
|
|
95
|
+
|
|
96
|
+
def _validate_value_type(self, value: T) -> bool:
|
|
97
|
+
"""*_validate_value_type()* checks if the type of the value is the same as the type of the *MapEntry*.
|
|
98
|
+
|
|
99
|
+
Args:
|
|
100
|
+
value (T): value to process in the *MapEntry*.
|
|
101
|
+
|
|
102
|
+
Raises:
|
|
103
|
+
TypeError: error if the type of the value to be added is not the same as the type of the values already contained in the *MapEntry*.
|
|
104
|
+
|
|
105
|
+
Returns:
|
|
106
|
+
bool: True if the type of the value is the same as the type of the *MapEntry*.
|
|
107
|
+
"""
|
|
108
|
+
if not isinstance(value, type(self._value)):
|
|
109
|
+
_msg = f"Invalid data type: {type(self._value)} "
|
|
110
|
+
_msg += f"for value data: {type(value)}"
|
|
111
|
+
raise TypeError(_msg)
|
|
112
|
+
return True
|
|
113
|
+
|
|
114
|
+
@property
|
|
115
|
+
def key(self) -> Optional[T]:
|
|
116
|
+
"""*key* Property to read the key in the *MapEntry*. Acts as a getter (*get()*) for the *_key* attribute.
|
|
117
|
+
|
|
118
|
+
Returns:
|
|
119
|
+
Optional[T]: recovered key in the *MapEntry*. None if the key is not set.
|
|
120
|
+
"""
|
|
121
|
+
return self._key
|
|
122
|
+
|
|
123
|
+
@key.setter
|
|
124
|
+
def key(self, key: T) -> None:
|
|
125
|
+
"""*key* Property to write the key in the *MapEntry*. Acts as a setter (*set()*) for the *_key* attribute.
|
|
126
|
+
Args:
|
|
127
|
+
key (T): key set in the *MapEntry*.
|
|
128
|
+
"""
|
|
129
|
+
# check already set key type
|
|
130
|
+
if self._key is not None and self._validate_key_type(key):
|
|
131
|
+
self._key = key
|
|
132
|
+
|
|
133
|
+
@property
|
|
134
|
+
def value(self) -> Optional[T]:
|
|
135
|
+
"""*value* Property to read the value in the *MapEntry*. Acts as a getter (*get()*) for the *_value* attribute.
|
|
136
|
+
|
|
137
|
+
Returns:
|
|
138
|
+
Optional[T]: recovered value in the *MapEntry*. None if the value is not set.
|
|
139
|
+
"""
|
|
140
|
+
return self._value
|
|
141
|
+
|
|
142
|
+
@value.setter
|
|
143
|
+
def value(self, value: T) -> None:
|
|
144
|
+
"""*value* Property to write the value in the *MapEntry*. Acts as a setter (*set()*) for the *_value* attribute.
|
|
145
|
+
|
|
146
|
+
Args:
|
|
147
|
+
value (T): value to be set in the *MapEntry*.
|
|
148
|
+
Raises:
|
|
149
|
+
"""
|
|
150
|
+
# check already set value type
|
|
151
|
+
if self._value is not None and self._validate_value_type(value):
|
|
152
|
+
self._value = value
|
|
153
|
+
|
|
154
|
+
def __str__(self) -> str:
|
|
155
|
+
"""*__str__()* function to return a string representation of the *MapEntry*.
|
|
156
|
+
|
|
157
|
+
Returns:
|
|
158
|
+
str: string representation of the *MapEntry*.
|
|
159
|
+
"""
|
|
160
|
+
_attr_lt = []
|
|
161
|
+
for attr, value in vars(self).items():
|
|
162
|
+
# Skip private attributes starting with "__"
|
|
163
|
+
if attr.startswith("__"):
|
|
164
|
+
continue
|
|
165
|
+
# Format callable attributes
|
|
166
|
+
if callable(value):
|
|
167
|
+
value = f"{value.__name__}{inspect.signature(value)}"
|
|
168
|
+
# Format attribute name and value
|
|
169
|
+
_attr_name = attr.lstrip("_")
|
|
170
|
+
_attr_lt.append(f"{_attr_name}={str(value)}")
|
|
171
|
+
|
|
172
|
+
# Format the string representation of MapEntry class and its attributes
|
|
173
|
+
_str = f"{self.__class__.__name__}({', '.join(_attr_lt)})"
|
|
174
|
+
return _str
|
|
175
|
+
|
|
176
|
+
def __repr__(self) -> str:
|
|
177
|
+
"""*__repr__()* function to return a string representation of the *MapEntry*.
|
|
178
|
+
|
|
179
|
+
Returns:
|
|
180
|
+
str: string representation of the *MapEntry*.
|
|
181
|
+
"""
|
|
182
|
+
return self.__str__()
|