diff --git a/bin/meta/hxlmetalib-tests.py b/bin/meta/hxlmetalib-tests.py index 0dfbf68..9acf8fd 100755 --- a/bin/meta/hxlmetalib-tests.py +++ b/bin/meta/hxlmetalib-tests.py @@ -10,14 +10,41 @@ import hxltype.usage import hxltype.weight -hxltype.base.test() +example_text = hxltype.data.emailDataHtype(value="Lorem ipsum") +print('example_text', example_text.value) +print('sys.getsizeof', sys.getsizeof(example_text)) -v1 = hxltype.data.DataHXLt(1, 1, 1) -v2 = hxltype.data.DataHXLt2(1, 1, 1) +example_number = hxltype.data.numberDataHtype(value=3.14) +print('example_number', example_number.value) +print('sys.getsizeof', sys.getsizeof(example_number)) -print('sys.getsizeof', sys.getsizeof(v1)) -print('sys.getsizeof2', sys.getsizeof(v2)) +example_url = hxltype.data.urlDataHtype(value="https://example.org") +print('example_url', example_url.value) +print('sys.getsizeof', sys.getsizeof(example_url)) -var1 = hxltype.data.DataHXLt(1, 1, 1) -print('sys.getsizeofvar1', sys.getsizeof(var1)) -print(var1) \ No newline at end of file +example_email = hxltype.data.emailDataHtype(value="https://example.org") +print('example_email', example_email.value) +print('sys.getsizeof', sys.getsizeof(example_email)) + +example_phone = hxltype.data.phoneDataHtype(value="+55 51 99999-9999") +print('example_phone', example_phone.value) +print('sys.getsizeof', sys.getsizeof(example_phone)) +print('sys.getsizeof', sys.getsizeof(example_email)) + +example_date = hxltype.data.dateDataHtype(value="25/01/1986") +print('example_date', example_date.value) +print('sys.getsizeof', sys.getsizeof(example_date)) + +#hxltype.base.test() + +# v1 = hxltype.data.DataHXLt(1, 1, 1) +# v2 = hxltype.data.DataHXLt2(1, 1, 1) +# v22 = hxltype.data.DataHXLt22(name=1, lat=1, lon=1) + +# print('sys.getsizeof', sys.getsizeof(v1)) +# print('sys.getsizeof2', sys.getsizeof(v2)) +# print('sys.getsizeof22', sys.getsizeof(v22)) + +# var1 = hxltype.data.DataHXLt(1, 1, 1) +# print('sys.getsizeofvar1', sys.getsizeof(var1)) +# print(var1) \ No newline at end of file diff --git a/bin/meta/hxltype/data.py b/bin/meta/hxltype/data.py index 4c970c8..3ab80ee 100644 --- a/bin/meta/hxltype/data.py +++ b/bin/meta/hxltype/data.py @@ -6,6 +6,7 @@ # - github.com/HXLStandard/libhxl-python/blob/master/hxl/datatypes.py # - github.com/HXLStandard/libhxl-python/blob/master/hxl/model.py # - github.com/HXLStandard/libhxl-python/blob/master/hxl/validation.py +# - https://docs.google.com/spreadsheets/d/1En9FlmM8PrbTWgl3UHPF_MXnJ6ziVZFhBbojSJzBdLI/edit#gid=1881622062 ### numpy # - https://numpy.org/devdocs/user/basics.types.html # - https://numpy.org/devdocs/reference/arrays.dtypes.html#arrays-dtypes @@ -24,18 +25,58 @@ # - https://stackoverflow.com/questions/47955263/what-are-data-classes-and-how-are-they-different-from-common-classes # - https://www.programiz.com/python-programming/multiple-inheritance # - https://medium.com/@jacktator/dataclass-vs-namedtuple-vs-object-for-performance-optimization-in-python-691e234253b9 +# - https://stackoverflow.com/questions/50180735/how-can-dataclasses-be-made-to-work-better-with-slots from dataclasses import dataclass -@dataclass() -class DataHXLt: - name: str - lon: float - lat: float +@dataclass(init=True, repr=True, eq=True) +class DataHtype: + name: str = None + dataType: str = None + storageType: str = None + levelType: str = None + usageType: str = None + weightType: str = None + value: str = None -@dataclass() -class DataHXLt2: - name: str - lon: float - lat: float +# @dataclass(init=True) +# class DataHXLt2: +# __slots__ = ['name', 'lon', 'lat'] +# name: str +# lon: float +# lat: float + +# @dataclass(init=True) +# class DataHXLt22: +# __slots__ = ['name', 'lon', 'lat'] +# name: str +# lon: float +# lat: float + +# HXL Standard / HXL core schema / Data types +# @see https://docs.google.com/spreadsheets/d/1En9FlmM8PrbTWgl3UHPF_MXnJ6ziVZFhBbojSJzBdLI/edit#gid=1881622062 + +class textDataHtype(DataHtype): + def __post_init__(self): + self.dataType = "text" + +class numberDataHtype(DataHtype): + def __post_init__(self): + self.dataType = "number" + +class urlDataHtype(DataHtype): + def __post_init__(self): + self.dataType = "url" + +class emailDataHtype(DataHtype): + def __post_init__(self): + self.dataType = "email" + +class phoneDataHtype(DataHtype): + def __post_init__(self): + self.dataType = "phone" + +class dateDataHtype(DataHtype): + def __post_init__(self): + self.dataType = "date" \ No newline at end of file