py10x-universe 0.1.3__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.
- core_10x/__init__.py +42 -0
- core_10x/backbone/__init__.py +0 -0
- core_10x/backbone/backbone_store.py +59 -0
- core_10x/backbone/backbone_traitable.py +30 -0
- core_10x/backbone/backbone_user.py +66 -0
- core_10x/backbone/bound_data_domain.py +49 -0
- core_10x/backbone/namespace.py +101 -0
- core_10x/backbone/vault.py +38 -0
- core_10x/code_samples/__init__.py +0 -0
- core_10x/code_samples/_package_manifest.py +3 -0
- core_10x/code_samples/directories.py +181 -0
- core_10x/code_samples/person.py +76 -0
- core_10x/concrete_traits.py +356 -0
- core_10x/conftest.py +12 -0
- core_10x/curve.py +321 -0
- core_10x/data_domain.py +48 -0
- core_10x/data_domain_binder.py +45 -0
- core_10x/directory.py +250 -0
- core_10x/entity.py +8 -0
- core_10x/entity_filter.py +5 -0
- core_10x/environment_variables.py +147 -0
- core_10x/exec_control.py +84 -0
- core_10x/experimental/__init__.py +0 -0
- core_10x/experimental/data_protocol_ex.py +34 -0
- core_10x/global_cache.py +121 -0
- core_10x/manual_tests/__init__.py +0 -0
- core_10x/manual_tests/calendar_test.py +35 -0
- core_10x/manual_tests/ctor_update_bug.py +58 -0
- core_10x/manual_tests/debug_graph_on.py +17 -0
- core_10x/manual_tests/debug_graphoff_inside_graph_on.py +28 -0
- core_10x/manual_tests/enum_bits_test.py +17 -0
- core_10x/manual_tests/env_vars_trivial_test.py +12 -0
- core_10x/manual_tests/existing_traitable.py +33 -0
- core_10x/manual_tests/k10x_test1.py +13 -0
- core_10x/manual_tests/named_constant_test.py +121 -0
- core_10x/manual_tests/nucleus_trivial_test.py +42 -0
- core_10x/manual_tests/polars_test.py +14 -0
- core_10x/manual_tests/py_class_test.py +4 -0
- core_10x/manual_tests/rc_test.py +42 -0
- core_10x/manual_tests/rdate_test.py +12 -0
- core_10x/manual_tests/reference_serialization_bug.py +19 -0
- core_10x/manual_tests/resource_trivial_test.py +10 -0
- core_10x/manual_tests/store_uri_test.py +6 -0
- core_10x/manual_tests/trait_definition_test.py +19 -0
- core_10x/manual_tests/trait_filter_test.py +15 -0
- core_10x/manual_tests/trait_flag_modification_test.py +42 -0
- core_10x/manual_tests/trait_modification_bug.py +26 -0
- core_10x/manual_tests/traitable_as_of_test.py +82 -0
- core_10x/manual_tests/traitable_heir_test.py +39 -0
- core_10x/manual_tests/traitable_history_test.py +41 -0
- core_10x/manual_tests/traitable_serialization_test.py +54 -0
- core_10x/manual_tests/traitable_trivial_test.py +71 -0
- core_10x/manual_tests/trivial_graph_test.py +16 -0
- core_10x/manual_tests/ts_class_association_test.py +64 -0
- core_10x/manual_tests/ts_trivial_test.py +35 -0
- core_10x/named_constant.py +425 -0
- core_10x/nucleus.py +81 -0
- core_10x/package_manifest.py +85 -0
- core_10x/package_refactoring.py +153 -0
- core_10x/py_class.py +431 -0
- core_10x/rc.py +155 -0
- core_10x/rdate.py +339 -0
- core_10x/resource.py +189 -0
- core_10x/roman_number.py +67 -0
- core_10x/testlib/__init__.py +0 -0
- core_10x/testlib/test_store.py +240 -0
- core_10x/testlib/traitable_history_tests.py +787 -0
- core_10x/testlib/ts_tests.py +280 -0
- core_10x/trait.py +377 -0
- core_10x/trait_definition.py +176 -0
- core_10x/trait_filter.py +205 -0
- core_10x/trait_method_error.py +36 -0
- core_10x/traitable.py +1082 -0
- core_10x/traitable_cli.py +153 -0
- core_10x/traitable_heir.py +33 -0
- core_10x/traitable_id.py +31 -0
- core_10x/ts_store.py +172 -0
- core_10x/ts_store_type.py +26 -0
- core_10x/ts_union.py +147 -0
- core_10x/ui_hint.py +153 -0
- core_10x/unit_tests/test_concrete_traits.py +156 -0
- core_10x/unit_tests/test_converters.py +51 -0
- core_10x/unit_tests/test_curve.py +157 -0
- core_10x/unit_tests/test_directory.py +54 -0
- core_10x/unit_tests/test_documentation.py +172 -0
- core_10x/unit_tests/test_environment_variables.py +15 -0
- core_10x/unit_tests/test_filters.py +239 -0
- core_10x/unit_tests/test_graph.py +348 -0
- core_10x/unit_tests/test_named_constant.py +98 -0
- core_10x/unit_tests/test_rc.py +11 -0
- core_10x/unit_tests/test_rdate.py +484 -0
- core_10x/unit_tests/test_trait_method_error.py +80 -0
- core_10x/unit_tests/test_trait_modification.py +19 -0
- core_10x/unit_tests/test_traitable.py +959 -0
- core_10x/unit_tests/test_traitable_history.py +1 -0
- core_10x/unit_tests/test_ts_store.py +1 -0
- core_10x/unit_tests/test_ts_union.py +369 -0
- core_10x/unit_tests/test_ui_nodes.py +81 -0
- core_10x/unit_tests/test_xxcalendar.py +471 -0
- core_10x/vault/__init__.py +0 -0
- core_10x/vault/sec_keys.py +133 -0
- core_10x/vault/security_keys_old.py +168 -0
- core_10x/vault/vault.py +56 -0
- core_10x/vault/vault_traitable.py +56 -0
- core_10x/vault/vault_user.py +70 -0
- core_10x/xdate_time.py +136 -0
- core_10x/xnone.py +71 -0
- core_10x/xxcalendar.py +228 -0
- infra_10x/__init__.py +0 -0
- infra_10x/manual_tests/__init__.py +0 -0
- infra_10x/manual_tests/test_misc.py +16 -0
- infra_10x/manual_tests/test_prepare_filter_and_pipeline.py +25 -0
- infra_10x/mongodb_admin.py +111 -0
- infra_10x/mongodb_store.py +346 -0
- infra_10x/mongodb_utils.py +129 -0
- infra_10x/unit_tests/conftest.py +13 -0
- infra_10x/unit_tests/test_mongo_db.py +36 -0
- infra_10x/unit_tests/test_mongo_history.py +1 -0
- py10x_universe-0.1.3.dist-info/METADATA +406 -0
- py10x_universe-0.1.3.dist-info/RECORD +214 -0
- py10x_universe-0.1.3.dist-info/WHEEL +4 -0
- py10x_universe-0.1.3.dist-info/licenses/LICENSE +21 -0
- ui_10x/__init__.py +0 -0
- ui_10x/apps/__init__.py +0 -0
- ui_10x/apps/collection_editor_app.py +100 -0
- ui_10x/choice.py +212 -0
- ui_10x/collection_editor.py +135 -0
- ui_10x/concrete_trait_widgets.py +220 -0
- ui_10x/conftest.py +8 -0
- ui_10x/entity_stocker.py +173 -0
- ui_10x/examples/__init__.py +0 -0
- ui_10x/examples/_guess_word_data.py +14076 -0
- ui_10x/examples/collection_editor.py +17 -0
- ui_10x/examples/date_selector.py +14 -0
- ui_10x/examples/entity_stocker.py +18 -0
- ui_10x/examples/guess_word.py +392 -0
- ui_10x/examples/message_box.py +20 -0
- ui_10x/examples/multi_choice.py +17 -0
- ui_10x/examples/py_data_browser.py +66 -0
- ui_10x/examples/radiobox.py +29 -0
- ui_10x/examples/single_choice.py +31 -0
- ui_10x/examples/style_sheet.py +47 -0
- ui_10x/examples/trivial_entity_editor.py +18 -0
- ui_10x/platform.py +20 -0
- ui_10x/platform_interface.py +517 -0
- ui_10x/py_data_browser.py +249 -0
- ui_10x/qt6/__init__.py +0 -0
- ui_10x/qt6/conftest.py +8 -0
- ui_10x/qt6/manual_tests/__init__.py +0 -0
- ui_10x/qt6/manual_tests/basic_test.py +35 -0
- ui_10x/qt6/platform_implementation.py +275 -0
- ui_10x/qt6/utils.py +665 -0
- ui_10x/rio/__init__.py +0 -0
- ui_10x/rio/apps/examples/examples/__init__.py +22 -0
- ui_10x/rio/apps/examples/examples/components/__init__.py +3 -0
- ui_10x/rio/apps/examples/examples/components/collection_editor.py +15 -0
- ui_10x/rio/apps/examples/examples/pages/collection_editor.py +21 -0
- ui_10x/rio/apps/examples/examples/pages/login_page.py +88 -0
- ui_10x/rio/apps/examples/examples/pages/style_sheet.py +21 -0
- ui_10x/rio/apps/examples/rio.toml +14 -0
- ui_10x/rio/component_builder.py +497 -0
- ui_10x/rio/components/__init__.py +9 -0
- ui_10x/rio/components/group_box.py +31 -0
- ui_10x/rio/components/labeled_checkbox.py +18 -0
- ui_10x/rio/components/line_edit.py +37 -0
- ui_10x/rio/components/radio_button.py +32 -0
- ui_10x/rio/components/separator.py +24 -0
- ui_10x/rio/components/splitter.py +121 -0
- ui_10x/rio/components/tree_view.py +75 -0
- ui_10x/rio/conftest.py +35 -0
- ui_10x/rio/internals/__init__.py +0 -0
- ui_10x/rio/internals/app.py +192 -0
- ui_10x/rio/manual_tests/__init__.py +0 -0
- ui_10x/rio/manual_tests/basic_test.py +24 -0
- ui_10x/rio/manual_tests/splitter.py +27 -0
- ui_10x/rio/platform_implementation.py +91 -0
- ui_10x/rio/style_sheet.py +53 -0
- ui_10x/rio/unit_tests/test_collection_editor.py +68 -0
- ui_10x/rio/unit_tests/test_internals.py +630 -0
- ui_10x/rio/unit_tests/test_style_sheet.py +37 -0
- ui_10x/rio/widgets/__init__.py +46 -0
- ui_10x/rio/widgets/application.py +109 -0
- ui_10x/rio/widgets/button.py +48 -0
- ui_10x/rio/widgets/button_group.py +60 -0
- ui_10x/rio/widgets/calendar.py +23 -0
- ui_10x/rio/widgets/checkbox.py +24 -0
- ui_10x/rio/widgets/dialog.py +137 -0
- ui_10x/rio/widgets/group_box.py +27 -0
- ui_10x/rio/widgets/layout.py +34 -0
- ui_10x/rio/widgets/line_edit.py +37 -0
- ui_10x/rio/widgets/list.py +105 -0
- ui_10x/rio/widgets/message_box.py +70 -0
- ui_10x/rio/widgets/scroll_area.py +31 -0
- ui_10x/rio/widgets/spacer.py +6 -0
- ui_10x/rio/widgets/splitter.py +45 -0
- ui_10x/rio/widgets/text_edit.py +28 -0
- ui_10x/rio/widgets/tree.py +89 -0
- ui_10x/rio/widgets/unit_tests/test_button.py +101 -0
- ui_10x/rio/widgets/unit_tests/test_button_group.py +33 -0
- ui_10x/rio/widgets/unit_tests/test_calendar.py +114 -0
- ui_10x/rio/widgets/unit_tests/test_checkbox.py +109 -0
- ui_10x/rio/widgets/unit_tests/test_group_box.py +158 -0
- ui_10x/rio/widgets/unit_tests/test_label.py +43 -0
- ui_10x/rio/widgets/unit_tests/test_line_edit.py +140 -0
- ui_10x/rio/widgets/unit_tests/test_list.py +146 -0
- ui_10x/table_header_view.py +305 -0
- ui_10x/table_view.py +174 -0
- ui_10x/trait_editor.py +189 -0
- ui_10x/trait_widget.py +131 -0
- ui_10x/traitable_editor.py +200 -0
- ui_10x/traitable_view.py +131 -0
- ui_10x/unit_tests/conftest.py +8 -0
- ui_10x/unit_tests/test_platform.py +9 -0
- ui_10x/utils.py +661 -0
core_10x/global_cache.py
ADDED
|
@@ -0,0 +1,121 @@
|
|
|
1
|
+
import inspect
|
|
2
|
+
|
|
3
|
+
from core_10x.xnone import XNone
|
|
4
|
+
|
|
5
|
+
# ===================================================================================================================================
|
|
6
|
+
# @cache must be used to cache results of function calls globally (at the process level)
|
|
7
|
+
#
|
|
8
|
+
# Notes:
|
|
9
|
+
#
|
|
10
|
+
# - non-hashable args are NOT supported for performance reasons
|
|
11
|
+
# - args MUST follow the declaration order for performance reasons (otherwise, the same result may be cached multiple times
|
|
12
|
+
# e.g. f(a=1, b=2) and f(b=2, a=1)
|
|
13
|
+
# - the most common 'users' are class methods
|
|
14
|
+
# ===================================================================================================================================
|
|
15
|
+
ARGS_KWARGS = (inspect.Parameter.VAR_POSITIONAL, inspect.Parameter.VAR_KEYWORD)
|
|
16
|
+
|
|
17
|
+
|
|
18
|
+
def cache(f):
|
|
19
|
+
sig = inspect.signature(f)
|
|
20
|
+
params = sig.parameters
|
|
21
|
+
num_args = len(params)
|
|
22
|
+
if num_args == 0:
|
|
23
|
+
return _cache_no_args(f)
|
|
24
|
+
|
|
25
|
+
if num_args == 1:
|
|
26
|
+
for param in params.values():
|
|
27
|
+
if param.kind not in ARGS_KWARGS and param.default is inspect.Parameter.empty:
|
|
28
|
+
return _cache_single_arg(f)
|
|
29
|
+
|
|
30
|
+
return _cache_with_args(f)
|
|
31
|
+
|
|
32
|
+
|
|
33
|
+
def _cache_no_args(f):
|
|
34
|
+
the_value = [XNone]
|
|
35
|
+
|
|
36
|
+
def getter():
|
|
37
|
+
v = the_value[0]
|
|
38
|
+
if v is XNone:
|
|
39
|
+
the_value[0] = v = f()
|
|
40
|
+
return v
|
|
41
|
+
|
|
42
|
+
def clear():
|
|
43
|
+
the_value[0] = XNone
|
|
44
|
+
|
|
45
|
+
getter.__name__ = f.__name__
|
|
46
|
+
getter.value = the_value
|
|
47
|
+
getter.clear = clear
|
|
48
|
+
return getter
|
|
49
|
+
|
|
50
|
+
|
|
51
|
+
def _cache_single_arg(f):
|
|
52
|
+
the_cache = {}
|
|
53
|
+
|
|
54
|
+
def getter(arg):
|
|
55
|
+
value = the_cache.get(arg, the_cache) # -- will throw if arg is not hashable!
|
|
56
|
+
if value is the_cache: # -- i.e., arg is seen for the first time
|
|
57
|
+
value = f(arg)
|
|
58
|
+
the_cache[arg] = value
|
|
59
|
+
|
|
60
|
+
return value
|
|
61
|
+
|
|
62
|
+
getter.__name__ = f.__name__
|
|
63
|
+
getter.cache = the_cache
|
|
64
|
+
getter.clear = lambda: the_cache.clear()
|
|
65
|
+
return getter
|
|
66
|
+
|
|
67
|
+
|
|
68
|
+
def _cache_with_args(f):
|
|
69
|
+
the_cache = {}
|
|
70
|
+
|
|
71
|
+
def getter(*args, **kwargs):
|
|
72
|
+
key = *args, *tuple(kwargs.items())
|
|
73
|
+
value = the_cache.get(key, the_cache) # -- will throw if key is not hashable!
|
|
74
|
+
if value is the_cache: # -- i.e., key is seen for the first time
|
|
75
|
+
value = f(*args, **kwargs)
|
|
76
|
+
the_cache[key] = value
|
|
77
|
+
|
|
78
|
+
return value
|
|
79
|
+
|
|
80
|
+
getter.__name__ = f.__name__
|
|
81
|
+
getter.cache = the_cache
|
|
82
|
+
getter.clear = lambda: the_cache.clear()
|
|
83
|
+
return getter
|
|
84
|
+
|
|
85
|
+
|
|
86
|
+
def standard_key(args: tuple, kwargs: dict) -> tuple:
|
|
87
|
+
sorted_kwargs = tuple((k, kwargs[k]) for k in sorted(kwargs))
|
|
88
|
+
return *args, *sorted_kwargs
|
|
89
|
+
|
|
90
|
+
|
|
91
|
+
# ========= The singleton
|
|
92
|
+
|
|
93
|
+
|
|
94
|
+
def ___operator_new(cls, *args, **kwargs):
|
|
95
|
+
key = standard_key((cls, *args), kwargs)
|
|
96
|
+
ptr = cls.___instances.get(key)
|
|
97
|
+
if not ptr:
|
|
98
|
+
ptr = object.__new__(cls)
|
|
99
|
+
cls.___ctor(ptr, *args, **kwargs)
|
|
100
|
+
cls.___instances[key] = ptr
|
|
101
|
+
return ptr
|
|
102
|
+
|
|
103
|
+
|
|
104
|
+
def ___operator_reset(cls):
|
|
105
|
+
cls.___instances = {}
|
|
106
|
+
|
|
107
|
+
|
|
108
|
+
def singleton(cls):
|
|
109
|
+
cls.___instances = {}
|
|
110
|
+
cls.__new__ = ___operator_new
|
|
111
|
+
cls.___ctor = cls.__init__
|
|
112
|
+
cls.__init__ = lambda self, *args, **kwargs: None
|
|
113
|
+
cls._reset_singleton = lambda: ___operator_reset(cls)
|
|
114
|
+
return cls
|
|
115
|
+
|
|
116
|
+
|
|
117
|
+
# def hash_key( obj ) -> int:
|
|
118
|
+
# try:
|
|
119
|
+
# return hash( obj )
|
|
120
|
+
# except Exception:
|
|
121
|
+
# return hash(str(obj))
|
|
File without changes
|
|
@@ -0,0 +1,35 @@
|
|
|
1
|
+
if __name__ == '__main__':
|
|
2
|
+
|
|
3
|
+
from datetime import date
|
|
4
|
+
|
|
5
|
+
from core_10x.xxcalendar import Calendar, CalendarAdjustment
|
|
6
|
+
|
|
7
|
+
us_c = Calendar(_replace = True,
|
|
8
|
+
name = 'US',
|
|
9
|
+
non_working_days = [
|
|
10
|
+
date(2025,1,1), date(2025,1,20), date(2025,2,17), date(2025,5,26), date(2025,7,4),
|
|
11
|
+
date(2025,9,1), date(2025,10,13), date(2025,11,11), date(2025,11,27), date(2025,12, 25)
|
|
12
|
+
]
|
|
13
|
+
)
|
|
14
|
+
|
|
15
|
+
uk_c = Calendar(_replace = True,
|
|
16
|
+
name = 'UK',
|
|
17
|
+
non_working_days = [
|
|
18
|
+
date(2025,1,1), date(2025,4,18), date(2025,5,5), date(2025,5,26), date(2025,8,25),
|
|
19
|
+
date(2025,12, 25), date(2025,12, 26)
|
|
20
|
+
]
|
|
21
|
+
)
|
|
22
|
+
|
|
23
|
+
c = Calendar.union('US', 'UK')
|
|
24
|
+
union_nwds = c.non_working_days
|
|
25
|
+
|
|
26
|
+
c2 = Calendar.intersection('US', 'UK')
|
|
27
|
+
cross_nwds = c2.non_working_days
|
|
28
|
+
|
|
29
|
+
sofr_adjust = CalendarAdjustment(_replace = True,
|
|
30
|
+
name = 'SOFR',
|
|
31
|
+
add_days = [date(2019, 4, 4)]
|
|
32
|
+
)
|
|
33
|
+
|
|
34
|
+
ca = Calendar(name = 'US', adjusted_for = 'SOFR')
|
|
35
|
+
nwds_ca = ca.non_working_days
|
|
@@ -0,0 +1,58 @@
|
|
|
1
|
+
from core_10x.traitable import RC, RC_TRUE, RT, T, Traitable
|
|
2
|
+
|
|
3
|
+
|
|
4
|
+
class Cross(Traitable):
|
|
5
|
+
cross: str = RT(T.ID) // 'e.g., GBP/USD or CHF/JPY'
|
|
6
|
+
|
|
7
|
+
base_ccy: str = RT(T.ID_LIKE) // 'Base (left) currency'
|
|
8
|
+
quote_ccy: str = RT(T.ID_LIKE) // 'Quote (right) currency'
|
|
9
|
+
|
|
10
|
+
def cross_get(self) -> str:
|
|
11
|
+
return f'{self.base_ccy}/{self.quote_ccy}'
|
|
12
|
+
|
|
13
|
+
def cross_set(self, trait, cross: str) -> RC:
|
|
14
|
+
parts = cross.split('/')
|
|
15
|
+
assert len(parts) == 2
|
|
16
|
+
c1, c2 = parts
|
|
17
|
+
rc1 = self.set_value('base_ccy', c1)
|
|
18
|
+
rc2 = self.set_value('quote_ccy', c2)
|
|
19
|
+
if rc1 and rc2:
|
|
20
|
+
return RC_TRUE
|
|
21
|
+
rc = RC(True)
|
|
22
|
+
rc <<= rc1
|
|
23
|
+
rc <<= rc2
|
|
24
|
+
return rc
|
|
25
|
+
|
|
26
|
+
|
|
27
|
+
if __name__ == '__main__':
|
|
28
|
+
cross = 'A/B'
|
|
29
|
+
|
|
30
|
+
# -- Does not complain that non-ID traits can't be set during initialization.
|
|
31
|
+
# -- Note the T.ID_LIKE declaration!
|
|
32
|
+
c1 = Cross(base_ccy='A', quote_ccy='B')
|
|
33
|
+
|
|
34
|
+
# -- Apparently, after setting base_ccy and quote_ccy, the cross is correct, but the id is wrong!
|
|
35
|
+
# -- This is also fixed by the T.ID_LIKE declaration!
|
|
36
|
+
c2 = Cross(_replace=True, base_ccy='A', quote_ccy='B')
|
|
37
|
+
assert c2.id().value == 'A/B'
|
|
38
|
+
|
|
39
|
+
# #-- Case 1 - doesn't allow to create the second instance claiming it sets non-ID traits
|
|
40
|
+
# c1 = Cross(cross = cross)
|
|
41
|
+
# try:
|
|
42
|
+
# c2 = Cross(cross = cross)
|
|
43
|
+
# except Exception as e:
|
|
44
|
+
# print(e)
|
|
45
|
+
#
|
|
46
|
+
# #-- Case 2 - update is "working" exactly as the ctor
|
|
47
|
+
# try:
|
|
48
|
+
# c3 = Cross.update(cross = cross)
|
|
49
|
+
# except Exception as e:
|
|
50
|
+
# print(e)
|
|
51
|
+
#
|
|
52
|
+
# #-- Case 3: update complains about not setting at least one ID-trait - WRONG!
|
|
53
|
+
# try:
|
|
54
|
+
# c4 = Cross.update(base_ccy = 'A', quote_ccy = 'B')
|
|
55
|
+
# except Exception as e:
|
|
56
|
+
# print(e)
|
|
57
|
+
#
|
|
58
|
+
# #-- Case 4:
|
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
from datetime import date
|
|
2
|
+
|
|
3
|
+
from infra_10x.mongodb_store import MongoStore
|
|
4
|
+
|
|
5
|
+
from core_10x.code_samples.person import Person
|
|
6
|
+
from core_10x.exec_control import GRAPH_ON
|
|
7
|
+
|
|
8
|
+
if __name__ == '__main__':
|
|
9
|
+
|
|
10
|
+
with MongoStore.instance(hostname ='localhost', dbname='test', username='', password=''):
|
|
11
|
+
p = Person(first_name = 'Ilya', last_name = 'Pevzner')
|
|
12
|
+
p.dob = date(1971,7,1)
|
|
13
|
+
p.save()
|
|
14
|
+
p.dob = date(1971,7,3)
|
|
15
|
+
assert p.dob== date(1971,7,3)
|
|
16
|
+
with GRAPH_ON():
|
|
17
|
+
assert p.dob == date(1971,7,3) # FIX: fails here!
|
|
@@ -0,0 +1,28 @@
|
|
|
1
|
+
from core_10x.code_samples.person import Person
|
|
2
|
+
from core_10x.exec_control import BTP, GRAPH_OFF, GRAPH_ON
|
|
3
|
+
from core_10x.xnone import XNone
|
|
4
|
+
|
|
5
|
+
|
|
6
|
+
def test():
|
|
7
|
+
p = Person(first_name = 'Sasha', last_name = 'Davidovich')
|
|
8
|
+
#p.weight_lbs = 100
|
|
9
|
+
#assert p.weight == 100
|
|
10
|
+
|
|
11
|
+
p.invalidate_value(p.T.weight)
|
|
12
|
+
p.invalidate_value(p.T.weight_lbs)
|
|
13
|
+
|
|
14
|
+
assert p.weight is XNone
|
|
15
|
+
|
|
16
|
+
if __name__ == '__main__':
|
|
17
|
+
|
|
18
|
+
with GRAPH_ON(convert_values = True, debug = True):
|
|
19
|
+
print(BTP.current().flags())
|
|
20
|
+
test()
|
|
21
|
+
with GRAPH_OFF():
|
|
22
|
+
test()
|
|
23
|
+
|
|
24
|
+
p = Person(first_name = 'Sasha', last_name = 'Davidovich')
|
|
25
|
+
with GRAPH_ON(convert_values = True):
|
|
26
|
+
p.weight_lbs = 'a'
|
|
27
|
+
|
|
28
|
+
|
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
from core_10x.named_constant import EnumBits
|
|
2
|
+
|
|
3
|
+
|
|
4
|
+
class STATE(EnumBits):
|
|
5
|
+
RESERVED = ()
|
|
6
|
+
RUNTIME = ()
|
|
7
|
+
ID = ()
|
|
8
|
+
|
|
9
|
+
class XSTATE(STATE):
|
|
10
|
+
EXPENSIVE = ()
|
|
11
|
+
|
|
12
|
+
if __name__ == '__main__':
|
|
13
|
+
r = STATE.RUNTIME | STATE.RESERVED | STATE.ID
|
|
14
|
+
|
|
15
|
+
r2 = r - STATE.RESERVED
|
|
16
|
+
|
|
17
|
+
e = XSTATE.EXPENSIVE
|
|
@@ -0,0 +1,33 @@
|
|
|
1
|
+
if __name__ == '__main__':
|
|
2
|
+
from core_10x.code_samples.person import Person
|
|
3
|
+
|
|
4
|
+
ppl_stored = [
|
|
5
|
+
Person(last_name='Davidovich', first_name='Sasha', weight_lbs=170, _replace=True),
|
|
6
|
+
Person(last_name='Pevzner', first_name='Ilya', weight_lbs=200, _replace=True),
|
|
7
|
+
Person(last_name='Lesin', first_name='Alex', weight_lbs=190, _replace=True),
|
|
8
|
+
Person(last_name='Smith', first_name='John', weight_lbs=180, _replace=True),
|
|
9
|
+
]
|
|
10
|
+
|
|
11
|
+
id_traits = ('last_name', 'first_name')
|
|
12
|
+
existing_id_traits = [{name: p.get_value(name) for name in id_traits} for p in ppl_stored]
|
|
13
|
+
|
|
14
|
+
ppl_found = [Person.existing_instance(**id_values) for id_values in existing_id_traits]
|
|
15
|
+
|
|
16
|
+
assert ppl_found == ppl_stored
|
|
17
|
+
|
|
18
|
+
p1 = Person.existing_instance(last_name='Smith', first_name='John')
|
|
19
|
+
assert p1
|
|
20
|
+
|
|
21
|
+
p2 = Person.existing_instance(last_name='Smith', first_name='Josh', _throw=False)
|
|
22
|
+
assert not p2
|
|
23
|
+
|
|
24
|
+
id1 = ppl_found[0].id()
|
|
25
|
+
p3 = Person.existing_instance_by_id(_id=id1)
|
|
26
|
+
|
|
27
|
+
id1_val = id1.value
|
|
28
|
+
p4 = Person.existing_instance_by_id(_id_value=id1_val)
|
|
29
|
+
assert p3 == p4
|
|
30
|
+
|
|
31
|
+
id2_val = 'Smith|Josh'
|
|
32
|
+
p5 = Person.existing_instance_by_id(_id_value=id2_val, _throw=False)
|
|
33
|
+
assert not p5
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
from py10x_core import NODE_TYPE, BasicNode
|
|
2
|
+
|
|
3
|
+
from core_10x.xnone import XNone # -- keep
|
|
4
|
+
|
|
5
|
+
n1 = BasicNode.create(NODE_TYPE.BASIC_GRAPH)
|
|
6
|
+
n1.assign('whatever')
|
|
7
|
+
|
|
8
|
+
n2 = BasicNode.create(NODE_TYPE.BASIC_GRAPH)
|
|
9
|
+
n2.set(100)
|
|
10
|
+
|
|
11
|
+
n2.add_parent(n1)
|
|
12
|
+
|
|
13
|
+
n2.set('Asya')
|
|
@@ -0,0 +1,121 @@
|
|
|
1
|
+
from __future__ import annotations
|
|
2
|
+
|
|
3
|
+
from math import exp, log
|
|
4
|
+
|
|
5
|
+
from core_10x.named_constant import (
|
|
6
|
+
Enum,
|
|
7
|
+
EnumBits,
|
|
8
|
+
ErrorCode,
|
|
9
|
+
NamedConstant,
|
|
10
|
+
NamedConstantTable,
|
|
11
|
+
NamedConstantValue,
|
|
12
|
+
Nucleus,
|
|
13
|
+
)
|
|
14
|
+
|
|
15
|
+
|
|
16
|
+
class COLOR(NamedConstant, lowercase_values = True):
|
|
17
|
+
RED = ()
|
|
18
|
+
BLUE = ()
|
|
19
|
+
GREEN = ()
|
|
20
|
+
LIGHTGREEN = ()
|
|
21
|
+
|
|
22
|
+
class XCOLOR(COLOR):
|
|
23
|
+
BLACK = ()
|
|
24
|
+
WHITE = ()
|
|
25
|
+
|
|
26
|
+
class WEIGHT(NamedConstant):
|
|
27
|
+
LB = ()
|
|
28
|
+
KG = ()
|
|
29
|
+
CT = ()
|
|
30
|
+
|
|
31
|
+
class COMPOUNDING(NamedConstant):
|
|
32
|
+
SIMPLE = ()
|
|
33
|
+
ANNUAL = ()
|
|
34
|
+
SEMI_ANNUAL = ()
|
|
35
|
+
QUARTERLY = ()
|
|
36
|
+
MONTHLY = ()
|
|
37
|
+
WEEKLY = ()
|
|
38
|
+
CONTINUOUS = ()
|
|
39
|
+
|
|
40
|
+
class COMPOUND_TRANSFORM(NamedConstant):
|
|
41
|
+
RATE_TO_ACCRUAL = ()
|
|
42
|
+
ACCRUAL_TO_RATE = ()
|
|
43
|
+
|
|
44
|
+
|
|
45
|
+
COLOR_WEIGHT = NamedConstantValue(
|
|
46
|
+
COLOR,
|
|
47
|
+
RED = 10,
|
|
48
|
+
BLUE = 20,
|
|
49
|
+
GREEN = 30,
|
|
50
|
+
LIGHTGREEN = 35
|
|
51
|
+
)
|
|
52
|
+
|
|
53
|
+
COLOR_CODE = NamedConstantValue(
|
|
54
|
+
COLOR,
|
|
55
|
+
RED = 1.0,
|
|
56
|
+
BLUE = 11.1,
|
|
57
|
+
GREEN = 12.2,
|
|
58
|
+
LIGHTGREEN = 13.3
|
|
59
|
+
)
|
|
60
|
+
|
|
61
|
+
COMPOUNDING_TRANSFORM_TABLE = NamedConstantTable(COMPOUNDING, COMPOUND_TRANSFORM,
|
|
62
|
+
# RATE_TO_ACCRUAL ACCRUAL_TO_RATE
|
|
63
|
+
SIMPLE = ( lambda t, r: 1. + r * t, lambda t, a: (a - 1.) / t if t else 0. ),
|
|
64
|
+
ANNUAL = ( lambda t, r: (1. + r ) ** t, lambda t, a: a ** (1. / t) - 1. if t else 0. ),
|
|
65
|
+
SEMI_ANNUAL = ( lambda t, r: (1. + r / 2.) ** (t * 2.), lambda t, a: (a ** (1. / t / 2.) - 1.) * 2. if t else 0. ),
|
|
66
|
+
QUARTERLY = ( lambda t, r: (1. + r / 4.) ** (t * 4.), lambda t, a: (a ** (1. / t / 4.) - 1.) * 4. if t else 0. ),
|
|
67
|
+
MONTHLY = ( lambda t, r: (1. + r / 12.) ** (t * 12.), lambda t, a: (a ** (1. / t / 12.) - 1.) * 12. if t else 0. ),
|
|
68
|
+
WEEKLY = ( lambda t, r: (1. + r / 52.) ** (t * 52.), lambda t, a: (a ** (1. / t / 52.) - 1.) * 52. if t else 0. ),
|
|
69
|
+
CONTINUOUS = ( lambda t, r: exp(r * t), lambda t, a: log(a) / t ),
|
|
70
|
+
)
|
|
71
|
+
|
|
72
|
+
class EVEN_NUMBER(Enum, step = 2):
|
|
73
|
+
ZERO = ()
|
|
74
|
+
TWO = ()
|
|
75
|
+
FOUR = ()
|
|
76
|
+
|
|
77
|
+
class A_PROBLEM(ErrorCode):
|
|
78
|
+
DOES_NOT_EXIST = 'Entity {cls}.{id} does not exist'
|
|
79
|
+
REV_CONFLICT = 'Entity {cls}.{id} - revision {rev} is outdated'
|
|
80
|
+
SAVE_FAILED = 'Failed to save entity {cls}.{id}'
|
|
81
|
+
|
|
82
|
+
class ICON(EnumBits):
|
|
83
|
+
FILE = ('material/file',)
|
|
84
|
+
STOP = ('material/stop',)
|
|
85
|
+
|
|
86
|
+
class TEXT_ALIGN(NamedConstant):
|
|
87
|
+
s_vertical = 0xf << 4
|
|
88
|
+
|
|
89
|
+
LEFT = 1
|
|
90
|
+
CENTER = 6
|
|
91
|
+
RIGHT = 11
|
|
92
|
+
TOP = LEFT << 4
|
|
93
|
+
V_CENTER = CENTER << 4
|
|
94
|
+
BOTTOM = RIGHT << 4
|
|
95
|
+
|
|
96
|
+
@classmethod
|
|
97
|
+
def from_str(cls, s: str) -> TEXT_ALIGN:
|
|
98
|
+
return super().from_str(s.upper()) # type: ignore[return-value]
|
|
99
|
+
|
|
100
|
+
def rio_attr(self) -> str:
|
|
101
|
+
return 'align_y' if self.value & self.s_vertical else 'align_x'
|
|
102
|
+
|
|
103
|
+
def rio_value(self) -> float:
|
|
104
|
+
return ((self.value >> 4 if self.value & self.s_vertical else self.value)-1) /10
|
|
105
|
+
|
|
106
|
+
if __name__ == '__main__':
|
|
107
|
+
from core_10x.manual_tests.named_constant_test import COLOR, XCOLOR
|
|
108
|
+
|
|
109
|
+
print( COLOR.LIGHTGREEN.value)
|
|
110
|
+
sgreen = Nucleus.serialize_any(COLOR.GREEN, False)
|
|
111
|
+
swhite = Nucleus.serialize_any(XCOLOR.WHITE, False)
|
|
112
|
+
print(sgreen)
|
|
113
|
+
print(swhite)
|
|
114
|
+
|
|
115
|
+
assert Nucleus.deserialize_dict(swhite) is XCOLOR.WHITE
|
|
116
|
+
#print(COLOR_WEIGHT.GREEN, COLOR_CODE.GREEN) #TODO: FIX!
|
|
117
|
+
|
|
118
|
+
print(A_PROBLEM.REV_CONFLICT(cls = 'XXX', id = '145678', rev = '3'))
|
|
119
|
+
|
|
120
|
+
x,y = TEXT_ALIGN.from_str('left'), TEXT_ALIGN.from_str('v_center')
|
|
121
|
+
print( x, y, x.rio_attr(), y.rio_attr(), x.value, y.value, x.rio_value(), y.rio_value() )
|
|
@@ -0,0 +1,42 @@
|
|
|
1
|
+
if __name__ == '__main__':
|
|
2
|
+
from datetime import date, datetime
|
|
3
|
+
|
|
4
|
+
from core_10x.named_constant import Enum, EnumBits
|
|
5
|
+
from core_10x.nucleus import Nucleus
|
|
6
|
+
|
|
7
|
+
class COLOR(Enum):
|
|
8
|
+
RED = ()
|
|
9
|
+
GREEN = ()
|
|
10
|
+
BLUE = ()
|
|
11
|
+
|
|
12
|
+
class STATE(EnumBits):
|
|
13
|
+
RUNNING = ()
|
|
14
|
+
SUSPENDED = ()
|
|
15
|
+
ABORTED = ()
|
|
16
|
+
|
|
17
|
+
data = {
|
|
18
|
+
bool: False,
|
|
19
|
+
int: 100,
|
|
20
|
+
type(None): None,
|
|
21
|
+
float: 1e-6,
|
|
22
|
+
complex: complex(5.43, -7.1),
|
|
23
|
+
str: 'plain text',
|
|
24
|
+
datetime: datetime.now(),
|
|
25
|
+
date: date.today(),
|
|
26
|
+
list: [ 10, 5.1, 'label', datetime.now(), date(2020, 1, 1), ['a', 100], dict( a = 1, b = 2) ],
|
|
27
|
+
tuple: ( 10, 5.1, 'label', datetime.now(), date(2020, 1, 1), ['a', 100], dict( a = 1, b = 2) ),
|
|
28
|
+
dict: { 1: 1, 'a': 'abc', 'b': [ 10, 100. ], 'c': dict(x = -100, y = -200) },
|
|
29
|
+
COLOR: COLOR.GREEN,
|
|
30
|
+
STATE: STATE.RUNNING | STATE.SUSPENDED
|
|
31
|
+
}
|
|
32
|
+
|
|
33
|
+
serialized_data = { dt: Nucleus.serialize_any(v, False) for dt, v in data.items() }
|
|
34
|
+
deserialized_data = { dt: Nucleus.deserialize_any(v, None) for dt, v in serialized_data.items() }
|
|
35
|
+
|
|
36
|
+
for dt, value in data.items():
|
|
37
|
+
s_value = deserialized_data.get(dt, deserialized_data)
|
|
38
|
+
if s_value is deserialized_data:
|
|
39
|
+
print(f'{dt} is missing')
|
|
40
|
+
else:
|
|
41
|
+
if s_value != value:
|
|
42
|
+
print(f'{dt}:\nexpected\n{value}\ngot\n{s_value}')
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
import polars as pl
|
|
2
|
+
from infra_10x.mongodb_store import MongoStore
|
|
3
|
+
|
|
4
|
+
from core_10x.code_samples.person import Person
|
|
5
|
+
|
|
6
|
+
if __name__=='__main__':
|
|
7
|
+
with MongoStore.instance(hostname ='localhost', dbname='test', username='', password=''):
|
|
8
|
+
objs = Person.load_many()
|
|
9
|
+
df = pl.DataFrame([o.serialize_object() for o in objs])
|
|
10
|
+
print(df)
|
|
11
|
+
df.write_database('people',connection="postgresql:///postgres?host=/tmp",engine='adbc',if_table_exists='replace')
|
|
12
|
+
|
|
13
|
+
df2 = pl.read_database('people',connection="postgresql:///postgres?host=/tmp",engine='adbc')
|
|
14
|
+
print(df2)
|
|
@@ -0,0 +1,42 @@
|
|
|
1
|
+
from core_10x.rc import RC, RC_TRUE, Enum, ErrorCode
|
|
2
|
+
|
|
3
|
+
|
|
4
|
+
class CONDITION(Enum):
|
|
5
|
+
BEGIN = ()
|
|
6
|
+
MAIN = ()
|
|
7
|
+
END = ()
|
|
8
|
+
|
|
9
|
+
class A_PROBLEM(ErrorCode):
|
|
10
|
+
DOES_NOT_EXIST = 'Entity {cls}.{id} does not exist'
|
|
11
|
+
REV_CONFLICT = 'Entity {cls}.{id} - revision {rev} is outdated'
|
|
12
|
+
SAVE_FAILED = 'Failed to save entity {cls}.{id}'
|
|
13
|
+
|
|
14
|
+
rc = RC_TRUE
|
|
15
|
+
print(rc)
|
|
16
|
+
|
|
17
|
+
try:
|
|
18
|
+
rc.add_error('error')
|
|
19
|
+
raise AssertionError('must have thrown')
|
|
20
|
+
except Exception as e:
|
|
21
|
+
print(str(e))
|
|
22
|
+
|
|
23
|
+
rc = RC(CONDITION.MAIN, dict( a = 1, b = 1))
|
|
24
|
+
print(rc)
|
|
25
|
+
|
|
26
|
+
rc.add_data([100, 200])
|
|
27
|
+
print(rc)
|
|
28
|
+
|
|
29
|
+
rc1 = RC(False, 'just an error')
|
|
30
|
+
print(rc1)
|
|
31
|
+
try:
|
|
32
|
+
rc1.throw()
|
|
33
|
+
except Exception as e:
|
|
34
|
+
print(str(e))
|
|
35
|
+
|
|
36
|
+
rc = RC(A_PROBLEM.REV_CONFLICT, dict(cls = 'XXX', id = '123456', rev = 3))
|
|
37
|
+
print(rc)
|
|
38
|
+
|
|
39
|
+
rc = RC(True)
|
|
40
|
+
rc.add_error('First error')
|
|
41
|
+
rc.add_error(rc1)
|
|
42
|
+
print(rc)
|
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
from py10x_core import BTraitableProcessor
|
|
2
|
+
|
|
3
|
+
from core_10x.code_samples.person import Person
|
|
4
|
+
from core_10x.trait_definition import T
|
|
5
|
+
|
|
6
|
+
|
|
7
|
+
class MarriedPerson(Person):
|
|
8
|
+
spouse: Person = T()
|
|
9
|
+
|
|
10
|
+
|
|
11
|
+
if __name__ == '__main__':
|
|
12
|
+
from core_10x.manual_tests.reference_serialization_bug import MarriedPerson
|
|
13
|
+
|
|
14
|
+
with BTraitableProcessor.create_root():
|
|
15
|
+
MarriedPerson(first_name='Ilya', last_name='Pevzner', spouse=MarriedPerson(first_name='Tatiana', last_name='Pevzner'), _replace=True).save(
|
|
16
|
+
save_references=True
|
|
17
|
+
)
|
|
18
|
+
|
|
19
|
+
assert type(MarriedPerson(first_name='Ilya', last_name='Pevzner').spouse) is MarriedPerson
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
import keyring
|
|
2
|
+
|
|
3
|
+
from core_10x.ts_store import TsStore
|
|
4
|
+
|
|
5
|
+
db1 = TsStore.instance_from_uri('mongodb://localhost:27017/mkt_data')
|
|
6
|
+
print(db1.collection_names())
|
|
7
|
+
|
|
8
|
+
user = 'admin'
|
|
9
|
+
db2 = TsStore.instance_from_uri(f'mongodb://{user}:{keyring.get_password("mongodb_local", user)}@localhost:27018/test')
|
|
10
|
+
print(db2.collection_names())
|
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
import inspect
|
|
2
|
+
|
|
3
|
+
from core_10x.trait_definition import T
|
|
4
|
+
|
|
5
|
+
|
|
6
|
+
class X:
|
|
7
|
+
user_id: str = T(T.ID | T.RUNTIME) #, Ui('User ID', tip = 'OS login', min_width = 50))
|
|
8
|
+
age: int = T()
|
|
9
|
+
#model: any = RT()
|
|
10
|
+
|
|
11
|
+
|
|
12
|
+
annotations = inspect.get_annotations(X)
|
|
13
|
+
|
|
14
|
+
#dir = TraitDefinition.dir( X.__dict__, annotations, {} )
|
|
15
|
+
|
|
16
|
+
#tdef: TraitDefinition = dir['user_id']
|
|
17
|
+
|
|
18
|
+
# t = Trait(tdef)
|
|
19
|
+
# t2 = copy.deepcopy(t)
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
from core_10x.code_samples.person import Person
|
|
2
|
+
from core_10x.exec_control import CACHE_ONLY
|
|
3
|
+
from core_10x.trait_filter import BETWEEN, NE, OR, f
|
|
4
|
+
|
|
5
|
+
if __name__ == '__main__':
|
|
6
|
+
with CACHE_ONLY():
|
|
7
|
+
p = Person(first_name = 'Sasha', last_name = 'Davidovich')
|
|
8
|
+
|
|
9
|
+
r = OR(
|
|
10
|
+
f(age=BETWEEN(50, 70), first_name=NE('Sasha')),
|
|
11
|
+
f(age=17)
|
|
12
|
+
)
|
|
13
|
+
|
|
14
|
+
print(r.prefix_notation())
|
|
15
|
+
print(r.eval(p))
|