Skip to content

Commit

Permalink
hxlquickmeta (#9): hxltype; added DataHtype, textDataHtype, numberDat…
Browse files Browse the repository at this point in the history
…aHtype, urlDataHtype, emailDataHtype, phoneDataHtype, dateDataHtype
  • Loading branch information
fititnt committed Feb 22, 2021
1 parent e34952a commit 5d12d38
Show file tree
Hide file tree
Showing 2 changed files with 86 additions and 18 deletions.
43 changes: 35 additions & 8 deletions bin/meta/hxlmetalib-tests.py
Original file line number Diff line number Diff line change
Expand Up @@ -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)
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)
61 changes: 51 additions & 10 deletions bin/meta/hxltype/data.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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"

0 comments on commit 5d12d38

Please sign in to comment.