-
Notifications
You must be signed in to change notification settings - Fork 14
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Add new QL endpoints of /v2/attr and /v2/attr/{attr_name} #16
Changes from 1 commit
d4f096a
59a2133
d2c2e90
c61a712
4707d31
5dae2ce
d9efbd5
acaa9ec
c05d5bd
7336e2b
b5ef5d7
8b2e6e2
8d9fe36
c62691f
dbe2509
2ce8ed6
4b74ad9
8943b12
26f0468
e62bb34
8b21edf
a263c55
62717d5
02e75c5
d606818
0a447f7
dfd6fcd
84e2cfa
897467c
20ec709
12789a0
6155f43
7e7456d
e74c382
c89bba2
56dbd45
5a97e4f
05acabc
a559c26
065f4c5
417d44c
7dacccf
0f97542
a9a38ac
c3635f6
3acda05
5506aab
c38c161
b6c1d76
46b645c
31cc39e
2ba624f
74bf0e5
2902081
4ba3441
3a47f75
4b58a6b
a7b9fd0
e874769
1f0e7aa
41e7349
4851bf2
0d4f3a6
f7efab5
d0ed358
de8445a
13e87df
8b07137
1380b37
5b41ad7
1f03a38
8a58574
d4dd719
ffd4966
66de989
48223ca
7dd685e
65c23f9
14b1bb0
424da3f
260943d
30674f6
98cdfcc
68765e0
1fc3c23
ef6b9c4
6ff93b1
e7d6328
821cf56
17214fd
635efd6
e4c8d0c
989894d
3316713
f78f1cb
ce4d2e4
5cb1408
463ab68
e5b7acd
1d3f591
75ffae9
863ecc5
681ffad
6a02bd1
231c0f7
d3bf32b
c230956
d39778f
05718f5
34ffafd
4d16b24
50205bc
c2fa9cf
b61e121
842e572
c528db0
8f4a9a5
8a49915
f1c334f
4d888fa
cfba646
96d84a5
a0a85b2
6e3a560
e2a6010
2cd1c8a
a1fb109
29c33f0
9d3280e
59b9c51
74cf079
0525af1
9700087
052ae36
529a89a
eb3702e
78e9ad1
b910989
f8eac32
6e61821
eb961be
32dd24a
a5ef21c
fed0dc3
f21b8c0
e9194a9
602c060
e4bfc59
70112a6
93e1665
b9acf77
0d4d85c
8da64a8
4adc011
31acf8e
6acfb62
9fa47d8
ae4c818
cc9a2c2
00ea4e0
8416c70
17901f6
5fe9468
0a610a5
e029962
3e89d81
cf1659c
92f2580
6c8a33f
339a8f8
c6afcef
ebd3caa
3bd8e2f
838b28f
17186e6
01b6a90
777b717
fd92497
b994891
2c0c456
98cfced
3f4c881
bbd073e
0097b17
eac5243
c388e2f
0d60af0
3f9c6bc
ccfdd51
eeea1f0
31ad393
668548d
005b7ba
7034f1a
77b96aa
3b286ef
84c5cf9
8e27c6e
0cfc7d4
e25c864
c54c9ef
882de62
f854572
68d5d6f
e55dfe0
49278e5
d457f3d
bad7f87
58037ee
ecf11c8
6f47368
4f331ef
d2e228d
5e46ea4
9a2c3b4
a6e1e91
b173b53
23f8dad
fbc7187
3dff267
bc26f9e
481fe94
4e4b00e
95bfee5
7c1fbdf
c3261ed
bbcbd4e
8317608
8560bd0
d2614e0
ddac69d
6f20580
1737977
00e7d5d
8a9a747
3f816e9
2162d59
fb18d6b
80eaa74
44a7059
41d63ba
ea33441
265a365
1dc4ed9
d083cbc
f7bc70a
7e2b998
cb67a91
e2db8dc
e50f00f
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -16,7 +16,10 @@ | |
AggrScope, \ | ||
AttributeValues, \ | ||
TimeSeries, \ | ||
TimeSeriesHeader | ||
TimeSeriesHeader, \ | ||
TimeSeriesAttrHeader, \ | ||
TimeSeriesEntities, \ | ||
EntityValues | ||
|
||
|
||
logger = logging.getLogger(__name__) | ||
|
@@ -907,3 +910,105 @@ def get_entity_attr_values_by_type(self, | |
AttributeValues(attrName=attr_name, | ||
values=item.get('values'))]) | ||
for item in res.get('values')] | ||
|
||
# v2/attrs | ||
def get_entity_by_attrs(self, *, | ||
entity_type: str = None, | ||
from_date: str = None, | ||
to_date: str = None, | ||
limit: int = None, | ||
offset: int = None | ||
) -> List[TimeSeriesAttrHeader]: | ||
""" | ||
Get list of timeseries data grouped by each existing attribute name. | ||
The timeseries data include all entities corresponding to each | ||
attribute name as well as the index and values of this attribute in | ||
this entity. | ||
|
||
Args: | ||
entity_type (str): Comma-separated list of entity types whose data | ||
are to be included in the response. Use only one (no comma) | ||
when required. If used to resolve ambiguity for the given | ||
entityId, make sure the given entityId exists for this | ||
entityType. | ||
from_date (str): The starting date and time (inclusive) from which | ||
the context information is queried. Must be in ISO8601 format | ||
(e.g., 2018-01-05T15:44:34) | ||
to_date (str): The final date and time (inclusive) from which the | ||
context information is queried. Must be in ISO8601 format | ||
(e.g., 2018-01-05T15:44:34). | ||
limit (int): Maximum number of results to be retrieved. | ||
Default value : 10000 | ||
offset (int): Offset for the results. | ||
|
||
Returns: | ||
List of TimeSeriesEntities | ||
""" | ||
url = urljoin(self.base_url, 'v2/attrs') | ||
res = self.__query_builder(url=url, | ||
entity_type=entity_type, | ||
from_date=from_date, | ||
to_date=to_date, | ||
limit=limit, | ||
offset=offset) | ||
return [TimeSeriesAttrHeader( | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. actually everything should somehow a TimeSeries Object in the very end |
||
attrName=attr_item.get('attrName'), | ||
types=[TimeSeriesEntities( | ||
entityType=entities_item.get('entityType'), | ||
entities=[EntityValues( | ||
entityId=entity.get('entityId'), | ||
index=entity.get('index'), | ||
values=entity.get('values')) | ||
for entity in entities_item.get('entities')]) | ||
for entities_item in attr_item.get('types')]) | ||
for attr_item in res.get('attrs')] | ||
|
||
# v2/attrs/{attr_name} | ||
def get_entity_by_attr_name(self, *, | ||
attr_name: str, | ||
entity_type: str = None, | ||
from_date: str = None, | ||
to_date: str = None, | ||
limit: int = None, | ||
offset: int = None | ||
) -> List[TimeSeriesEntities]: | ||
""" | ||
Get list of all entities containing this attribute name, as well as | ||
getting the index and values of this attribute in every corresponding | ||
entity. | ||
|
||
Args: | ||
attr_name (str): The attribute name in interest. | ||
entity_type (str): Comma-separated list of entity types whose data | ||
are to be included in the response. Use only one (no comma) | ||
when required. If used to resolve ambiguity for the given | ||
entityId, make sure the given entityId exists for this | ||
entityType. | ||
from_date (str): The starting date and time (inclusive) from which | ||
the context information is queried. Must be in ISO8601 format | ||
(e.g., 2018-01-05T15:44:34) | ||
to_date (str): The final date and time (inclusive) from which the | ||
context information is queried. Must be in ISO8601 format | ||
(e.g., 2018-01-05T15:44:34). | ||
limit (int): Maximum number of results to be retrieved. | ||
Default value : 10000 | ||
offset (int): Offset for the results. | ||
|
||
Returns: | ||
List of TimeSeriesEntities | ||
""" | ||
url = urljoin(self.base_url, f'/v2/attrs/{attr_name}') | ||
res = self.__query_builder(url=url, | ||
entity_type=entity_type, | ||
from_date=from_date, | ||
to_date=to_date, | ||
limit=limit, | ||
offset=offset) | ||
return [TimeSeriesEntities( | ||
entityType=entities_item.get('entityType'), | ||
entities=[EntityValues( | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. is there a possibility to use itertools.product here instead of nested for-loops? |
||
entityId=entity.get('entityId'), | ||
index=entity.get('index'), | ||
values=entity.get('values')) | ||
for entity in entities_item.get('entities')]) | ||
for entities_item in res.get('types')] |
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -109,6 +109,46 @@ class Config: | |
allow_population_by_field_name = True | ||
|
||
|
||
class TimeSeriesAttrHeader(BaseModel): | ||
""" | ||
Model for timeseries data grouped by attribute names | ||
""" | ||
attrName: str = Field( | ||
title="Attribute name", | ||
description="" | ||
) | ||
types: List[Any] = Field( | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. according to the docs there is model used for the types. .. Please reconsider how you use the models. The field type containes a list of entities and the a entityType { |
||
default=None, | ||
description="Array of entities grouped by each entityType." | ||
) | ||
|
||
class TimeSeriesEntities(BaseModel): | ||
""" | ||
Model for entities grouped by entityType | ||
""" | ||
entityType: str = Field(default=None, | ||
alias="entityType", | ||
description="The type of an entity") | ||
entities: List[Any] = Field( | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Aren't the entities a list of something? I think here the same applies |
||
default=None, | ||
description="Array of entities." | ||
) | ||
|
||
|
||
class EntityValues(TimeSeriesBase, IndexedValues): | ||
""" | ||
Model of indexed attribute values with entityId | ||
""" | ||
entityId: str = Field(default=None, | ||
alias="entityId", | ||
description="The entity id the time series api." | ||
"If the id is unique among all entity " | ||
"types, this could be used to uniquely " | ||
"identify the entity instance. Otherwise," | ||
" you will have to use the entityType " | ||
"attribute to resolve ambiguity.") | ||
|
||
|
||
class AggrMethod(str, Enum): | ||
""" | ||
Aggregation Methods | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
check if you can use itertools instead of nested forloops